Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

When picking fast sync pivot block, use the peer with the best total difficulty #899

Merged
merged 3 commits into from
Feb 19, 2019

Conversation

ajsutton
Copy link
Contributor

PR description

When picking the fast sync pivot block, ensure the peer we consider best is evaluated on total difficulty, instead of chain height. Otherwise on MainNet we tend to pick an ETC node and pivot block because it has a greater height even though it has lower total difficulty.

@@ -33,6 +33,9 @@
public static final Comparator<EthPeer> CHAIN_HEIGHT =
Comparator.comparing(((final EthPeer p) -> p.chainState().getEstimatedHeight()));

private static final Comparator<EthPeer> HIGHEST_TOTAL_DIFFICULTY_PEER =
TOTAL_DIFFICULTY.thenComparing(CHAIN_HEIGHT);
Copy link
Contributor

@shemnon shemnon Feb 19, 2019

Choose a reason for hiding this comment

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

Apart from total difficulty (which is the only thing the yellow paper defines) do we know what other clients do to distinguish heavier chains? Chain height is a quick win but Ghost also originally defined ommers as adding to the difficulty (but that's not in the yellow paper). Section 10 implies chain height but it doesn't make it into the formal definition equations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only thing that matters is total difficulty - if two chains have the same difficulty then clients will generally stick with whichever one they had first (ie equal difficulty does not trigger a re-org) although I have a vague memory of Geth including randomness in there for some reason.

Since Byzantium the difficulty of a block is increased if it contains any ommers.

@ajsutton ajsutton merged commit dd8d338 into PegaSysEng:master Feb 19, 2019
@ajsutton ajsutton deleted the best-total-difficulty branch February 19, 2019 20:32
rain-on pushed a commit to rain-on/pantheon that referenced this pull request Feb 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants