From f492247b090ea58fe597cc26f4b2a67f3fdfa967 Mon Sep 17 00:00:00 2001 From: Ian Suvak Date: Fri, 11 Oct 2024 09:20:08 -0400 Subject: [PATCH] pass in context to NewManager --- vms/platformvm/validators/manager.go | 3 ++- vms/platformvm/validators/manager_benchmark_test.go | 5 ++++- vms/platformvm/vm.go | 5 +++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/vms/platformvm/validators/manager.go b/vms/platformvm/validators/manager.go index 331782901fc9..d65823f372da 100644 --- a/vms/platformvm/validators/manager.go +++ b/vms/platformvm/validators/manager.go @@ -90,6 +90,7 @@ type State interface { } func NewManager( + ctx context.Context, log logging.Logger, cfg config.Config, state State, @@ -104,7 +105,7 @@ func NewManager( TTL: recentlyAcceptedWindowTTL, }, ) - go recentlyAccepted.EvictEvery(context.Background(), recentlyAcceptedEvictFrequency) + go recentlyAccepted.EvictEvery(ctx, recentlyAcceptedEvictFrequency) return &manager{ log: log, diff --git a/vms/platformvm/validators/manager_benchmark_test.go b/vms/platformvm/validators/manager_benchmark_test.go index 0b2222f45f1a..6eaa349c8504 100644 --- a/vms/platformvm/validators/manager_benchmark_test.go +++ b/vms/platformvm/validators/manager_benchmark_test.go @@ -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, @@ -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) diff --git a/vms/platformvm/vm.go b/vms/platformvm/vm.go index 975e13f7ebd5..e34c4436b754 100644 --- a/vms/platformvm/vm.go +++ b/vms/platformvm/vm.go @@ -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) @@ -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)