diff --git a/blockmanager.go b/blockmanager.go index 541486aeaf..6a89a8c5a7 100644 --- a/blockmanager.go +++ b/blockmanager.go @@ -274,6 +274,24 @@ type blockManagerConfig struct { NotifyWinningTickets func(*rpcserver.WinningTicketsNtfnData) PruneRebroadcastInventory func() RpcServer func() *rpcserver.Server + + // DisableCheckpoints indicates whether or not the block manager should make + // use of checkpoints. + DisableCheckpoints bool + + // NoMiningStateSync indicates whether or not the block manager should + // perform an initial mining state synchronization with peers once they are + // believed to be fully synced. + NoMiningStateSync bool + + // MaxPeers specifies the maximum number of peers the server is expected to + // be connected with. It is primarily used as a hint for more efficient + // synchronization. + MaxPeers int + + // MaxOrphanTxs specifies the maximum number of orphan transactions the + // transaction pool associated with the server supports. + MaxOrphanTxs int } // peerSyncState stores additional information that the blockManager tracks @@ -374,11 +392,6 @@ func (b *blockManager) SyncHeight() int64 { // later than the final checkpoint or some other reason such as disabled // checkpoints. func (b *blockManager) findNextHeaderCheckpoint(height int64) *chaincfg.Checkpoint { - // There is no next checkpoint if checkpoints are disabled or there are - // none for this current network. - if cfg.DisableCheckpoints { - return nil - } checkpoints := b.cfg.Chain.Checkpoints() if len(checkpoints) == 0 { return nil @@ -490,7 +503,7 @@ func (b *blockManager) startSync() { // downloads when in regression test mode. if b.nextCheckpoint != nil && best.Height < b.nextCheckpoint.Height && - !cfg.DisableCheckpoints { + !b.cfg.DisableCheckpoints { err := bestPeer.PushGetHeadersMsg(locator, b.nextCheckpoint.Hash) if err != nil { @@ -602,8 +615,8 @@ func (b *blockManager) handleNewPeerMsg(peer *peerpkg.Peer) { b.startSync() } - // Grab the mining state from this peer after we're synced. - if !cfg.NoMiningStateSync { + // Grab the mining state from this peer once synced when enabled. + if !b.cfg.NoMiningStateSync { b.syncMiningStateAfterSync(peer) } } @@ -746,7 +759,7 @@ func (b *blockManager) handleTxMsg(tmsg *txMsg) { // Process the transaction to include validation, insertion in the // memory pool, orphan handling, etc. - allowOrphans := cfg.MaxOrphanTxs > 0 + allowOrphans := b.cfg.MaxOrphanTxs > 0 acceptedTxs, err := b.cfg.TxMemPool.ProcessTransaction(tmsg.tx, allowOrphans, true, true, mempool.Tag(tmsg.peer.ID())) @@ -2490,7 +2503,7 @@ func newBlockManager(config *blockManagerConfig) (*blockManager, error) { requestedBlocks: make(map[chainhash.Hash]struct{}), peerStates: make(map[*peerpkg.Peer]*peerSyncState), progressLogger: newBlockProgressLogger("Processed", bmgrLog), - msgChan: make(chan interface{}, cfg.MaxPeers*3), + msgChan: make(chan interface{}, config.MaxPeers*3), headerList: list.New(), quit: make(chan struct{}), orphans: make(map[chainhash.Hash]*orphanBlock), @@ -2498,7 +2511,7 @@ func newBlockManager(config *blockManagerConfig) (*blockManager, error) { } best := bm.cfg.Chain.BestSnapshot() - if !cfg.DisableCheckpoints { + if !bm.cfg.DisableCheckpoints { // Initialize the next checkpoint based on the current height. bm.nextCheckpoint = bm.findNextHeaderCheckpoint(best.Height) if bm.nextCheckpoint != nil { diff --git a/server.go b/server.go index b828b4c613..9bedae4e7f 100644 --- a/server.go +++ b/server.go @@ -3258,6 +3258,10 @@ func newServer(ctx context.Context, listenAddrs []string, db database.DB, chainP RpcServer: func() *rpcserver.Server { return s.rpcServer }, + DisableCheckpoints: cfg.DisableCheckpoints, + NoMiningStateSync: cfg.NoMiningStateSync, + MaxPeers: cfg.MaxPeers, + MaxOrphanTxs: cfg.MaxOrphanTxs, }) if err != nil { return nil, err