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

Send correct state root with finalization event #13842

Merged
merged 1 commit into from
Apr 2, 2024
Merged

Conversation

rkapka
Copy link
Contributor

@rkapka rkapka commented Apr 2, 2024

What type of PR is this?

Bug fix

What does this PR do? Why is it needed?

When sending the finalized event to the event feed we send the root of the received block's state as the finalized state root, but it should be the root of the finalized block's state.

Which issues(s) does this PR fix?

Fixes #13752

@rkapka rkapka added the Ready For Review A pull request ready for code review label Apr 2, 2024
@rkapka rkapka requested a review from a team as a code owner April 2, 2024 06:37
@rkapka rkapka enabled auto-merge April 2, 2024 08:02
e := notifier.ReceivedEvents()[0]
assert.Equal(t, statefeed.FinalizedCheckpoint, int(e.Type))
fc, ok := e.Data.(*ethpbv1.EventFinalizedCheckpoint)
require.Equal(t, true, ok, "event has wrong data type")
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 true then it should be okay, why do you have what seems like an error message here as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

In the require.Equal fails during tests execution, then "event has wrong data type" is displayed. It helps for test debugging.

@@ -443,16 +443,25 @@ func (s *Service) updateFinalizationOnBlock(ctx context.Context, preState, postS

// sendNewFinalizedEvent sends a new finalization checkpoint event over the
// event feed. It needs to be called on the background
func (s *Service) sendNewFinalizedEvent(signed interfaces.ReadOnlySignedBeaconBlock, postState state.BeaconState) {
func (s *Service) sendNewFinalizedEvent(ctx context.Context, postState state.BeaconState) {
isValidPayload := false
s.headLock.RLock()
if s.head != nil {
isValidPayload = s.head.optimistic
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this line has not be modified in this PR, but this case is not tested, and I guess it's quite an important case to test.

isValidPayload := false
s.headLock.RLock()
if s.head != nil {
isValidPayload = s.head.optimistic
}
s.headLock.RUnlock()

blk, err := s.cfg.BeaconDB.Block(ctx, bytesutil.ToBytes32(postState.FinalizedCheckpoint().Root))
if err != nil {
log.WithError(err).Error("Could not retrieve block for finalized checkpoint root. Finalized event will not be emitted")
Copy link
Contributor

Choose a reason for hiding this comment

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

(Not tested.)

return
}
if blk == nil || blk.IsNil() || blk.Block() == nil || blk.Block().IsNil() {
log.WithError(err).Error("Block retrieved for finalized checkpoint root is nil. Finalized event will not be emitted")
Copy link
Contributor

Choose a reason for hiding this comment

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

(Not tested.)

@rkapka rkapka added this pull request to the merge queue Apr 2, 2024
Merged via the queue into develop with commit d1084cb Apr 2, 2024
17 checks passed
@rkapka rkapka deleted the finalized-event-fix branch April 2, 2024 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready For Review A pull request ready for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

finalized_checkpoint event returns incorrect data
3 participants