Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

peer, main, netsync, blockchain: parallel block downloads #2226

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
netsync, main: add ConnectedPeers to Manager
ConnectedPeers returns all the currently connected peers and any new
peer that's additionally connected through the returned channel.  This
method is required for query.Workmanager as it needs ot receive peers
that it can request blocks from.
  • Loading branch information
kcalvinalvin committed Dec 9, 2024
commit 0a9f2072d333a51da43a4189daf9adcc4f2e27db
3 changes: 3 additions & 0 deletions netsync/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ type Config struct {
MaxPeers int

FeeEstimator *mempool.FeeEstimator

// ConnectedPeers returns all the currently connected peers.
ConnectedPeers func() []*peer.Peer
}
25 changes: 25 additions & 0 deletions netsync/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ type SyncManager struct {
queuedBlocks map[chainhash.Hash]*blockMsg
queuedBlocksPrevHash map[chainhash.Hash]chainhash.Hash
peerSubscribers []*peerSubscription
connectedPeers func() []*peerpkg.Peer

// An optional fee estimator.
feeEstimator *mempool.FeeEstimator
Expand Down Expand Up @@ -1919,6 +1920,29 @@ type peerSubscription struct {
cancel <-chan struct{}
}

// ConnectedPeers returns all the currently connected peers to the channel
// and then any additional new peers on connect.
func (sm *SyncManager) ConnectedPeers() (<-chan query.Peer, func(), error) {
peers := sm.connectedPeers()
peerChan := make(chan query.Peer, len(peers))

for _, peer := range peers {
if sm.isSyncCandidate(peer) {
peerChan <- peer
}
}

cancelChan := make(chan struct{})
sm.peerSubscribers = append(sm.peerSubscribers, &peerSubscription{
peers: peerChan,
cancel: cancelChan,
})

return peerChan, func() {
close(cancelChan)
}, nil
}

// New constructs a new SyncManager. Use Start to begin processing asynchronous
// block, tx, and inv updates.
func New(config *Config) (*SyncManager, error) {
Expand All @@ -1938,6 +1962,7 @@ func New(config *Config) (*SyncManager, error) {
queuedBlocks: make(map[chainhash.Hash]*blockMsg),
queuedBlocksPrevHash: make(map[chainhash.Hash]chainhash.Hash),
feeEstimator: config.FeeEstimator,
connectedPeers: config.ConnectedPeers,
}

best := sm.chain.BestSnapshot()
Expand Down
1 change: 1 addition & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2940,6 +2940,7 @@ func newServer(listenAddrs, agentBlacklist, agentWhitelist []string,
DisableCheckpoints: cfg.DisableCheckpoints,
MaxPeers: cfg.MaxPeers,
FeeEstimator: s.feeEstimator,
ConnectedPeers: s.ConnectedPeers,
})
if err != nil {
return nil, err
Expand Down