eth, eth/downloader: better remote head tracking #2861
Merged
+59
−50
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently the downloader has a bad bug: it caches the known head of a remote peer when it connects and never updates that head (inside the downloader). This means that if after the initial sync cycle a new cycle is initiated against a long connected peer, it will start syncing assuming that ooold head, resulting in a ton of duplicate blocks being pulled, imported and ignored.
The solution is to replace the cached head with a callback (:trollface:) that can fetch the actual current head. This is somewhat complicated by the fact that in the eth protocol handler we were a bit liberal in how we set the current head. The PR also fixes this by only ever updating the head header of a remote peer when receiving a propagated block, but even then only setting it to
propagated block - 1
. This is good for a variety of reasons:N
might be valid, then blockN-1
surely is. So by setting the head toN-1
instead ofN
, it is surely a correct hash/difficulty.HEAD - 1
instead of the potentially real head we have a nice side effect that sync cycles are only spawned if there's a gap of two blocks between our chain and a remote chain. This works around races between propagated/announced blocks and sync cycle startups.