diff options
author | Wei-Ning Huang <w@cobinhood.com> | 2018-10-16 10:37:01 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-06-12 17:23:39 +0800 |
commit | 7e45adbb9a08b76c667d235ed397a705495f9852 (patch) | |
tree | 927e218acfbf84b88b4c99391f7544b8e6b18d50 /core | |
parent | e5137c6582c1ffb6943842aed88b3a31a31c34f1 (diff) | |
download | go-tangerine-7e45adbb9a08b76c667d235ed397a705495f9852.tar go-tangerine-7e45adbb9a08b76c667d235ed397a705495f9852.tar.gz go-tangerine-7e45adbb9a08b76c667d235ed397a705495f9852.tar.bz2 go-tangerine-7e45adbb9a08b76c667d235ed397a705495f9852.tar.lz go-tangerine-7e45adbb9a08b76c667d235ed397a705495f9852.tar.xz go-tangerine-7e45adbb9a08b76c667d235ed397a705495f9852.tar.zst go-tangerine-7e45adbb9a08b76c667d235ed397a705495f9852.zip |
core: fix nil map initialization
Diffstat (limited to 'core')
-rw-r--r-- | core/blockchain.go | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/core/blockchain.go b/core/blockchain.go index 88287a21d..8d90c9348 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -230,6 +230,9 @@ func (bc *BlockChain) AddConfirmedBlock(block *coreTypes.Block) { defer bc.confirmedBlockMu.Unlock() bc.confirmedBlock[block.Hash] = block + if bc.filteredConfirmedBlock[block.Position.ChainID] == nil { + bc.filteredConfirmedBlock[block.Position.ChainID] = make(map[coreCommon.Hash]*coreTypes.Block) + } bc.filteredConfirmedBlock[block.Position.ChainID][block.Hash] = block } @@ -240,6 +243,10 @@ func (bc *BlockChain) RemoveConfirmedBlock(hash coreCommon.Hash) { block := bc.confirmedBlock[hash] delete(bc.filteredConfirmedBlock[block.Position.ChainID], block.Hash) delete(bc.confirmedBlock, block.Hash) + + if len(bc.filteredConfirmedBlock[block.Position.ChainID]) == 0 { + bc.filteredConfirmedBlock[block.Position.ChainID] = nil + } } func (bc *BlockChain) GetConfirmedBlockByHash(hash coreCommon.Hash) *coreTypes.Block { |