diff --git a/services/horizon/internal/actions_root.go b/services/horizon/internal/actions_root.go index b57982011d..993b3ca8f9 100644 --- a/services/horizon/internal/actions_root.go +++ b/services/horizon/internal/actions_root.go @@ -26,15 +26,16 @@ func (action *RootAction) JSON() error { "strictReceivePaths": StrictReceivePathsQuery{}.URITemplate(), "strictSendPaths": FindFixedPathsQuery{}.URITemplate(), } + coreInfo := action.App.coreSettings.get() resourceadapter.PopulateRoot( action.R.Context(), &res, ledger.CurrentState(), action.App.horizonVersion, - action.App.coreVersion, + coreInfo.coreVersion, action.App.config.NetworkPassphrase, - action.App.currentProtocolVersion, - action.App.coreSupportedProtocolVersion, + coreInfo.currentProtocolVersion, + coreInfo.coreSupportedProtocolVersion, action.App.config.FriendbotURL, templates, ) diff --git a/services/horizon/internal/app.go b/services/horizon/internal/app.go index fab0f5c08f..e26ba84a7f 100644 --- a/services/horizon/internal/app.go +++ b/services/horizon/internal/app.go @@ -12,6 +12,7 @@ import ( metrics "github.com/rcrowley/go-metrics" "github.com/stellar/go/clients/stellarcore" + proto "github.com/stellar/go/protocols/stellarcore" horizonContext "github.com/stellar/go/services/horizon/internal/context" "github.com/stellar/go/services/horizon/internal/db2/core" "github.com/stellar/go/services/horizon/internal/db2/history" @@ -30,24 +31,47 @@ import ( graceful "gopkg.in/tylerb/graceful.v1" ) -// App represents the root of the state of a horizon instance. -type App struct { - config Config - web *web - historyQ *history.Q - coreQ *core.Q - ctx context.Context - cancel func() - coreVersion string - horizonVersion string +type coreSettings struct { currentProtocolVersion int32 coreSupportedProtocolVersion int32 - orderBookStream *expingest.OrderBookStream - submitter *txsub.System - paths paths.Finder - expingester *expingest.System - reaper *reap.System - ticks *time.Ticker + coreVersion string +} + +type coreSettingsStore struct { + sync.RWMutex + coreSettings +} + +func (c *coreSettingsStore) set(resp *proto.InfoResponse) { + c.Lock() + defer c.Unlock() + c.coreVersion = resp.Info.Build + c.currentProtocolVersion = int32(resp.Info.Ledger.Version) + c.coreSupportedProtocolVersion = int32(resp.Info.ProtocolVersion) +} + +func (c *coreSettingsStore) get() coreSettings { + c.RLock() + defer c.RUnlock() + return c.coreSettings +} + +// App represents the root of the state of a horizon instance. +type App struct { + config Config + web *web + historyQ *history.Q + coreQ *core.Q + ctx context.Context + cancel func() + horizonVersion string + coreSettings coreSettingsStore + orderBookStream *expingest.OrderBookStream + submitter *txsub.System + paths paths.Finder + expingester *expingest.System + reaper *reap.System + ticks *time.Ticker // metrics metrics metrics.Registry @@ -384,9 +408,7 @@ func (a *App) UpdateStellarCoreInfo() { os.Exit(1) } - a.coreVersion = resp.Info.Build - a.currentProtocolVersion = int32(resp.Info.Ledger.Version) - a.coreSupportedProtocolVersion = int32(resp.Info.ProtocolVersion) + a.coreSettings.set(resp) } // UpdateMetrics triggers a refresh of several metrics gauges, such as open