diff options
author | Bojie Wu <bojie@dexon.org> | 2018-10-09 13:28:45 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2018-12-19 20:54:27 +0800 |
commit | 974490f217787b309158335e7d180221d6110090 (patch) | |
tree | 856e3925d276c514db4300454f408b3937fc7d84 | |
parent | bed3b0b6dd9eb86dd8e6d100904e7299446585f5 (diff) | |
download | dexon-974490f217787b309158335e7d180221d6110090.tar dexon-974490f217787b309158335e7d180221d6110090.tar.gz dexon-974490f217787b309158335e7d180221d6110090.tar.bz2 dexon-974490f217787b309158335e7d180221d6110090.tar.lz dexon-974490f217787b309158335e7d180221d6110090.tar.xz dexon-974490f217787b309158335e7d180221d6110090.tar.zst dexon-974490f217787b309158335e7d180221d6110090.zip |
app: fix concurrent map read write issue and accept fail transaction when round change
-rw-r--r-- | core/blockchain.go | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/core/blockchain.go b/core/blockchain.go index a77514c57..7c9b1efb2 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -148,7 +148,8 @@ type BlockChain struct { addressCounter map[common.Address]uint64 chainLastHeight map[uint32]uint64 - pendingBlocks map[uint64]struct { + pendingBlockMu *sync.Mutex + pendingBlocks map[uint64]struct { block *types.Block receipts types.Receipts } @@ -193,6 +194,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par block *types.Block receipts types.Receipts }), + pendingBlockMu: &sync.Mutex{}, addressNonce: make(map[common.Address]uint64), addressCost: make(map[common.Address]*big.Int), addressCounter: make(map[common.Address]uint64), @@ -1637,7 +1639,9 @@ func (bc *BlockChain) processPendingBlock(block *types.Block, witness *coreTypes case SideStatTy: return 0, nil, nil, fmt.Errorf("insert pending block and fork found") } + bc.pendingBlockMu.Lock() delete(bc.pendingBlocks, pendingHeight) + bc.pendingBlockMu.Unlock() stats.processed++ stats.usedGas += pendingIns.block.GasUsed() @@ -1654,6 +1658,8 @@ func (bc *BlockChain) processPendingBlock(block *types.Block, witness *coreTypes } func (bc *BlockChain) GetPendingBlockByHeight(height uint64) *types.Block { + bc.pendingBlockMu.Lock() + defer bc.pendingBlockMu.Unlock() return bc.pendingBlocks[height].block } |