Skip to content

Introduce HeightMonitor to track chain height relative to peers#288

Merged
rustaceanrob merged 2 commits intomasterfrom
height-tracker-2-7
Feb 9, 2025
Merged

Introduce HeightMonitor to track chain height relative to peers#288
rustaceanrob merged 2 commits intomasterfrom
height-tracker-2-7

Conversation

@rustaceanrob
Copy link
Collaborator

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 PeerMap and Chain previously communicated via the Node, but there is no reason they can't share some common memory behind an Arc and Mutex.

Here I introduce a structure that keeps track of a peer and their height, and allows for the Chain to get the current maximum. I use the tokio::sync::Mutex to wrap this type, so the lock may be potentially held across await points 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

@rustaceanrob rustaceanrob marked this pull request as ready for review February 8, 2025 20:24
@rustaceanrob
Copy link
Collaborator Author

I have a machine running this patch on Testnet4 and multiple reorgs have been handled properly + the node is in sync with the rest of the network. Going to self-ACK since this is a massive improvement in code quality with not much functional change imo.

@rustaceanrob rustaceanrob merged commit bbe6b2d into master Feb 9, 2025
14 checks passed
@rustaceanrob rustaceanrob deleted the height-tracker-2-7 branch February 9, 2025 22:50
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.

1 participant