Introduce HeightMonitor to track chain height relative to peers#288
Merged
rustaceanrob merged 2 commits intomasterfrom Feb 9, 2025
Merged
Introduce HeightMonitor to track chain height relative to peers#288rustaceanrob merged 2 commits intomasterfrom
HeightMonitor to track chain height relative to peers#288rustaceanrob merged 2 commits intomasterfrom
Conversation
627bf9c to
6b3cf13
Compare
Collaborator
Author
|
I have a machine running this patch on |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The previous design of determining if the chain is synced is a horrible artifact of moving from a proof-of-concept to an actual library. The
PeerMapandChainpreviously communicated via theNode, but there is no reason they can't share some common memory behind anArcandMutex.Here I introduce a structure that keeps track of a peer and their height, and allows for the
Chainto get the current maximum. I use thetokio::sync::Mutexto wrap this type, so the lock may be potentially held acrossawaitpoints if necessary.With this design, if a peer tries to grief the node by sending a ridiculous height, but cannot send the headers to reach that height, the node will disconnect from them and the height the malicious peer reported will no longer be used to determine if the node is synced.
cc @nyonson