Skip to content

Commit

Permalink
pass in context to NewManager
Browse files Browse the repository at this point in the history
  • Loading branch information
iansuvak committed Oct 11, 2024
1 parent 335b222 commit f492247
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion vms/platformvm/validators/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ type State interface {
}

func NewManager(
ctx context.Context,
log logging.Logger,
cfg config.Config,
state State,
Expand All @@ -104,7 +105,7 @@ func NewManager(
TTL: recentlyAcceptedWindowTTL,
},
)
go recentlyAccepted.EvictEvery(context.Background(), recentlyAcceptedEvictFrequency)
go recentlyAccepted.EvictEvery(ctx, recentlyAcceptedEvictFrequency)

return &manager{
log: log,
Expand Down
5 changes: 4 additions & 1 deletion vms/platformvm/validators/manager_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ func BenchmarkGetValidatorSet(b *testing.B) {
Validators: vdrs,
})

ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()

m := NewManager(
ctx,
logging.NoLog{},
config.Config{
Validators: vdrs,
Expand Down Expand Up @@ -88,7 +92,6 @@ func BenchmarkGetValidatorSet(b *testing.B) {
require.NoError(addSubnetDelegator(s, subnetID, genesistest.DefaultValidatorStartTime, genesistest.DefaultValidatorEndTime, nodeIDs, currentHeight))
}

ctx := context.Background()
height, err := m.GetCurrentHeight(ctx)
require.NoError(err)
require.Equal(currentHeight, height)
Expand Down
5 changes: 3 additions & 2 deletions vms/platformvm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ func (vm *VM) Initialize(
return err
}

validatorManager := pvalidators.NewManager(chainCtx.Log, vm.Config, vm.state, vm.metrics, &vm.clock)
vm.onShutdownCtx, vm.onShutdownCtxCancel = context.WithCancel(context.Background())

validatorManager := pvalidators.NewManager(vm.onShutdownCtx, chainCtx.Log, vm.Config, vm.state, vm.metrics, &vm.clock)
vm.State = validatorManager
utxoVerifier := utxo.NewVerifier(vm.ctx, &vm.clock, vm.fx)
vm.uptimeManager = uptime.NewManager(vm.state, &vm.clock)
Expand Down Expand Up @@ -199,7 +201,6 @@ func (vm *VM) Initialize(
return fmt.Errorf("failed to initialize network: %w", err)
}

vm.onShutdownCtx, vm.onShutdownCtxCancel = context.WithCancel(context.Background())
// TODO: Wait for this goroutine to exit during Shutdown once the platformvm
// has better control of the context lock.
go vm.Network.PushGossip(vm.onShutdownCtx)
Expand Down

0 comments on commit f492247

Please sign in to comment.