decred / dcrwallet

A secure Decred wallet daemon written in Go (golang).
https://decred.org
ISC License
216 stars 155 forks source link

spv: Drop unsynced peers earlier #2299

Closed matheusd closed 10 months ago

matheusd commented 10 months ago

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 commented 10 months ago

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 commented 10 months ago

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).