From cefb9706f9bd930ec79f9f9d58d72c894beffbef Mon Sep 17 00:00:00 2001 From: Stephan D Date: Wed, 24 Dec 2025 01:59:37 +0100 Subject: [PATCH] extended logging + timeout setting --- api/gateway/chain/config.yml | 1 + .../service/gateway/commands/transfer/deps.go | 1 + .../service/gateway/commands/transfer/fee.go | 6 +++++- .../service/gateway/commands/wallet/deps.go | 1 + .../gateway/commands/wallet/onchain_balance.go | 6 +++++- .../internal/service/gateway/rpcclient/clients.go | 5 +++-- .../chain/internal/service/gateway/service.go | 2 ++ .../chain/internal/service/gateway/settings.go | 13 +++++++++++++ 8 files changed, 31 insertions(+), 4 deletions(-) diff --git a/api/gateway/chain/config.yml b/api/gateway/chain/config.yml index 241259e..a8b23c5 100644 --- a/api/gateway/chain/config.yml +++ b/api/gateway/chain/config.yml @@ -60,3 +60,4 @@ key_management: cache: wallet_balance_ttl_seconds: 120 + rpc_request_timeout_seconds: 15 diff --git a/api/gateway/chain/internal/service/gateway/commands/transfer/deps.go b/api/gateway/chain/internal/service/gateway/commands/transfer/deps.go index 8007bec..92a5596 100644 --- a/api/gateway/chain/internal/service/gateway/commands/transfer/deps.go +++ b/api/gateway/chain/internal/service/gateway/commands/transfer/deps.go @@ -15,6 +15,7 @@ type Deps struct { Networks *rpcclient.Registry Storage storage.Repository Clock clockpkg.Clock + RPCTimeout time.Duration EnsureRepository func(context.Context) error LaunchExecution func(transferRef, sourceWalletRef string, network shared.Network) } diff --git a/api/gateway/chain/internal/service/gateway/commands/transfer/fee.go b/api/gateway/chain/internal/service/gateway/commands/transfer/fee.go index 2a9e9a3..aec9c8c 100644 --- a/api/gateway/chain/internal/service/gateway/commands/transfer/fee.go +++ b/api/gateway/chain/internal/service/gateway/commands/transfer/fee.go @@ -122,7 +122,11 @@ func estimateNetworkFee(ctx context.Context, logger mlogger.Logger, network shar } defer client.Close() - timeoutCtx, cancel := context.WithTimeout(ctx, 15*time.Second) + timeout := c.deps.RPCTimeout + if timeout <= 0 { + timeout = 15 * time.Second + } + timeoutCtx, cancel := context.WithTimeout(ctx, timeout) defer cancel() tokenABI, err := abi.JSON(strings.NewReader(erc20TransferABI)) diff --git a/api/gateway/chain/internal/service/gateway/commands/wallet/deps.go b/api/gateway/chain/internal/service/gateway/commands/wallet/deps.go index 9fbc88d..db2b22c 100644 --- a/api/gateway/chain/internal/service/gateway/commands/wallet/deps.go +++ b/api/gateway/chain/internal/service/gateway/commands/wallet/deps.go @@ -18,6 +18,7 @@ type Deps struct { Storage storage.Repository Clock clockpkg.Clock BalanceCacheTTL time.Duration + RPCTimeout time.Duration EnsureRepository func(context.Context) error } diff --git a/api/gateway/chain/internal/service/gateway/commands/wallet/onchain_balance.go b/api/gateway/chain/internal/service/gateway/commands/wallet/onchain_balance.go index 2ac17ed..23192f8 100644 --- a/api/gateway/chain/internal/service/gateway/commands/wallet/onchain_balance.go +++ b/api/gateway/chain/internal/service/gateway/commands/wallet/onchain_balance.go @@ -64,7 +64,11 @@ func onChainWalletBalance(ctx context.Context, deps Deps, wallet *model.ManagedW return nil, err } - timeoutCtx, cancel := context.WithTimeout(ctx, 10*time.Second) + timeout := deps.RPCTimeout + if timeout <= 0 { + timeout = 10 * time.Second + } + timeoutCtx, cancel := context.WithTimeout(ctx, timeout) defer cancel() tokenABI, err := abi.JSON(strings.NewReader(erc20ABIJSON)) diff --git a/api/gateway/chain/internal/service/gateway/rpcclient/clients.go b/api/gateway/chain/internal/service/gateway/rpcclient/clients.go index caba020..2049384 100644 --- a/api/gateway/chain/internal/service/gateway/rpcclient/clients.go +++ b/api/gateway/chain/internal/service/gateway/rpcclient/clients.go @@ -154,9 +154,10 @@ func (l *loggingRoundTripper) RoundTrip(req *http.Request) (*http.Response, erro respFields = append(respFields, zap.String("rpc_response", truncate(string(bodyBytes), 2048))) } if resp.StatusCode >= 400 { - l.logger.Warn("rpc response error", respFields...) + l.logger.Warn("RPC response error", respFields...) } else { - l.logger.Debug("rpc response", respFields...) + // Log response content so downstream parse failures can be inspected without debug logs. + l.logger.Warn("RPC response", respFields...) } return resp, nil diff --git a/api/gateway/chain/internal/service/gateway/service.go b/api/gateway/chain/internal/service/gateway/service.go index a23e506..2a9a524 100644 --- a/api/gateway/chain/internal/service/gateway/service.go +++ b/api/gateway/chain/internal/service/gateway/service.go @@ -140,6 +140,7 @@ func commandsWalletDeps(s *Service) wallet.Deps { Storage: s.storage, Clock: s.clock, BalanceCacheTTL: s.settings.walletBalanceCacheTTL(), + RPCTimeout: s.settings.rpcTimeout(), EnsureRepository: s.ensureRepository, } } @@ -150,6 +151,7 @@ func commandsTransferDeps(s *Service) transfer.Deps { Networks: s.networkRegistry, Storage: s.storage, Clock: s.clock, + RPCTimeout: s.settings.rpcTimeout(), EnsureRepository: s.ensureRepository, LaunchExecution: s.launchTransferExecution, } diff --git a/api/gateway/chain/internal/service/gateway/settings.go b/api/gateway/chain/internal/service/gateway/settings.go index 320af23..edbbd85 100644 --- a/api/gateway/chain/internal/service/gateway/settings.go +++ b/api/gateway/chain/internal/service/gateway/settings.go @@ -3,15 +3,18 @@ package gateway import "time" const defaultWalletBalanceCacheTTL = 120 * time.Second +const defaultRPCRequestTimeout = 15 * time.Second // CacheSettings holds tunable gateway behaviour. type CacheSettings struct { WalletBalanceCacheTTLSeconds int `yaml:"wallet_balance_ttl_seconds"` + RPCRequestTimeoutSeconds int `yaml:"rpc_request_timeout_seconds"` } func defaultSettings() CacheSettings { return CacheSettings{ WalletBalanceCacheTTLSeconds: int(defaultWalletBalanceCacheTTL.Seconds()), + RPCRequestTimeoutSeconds: int(defaultRPCRequestTimeout.Seconds()), } } @@ -19,6 +22,9 @@ func (s CacheSettings) withDefaults() CacheSettings { if s.WalletBalanceCacheTTLSeconds <= 0 { s.WalletBalanceCacheTTLSeconds = int(defaultWalletBalanceCacheTTL.Seconds()) } + if s.RPCRequestTimeoutSeconds <= 0 { + s.RPCRequestTimeoutSeconds = int(defaultRPCRequestTimeout.Seconds()) + } return s } @@ -28,3 +34,10 @@ func (s CacheSettings) walletBalanceCacheTTL() time.Duration { } return time.Duration(s.WalletBalanceCacheTTLSeconds) * time.Second } + +func (s CacheSettings) rpcTimeout() time.Duration { + if s.RPCRequestTimeoutSeconds <= 0 { + return defaultRPCRequestTimeout + } + return time.Duration(s.RPCRequestTimeoutSeconds) * time.Second +}