Skip to content

Commit

Permalink
fix races
Browse files Browse the repository at this point in the history
  • Loading branch information
darioush committed Sep 28, 2024
1 parent 559c20b commit a149479
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
1 change: 1 addition & 0 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ func (s *Ethereum) Stop() error {
s.bloomIndexer.Close()
close(s.closeBloomHandler)
s.txPool.Close()
s.miner.Close()
s.blockchain.Stop()
s.engine.Close()

Expand Down
12 changes: 12 additions & 0 deletions miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,15 @@ func (miner *Miner) GenerateBlock(predicateContext *precompileconfig.PredicateCo
func (miner *Miner) SubscribePendingLogs(ch chan<- []*types.Log) event.Subscription {
return miner.worker.pendingLogsFeed.Subscribe(ch)
}

func (miner *Miner) Stop() {
miner.worker.stop()
}

func (miner *Miner) Start() {
miner.worker.start()
}

func (miner *Miner) Close() {
miner.worker.close()
}
16 changes: 8 additions & 8 deletions plugin/evm/syncervm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ func TestStateSyncToggleEnabledToDisabled(t *testing.T) {
rand.Seed(1)
// Hack: registering metrics uses global variables, so we need to disable metrics here so that we can initialize the VM twice.
metrics.Enabled = false
defer func() {
t.Cleanup(func() {
metrics.Enabled = true
}()
})

var lock sync.Mutex
reqCount := 0
Expand Down Expand Up @@ -154,12 +154,9 @@ func TestStateSyncToggleEnabledToDisabled(t *testing.T) {
); err != nil {
t.Fatal(err)
}

defer func() {
if err := syncDisabledVM.Shutdown(context.Background()); err != nil {
t.Fatal(err)
}
}()
t.Cleanup(func() {
require.NoError(t, syncDisabledVM.Shutdown(context.Background()))
})

if height := syncDisabledVM.LastAcceptedBlockInternal().Height(); height != 0 {
t.Fatalf("Unexpected last accepted height: %d", height)
Expand Down Expand Up @@ -217,6 +214,9 @@ func TestStateSyncToggleEnabledToDisabled(t *testing.T) {
); err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
require.NoError(t, syncReEnabledVM.Shutdown(context.Background()))
})

// override [serverVM]'s SendAppResponse function to trigger AppResponse on [syncerVM]
vmSetup.serverAppSender.SendAppResponseF = func(ctx context.Context, nodeID ids.NodeID, requestID uint32, response []byte) error {
Expand Down
3 changes: 3 additions & 0 deletions plugin/evm/vm_warp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,13 +424,16 @@ func TestReceiveWarpMessage(t *testing.T) {
true, // RequirePrimaryNetworkSigners
)

// Stop the miner to change the upgrade config to avoid a data race
vm.miner.Stop()
vm.chainConfig.UpgradeConfig = params.UpgradeConfig{
PrecompileUpgrades: []params.PrecompileUpgrade{
{Config: enableConfig},
{Config: disableConfig},
{Config: reEnableConfig},
},
}
vm.miner.Start()

type test struct {
name string
Expand Down

0 comments on commit a149479

Please sign in to comment.