From 219c0b36bddc6cb40ad3e9051eeda772f97f4cb6 Mon Sep 17 00:00:00 2001 From: Roshan <48975233+Pythonberg1997@users.noreply.github.com> Date: Tue, 2 Apr 2024 17:01:13 +0800 Subject: [PATCH] fix: concurrent map write issue (#15) --- core/blockchain.go | 2 +- miner/worker_builder.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/core/blockchain.go b/core/blockchain.go index 0045932e9d..787a74d04d 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -412,7 +412,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis // Make sure the state associated with the block is available, or log out // if there is no available state, waiting for state sync. head := bc.CurrentBlock() - if !bc.NoTries() && !bc.HasState(head.Root) { + if !bc.HasState(head.Root) { if head.Number.Uint64() == 0 { // The genesis state is missing, which is only possible in the path-based // scheme. This situation occurs when the initial state sync is not finished diff --git a/miner/worker_builder.go b/miner/worker_builder.go index bb4c32e7d1..64143704c6 100644 --- a/miner/worker_builder.go +++ b/miner/worker_builder.go @@ -284,9 +284,12 @@ func (w *worker) simulateBundles(env *environment, bundles []*types.Bundle) ([]* simResult := make(map[common.Hash]*types.SimulatedBundle) var wg sync.WaitGroup + var mu sync.Mutex for i, bundle := range bundles { if simmed, ok := simCache.GetSimulatedBundle(bundle.Hash()); ok { + mu.Lock() simResult[bundle.Hash()] = simmed + mu.Unlock() continue } @@ -301,6 +304,8 @@ func (w *worker) simulateBundles(env *environment, bundles []*types.Bundle) ([]* return } + mu.Lock() + defer mu.Unlock() simResult[bundle.Hash()] = simmed }(i, bundle, env.state.Copy()) }