From de1ecf2d60f9728541a040e5da28b706d67347f7 Mon Sep 17 00:00:00 2001 From: Potuz Date: Mon, 25 Jul 2022 14:05:32 -0300 Subject: [PATCH] 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 --- beacon-chain/blockchain/chain_info.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/beacon-chain/blockchain/chain_info.go b/beacon-chain/blockchain/chain_info.go index 1e38895bc4..1c8e38c055 100644 --- a/beacon-chain/blockchain/chain_info.go +++ b/beacon-chain/blockchain/chain_info.go @@ -343,8 +343,14 @@ func (s *Service) IsOptimisticForRoot(ctx context.Context, root [32]byte) (bool, 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 { - return false, nil + return !isCanonical, nil } // 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 { 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 }