aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorBojie Wu <bojie@dexon.org>2018-10-09 13:28:45 +0800
committerWei-Ning Huang <w@dexon.org>2019-04-09 21:32:52 +0800
commitd4883d04e8cca644800a57cd842a01f577c1a16f (patch)
treeaf841497615956f11c8c52e8615987bf8adb0ff0 /core
parent6e0cf992988f29daabd39e67f2f6ce8034ba4513 (diff)
downloaddexon-d4883d04e8cca644800a57cd842a01f577c1a16f.tar
dexon-d4883d04e8cca644800a57cd842a01f577c1a16f.tar.gz
dexon-d4883d04e8cca644800a57cd842a01f577c1a16f.tar.bz2
dexon-d4883d04e8cca644800a57cd842a01f577c1a16f.tar.lz
dexon-d4883d04e8cca644800a57cd842a01f577c1a16f.tar.xz
dexon-d4883d04e8cca644800a57cd842a01f577c1a16f.tar.zst
dexon-d4883d04e8cca644800a57cd842a01f577c1a16f.zip
app: fix concurrent map read write issue and accept fail transaction when round change
Diffstat (limited to 'core')
-rw-r--r--core/blockchain.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/core/blockchain.go b/core/blockchain.go
index 429b3a4cc..9b0620679 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),
@@ -1643,7 +1645,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()
@@ -1660,6 +1664,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
}