-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Conversation
There was a problem hiding this 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
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 |
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 := ðpb.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 | ||
} |
There was a problem hiding this comment.
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?
|
||
_, err = c.IsOptimisticForRoot(ctx, optimisticRoot) | ||
require.ErrorContains(t, "nil summary returned from the DB", err) | ||
|
||
require.NoError(t, beaconDB.SaveStateSummary(context.Background(), ðpb.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(), ðpb.StateSummary{Root: validatedRoot[:], Slot: 9})) | ||
cp := ðpb.Checkpoint{ | ||
Epoch: 1, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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