diff --git a/pkg/solana/cache_test.go b/pkg/solana/cache_test.go index ef1fb7cdb..75649d35a 100644 --- a/pkg/solana/cache_test.go +++ b/pkg/solana/cache_test.go @@ -106,9 +106,10 @@ func TestGetState(t *testing.T) { })) defer mockServer.Close() - reader := func() (client.AccountReader, error) { return testSetupReader(t, mockServer.URL), nil } + reader := testSetupReader(t, mockServer.URL) + getReader := func() (client.AccountReader, error) { return reader, nil } // happy path does not error (actual state decoding handled in types_test) - _, _, err := GetState(context.TODO(), reader, solana.PublicKey{}, "") + _, _, err := GetState(context.TODO(), getReader, solana.PublicKey{}, "") require.NoError(t, err) } @@ -133,18 +134,19 @@ func TestGetLatestTransmission(t *testing.T) { })) defer mockServer.Close() - reader := func() (client.AccountReader, error) { return testSetupReader(t, mockServer.URL), nil } - a, _, err := GetLatestTransmission(context.TODO(), reader, solana.PublicKey{}, "") + reader := testSetupReader(t, mockServer.URL) + getReader := func() (client.AccountReader, error) { return reader, nil } + a, _, err := GetLatestTransmission(context.TODO(), getReader, solana.PublicKey{}, "") assert.NoError(t, err) assert.Equal(t, expectedTime, a.Timestamp) assert.Equal(t, expectedAns, a.Data.String()) // fail if returned transmission header is too short - _, _, err = GetLatestTransmission(context.TODO(), reader, solana.PublicKey{}, "") + _, _, err = GetLatestTransmission(context.TODO(), getReader, solana.PublicKey{}, "") assert.Error(t, err) // fail if returned transmission is too short - _, _, err = GetLatestTransmission(context.TODO(), reader, solana.PublicKey{}, "") + _, _, err = GetLatestTransmission(context.TODO(), getReader, solana.PublicKey{}, "") assert.Error(t, err) } @@ -167,14 +169,16 @@ func TestCache(t *testing.T) { w.Write(testTransmissionsResponse(t, body, 0)) //nolint:errcheck })) - reader := func() (client.Reader, error) { return testSetupReader(t, mockServer.URL), nil } + reader := testSetupReader(t, mockServer.URL) + getReader := func() (client.Reader, error) { return reader, nil } + getAccountReader := func() (client.AccountReader, error) { return reader, nil } lggr := logger.Test(t) stateCache := NewStateCache( solana.MustPublicKeyFromBase58("11111111111111111111111111111111"), "test-chain-id", config.NewDefault(), - reader, + getReader, lggr, ) require.NoError(t, stateCache.Start(ctx)) @@ -189,7 +193,7 @@ func TestCache(t *testing.T) { solana.MustPublicKeyFromBase58("11111111111111111111111111111112"), "test-chain-id", config.NewDefault(), - reader, + getAccountReader, lggr, ) require.NoError(t, transmissionsCache.Start(ctx)) @@ -223,17 +227,19 @@ func TestNilPointerHandling(t *testing.T) { defer mockServer.Close() errString := "nil pointer returned in " - reader := func() (client.AccountReader, error) { return testSetupReader(t, mockServer.URL), nil } + + reader := testSetupReader(t, mockServer.URL) + getReader := func() (client.AccountReader, error) { return reader, nil } // fail on get state query - _, _, err := GetState(context.TODO(), reader, solana.PublicKey{}, "") + _, _, err := GetState(context.TODO(), getReader, solana.PublicKey{}, "") assert.EqualError(t, err, errString+"GetState.GetAccountInfoWithOpts") // fail on transmissions header query - _, _, err = GetLatestTransmission(context.TODO(), reader, solana.PublicKey{}, "") + _, _, err = GetLatestTransmission(context.TODO(), getReader, solana.PublicKey{}, "") assert.EqualError(t, err, errString+"GetLatestTransmission.GetAccountInfoWithOpts.Header") passFirst = true // allow proper response for header query, fail on transmission - _, _, err = GetLatestTransmission(context.TODO(), reader, solana.PublicKey{}, "") + _, _, err = GetLatestTransmission(context.TODO(), getReader, solana.PublicKey{}, "") assert.EqualError(t, err, errString+"GetLatestTransmission.GetAccountInfoWithOpts.Transmission") } diff --git a/pkg/solana/client/multinode/poller.go b/pkg/solana/client/multinode/poller.go index 4f426ec02..0ce87fade 100644 --- a/pkg/solana/client/multinode/poller.go +++ b/pkg/solana/client/multinode/poller.go @@ -65,8 +65,7 @@ func (p *Poller[T]) Err() <-chan error { } func (p *Poller[T]) pollingLoop(ctx context.Context) { - tickerCfg := services.TickerConfig{Initial: 0, JitterPct: services.DefaultJitter} - ticker := tickerCfg.NewTicker(p.pollingInterval) + ticker := services.NewTicker(p.pollingInterval) defer ticker.Stop() for { diff --git a/pkg/solana/config_tracker.go b/pkg/solana/config_tracker.go index 9a1fa8e28..3ddff2715 100644 --- a/pkg/solana/config_tracker.go +++ b/pkg/solana/config_tracker.go @@ -9,7 +9,7 @@ import ( type ConfigTracker struct { stateCache *StateCache - reader GetReader + getReader GetReader } func (c *ConfigTracker) Notify() <-chan struct{} { @@ -73,7 +73,7 @@ func (c *ConfigTracker) LatestConfig(ctx context.Context, changedInBlock uint64) // LatestBlockHeight returns the height of the most recent block in the chain. func (c *ConfigTracker) LatestBlockHeight(ctx context.Context) (blockHeight uint64, err error) { - reader, err := c.reader() + reader, err := c.getReader() if err != nil { return 0, err } diff --git a/pkg/solana/config_tracker_test.go b/pkg/solana/config_tracker_test.go index 88ba0442e..d0e2d8625 100644 --- a/pkg/solana/config_tracker_test.go +++ b/pkg/solana/config_tracker_test.go @@ -21,7 +21,7 @@ func TestLatestBlockHeight(t *testing.T) { ctx := context.Background() c := &ConfigTracker{ - reader: func() (client.Reader, error) { return testSetupReader(t, mockServer.URL), nil }, + getReader: func() (client.Reader, error) { return testSetupReader(t, mockServer.URL), nil }, } h, err := c.LatestBlockHeight(ctx) diff --git a/pkg/solana/relay.go b/pkg/solana/relay.go index bbae6b961..4e6009027 100644 --- a/pkg/solana/relay.go +++ b/pkg/solana/relay.go @@ -154,7 +154,8 @@ func (r *Relayer) NewMedianProvider(ctx context.Context, rargs relaytypes.RelayA } cfg := configWatcher.chain.Config() - transmissionsCache := NewTransmissionsCache(transmissionsID, relayConfig.ChainID, cfg, configWatcher.chain.Reader, r.lggr) + getReader := func() (client.AccountReader, error) { return configWatcher.chain.Reader() } + transmissionsCache := NewTransmissionsCache(transmissionsID, relayConfig.ChainID, cfg, getReader, r.lggr) return &medianProvider{ configProvider: configWatcher, transmissionsCache: transmissionsCache, @@ -187,8 +188,6 @@ func (r *Relayer) NewAutomationProvider(ctx context.Context, rargs relaytypes.Re var _ relaytypes.ConfigProvider = &configProvider{} -type GetReader func() (client.Reader, error) - type configProvider struct { services.StateMachine chainID string @@ -231,7 +230,7 @@ func newConfigProvider(_ context.Context, lggr logger.Logger, chain Chain, args storeProgramID: storeProgramID, stateCache: stateCache, offchainConfigDigester: offchainConfigDigester, - configTracker: &ConfigTracker{stateCache: stateCache, reader: chain.Reader}, + configTracker: &ConfigTracker{stateCache: stateCache, getReader: chain.Reader}, chain: chain, }, nil } diff --git a/pkg/solana/state_cache.go b/pkg/solana/state_cache.go index 614ad0d81..06fc4c62b 100644 --- a/pkg/solana/state_cache.go +++ b/pkg/solana/state_cache.go @@ -23,19 +23,20 @@ type StateCache struct { *client.Cache[State] } +type GetReader func() (client.Reader, error) type GetAccountReader func() (client.AccountReader, error) -func NewStateCache(stateID solana.PublicKey, chainID string, cfg config.Config, reader GetReader, lggr logger.Logger) *StateCache { +func NewStateCache(stateID solana.PublicKey, chainID string, cfg config.Config, getReader GetReader, lggr logger.Logger) *StateCache { name := "ocr2_median_state" getter := func(ctx context.Context) (State, uint64, error) { - getAccountReader := func() (client.AccountReader, error) { return reader() } + getAccountReader := func() (client.AccountReader, error) { return getReader() } return GetState(ctx, getAccountReader, stateID, cfg.Commitment()) } return &StateCache{client.NewCache(name, stateID, chainID, cfg, getter, logger.With(lggr, "cache", name))} } -func GetState(ctx context.Context, reader GetAccountReader, account solana.PublicKey, commitment rpc.CommitmentType) (State, uint64, error) { - r, err := reader() +func GetState(ctx context.Context, getReader GetAccountReader, account solana.PublicKey, commitment rpc.CommitmentType) (State, uint64, error) { + r, err := getReader() if err != nil { return State{}, 0, fmt.Errorf("failed to get reader: %w", err) } diff --git a/pkg/solana/transmissions_cache.go b/pkg/solana/transmissions_cache.go index bdf258180..acc530cbb 100644 --- a/pkg/solana/transmissions_cache.go +++ b/pkg/solana/transmissions_cache.go @@ -19,11 +19,10 @@ type TransmissionsCache struct { *client.Cache[Answer] } -func NewTransmissionsCache(transmissionsID solana.PublicKey, chainID string, cfg config.Config, getReader GetReader, lggr logger.Logger) *TransmissionsCache { +func NewTransmissionsCache(transmissionsID solana.PublicKey, chainID string, cfg config.Config, getReader GetAccountReader, lggr logger.Logger) *TransmissionsCache { name := "ocr2_median_transmissions" getter := func(ctx context.Context) (Answer, uint64, error) { - getAccountReader := func() (client.AccountReader, error) { return getReader() } - return GetLatestTransmission(ctx, getAccountReader, transmissionsID, cfg.Commitment()) + return GetLatestTransmission(ctx, getReader, transmissionsID, cfg.Commitment()) } return &TransmissionsCache{client.NewCache(name, transmissionsID, chainID, cfg, getter, logger.With(lggr, "cache", name))} }