From bb77ebf738dbc9937eb289092a30c0a785ccd515 Mon Sep 17 00:00:00 2001 From: Bojie Wu Date: Tue, 9 Oct 2018 13:28:45 +0800 Subject: app: fix concurrent read write issue with map --- core/blockchain.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/blockchain.go b/core/blockchain.go index 7bf19ebbd..f4f01d315 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -260,10 +260,16 @@ func (bc *BlockChain) RemoveConfirmedBlock(hash coreCommon.Hash) { } func (bc *BlockChain) GetConfirmedBlockByHash(hash coreCommon.Hash) *coreTypes.Block { + bc.confirmedBlockMu.Lock() + defer bc.confirmedBlockMu.Unlock() + return bc.confirmedBlocks[hash] } func (bc *BlockChain) GetConfirmedTxsByAddress(chainID uint32, address common.Address) (types.Transactions, error) { + bc.confirmedBlockMu.Lock() + defer bc.confirmedBlockMu.Unlock() + var addressTxs types.Transactions for _, block := range bc.chainConfirmedBlocks[chainID] { var transactions types.Transactions -- cgit v1.2.3