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

spv: Drop unsynced peers earlier #2299

Merged
merged 3 commits into from
Nov 16, 2023

Conversation

matheusd
Copy link
Member

This disconnects SPV peers ealier in the peer startup sequence, before they are added to the remotes map. This improves the SPV loop by ensuring peers that are too much behind the wallet's tip are not given a chance of being selected for any operations and a new peer connection is attempted.

It also adds tracking of the last returned header per peer, which will be useful in future refactorings.

@jrick
Copy link
Member

jrick commented Nov 16, 2023

Not sure about this. We already do set the required peer height with lp.RequirePeerHeight called early on in the spv syncer's Run method and each time the main chain is extended. This results in an announced height check in lp.ConnectOutbound and will cause that to error before the syncer ever adds the remote peer to the remotes map.

(And the height check at the top of startupSync looks completely superfluous.)

@matheusd
Copy link
Member Author

Fair point. I'll drop the check after ConnectOutbound (as it is superflous as you point out) and add a missing check to update RequirePeerHeight.

I'll also add a commit that drops peers that have been left behind after processing a batch of headers (to ensure if we overtake a peer, than that peer is disconnected in order to make room for a new, possibly more updated peer).

@matheusd matheusd force-pushed the drop-unsynced-peers-earlier branch from a6e434f to 7d54640 Compare November 16, 2023 15:20
This adds tracking of the last height of any header returned by a remote
peer.

This will be used in the future to determine whether the peer correctly
sent all headers it should have.
The p2p package already ensures peers are dropped if they are behind the
wallet's main chain tip height, therefore this check is redundant in the
spv syncer.
@matheusd matheusd force-pushed the drop-unsynced-peers-earlier branch 2 times, most recently from 709cc35 to 31b9f47 Compare November 16, 2023 15:33
spv/sync.go Outdated Show resolved Hide resolved
This adds a function to force disconnection from peers that have been
overtaken by the wallet.

During initial sync, we might connect to a peer that is useful during
the earlier block ranges but which is overtaken due to the wallet
connecting to peers with more up to date blocks.

After initial sync completes and the sendheaders message is sent, the
remote peers should be announcing new blocks via headers message. If
a particular peer don't send any headers after the wallet has received
several new headers, it probably means that peer has poor connectivity
to the network and should be disconnected in favor of attempting to find
a better peer.
@matheusd matheusd force-pushed the drop-unsynced-peers-earlier branch from 31b9f47 to 6f510a5 Compare November 16, 2023 16:58
@jrick jrick merged commit 6f510a5 into decred:master Nov 16, 2023
2 checks passed
@matheusd matheusd deleted the drop-unsynced-peers-earlier branch November 16, 2023 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants