diff --git a/cmd/soroban-rpc/internal/config/config.go b/cmd/soroban-rpc/internal/config/config.go index 1f89ab2b5..64c8edb81 100644 --- a/cmd/soroban-rpc/internal/config/config.go +++ b/cmd/soroban-rpc/internal/config/config.go @@ -29,6 +29,7 @@ type Config struct { FriendbotURL string HistoryArchiveURLs []string IngestionTimeout time.Duration + CaptiveCoreTimeout time.Duration LogFormat LogFormat LogLevel logrus.Level MaxEventsLimit uint diff --git a/cmd/soroban-rpc/internal/config/options.go b/cmd/soroban-rpc/internal/config/options.go index cecfb2e7d..6f5f6255b 100644 --- a/cmd/soroban-rpc/internal/config/options.go +++ b/cmd/soroban-rpc/internal/config/options.go @@ -174,6 +174,12 @@ func (cfg *Config) options() ConfigOptions { } }, }, + { + Name: "captive-core-timeout", + Usage: "Timeout for configuring and connecting to the specified Stellar Core instance", + ConfigKey: &cfg.CaptiveCoreTimeout, + DefaultValue: 1 * time.Minute, + }, { Name: "history-archive-urls", Usage: "comma-separated list of stellar history archives to connect with", diff --git a/cmd/soroban-rpc/internal/daemon/daemon.go b/cmd/soroban-rpc/internal/daemon/daemon.go index 63afb9a71..c4d6602e2 100644 --- a/cmd/soroban-rpc/internal/daemon/daemon.go +++ b/cmd/soroban-rpc/internal/daemon/daemon.go @@ -113,6 +113,8 @@ func newCaptiveCore(cfg *config.Config, logger *supportlog.Entry) (*ledgerbacken logger.WithError(err).Fatal("Invalid captive core toml") } + newCaptiveCoreCtx, cancelNewCaptiveCore := context.WithTimeout(context.Background(), cfg.CaptiveCoreTimeout) + defer cancelNewCaptiveCore() captiveConfig := ledgerbackend.CaptiveCoreConfig{ BinaryPath: cfg.StellarCoreBinaryPath, StoragePath: cfg.CaptiveCoreStoragePath, @@ -123,6 +125,7 @@ func newCaptiveCore(cfg *config.Config, logger *supportlog.Entry) (*ledgerbacken Toml: captiveCoreToml, UserAgent: "captivecore", UseDB: true, + Context: newCaptiveCoreCtx, } return ledgerbackend.NewCaptive(captiveConfig)