diff options
author | Wei-Ning Huang <w@dexon.org> | 2018-11-05 13:49:08 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-03-12 12:19:09 +0800 |
commit | 1a75ec877713fb50021410a5d0474563299b16a0 (patch) | |
tree | 9d6fc5e152769faad486a0b5f4f894c68165ee1e /core/blockchain.go | |
parent | fd48d4b21645ee8fd8cfafe63f7bd2630bb77611 (diff) | |
download | dexon-1a75ec877713fb50021410a5d0474563299b16a0.tar dexon-1a75ec877713fb50021410a5d0474563299b16a0.tar.gz dexon-1a75ec877713fb50021410a5d0474563299b16a0.tar.bz2 dexon-1a75ec877713fb50021410a5d0474563299b16a0.tar.lz dexon-1a75ec877713fb50021410a5d0474563299b16a0.tar.xz dexon-1a75ec877713fb50021410a5d0474563299b16a0.tar.zst dexon-1a75ec877713fb50021410a5d0474563299b16a0.zip |
core: validate roundHeight mapping in governance contract
Diffstat (limited to 'core/blockchain.go')
-rw-r--r-- | core/blockchain.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/core/blockchain.go b/core/blockchain.go index 684bdbe21..85ed86374 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -143,6 +143,8 @@ type BlockChain struct { badBlocks *lru.Cache // Bad block cache shouldPreserve func(*types.Block) bool // Function used to determine whether should preserve the given block. + roundHeightMap sync.Map + confirmedBlockInitMu sync.Mutex confirmedBlocks map[uint32]map[coreCommon.Hash]*blockInfo addressNonce map[uint32]map[common.Address]uint64 @@ -1664,6 +1666,11 @@ func (bc *BlockChain) processPendingBlock(block *types.Block, witness *coreTypes cache, _ := bc.stateCache.TrieDB().Size() stats.report([]*types.Block{pendingIns.block}, 0, cache) + + _, ok := bc.roundHeightMap.Load(pendingIns.block.Round()) + if !ok { + bc.roundHeightMap.Store(pendingIns.block.Round(), pendingHeight) + } } // Append a single chain head event if we've progressed the chain if lastCanon != nil && bc.CurrentBlock().Hash() == lastCanon.Hash() { @@ -2046,3 +2053,8 @@ func (bc *BlockChain) SubscribeChainSideEvent(ch chan<- ChainSideEvent) event.Su func (bc *BlockChain) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription { return bc.scope.Track(bc.logsFeed.Subscribe(ch)) } + +// GetRoundHeightMap returns the mapping between round and height. +func (bc *BlockChain) GetRoundHeightMap() sync.Map { + return bc.roundHeightMap +} |