Skip to content
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

feat(sync): bifurcation for syncTarget #219

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
9 changes: 7 additions & 2 deletions sync/sync_head.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (s *Syncer[H]) incomingNetworkHead(ctx context.Context, head H) error {
}

// verify verifies given network head candidate.
func (s *Syncer[H]) verify(ctx context.Context, newHead H) (bool, error) {
func (s *Syncer[H]) verify(ctx context.Context, newHead H) (isSoft bool, _ error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the point of naming the return vals here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To say exactly what this bool means. It's not clear (at all) from doc-comment. I'm fine to add a line to doc-comment and leave result param unnamed.

sbjHead, err := s.subjectiveHead(ctx)
if err != nil {
log.Errorw("getting subjective head during validation", "err", err)
Expand Down Expand Up @@ -203,6 +203,8 @@ func (s *Syncer[H]) verify(ctx context.Context, newHead H) (bool, error) {
// subjectiveHead.
// A non-nil error is returned when networkHead can't be verified.
func (s *Syncer[H]) verifyBifurcating(ctx context.Context, subjHead, networkHead H) error {
log.Warnw("sync: header bifurcation started", "height", networkHead.Height(), "hash", networkHead.Hash().String())
cristaloleg marked this conversation as resolved.
Show resolved Hide resolved

subjHeight := subjHead.Height()

cristaloleg marked this conversation as resolved.
Show resolved Hide resolved
diff := networkHead.Height() - subjHeight
Expand Down Expand Up @@ -238,7 +240,10 @@ func (s *Syncer[H]) verifyBifurcating(ctx context.Context, subjHead, networkHead
s.metrics.failedBifurcation(ctx, int64(networkHead.Height()), networkHead.Hash().String())
log.Warnw("sync: header validation against subjHead", "height", networkHead.Height(), "hash", networkHead.Hash().String())
cristaloleg marked this conversation as resolved.
Show resolved Hide resolved

return fmt.Errorf("sync: header validation against subjHead height:%d hash:%x", networkHead.Height(), networkHead.Hash().String())
return &header.VerifyError{
Reason: fmt.Errorf("sync: header validation against subjHead height:%d hash:%x", networkHead.Height(), networkHead.Hash().String()),
cristaloleg marked this conversation as resolved.
Show resolved Hide resolved
SoftFailure: false,
}
}

// isExpired checks if header is expired against trusting period.
Expand Down
Loading