Skip to content

Commit

Permalink
refactor(sync): drop storeHeaders helper
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg committed Jun 3, 2024
1 parent edbc71d commit bab7210
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
15 changes: 2 additions & 13 deletions sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func (s *Syncer[H]) processHeaders(
}

// apply cached headers
if err = s.storeHeaders(ctx, headers...); err != nil {
if err := s.store.Append(ctx, headers...); err != nil {
return err
}

Expand Down Expand Up @@ -325,7 +325,7 @@ func (s *Syncer[H]) requestHeaders(
return err
}

if err := s.storeHeaders(ctx, headers...); err != nil {
if err := s.store.Append(ctx, headers...); err != nil {
return err
}

Expand All @@ -334,14 +334,3 @@ func (s *Syncer[H]) requestHeaders(
}
return nil
}

// storeHeaders updates store with new headers and updates current syncStore's Head.
func (s *Syncer[H]) storeHeaders(ctx context.Context, headers ...H) error {
// we don't expect any issues in storing right now, as all headers are now verified.
// So, we should return immediately in case an error appears.
err := s.store.Append(ctx, headers...)
if err != nil {
return err
}
return nil
}
2 changes: 1 addition & 1 deletion sync/sync_head.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (s *Syncer[H]) setSubjectiveHead(ctx context.Context, netHead H) {
// * Allow storing any valid header here in Store
// * Remove ErrNonAdjacent
// * Remove writeHead from the canonical store implementation
err := s.storeHeaders(ctx, netHead)
err := s.store.Append(ctx, netHead)
var nonAdj *header.ErrNonAdjacent
if err != nil && !errors.As(err, &nonAdj) {
// might be a storage error or something else, but we can still try to continue processing netHead
Expand Down

0 comments on commit bab7210

Please sign in to comment.