aboutsummaryrefslogtreecommitdiff
path: root/core/blockchain.go
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2020-08-12 22:00:39 -0400
committerDeterminant <[email protected]>2020-08-12 22:00:39 -0400
commit4beccc4f5ddb8a7f7366d036156ec06d7378fa6d (patch)
tree24f302be45e089bb4da4ebe148b4d5d3fa3a7f06 /core/blockchain.go
parent89df16782ed7a6b45600f3685371b8574b12f1ff (diff)
grab chainmu in GetBlockBy{Hash,Number} to avoid possible race with InsertChainv0.2.8-rc.2
Diffstat (limited to 'core/blockchain.go')
-rw-r--r--core/blockchain.go4
1 files changed, 4 insertions, 0 deletions
diff --git a/core/blockchain.go b/core/blockchain.go
index dddca62..0510151 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -732,6 +732,8 @@ func (bc *BlockChain) GetBlock(hash common.Hash, number uint64) *types.Block {
// GetBlockByHash retrieves a block from the database by hash, caching it if found.
func (bc *BlockChain) GetBlockByHash(hash common.Hash) *types.Block {
+ bc.chainmu.Lock()
+ defer bc.chainmu.Unlock()
number := bc.hc.GetBlockNumber(hash)
if number == nil {
return nil
@@ -742,6 +744,8 @@ func (bc *BlockChain) GetBlockByHash(hash common.Hash) *types.Block {
// GetBlockByNumber retrieves a block from the database by number, caching it
// (associated with its hash) if found.
func (bc *BlockChain) GetBlockByNumber(number uint64) *types.Block {
+ bc.chainmu.Lock()
+ defer bc.chainmu.Unlock()
hash := rawdb.ReadCanonicalHash(bc.db, number)
if hash == (common.Hash{}) {
return nil