Skip to content

Commit 4268cb8

Browse files
authored
Merge pull request ethereum#3534 from bas-vk/writemipmaprace
core: fix race condition in WriteMipmapBloom
2 parents 3f1a729 + 2fed476 commit 4268cb8

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

core/database_util.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"errors"
2424
"fmt"
2525
"math/big"
26+
"sync"
2627

2728
"github.com/ethereum/go-ethereum/common"
2829
"github.com/ethereum/go-ethereum/core/types"
@@ -63,6 +64,8 @@ var (
6364
oldBlockHashPrefix = []byte("block-hash-") // [deprecated by the header/block split, remove eventually]
6465

6566
ChainConfigNotFoundErr = errors.New("ChainConfig not found") // general config not found error
67+
68+
mipmapBloomMu sync.Mutex // protect against race condition when updating mipmap blooms
6669
)
6770

6871
// encodeBlockNumber encodes a block number as big endian uint64
@@ -564,6 +567,9 @@ func mipmapKey(num, level uint64) []byte {
564567
// WriteMapmapBloom writes each address included in the receipts' logs to the
565568
// MIP bloom bin.
566569
func WriteMipmapBloom(db ethdb.Database, number uint64, receipts types.Receipts) error {
570+
mipmapBloomMu.Lock()
571+
defer mipmapBloomMu.Unlock()
572+
567573
batch := db.NewBatch()
568574
for _, level := range MIPMapLevels {
569575
key := mipmapKey(number, level)

0 commit comments

Comments
 (0)