Skip to content

Commit 8409a6d

Browse files
authored
Merge pull request #2335 from CortexFoundation/dev
core/filtermaps: make ChainView thread safe
2 parents 5de9364 + 2b6a977 commit 8409a6d

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

core/filtermaps/chain_view.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/CortexFoundation/CortexTheseus/common"
2121
"github.com/CortexFoundation/CortexTheseus/core/types"
2222
"github.com/CortexFoundation/CortexTheseus/log"
23+
"sync"
2324
)
2425

2526
// blockchain represents the underlying blockchain of ChainView.
@@ -39,6 +40,7 @@ type blockchain interface {
3940
// of the underlying blockchain, it should only possess the block headers
4041
// and receipts up until the expected chain view head.
4142
type ChainView struct {
43+
lock sync.Mutex
4244
chain blockchain
4345
headNumber uint64
4446
hashes []common.Hash // block hashes starting backwards from headNumber until first canonical hash
@@ -147,6 +149,9 @@ func (cv *ChainView) extendNonCanonical() bool {
147149

148150
// blockHash returns the given block hash without doing the head number check.
149151
func (cv *ChainView) blockHash(number uint64) common.Hash {
152+
cv.lock.Lock()
153+
defer cv.lock.Unlock()
154+
150155
if number+uint64(len(cv.hashes)) <= cv.headNumber {
151156
hash := cv.chain.GetCanonicalHash(number)
152157
if !cv.extendNonCanonical() {

0 commit comments

Comments
 (0)