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

Make checkpoint sync work when finalized state is transitioned with empty slot(s) #7981

Closed

Conversation

StefanBratanov
Copy link
Contributor

@StefanBratanov StefanBratanov commented Feb 14, 2024

PR Description

Override the consistency check for an AnchorPoint since the finalized state can be transitioned with empty slot(s)

Fixed Issue(s)

fixes #7956

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.

@StefanBratanov StefanBratanov changed the title Make checkpoint sync work when finalized state is transitioned with e… Make checkpoint sync work when finalized state is transitioned with empty slots Feb 14, 2024
@StefanBratanov StefanBratanov changed the title Make checkpoint sync work when finalized state is transitioned with empty slots Make checkpoint sync work when finalized state is transitioned with empty slot Feb 19, 2024
@StefanBratanov StefanBratanov marked this pull request as ready for review February 19, 2024 08:43
@StefanBratanov StefanBratanov changed the title Make checkpoint sync work when finalized state is transitioned with empty slot Make checkpoint sync work when finalized state is transitioned with empty slot(s) Feb 19, 2024
Copy link
Contributor

@zilm13 zilm13 left a comment

Choose a reason for hiding this comment

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

I like the way you've kept the check in Summary while avoiding it in some cases in AnchorPoint but I still have a lot of doubts on 2 major points of this change:

  • Could weakening of AnchorPoint creation checks introduce a bugs when AnchorPoint is created not from checkpoint sync it has not failed, but it's a bad AnchorPoint
  • How transitioned AnchorPoint could affect its consumers when we start Teku

While from quick check I don't see any issues with 1st, 2nd could be definitely an issue in many places. I've commented one case in the Store, another one for example is initalization of the Store:

    // Track latest finalized block
    this.finalizedAnchor = finalizedAnchor;
    this.maybeEpochStates = maybeEpochStates;
    states.cache(finalizedAnchor.getRoot(), finalizedAnchor);

This way we are putting incorrect cache in states cache which is widely used. And there are a lot of other places where finalizedAnchor spreads, we should check them all and decide how to handle it. Maybe this kind of Anchor will need extra identification so we could avoid polluting some things like this state cache with it.

protected void verifyStateAndBlockConsistency() {
if (state.getSlot().isGreaterThan(blockSummary.getSlot())) {
// the finalized state is transitioned with empty slot(s)
checkArgument(
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd also add verification for state.block_roots (block slot - state slot interval) and state.state_roots (block slot)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added those checks, made it bit more complex, since don't have access to spec in super class.

Optional.of(
StateAndBlockSummary.create(
finalizedAnchor.getBlockSummary(), finalizedAnchor.getState())));
return SafeFuture.completedFuture(Optional.of(finalizedAnchor));
Copy link
Contributor

Choose a reason for hiding this comment

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

If it's transitioned anchor, it will be incorrect state for requested block_root

Copy link
Contributor Author

@StefanBratanov StefanBratanov Feb 19, 2024

Choose a reason for hiding this comment

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

AnchorPoint.getStateRoot() still returns the state_root of the finalzied block (last block header), not the state

Copy link
Contributor

Choose a reason for hiding this comment

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

Method private SafeFuture<Optional<StateAndBlockSummary>> getOrRegenerateBlockAndState( final Bytes32 blockRoot) should return state at block with blockRoot, transitioned state is not this state. This method is used by a lot of different consumers, it could be an issue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah AnchorPoint.getStateRoot() returns the state_root of the blockSummary, so would be the state associated with the block

Copy link
Contributor Author

@StefanBratanov StefanBratanov Feb 20, 2024

Choose a reason for hiding this comment

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

In any case, StateAndBlockSummary.create(finalizedAnchor.getBlockSummary(), finalizedAnchor.getState()) is same as just returning finalizedAnchor

Copy link
Contributor

Choose a reason for hiding this comment

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

On startup we definitely create the Store with the anchor coming from the checkpoint URL. So it is possible that we could return it from here...

@StefanBratanov
Copy link
Contributor Author

Closing this in favour of #8221

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.

Checkpoint sync is not working when finalized state is transitioned with empty slots
3 participants