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.
This commit is contained in:
Dave Collins 2015-12-08 01:54:49 -06:00
parent 2a7f41cddb
commit 2f6aeacfab

View file

@ -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 {