From a8a466aff09d15117a54f7b92c355e5bd6046d2e Mon Sep 17 00:00:00 2001 From: Serge Khorun <104387024+sergekh2@users.noreply.github.com> Date: Tue, 25 Jun 2024 17:23:27 -0700 Subject: [PATCH] Do not use context.Background() (#283) --- core/node/crypto/config.go | 16 ++++++++-------- core/node/crypto/config_test.go | 8 +++++--- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/core/node/crypto/config.go b/core/node/crypto/config.go index 82d950e31..118ce77f1 100644 --- a/core/node/crypto/config.go +++ b/core/node/crypto/config.go @@ -254,7 +254,7 @@ func (occ *onChainConfiguration) loadFromChain(ctx context.Context, activeBlock if err != nil { return err } - occ.settings.Set(key, setting.BlockNumber, value) + occ.settings.Set(ctx, key, setting.BlockNumber, value) } return nil @@ -277,7 +277,7 @@ func (occ *onChainConfiguration) loadMissing(ctx context.Context, activeBlock ui "activeBlock", activeBlock, ) - occ.settings.Set(key, activeBlock, key.defaultValue) + occ.settings.Set(ctx, key, activeBlock, key.defaultValue) } } @@ -307,7 +307,7 @@ func (occ *onChainConfiguration) onConfigChanged(ctx context.Context, event type } if e.Deleted { - occ.settings.Remove(configKey, e.Block) + occ.settings.Remove(ctx, configKey, e.Block) } else { value, err := configKey.decode(e.Value) if err != nil { @@ -315,7 +315,7 @@ func (occ *onChainConfiguration) onConfigChanged(ctx context.Context, event type "tx", event.TxHash, "key", configKey.name, "err", err) return } - occ.settings.Set(configKey, e.Block, value) + occ.settings.Set(ctx, configKey, e.Block, value) } } @@ -399,9 +399,9 @@ func (occ *onChainConfiguration) All() (*AllSettings, error) { return &all, nil } -func (ocs *onChainSettings) Remove(key chainKeyImpl, activeOnBlockNumber uint64) { +func (ocs *onChainSettings) Remove(ctx context.Context, key chainKeyImpl, activeOnBlockNumber uint64) { var ( - log = dlog.FromCtx(context.Background()) // lint:ignore context.Background() is fine here + log = dlog.FromCtx(ctx) keyID = key.ID() ) @@ -420,9 +420,9 @@ func (ocs *onChainSettings) Remove(key chainKeyImpl, activeOnBlockNumber uint64) // Set the given value to the settings identified by the given key for the // given block number. -func (ocs *onChainSettings) Set(key chainKeyImpl, activeOnBlockNumber uint64, value any) { +func (ocs *onChainSettings) Set(ctx context.Context, key chainKeyImpl, activeOnBlockNumber uint64, value any) { var ( - log = dlog.FromCtx(context.Background()) // lint:ignore context.Background() is fine here + log = dlog.FromCtx(ctx) keyID = key.ID() ) diff --git a/core/node/crypto/config_test.go b/core/node/crypto/config_test.go index 2eb2c9fba..cfb50f62e 100644 --- a/core/node/crypto/config_test.go +++ b/core/node/crypto/config_test.go @@ -32,11 +32,13 @@ func TestOnChainConfigSettingMultipleActiveBlockValues(t *testing.T) { settings = &onChainSettings{ s: map[common.Hash]settings{}, } + ctx, cancel = test.NewTestContext() ) + defer cancel() - settings.Set(StreamReplicationFactorConfigKey, 20, uint64(3)) - settings.Set(StreamReplicationFactorConfigKey, 5, uint64(1)) - settings.Set(StreamReplicationFactorConfigKey, 10, uint64(2)) + settings.Set(ctx, StreamReplicationFactorConfigKey, 20, uint64(3)) + settings.Set(ctx, StreamReplicationFactorConfigKey, 5, uint64(1)) + settings.Set(ctx, StreamReplicationFactorConfigKey, 10, uint64(2)) for _, tt := range tests { val, err := settings.getOnBlock(tt.Key, tt.Block).Uint64()