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

Recover State Summary Correctly #12214

Merged
merged 3 commits into from
Mar 30, 2023
Merged

Recover State Summary Correctly #12214

merged 3 commits into from
Mar 30, 2023

Conversation

nisdas
Copy link
Member

@nisdas nisdas commented Mar 30, 2023

What type of PR is this?

Bug Fix

What does this PR do? Why is it needed?

In the event we have the referenced block in our database but not its summary, we fallback and correctly recover it.

Which issues(s) does this PR fix?

Fixes #12208

Other notes for review

@nisdas nisdas added Bug Something isn't working Priority: High High priority item labels Mar 30, 2023
@nisdas nisdas requested a review from a team as a code owner March 30, 2023 05:55
terencechain
terencechain previously approved these changes Mar 30, 2023
Copy link
Member

@terencechain terencechain left a comment

Choose a reason for hiding this comment

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

Might worth a metric

@nisdas
Copy link
Member Author

nisdas commented Mar 30, 2023

We don't have the metric in stategen, which is why I havent added in anything new. Basically just followed how we handled it in stategen

Comment on lines +486 to +499
func (s *Service) recoverStateSummary(ctx context.Context, blockRoot [32]byte) (*ethpb.StateSummary, error) {
if s.cfg.BeaconDB.HasBlock(ctx, blockRoot) {
b, err := s.cfg.BeaconDB.Block(ctx, blockRoot)
if err != nil {
return nil, err
}
summary := &ethpb.StateSummary{Slot: b.Block().Slot(), Root: blockRoot[:]}
if err := s.cfg.BeaconDB.SaveStateSummary(ctx, summary); err != nil {
return nil, err
}
return summary, nil
}
return nil, errBlockDoesNotExist
}
Copy link
Member

Choose a reason for hiding this comment

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

Want to add a test for this method?

Comment on lines 520 to 526

_, err = c.IsOptimisticForRoot(ctx, optimisticRoot)
require.ErrorContains(t, "nil summary returned from the DB", err)

require.NoError(t, beaconDB.SaveStateSummary(context.Background(), &ethpb.StateSummary{Root: optimisticRoot[:], Slot: 11}))
optimistic, err := c.IsOptimisticForRoot(ctx, optimisticRoot)
require.NoError(t, err)
require.Equal(t, true, optimistic)

require.NoError(t, beaconDB.SaveStateSummary(context.Background(), &ethpb.StateSummary{Root: validatedRoot[:], Slot: 9}))
cp := &ethpb.Checkpoint{
Epoch: 1,
Copy link
Member

Choose a reason for hiding this comment

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

Could you add some kind of regression test? This might be the test already, but you can assert that = BeaconDB.StateSummary returns nil and returns non-nil after calling IsOptimisticForRoot

Copy link
Member

@prestonvanloon prestonvanloon left a comment

Choose a reason for hiding this comment

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

LGTM

@prestonvanloon prestonvanloon merged commit 5ecebbe into develop Mar 30, 2023
@delete-merged-branch delete-merged-branch bot deleted the fixSummaryRecovery branch March 30, 2023 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Priority: High High priority item
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Beacon api get header error: nil summary returned from the DB
3 participants