diff options
author | Wei-Ning Huang <w@dexon.org> | 2018-11-05 13:49:08 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-04-09 21:32:52 +0800 |
commit | c66af2d7f54b14e856c3d3b6a98a961daf617216 (patch) | |
tree | 9f9ceb4abf1ead399de23abe9efe7f8ebbfe510b /core/blockchain.go | |
parent | a2daec1ea649de60557c382bb3756ddf2466b2b2 (diff) | |
download | dexon-c66af2d7f54b14e856c3d3b6a98a961daf617216.tar.gz dexon-c66af2d7f54b14e856c3d3b6a98a961daf617216.tar.zst dexon-c66af2d7f54b14e856c3d3b6a98a961daf617216.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 fe9e137c8..04b154ade 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() { @@ -2068,3 +2075,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 +} |