-
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
Use headstate for recent checkpoints #13746
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,17 +18,63 @@ import ( | |
"github.com/prysmaticlabs/prysm/v5/time/slots" | ||
) | ||
|
||
// getAttPreState retrieves the att pre state by either from the cache or the DB. | ||
func (s *Service) getAttPreState(ctx context.Context, c *ethpb.Checkpoint) (state.ReadOnlyBeaconState, error) { | ||
// If the attestation is recent and canonical we can use the head state to compute the shuffling. | ||
func (s *Service) getRecentPreState(ctx context.Context, c *ethpb.Checkpoint) state.ReadOnlyBeaconState { | ||
headEpoch := slots.ToEpoch(s.HeadSlot()) | ||
if c.Epoch < headEpoch { | ||
return nil | ||
} | ||
if !s.cfg.ForkChoiceStore.IsCanonical([32]byte(c.Root)) { | ||
return nil | ||
} | ||
if c.Epoch == headEpoch { | ||
targetSlot, err := s.cfg.ForkChoiceStore.Slot([32]byte(c.Root)) | ||
if err == nil && slots.ToEpoch(targetSlot)+1 >= headEpoch { | ||
if s.cfg.ForkChoiceStore.IsCanonical([32]byte(c.Root)) { | ||
return s.HeadStateReadOnly(ctx) | ||
} | ||
if err != nil { | ||
return nil | ||
} | ||
if slots.ToEpoch(targetSlot)+1 < headEpoch { | ||
return nil | ||
} | ||
st, err := s.HeadStateReadOnly(ctx) | ||
if err != nil { | ||
return nil | ||
} | ||
return st | ||
} | ||
slot, err := slots.EpochStart(c.Epoch) | ||
if err != nil { | ||
return nil | ||
} | ||
// Try if we have already set the checkpoint cache | ||
epochKey := strconv.FormatUint(uint64(c.Epoch), 10 /* base 10 */) | ||
lock := async.NewMultilock(string(c.Root) + epochKey) | ||
lock.Lock() | ||
defer lock.Unlock() | ||
cachedState, err := s.checkpointStateCache.StateByCheckpoint(c) | ||
if err != nil { | ||
return nil | ||
} | ||
if cachedState != nil && !cachedState.IsNil() { | ||
return cachedState | ||
} | ||
st, err := s.HeadState(ctx) | ||
if err != nil { | ||
return nil | ||
} | ||
st, err = transition.ProcessSlotsUsingNextSlotCache(ctx, st, c.Root, slot) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am worried about advancing slots this way, this becomes expensive. why can't we just return the read only head state here ? If slot 0 is missed, the head state should still be able to verify an attestation from slot 31 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the attestation is not from slot 31, it's from slot 0, you need to check that the attester is in the right committee |
||
if err != nil { | ||
return nil | ||
} | ||
if err := s.checkpointStateCache.AddCheckpointState(c, st); err != nil { | ||
return nil | ||
} | ||
return st | ||
} | ||
|
||
// getAttPreState retrieves the att pre state by either from the cache or the DB. | ||
func (s *Service) getAttPreState(ctx context.Context, c *ethpb.Checkpoint) (state.ReadOnlyBeaconState, error) { | ||
// If the attestation is recent and canonical we can use the head state to compute the shuffling. | ||
if st := s.getRecentPreState(ctx, c); st != nil { | ||
return st, nil | ||
} | ||
// Use a multilock to allow scoped holding of a mutex by a checkpoint root + epoch | ||
// allowing us to behave smarter in terms of how this function is used concurrently. | ||
|
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.
you have to move it up before you fetch the head state.