Skip to content

Commit

Permalink
Do not use context.Background() (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergekh2 authored Jun 26, 2024
1 parent 8824f8c commit a8a466a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
16 changes: 8 additions & 8 deletions core/node/crypto/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}

Expand Down Expand Up @@ -307,15 +307,15 @@ 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 {
log.Error("OnChainConfiguration: received config update with invalid value",
"tx", event.TxHash, "key", configKey.name, "err", err)
return
}
occ.settings.Set(configKey, e.Block, value)
occ.settings.Set(ctx, configKey, e.Block, value)
}
}

Expand Down Expand Up @@ -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()
)

Expand All @@ -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()
)

Expand Down
8 changes: 5 additions & 3 deletions core/node/crypto/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit a8a466a

Please sign in to comment.