diff --git a/go.mod b/go.mod index 8d057f5c858..0685f46c55d 100644 --- a/go.mod +++ b/go.mod @@ -51,6 +51,7 @@ require ( go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.11.0 go.opentelemetry.io/otel/sdk v1.11.0 go.opentelemetry.io/otel/trace v1.11.0 + go.uber.org/goleak v1.2.1 go.uber.org/zap v1.24.0 golang.org/x/crypto v0.1.0 golang.org/x/exp v0.0.0-20230206171751-46f607a40771 diff --git a/go.sum b/go.sum index c67d94d2194..7f91f2c068e 100644 --- a/go.sum +++ b/go.sum @@ -604,7 +604,8 @@ go.opentelemetry.io/proto/otlp v0.19.0/go.mod h1:H7XAot3MsfNsj7EXtrA2q5xSNQ10UqI go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ= go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= -go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA= +go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= +go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4= go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8= go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak= go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= diff --git a/vms/proposervm/batched_vm_test.go b/vms/proposervm/batched_vm_test.go index f07c956ab11..a4e11bec77b 100644 --- a/vms/proposervm/batched_vm_test.go +++ b/vms/proposervm/batched_vm_test.go @@ -30,6 +30,9 @@ func TestCoreVMNotRemote(t *testing.T) { // if coreVM is not remote VM, a specific error is returned require := require.New(t) _, _, proVM, _, _ := initTestProposerVM(t, time.Time{}, 0) // enable ProBlks + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() blkID := ids.Empty maxBlocksNum := 1000 // a high value to get all built blocks @@ -52,6 +55,9 @@ func TestCoreVMNotRemote(t *testing.T) { func TestGetAncestorsPreForkOnly(t *testing.T) { require := require.New(t) coreVM, proRemoteVM, coreGenBlk := initTestRemoteProposerVM(t, mockable.MaxTime) // disable ProBlks + defer func() { + require.NoError(proRemoteVM.Shutdown(context.Background())) + }() // Build some prefork blocks.... coreBlk1 := &snowman.TestBlock{ @@ -195,6 +201,9 @@ func TestGetAncestorsPreForkOnly(t *testing.T) { func TestGetAncestorsPostForkOnly(t *testing.T) { require := require.New(t) coreVM, proRemoteVM, coreGenBlk := initTestRemoteProposerVM(t, time.Time{}) // enable ProBlks + defer func() { + require.NoError(proRemoteVM.Shutdown(context.Background())) + }() // Build some post-Fork blocks.... coreBlk1 := &snowman.TestBlock{ @@ -347,8 +356,12 @@ func TestGetAncestorsAtSnomanPlusPlusFork(t *testing.T) { preForkTime := currentTime.Add(5 * time.Minute) forkTime := currentTime.Add(10 * time.Minute) postForkTime := currentTime.Add(15 * time.Minute) + // enable ProBlks in next future coreVM, proRemoteVM, coreGenBlk := initTestRemoteProposerVM(t, forkTime) + defer func() { + require.NoError(proRemoteVM.Shutdown(context.Background())) + }() // Build some prefork blocks.... proRemoteVM.Set(preForkTime) @@ -546,6 +559,9 @@ func TestGetAncestorsAtSnomanPlusPlusFork(t *testing.T) { func TestBatchedParseBlockPreForkOnly(t *testing.T) { require := require.New(t) coreVM, proRemoteVM, coreGenBlk := initTestRemoteProposerVM(t, mockable.MaxTime) // disable ProBlks + defer func() { + require.NoError(proRemoteVM.Shutdown(context.Background())) + }() // Build some prefork blocks.... coreBlk1 := &snowman.TestBlock{ @@ -664,6 +680,9 @@ func TestBatchedParseBlockPreForkOnly(t *testing.T) { func TestBatchedParseBlockPostForkOnly(t *testing.T) { require := require.New(t) coreVM, proRemoteVM, coreGenBlk := initTestRemoteProposerVM(t, time.Time{}) // enable ProBlks + defer func() { + require.NoError(proRemoteVM.Shutdown(context.Background())) + }() // Build some post-Fork blocks.... coreBlk1 := &snowman.TestBlock{ @@ -773,8 +792,12 @@ func TestBatchedParseBlockAtSnomanPlusPlusFork(t *testing.T) { preForkTime := currentTime.Add(5 * time.Minute) forkTime := currentTime.Add(10 * time.Minute) postForkTime := currentTime.Add(15 * time.Minute) + // enable ProBlks in next future coreVM, proRemoteVM, coreGenBlk := initTestRemoteProposerVM(t, forkTime) + defer func() { + require.NoError(proRemoteVM.Shutdown(context.Background())) + }() // Build some prefork blocks.... proRemoteVM.Set(preForkTime) diff --git a/vms/proposervm/main_test.go b/vms/proposervm/main_test.go new file mode 100644 index 00000000000..263fabf0b66 --- /dev/null +++ b/vms/proposervm/main_test.go @@ -0,0 +1,16 @@ +// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package proposervm + +import ( + "testing" + + "go.uber.org/goleak" +) + +// TestMain uses goleak to verify tests in this package do not leak unexpected +// goroutines. +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} diff --git a/vms/proposervm/post_fork_block_test.go b/vms/proposervm/post_fork_block_test.go index 0c23ad024fe..b2b36073335 100644 --- a/vms/proposervm/post_fork_block_test.go +++ b/vms/proposervm/post_fork_block_test.go @@ -39,6 +39,10 @@ func TestOracle_PostForkBlock_ImplementsInterface(t *testing.T) { // setup _, _, proVM, _, _ := initTestProposerVM(t, time.Time{}, 0) // enable ProBlks + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() + innerOracleBlk := &TestOptionsBlock{ TestBlock: snowman.TestBlock{ TestDecidable: choices.TestDecidable{ @@ -91,6 +95,10 @@ func TestBlockVerify_PostForkBlock_ParentChecks(t *testing.T) { require := require.New(t) coreVM, valState, proVM, coreGenBlk, _ := initTestProposerVM(t, time.Time{}, 0) // enable ProBlks + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() + pChainHeight := uint64(100) valState.GetCurrentHeightF = func(context.Context) (uint64, error) { return pChainHeight, nil @@ -185,6 +193,10 @@ func TestBlockVerify_PostForkBlock_TimestampChecks(t *testing.T) { require := require.New(t) coreVM, valState, proVM, coreGenBlk, _ := initTestProposerVM(t, time.Time{}, 0) // enable ProBlks + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() + pChainHeight := uint64(100) valState.GetCurrentHeightF = func(context.Context) (uint64, error) { return pChainHeight, nil @@ -353,6 +365,10 @@ func TestBlockVerify_PostForkBlock_PChainHeightChecks(t *testing.T) { require := require.New(t) coreVM, valState, proVM, coreGenBlk, _ := initTestProposerVM(t, time.Time{}, 0) // enable ProBlks + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() + pChainHeight := uint64(100) valState.GetCurrentHeightF = func(context.Context) (uint64, error) { return pChainHeight, nil @@ -487,6 +503,10 @@ func TestBlockVerify_PostForkBlockBuiltOnOption_PChainHeightChecks(t *testing.T) require := require.New(t) coreVM, valState, proVM, coreGenBlk, _ := initTestProposerVM(t, time.Time{}, 0) // enable ProBlks + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() + pChainHeight := uint64(100) valState.GetCurrentHeightF = func(context.Context) (uint64, error) { return pChainHeight, nil @@ -665,6 +685,10 @@ func TestBlockVerify_PostForkBlock_CoreBlockVerifyIsCalledOnce(t *testing.T) { // Verify a block once (in this test by building it). // Show that other verify call would not call coreBlk.Verify() coreVM, valState, proVM, coreGenBlk, _ := initTestProposerVM(t, time.Time{}, 0) // enable ProBlks + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() + pChainHeight := uint64(2000) valState.GetCurrentHeightF = func(context.Context) (uint64, error) { return pChainHeight, nil @@ -724,6 +748,10 @@ func TestBlockAccept_PostForkBlock_SetsLastAcceptedBlock(t *testing.T) { // setup coreVM, valState, proVM, coreGenBlk, _ := initTestProposerVM(t, time.Time{}, 0) // enable ProBlks + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() + pChainHeight := uint64(2000) valState.GetCurrentHeightF = func(context.Context) (uint64, error) { return pChainHeight, nil @@ -783,6 +811,10 @@ func TestBlockAccept_PostForkBlock_TwoProBlocksWithSameCoreBlock_OneIsAccepted(t require := require.New(t) coreVM, valState, proVM, coreGenBlk, _ := initTestProposerVM(t, time.Time{}, 0) // enable ProBlks + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() + var minimumHeight uint64 valState.GetMinimumHeightF = func(context.Context) (uint64, error) { return minimumHeight, nil @@ -827,6 +859,10 @@ func TestBlockReject_PostForkBlock_InnerBlockIsNotRejected(t *testing.T) { require := require.New(t) coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, time.Time{}, 0) // enable ProBlks + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() + coreBlk := &snowman.TestBlock{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(111), @@ -857,6 +893,9 @@ func TestBlockVerify_PostForkBlock_ShouldBePostForkOption(t *testing.T) { coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, time.Time{}, 0) proVM.Set(coreGenBlk.Timestamp()) + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() // create post fork oracle block ... oracleCoreBlk := &TestOptionsBlock{ @@ -969,6 +1008,9 @@ func TestBlockVerify_PostForkBlock_PChainTooLow(t *testing.T) { coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, time.Time{}, 5) proVM.Set(coreGenBlk.Timestamp()) + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() coreBlk := &snowman.TestBlock{ TestDecidable: choices.TestDecidable{ diff --git a/vms/proposervm/post_fork_option_test.go b/vms/proposervm/post_fork_option_test.go index 92851a9078f..c82bb4db875 100644 --- a/vms/proposervm/post_fork_option_test.go +++ b/vms/proposervm/post_fork_option_test.go @@ -41,6 +41,9 @@ func TestBlockVerify_PostForkOption_ParentChecks(t *testing.T) { coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, time.Time{}, 0) proVM.Set(coreGenBlk.Timestamp()) + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() // create post fork oracle block ... oracleCoreBlk := &TestOptionsBlock{ @@ -154,6 +157,9 @@ func TestBlockVerify_PostForkOption_CoreBlockVerifyIsCalledOnce(t *testing.T) { // Verify an option once; then show that another verify call would not call coreBlk.Verify() coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, time.Time{}, 0) proVM.Set(coreGenBlk.Timestamp()) + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() // create post fork oracle block ... oracleCoreBlk := &TestOptionsBlock{ @@ -253,6 +259,9 @@ func TestBlockAccept_PostForkOption_SetsLastAcceptedBlock(t *testing.T) { coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, time.Time{}, 0) proVM.Set(coreGenBlk.Timestamp()) + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() // create post fork oracle block ... oracleCoreBlk := &TestOptionsBlock{ @@ -360,6 +369,9 @@ func TestBlockReject_InnerBlockIsNotRejected(t *testing.T) { coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, time.Time{}, 0) proVM.Set(coreGenBlk.Timestamp()) + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() // create post fork oracle block ... oracleCoreBlk := &TestOptionsBlock{ @@ -459,6 +471,9 @@ func TestBlockVerify_PostForkOption_ParentIsNotOracleWithError(t *testing.T) { // Verify an option once; then show that another verify call would not call coreBlk.Verify() coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, time.Time{}, 0) proVM.Set(coreGenBlk.Timestamp()) + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() coreBlk := &TestOptionsBlock{ TestBlock: snowman.TestBlock{ @@ -641,9 +656,9 @@ func TestOptionTimestampValidity(t *testing.T) { require.Equal(expectedTime, option.Timestamp()) require.NoError(option.Accept(context.Background())) + require.NoError(proVM.Shutdown(context.Background())) // Restart the node. - ctx := proVM.ctx proVM = New( coreVM, @@ -711,6 +726,9 @@ func TestOptionTimestampValidity(t *testing.T) { nil, nil, )) + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() statefulOptionBlock, err := proVM.ParseBlock(context.Background(), option.Bytes()) require.NoError(err) diff --git a/vms/proposervm/pre_fork_block_test.go b/vms/proposervm/pre_fork_block_test.go index 0ba73342b75..1dfdedfcd56 100644 --- a/vms/proposervm/pre_fork_block_test.go +++ b/vms/proposervm/pre_fork_block_test.go @@ -52,6 +52,9 @@ func TestOracle_PreForkBlkCanBuiltOnPreForkOption(t *testing.T) { require := require.New(t) coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, mockable.MaxTime, 0) + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() // create pre fork oracle block ... oracleCoreBlk := &TestOptionsBlock{ @@ -138,6 +141,9 @@ func TestOracle_PostForkBlkCanBuiltOnPreForkOption(t *testing.T) { activationTime := genesisTimestamp.Add(10 * time.Second) coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, 0) + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() // create pre fork oracle block pre activation time... oracleCoreBlk := &TestOptionsBlock{ @@ -229,6 +235,9 @@ func TestBlockVerify_PreFork_ParentChecks(t *testing.T) { activationTime := genesisTimestamp.Add(10 * time.Second) coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, 0) + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() require.True(coreGenBlk.Timestamp().Before(activationTime)) @@ -299,6 +308,10 @@ func TestBlockVerify_BlocksBuiltOnPreForkGenesis(t *testing.T) { activationTime := genesisTimestamp.Add(10 * time.Second) coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, 0) + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() + require.True(coreGenBlk.Timestamp().Before(activationTime)) preActivationTime := activationTime.Add(-1 * time.Second) proVM.Set(preActivationTime) @@ -427,6 +440,9 @@ func TestBlockVerify_BlocksBuiltOnPostForkGenesis(t *testing.T) { activationTime := genesisTimestamp.Add(-1 * time.Second) coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, 0) proVM.Set(activationTime) + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() // build parent block after fork activation time ... coreBlock := &snowman.TestBlock{ @@ -464,6 +480,9 @@ func TestBlockAccept_PreFork_SetsLastAcceptedBlock(t *testing.T) { // setup coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, mockable.MaxTime, 0) + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() coreBlk := &snowman.TestBlock{ TestDecidable: choices.TestDecidable{ @@ -519,6 +538,10 @@ func TestBlockReject_PreForkBlock_InnerBlockIsRejected(t *testing.T) { require := require.New(t) coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, mockable.MaxTime, 0) // disable ProBlks + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() + coreBlk := &snowman.TestBlock{ TestDecidable: choices.TestDecidable{ IDV: ids.Empty.Prefix(111), @@ -547,6 +570,10 @@ func TestBlockVerify_ForkBlockIsOracleBlock(t *testing.T) { activationTime := genesisTimestamp.Add(10 * time.Second) coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, 0) + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() + require.True(coreGenBlk.Timestamp().Before(activationTime)) postActivationTime := activationTime.Add(time.Second) proVM.Set(postActivationTime) @@ -634,6 +661,10 @@ func TestBlockVerify_ForkBlockIsOracleBlockButChildrenAreSigned(t *testing.T) { activationTime := genesisTimestamp.Add(10 * time.Second) coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, activationTime, 0) + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() + require.True(coreGenBlk.Timestamp().Before(activationTime)) postActivationTime := activationTime.Add(time.Second) proVM.Set(postActivationTime) diff --git a/vms/proposervm/scheduler/scheduler.go b/vms/proposervm/scheduler/scheduler.go index e0062019f96..5946a67b9b7 100644 --- a/vms/proposervm/scheduler/scheduler.go +++ b/vms/proposervm/scheduler/scheduler.go @@ -14,6 +14,9 @@ import ( type Scheduler interface { Dispatch(startTime time.Time) + + // Client must guarantee that [SetBuildBlockTime] + // is never called after [Close] SetBuildBlockTime(t time.Time) Close() } diff --git a/vms/proposervm/state_syncable_vm_test.go b/vms/proposervm/state_syncable_vm_test.go index 5e5572edb7a..4490bd99f45 100644 --- a/vms/proposervm/state_syncable_vm_test.go +++ b/vms/proposervm/state_syncable_vm_test.go @@ -105,6 +105,9 @@ func TestStateSyncEnabled(t *testing.T) { require := require.New(t) innerVM, vm := helperBuildStateSyncTestObjects(t) + defer func() { + require.NoError(vm.Shutdown(context.Background())) + }() // ProposerVM State Sync disabled if innerVM State sync is disabled vm.hIndexer.MarkRepaired(true) @@ -128,6 +131,9 @@ func TestStateSyncGetOngoingSyncStateSummary(t *testing.T) { require := require.New(t) innerVM, vm := helperBuildStateSyncTestObjects(t) + defer func() { + require.NoError(vm.Shutdown(context.Background())) + }() innerSummary := &block.TestStateSummary{ IDV: ids.ID{'s', 'u', 'm', 'm', 'a', 'r', 'y', 'I', 'D'}, @@ -210,6 +216,9 @@ func TestStateSyncGetLastStateSummary(t *testing.T) { require := require.New(t) innerVM, vm := helperBuildStateSyncTestObjects(t) + defer func() { + require.NoError(vm.Shutdown(context.Background())) + }() innerSummary := &block.TestStateSummary{ IDV: ids.ID{'s', 'u', 'm', 'm', 'a', 'r', 'y', 'I', 'D'}, @@ -292,6 +301,9 @@ func TestStateSyncGetStateSummary(t *testing.T) { require := require.New(t) innerVM, vm := helperBuildStateSyncTestObjects(t) + defer func() { + require.NoError(vm.Shutdown(context.Background())) + }() reqHeight := uint64(1969) innerSummary := &block.TestStateSummary{ @@ -376,6 +388,9 @@ func TestStateSyncGetStateSummary(t *testing.T) { func TestParseStateSummary(t *testing.T) { require := require.New(t) innerVM, vm := helperBuildStateSyncTestObjects(t) + defer func() { + require.NoError(vm.Shutdown(context.Background())) + }() reqHeight := uint64(1969) innerSummary := &block.TestStateSummary{ @@ -452,6 +467,9 @@ func TestStateSummaryAccept(t *testing.T) { require := require.New(t) innerVM, vm := helperBuildStateSyncTestObjects(t) + defer func() { + require.NoError(vm.Shutdown(context.Background())) + }() reqHeight := uint64(1969) innerSummary := &block.TestStateSummary{ @@ -522,6 +540,9 @@ func TestStateSummaryAcceptOlderBlock(t *testing.T) { require := require.New(t) innerVM, vm := helperBuildStateSyncTestObjects(t) + defer func() { + require.NoError(vm.Shutdown(context.Background())) + }() reqHeight := uint64(1969) innerSummary := &block.TestStateSummary{ @@ -589,6 +610,10 @@ func TestNoStateSummariesServedWhileRepairingHeightIndex(t *testing.T) { // Note: by default proVM is built such that heightIndex will be considered complete coreVM, _, proVM, _, _ := initTestProposerVM(t, time.Time{}, 0) // enable ProBlks + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() + require.NoError(proVM.VerifyHeightIndex(context.Background())) // let coreVM be always ready to serve summaries diff --git a/vms/proposervm/vm.go b/vms/proposervm/vm.go index 54b9d7acf16..ee0ac9f2f75 100644 --- a/vms/proposervm/vm.go +++ b/vms/proposervm/vm.go @@ -263,6 +263,8 @@ func (vm *VM) Initialize( func (vm *VM) Shutdown(ctx context.Context) error { vm.onShutdown() + vm.Scheduler.Close() + if err := vm.db.Commit(); err != nil { return err } diff --git a/vms/proposervm/vm_byzantine_test.go b/vms/proposervm/vm_byzantine_test.go index 37e89848805..c53830077bc 100644 --- a/vms/proposervm/vm_byzantine_test.go +++ b/vms/proposervm/vm_byzantine_test.go @@ -35,6 +35,9 @@ func TestInvalidByzantineProposerParent(t *testing.T) { forkTime := time.Unix(0, 0) // enable ProBlks coreVM, _, proVM, gBlock, _ := initTestProposerVM(t, forkTime, 0) + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() xBlock := &snowman.TestBlock{ TestDecidable: choices.TestDecidable{ @@ -102,6 +105,9 @@ func TestInvalidByzantineProposerOracleParent(t *testing.T) { coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, time.Time{}, 0) proVM.Set(coreGenBlk.Timestamp()) + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() xBlockID := ids.GenerateTestID() xBlock := &TestOptionsBlock{ @@ -207,6 +213,9 @@ func TestInvalidByzantineProposerPreForkParent(t *testing.T) { forkTime := time.Unix(0, 0) // enable ProBlks coreVM, _, proVM, gBlock, _ := initTestProposerVM(t, forkTime, 0) + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() xBlock := &snowman.TestBlock{ TestDecidable: choices.TestDecidable{ @@ -293,6 +302,9 @@ func TestBlockVerify_PostForkOption_FaultyParent(t *testing.T) { coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, time.Time{}, 0) proVM.Set(coreGenBlk.Timestamp()) + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() xBlock := &TestOptionsBlock{ TestBlock: snowman.TestBlock{ @@ -389,6 +401,9 @@ func TestBlockVerify_InvalidPostForkOption(t *testing.T) { coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, time.Time{}, 0) proVM.Set(coreGenBlk.Timestamp()) + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() // create an Oracle pre-fork block X xBlockID := ids.GenerateTestID() @@ -572,6 +587,9 @@ func TestGetBlock_MutatedSignature(t *testing.T) { require := require.New(t) coreVM, valState, proVM, coreGenBlk, _ := initTestProposerVM(t, time.Time{}, 0) + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() // Make sure that we will be sampled to perform the proposals. valState.GetValidatorSetF = func(context.Context, uint64, ids.ID) (map[ids.NodeID]*validators.GetValidatorOutput, error) { diff --git a/vms/proposervm/vm_test.go b/vms/proposervm/vm_test.go index 4fa24fecd6d..09df3875410 100644 --- a/vms/proposervm/vm_test.go +++ b/vms/proposervm/vm_test.go @@ -214,6 +214,10 @@ func TestBuildBlockTimestampAreRoundedToSeconds(t *testing.T) { // given the same core block, BuildBlock returns the same proposer block coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, time.Time{}, 0) // enable ProBlks + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() + skewedTimestamp := time.Now().Truncate(time.Second).Add(time.Millisecond) proVM.Set(skewedTimestamp) @@ -243,6 +247,9 @@ func TestBuildBlockIsIdempotent(t *testing.T) { // given the same core block, BuildBlock returns the same proposer block coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, time.Time{}, 0) // enable ProBlks + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() coreBlk := &snowman.TestBlock{ TestDecidable: choices.TestDecidable{ @@ -273,6 +280,9 @@ func TestFirstProposerBlockIsBuiltOnTopOfGenesis(t *testing.T) { // setup coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, time.Time{}, 0) // enable ProBlks + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() coreBlk := &snowman.TestBlock{ TestDecidable: choices.TestDecidable{ @@ -304,6 +314,9 @@ func TestProposerBlocksAreBuiltOnPreferredProBlock(t *testing.T) { require := require.New(t) coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, time.Time{}, 0) // enable ProBlks + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() // add two proBlks... coreBlk1 := &snowman.TestBlock{ @@ -396,6 +409,9 @@ func TestCoreBlocksMustBeBuiltOnPreferredCoreBlock(t *testing.T) { require := require.New(t) coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, time.Time{}, 0) // enable ProBlks + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() coreBlk1 := &snowman.TestBlock{ TestDecidable: choices.TestDecidable{ @@ -489,6 +505,9 @@ func TestCoreBlockFailureCauseProposerBlockParseFailure(t *testing.T) { require := require.New(t) coreVM, _, proVM, _, _ := initTestProposerVM(t, time.Time{}, 0) // enable ProBlks + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() innerBlk := &snowman.TestBlock{ BytesV: []byte{1}, @@ -525,6 +544,9 @@ func TestTwoProBlocksWrappingSameCoreBlockCanBeParsed(t *testing.T) { require := require.New(t) coreVM, _, proVM, gencoreBlk, _ := initTestProposerVM(t, time.Time{}, 0) // enable ProBlks + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() // create two Proposer blocks at the same height innerBlk := &snowman.TestBlock{ @@ -593,6 +615,9 @@ func TestTwoProBlocksWithSameParentCanBothVerify(t *testing.T) { require := require.New(t) coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, time.Time{}, 0) // enable ProBlks + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() // one block is built from this proVM localcoreBlk := &snowman.TestBlock{ @@ -658,6 +683,9 @@ func TestPreFork_Initialize(t *testing.T) { require := require.New(t) _, _, proVM, coreGenBlk, _ := initTestProposerVM(t, mockable.MaxTime, 0) // disable ProBlks + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() // checks blkID, err := proVM.LastAccepted(context.Background()) @@ -674,6 +702,9 @@ func TestPreFork_BuildBlock(t *testing.T) { require := require.New(t) coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, mockable.MaxTime, 0) // disable ProBlks + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() coreBlk := &snowman.TestBlock{ TestDecidable: choices.TestDecidable{ @@ -710,6 +741,9 @@ func TestPreFork_ParseBlock(t *testing.T) { // setup coreVM, _, proVM, _, _ := initTestProposerVM(t, mockable.MaxTime, 0) // disable ProBlks + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() coreBlk := &snowman.TestBlock{ TestDecidable: choices.TestDecidable{ @@ -742,6 +776,9 @@ func TestPreFork_SetPreference(t *testing.T) { require := require.New(t) coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, mockable.MaxTime, 0) // disable ProBlks + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() coreBlk0 := &snowman.TestBlock{ TestDecidable: choices.TestDecidable{ @@ -897,6 +934,9 @@ func TestExpiredBuildBlock(t *testing.T) { nil, nil, )) + defer func() { + require.NoError(proVM.Shutdown(context.TODO())) + }() // Initialize shouldn't be called again coreVM.InitializeF = nil @@ -1003,6 +1043,9 @@ func TestInnerBlockDeduplication(t *testing.T) { require := require.New(t) coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, time.Time{}, 0) // disable ProBlks + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() coreBlk := &snowman.TestBlock{ TestDecidable: choices.TestDecidable{ @@ -1248,9 +1291,8 @@ func TestInnerVMRollback(t *testing.T) { require.Equal(choices.Accepted, fetchedBlock.Status()) // Restart the node and have the inner VM rollback state. - + require.NoError(proVM.Shutdown(context.Background())) coreBlk.StatusV = choices.Processing - proVM = New( coreVM, time.Time{}, @@ -1271,6 +1313,9 @@ func TestInnerVMRollback(t *testing.T) { nil, nil, )) + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() lastAcceptedID, err := proVM.LastAccepted(context.Background()) require.NoError(err) @@ -1287,6 +1332,9 @@ func TestBuildBlockDuringWindow(t *testing.T) { require := require.New(t) coreVM, valState, proVM, coreGenBlk, _ := initTestProposerVM(t, time.Time{}, 0) // enable ProBlks + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() valState.GetValidatorSetF = func(context.Context, uint64, ids.ID) (map[ids.NodeID]*validators.GetValidatorOutput, error) { return map[ids.NodeID]*validators.GetValidatorOutput{ @@ -1388,6 +1436,9 @@ func TestTwoForks_OneIsAccepted(t *testing.T) { forkTime := time.Unix(0, 0) coreVM, _, proVM, gBlock, _ := initTestProposerVM(t, forkTime, 0) + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() // create pre-fork block X and post-fork block A xBlock := &snowman.TestBlock{ @@ -1481,6 +1532,9 @@ func TestTooFarAdvanced(t *testing.T) { forkTime := time.Unix(0, 0) coreVM, _, proVM, gBlock, _ := initTestProposerVM(t, forkTime, 0) + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() xBlock := &snowman.TestBlock{ TestDecidable: choices.TestDecidable{ @@ -1569,6 +1623,9 @@ func TestTwoOptions_OneIsAccepted(t *testing.T) { coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, time.Time{}, 0) proVM.Set(coreGenBlk.Timestamp()) + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() xBlockID := ids.GenerateTestID() xBlock := &TestOptionsBlock{ @@ -1641,6 +1698,9 @@ func TestLaggedPChainHeight(t *testing.T) { coreVM, _, proVM, coreGenBlk, _ := initTestProposerVM(t, time.Time{}, 0) proVM.Set(coreGenBlk.Timestamp()) + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() innerBlock := &snowman.TestBlock{ TestDecidable: choices.TestDecidable{ @@ -1789,6 +1849,9 @@ func TestRejectedHeightNotIndexed(t *testing.T) { nil, nil, )) + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() // Initialize shouldn't be called again coreVM.InitializeF = nil @@ -1997,6 +2060,9 @@ func TestRejectedOptionHeightNotIndexed(t *testing.T) { nil, nil, )) + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() // Initialize shouldn't be called again coreVM.InitializeF = nil @@ -2121,6 +2187,7 @@ func TestVMInnerBlkCache(t *testing.T) { gomock.Any(), gomock.Any(), ).Return(nil) + innerVM.EXPECT().Shutdown(gomock.Any()).Return(nil) ctx := snow.DefaultContextTest() ctx.NodeID = ids.NodeIDFromCert(pTestCert.Leaf) @@ -2136,6 +2203,10 @@ func TestVMInnerBlkCache(t *testing.T) { nil, nil, )) + defer func() { + require.NoError(vm.Shutdown(context.Background())) + }() + state := state.NewMockState(ctrl) // mock state vm.State = state @@ -2188,6 +2259,9 @@ func TestVMInnerBlkCacheDeduplicationRegression(t *testing.T) { require := require.New(t) forkTime := time.Unix(0, 0) coreVM, _, proVM, gBlock, _ := initTestProposerVM(t, forkTime, 0) + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() // create pre-fork block X and post-fork block A xBlock := &snowman.TestBlock{ @@ -2261,6 +2335,9 @@ func TestVMInnerBlkMarkedAcceptedRegression(t *testing.T) { require := require.New(t) forkTime := time.Unix(0, 0) coreVM, _, proVM, gBlock, _ := initTestProposerVM(t, forkTime, 0) + defer func() { + require.NoError(proVM.Shutdown(context.Background())) + }() // create an inner block and wrap it in an postForkBlock. innerBlock := &snowman.TestBlock{ @@ -2333,6 +2410,7 @@ func TestVM_VerifyBlockWithContext(t *testing.T) { gomock.Any(), gomock.Any(), ).Return(nil) + innerVM.EXPECT().Shutdown(gomock.Any()).Return(nil) snowCtx := snow.DefaultContextTest() snowCtx.NodeID = ids.NodeIDFromCert(pTestCert.Leaf) @@ -2348,6 +2426,9 @@ func TestVM_VerifyBlockWithContext(t *testing.T) { nil, nil, )) + defer func() { + require.NoError(vm.Shutdown(context.Background())) + }() { pChainHeight := uint64(0)