non-canonical IsOptimistic check (#11088)

When requesting with IsOptimistic for a root which is non-canonical and
historic, we should check if it is canonical before returning false.

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
This commit is contained in:
Potuz 2022-07-25 14:05:32 -03:00 committed by GitHub
parent 7aee67af90
commit de1ecf2d60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -343,8 +343,14 @@ func (s *Service) IsOptimisticForRoot(ctx context.Context, root [32]byte) (bool,
return true, nil return true, nil
} }
// Historical non-canonical blocks here are returned as optimistic for safety.
isCanonical, err := s.IsCanonical(ctx, root)
if err != nil {
return false, err
}
if slots.ToEpoch(ss.Slot)+1 < validatedCheckpoint.Epoch { if slots.ToEpoch(ss.Slot)+1 < validatedCheckpoint.Epoch {
return false, nil return !isCanonical, nil
} }
// Checkpoint root could be zeros before the first finalized epoch. Use genesis root if the case. // Checkpoint root could be zeros before the first finalized epoch. Use genesis root if the case.
@ -359,13 +365,6 @@ func (s *Service) IsOptimisticForRoot(ctx context.Context, root [32]byte) (bool,
if ss.Slot > lastValidated.Slot { if ss.Slot > lastValidated.Slot {
return true, nil return true, nil
} }
isCanonical, err := s.IsCanonical(ctx, root)
if err != nil {
return false, err
}
// Historical non-canonical blocks here are returned as optimistic for safety.
return !isCanonical, nil return !isCanonical, nil
} }