From e917edd939829d916278fcd339b067cb87947af9 Mon Sep 17 00:00:00 2001 From: cryptooda Date: Sat, 11 Oct 2025 13:43:32 +0700 Subject: [PATCH] Add more logs, 95%ram alert for GmxMarkets, Proxy retry 2times max --- src/Managing.Infrastructure.Web3/EvmManager.cs | 10 +++++++++- .../Services/Web3ProxyService.cs | 4 ++-- src/Managing.Web3Proxy/src/plugins/custom/gmx.ts | 9 +++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Managing.Infrastructure.Web3/EvmManager.cs b/src/Managing.Infrastructure.Web3/EvmManager.cs index 5bca3883..77b13fd2 100644 --- a/src/Managing.Infrastructure.Web3/EvmManager.cs +++ b/src/Managing.Infrastructure.Web3/EvmManager.cs @@ -1,5 +1,6 @@ using System.Net.Http.Json; using System.Numerics; +using System.Text.Json; using Managing.Application.Abstractions.Repositories; using Managing.Application.Abstractions.Services; using Managing.Common; @@ -424,6 +425,7 @@ public class EvmManager : IEvmManager { Console.WriteLine( $"Warning: GMX API returned empty candles array for ticker {ticker}, timeframe {timeframe}, startDate {startDate:yyyy-MM-dd HH:mm:ss}"); + return new List(); } @@ -433,6 +435,8 @@ public class EvmManager : IEvmManager { Console.WriteLine( $"Warning: No candles found after filtering for ticker {ticker}, timeframe {timeframe}, startDate {startDate:yyyy-MM-dd HH:mm:ss}. Total candles before filtering: {gmxPrices.Candles.Count}"); + Console.WriteLine(JsonSerializer.Serialize(filteredCandles)); + SentrySdk.CaptureException(new Exception($"No candles found after filtering for ticker {ticker}, timeframe {timeframe}, startDate {startDate:yyyy-MM-dd HH:mm:ss}. Total candles before filtering: {gmxPrices.Candles.Count}")); return new List(); } @@ -548,6 +552,7 @@ public class EvmManager : IEvmManager } catch (Exception ex) { + SentrySdk.CaptureException(ex); return false; } } @@ -735,7 +740,7 @@ public class EvmManager : IEvmManager } catch (Exception e) { - Console.WriteLine(e); + SentrySdk.CaptureException(e); throw; } } @@ -751,6 +756,7 @@ public class EvmManager : IEvmManager } catch (Exception ex) { + SentrySdk.CaptureException(ex); throw; } @@ -777,6 +783,7 @@ public class EvmManager : IEvmManager } catch (Exception ex) { + SentrySdk.CaptureException(ex); throw; } @@ -874,6 +881,7 @@ public class EvmManager : IEvmManager } catch (Exception ex) { + SentrySdk.CaptureException(ex); Console.Error.WriteLine($"Error getting estimated gas fee: {ex.Message}"); return 0; } diff --git a/src/Managing.Infrastructure.Web3/Services/Web3ProxyService.cs b/src/Managing.Infrastructure.Web3/Services/Web3ProxyService.cs index 95da35f6..6760faad 100644 --- a/src/Managing.Infrastructure.Web3/Services/Web3ProxyService.cs +++ b/src/Managing.Infrastructure.Web3/Services/Web3ProxyService.cs @@ -21,8 +21,8 @@ namespace Managing.Infrastructure.Evm.Services public class Web3ProxySettings { public string BaseUrl { get; set; } = "http://localhost:3000"; - public int MaxRetryAttempts { get; set; } = 3; - public int RetryDelayMs { get; set; } = 1000; + public int MaxRetryAttempts { get; set; } = 2; + public int RetryDelayMs { get; set; } = 2500; public int TimeoutSeconds { get; set; } = 30; } diff --git a/src/Managing.Web3Proxy/src/plugins/custom/gmx.ts b/src/Managing.Web3Proxy/src/plugins/custom/gmx.ts index d1650555..4f7cecda 100644 --- a/src/Managing.Web3Proxy/src/plugins/custom/gmx.ts +++ b/src/Managing.Web3Proxy/src/plugins/custom/gmx.ts @@ -50,12 +50,13 @@ interface CacheEntry { timestamp: number; } -const CACHE_TTL = 30 * 60 * 1000; // 30 minutes in milliseconds +const CACHE_TTL = 60 * 60 * 1000; // 60 minutes in milliseconds (increased from 30 minutes) const marketsCache = new Map(); -const MAX_CACHE_SIZE = 5; // Limit cache size to prevent memory issues +const MAX_CACHE_SIZE = 20; // Increased cache size to allow more markets data const OPERATION_TIMEOUT = 30000; // 30 seconds timeout for operations -const MEMORY_WARNING_THRESHOLD = 0.8; // Warn when memory usage exceeds 80% +const MEMORY_WARNING_THRESHOLD = 0.85; // Warn when memory usage exceeds 85% +const MEMORY_CLEAR_THRESHOLD = 0.95; // Clear cache when memory usage exceeds 95% const MAX_GAS_FEE_USD = 1.5; // Maximum gas fee in USD (1 USDC) // Memory monitoring function @@ -68,7 +69,7 @@ function checkMemoryUsage() { console.warn(`⚠️ High memory usage detected: ${(usage * 100).toFixed(1)}% (${Math.round(used.heapUsed / 1024 / 1024)}MB / ${Math.round(total / 1024 / 1024)}MB)`); // Clear cache if memory usage is too high - if (usage > 0.9) { + if (usage > MEMORY_CLEAR_THRESHOLD) { console.warn(`🧹 Clearing markets cache due to high memory usage`); marketsCache.clear(); pendingRequests.clear();