Skip to content

Commit

Permalink
core: fix race condition in WriteMipmapBloom
Browse files Browse the repository at this point in the history
  • Loading branch information
bas-vk authored and karalabe committed Jan 9, 2017
1 parent 88cc1ca commit 2fed476
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/database_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"errors"
"fmt"
"math/big"
"sync"

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

ChainConfigNotFoundErr = errors.New("ChainConfig not found") // general config not found error

mipmapBloomMu sync.Mutex // protect against race condition when updating mipmap blooms
)

// encodeBlockNumber encodes a block number as big endian uint64
Expand Down Expand Up @@ -564,6 +567,9 @@ func mipmapKey(num, level uint64) []byte {
// WriteMapmapBloom writes each address included in the receipts' logs to the
// MIP bloom bin.
func WriteMipmapBloom(db ethdb.Database, number uint64, receipts types.Receipts) error {
mipmapBloomMu.Lock()
defer mipmapBloomMu.Unlock()

batch := db.NewBatch()
for _, level := range MIPMapLevels {
key := mipmapKey(number, level)
Expand Down

0 comments on commit 2fed476

Please sign in to comment.