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

eth/protocols/eth: add JustifiedNumber into StatusPacket #2702

Conversation

buddh0
Copy link
Collaborator

@buddh0 buddh0 commented Sep 12, 2024

Description

eth/protocols/eth: add JustifiedNumber into StatusPacket

Rationale

Until now, when a node attempts to select a peer for full synchronization, it only compares peers based on td (total difficulty). However, the correct logic should follow the approach in ReorgNeededWithFastFinality:

1. First, compare the justifiedNumber.
2. If the justifiedNumber is equal, then compare td.

Relying solely on td can cause a node to select the wrong peer for synchronization. In certain edge cases, this can split the network and cause the chain to stall, as was observed in the chapel network.
To resolve this issue:

1. Introduce an optional JustifiedNumber in the StatusPacket.
2. When updating a peer's head, prioritize the comparison of justifiedNumber before td.

To avoid creating a new version of the Ethereum protocol (e.g., eth70), the fix can be implemented in three phases:

1. Add the optional JustifiedNumber in the client.
2. After a hard fork, once all nodes are able to parse the updated StatusPacket, pass the JustifiedNumber in the StatusMsg during a maintenance release.
3. After a subsequent hard fork, enforce the use of JustifiedNumber in StatusMsg, and reject messages without it in a future maintenance release.

This pull request (PR) covers only the first phase. The following two phases are ready, requiring just one or two lines of code to be uncommented.

Example

add an example CLI or API response...

Changes

Notable changes:

  • add each change in a bullet point here
  • ...

@buddh0 buddh0 force-pushed the select_sync_peer_use_justified_than_td branch 8 times, most recently from cbb9f3e to b4baf2d Compare September 13, 2024 07:50
@buddh0 buddh0 force-pushed the select_sync_peer_use_justified_than_td branch from b4baf2d to 093d504 Compare September 13, 2024 07:51
@buddh0 buddh0 marked this pull request as ready for review September 13, 2024 08:41
Comment on lines +159 to +161
// Head constructs a function to retrieve a peer's current head hash,
// justifiedNumber and total difficulty.
func (dlp *downloadTesterPeer) Head() (common.Hash, *uint64, *big.Int) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bug, should changed

@buddh0 buddh0 closed this Nov 7, 2024
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.

4 participants