Skip to content

Commit

Permalink
fix: concurrent map write issue (bnb-chain#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonberg1997 authored Apr 2, 2024
1 parent 0ca13b9 commit 219c0b3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions miner/worker_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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())
}
Expand Down

0 comments on commit 219c0b3

Please sign in to comment.