From 2f6aeacfab95db5c6afee054f8a118aee5821c97 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Tue, 8 Dec 2015 01:54:49 -0600 Subject: [PATCH] server: Correct mempool/CPU miner initialize order. The CPU miner relies on the mempool, so the mempool has to be created before calling the function to create the CPU miner. When PR #568 introduced the mempool config struct, it moved the mempool creation after the miner creation, which leads to the CPU miner crashing due to trying to access a nil mempool. This move the CPU miner creation after the mempool creation appropriately. --- server.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/server.go b/server.go index 28c9e90f..9ed3cca4 100644 --- a/server.go +++ b/server.go @@ -2354,15 +2354,6 @@ func newServer(listenAddrs []string, db database.Db, chainParams *chaincfg.Param } s.blockManager = bm - // Create the mining policy based on the configuration options. - policy := mining.Policy{ - BlockMinSize: cfg.BlockMinSize, - BlockMaxSize: cfg.BlockMaxSize, - BlockPrioritySize: cfg.BlockPrioritySize, - TxMinFreeFee: cfg.minRelayTxFee, - } - s.cpuMiner = newCPUMiner(&policy, &s) - txC := mempoolConfig{ DisableRelayPriority: cfg.NoRelayPriority, EnableAddrIndex: cfg.AddrIndex, @@ -2377,6 +2368,17 @@ func newServer(listenAddrs []string, db database.Db, chainParams *chaincfg.Param } s.txMemPool = newTxMemPool(&txC) + // Create the mining policy based on the configuration options. + // NOTE: The CPU miner relies on the mempool, so the mempool has to be + // created before calling the function to create the CPU miner. + policy := mining.Policy{ + BlockMinSize: cfg.BlockMinSize, + BlockMaxSize: cfg.BlockMaxSize, + BlockPrioritySize: cfg.BlockPrioritySize, + TxMinFreeFee: cfg.minRelayTxFee, + } + s.cpuMiner = newCPUMiner(&policy, &s) + if cfg.AddrIndex { ai, err := newAddrIndexer(&s) if err != nil {