Skip to content

Remain in optimistic mode if there is no viable head#6071

Merged
ajsutton merged 3 commits intoConsensys:masterfrom
ajsutton:remain-optimistic
Aug 15, 2022
Merged

Remain in optimistic mode if there is no viable head#6071
ajsutton merged 3 commits intoConsensys:masterfrom
ajsutton:remain-optimistic

Conversation

@ajsutton
Copy link
Contributor

PR Description

During optimistic sync it is possible to import blocks that include enough attestations to update the justified checkpoint, but then discover the blocks including those attestations were invalid. This potentially makes the valid chain non-viable because it doesn't (yet) include enough attestations to reach that same justified checkpoint. Note that in this case the justified checkpoint itself is valid and eventually the attestations required to justify will be included in a valid chain.

Until that point though, our node should remain in optimistic mode so that it doesn't create attestations with the source of the updated justified checkpoint which may lead to later being unable to attest without creating a surround vote.

See ethereum/consensus-specs#2955 for more details.

Documentation

  • I thought about documentation and added the doc-change-required label to this PR if updates are required.

Changelog

  • I thought about adding a changelog entry, and added one if I deemed necessary.

// Perform a sanity check that the node is indeed valid to be the head.
if (!nodeIsViableForHead(bestNode) && !bestNode.equals(justifiedNode)) {
throw new RuntimeException("ProtoArray: Best node is not viable for head");
throw new IllegalStateException("ProtoArray: Best node is not viable for head");
Copy link
Contributor

Choose a reason for hiding this comment

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

is it worth adding block root and slot here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like a good idea yeah.

Copy link
Contributor

@rolfyone rolfyone left a comment

Choose a reason for hiding this comment

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

LGTM

newChainHead = generateBlockAtSlot(slot, blockOptions);
addedBlockAndStates.add(newChainHead);
}
final Checkpoint finalizedCheckpoint = newChainHead.getState().getFinalizedCheckpoint();

Check warning

Code scanning / CodeQL

Dereferenced variable may be null

Variable [newChainHead](1) may be null here because of [this](2) assignment.
@ajsutton ajsutton enabled auto-merge (squash) August 15, 2022 00:35
@ajsutton ajsutton merged commit d00391a into Consensys:master Aug 15, 2022
@ajsutton ajsutton deleted the remain-optimistic branch August 15, 2022 00:52
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.

2 participants