Skip to content

Commit

Permalink
review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg committed Nov 5, 2024
1 parent f9d2daf commit 6d035aa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
21 changes: 11 additions & 10 deletions sync/sync_head.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,22 +196,23 @@ func (s *Syncer[H]) verify(ctx context.Context, newHead H) (bool, error) {
return false, err
}

// verifySkipping will try to find such headers in range (subjHead, networkHeader)
// that can be verified by subjHead, literally:
//
// header.Verify(subjHead, candidate)
//
// and also such headers can verify `networkHeader`, literally
//
// header.Verify(candidate, networkHeader)
// verifySkipping performs a bifurcated header verification process such that
// it tries to find a header (or several headers if necessary)
// between the networkHead and the subjectiveHead such that non-adjacent
// (or in the worst case adjacent) verification passes and the networkHead
// can be verified as a valid sync target against the syncer's subjectiveHead.
//
// When such candidates cannot be found [NewValidatorSetCantBeTrustedError] will be returned.
func (s *Syncer[H]) verifySkipping(ctx context.Context, subjHead, networkHeader H) error {
subjHeight := subjHead.Height()

diff := networkHeader.Height() - subjHeight
if diff <= 0 {
panic(fmt.Sprintf("implementation bug: diff is %d", diff))
panic(fmt.Sprintf("implementation bug: diff %d, subjective height %d (%X), network height %d (%X)",
diff,
subjHeight, subjHead.Hash(),
networkHeader.Height(), networkHeader.Hash(),
))
}

for diff > 1 {
Expand All @@ -230,7 +231,7 @@ func (s *Syncer[H]) verifySkipping(ctx context.Context, subjHead, networkHeader

// candidate was validated properly, update subjHead.
subjHead = candidateHeader
// TODO: s.setSubjectiveHead(ctx, subjHead)
s.setSubjectiveHead(ctx, subjHead)

if err := header.Verify(subjHead, networkHeader); err == nil {
// network head validate properly, return success.
Expand Down
2 changes: 1 addition & 1 deletion sync/sync_head_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func TestSyncer_verifySkippingCannotVerify(t *testing.T) {

err = syncer.verifySkipping(ctx, subjHead, headers[total-1])
var verErr *NewValidatorSetCantBeTrustedError
assert.ErrorAs(t, err, &verErr, "%T", err)
assert.ErrorIs(t, err, verErr, "%T", err)
}

type wrappedGetter struct {
Expand Down

0 comments on commit 6d035aa

Please sign in to comment.