aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWei-Ning Huang <w@cobinhood.com>2018-10-16 10:37:01 +0800
committerWei-Ning Huang <w@dexon.org>2019-04-09 13:49:53 +0800
commitb26b0b063b77c02b6358d61ba45a1db2d37b3334 (patch)
treec682356a9bb8faab37e6787c7a6ff1d389d7149f
parent9bc6509251d76f9e9a58c7d8dfe4a492dd265c4f (diff)
downloaddexon-b26b0b063b77c02b6358d61ba45a1db2d37b3334.tar
dexon-b26b0b063b77c02b6358d61ba45a1db2d37b3334.tar.gz
dexon-b26b0b063b77c02b6358d61ba45a1db2d37b3334.tar.bz2
dexon-b26b0b063b77c02b6358d61ba45a1db2d37b3334.tar.lz
dexon-b26b0b063b77c02b6358d61ba45a1db2d37b3334.tar.xz
dexon-b26b0b063b77c02b6358d61ba45a1db2d37b3334.tar.zst
dexon-b26b0b063b77c02b6358d61ba45a1db2d37b3334.zip
core: fix nil map initialization
-rw-r--r--core/blockchain.go7
-rw-r--r--dex/app.go3
2 files changed, 9 insertions, 1 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 {
diff --git a/dex/app.go b/dex/app.go
index 06b5a5381..1e97c4859 100644
--- a/dex/app.go
+++ b/dex/app.go
@@ -20,11 +20,12 @@ package dex
import (
"bytes"
"fmt"
- "github.com/dexon-foundation/dexon/log"
"math/big"
"sync"
"time"
+ "github.com/dexon-foundation/dexon/log"
+
coreCommon "github.com/dexon-foundation/dexon-consensus-core/common"
coreTypes "github.com/dexon-foundation/dexon-consensus-core/core/types"