aboutsummaryrefslogtreecommitdiffstats
path: root/core/blockchain.go
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2018-11-05 13:49:08 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:27:17 +0800
commitf25aef2df9d8fee03569bdd47a923a24ed311299 (patch)
tree0f4327925c48dbff3e4f2cc3c202bbb7231e4208 /core/blockchain.go
parent0542a6a1b13c3c1235f68a2d0cca23976c241ca9 (diff)
downloadgo-tangerine-f25aef2df9d8fee03569bdd47a923a24ed311299.tar
go-tangerine-f25aef2df9d8fee03569bdd47a923a24ed311299.tar.gz
go-tangerine-f25aef2df9d8fee03569bdd47a923a24ed311299.tar.bz2
go-tangerine-f25aef2df9d8fee03569bdd47a923a24ed311299.tar.lz
go-tangerine-f25aef2df9d8fee03569bdd47a923a24ed311299.tar.xz
go-tangerine-f25aef2df9d8fee03569bdd47a923a24ed311299.tar.zst
go-tangerine-f25aef2df9d8fee03569bdd47a923a24ed311299.zip
core: validate roundHeight mapping in governance contract
Diffstat (limited to 'core/blockchain.go')
-rw-r--r--core/blockchain.go12
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
+}