File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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.
4142type 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.
149151func (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 () {
You can’t perform that action at this time.
0 commit comments