Skip to content

Commit

Permalink
blockmanager: Decouple from global config var.
Browse files Browse the repository at this point in the history
This adds configuration parameters used by the block manager to its own
config struct versus directly using the global config variable.
  • Loading branch information
davecgh committed Dec 14, 2020
1 parent 9cb4802 commit 03931c5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
35 changes: 24 additions & 11 deletions blockmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,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
Expand Down Expand Up @@ -361,11 +379,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
Expand Down Expand Up @@ -477,7 +490,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 {
Expand Down Expand Up @@ -589,8 +602,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)
}
}
Expand Down Expand Up @@ -733,7 +746,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()))

Expand Down Expand Up @@ -2458,15 +2471,15 @@ 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),
prevOrphans: make(map[chainhash.Hash][]*orphanBlock),
}

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 {
Expand Down
4 changes: 4 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3248,6 +3248,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
Expand Down

0 comments on commit 03931c5

Please sign in to comment.