Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg committed May 31, 2024
1 parent ea28e37 commit 6ee77e4
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 30 deletions.
15 changes: 0 additions & 15 deletions interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package header
import (
"context"
"errors"
"fmt"

pubsub "github.com/libp2p/go-libp2p-pubsub"
)
Expand Down Expand Up @@ -59,16 +58,6 @@ var (
ErrHeadersLimitExceeded = errors.New("header/p2p: header limit per 1 request exceeded")
)

// ErrNonAdjacent is returned when Store is appended with a header not adjacent to the stored head.
type ErrNonAdjacent struct {
Head uint64
Attempted uint64
}

func (ena *ErrNonAdjacent) Error() string {
return fmt.Sprintf("header/store: non-adjacent: head %d, attempted %d", ena.Head, ena.Attempted)
}

// Store encompasses the behavior necessary to store and retrieve Headers
// from a node's local storage.
type Store[H Header[H]] interface {
Expand All @@ -88,10 +77,6 @@ type Store[H Header[H]] interface {
HasAt(context.Context, uint64) bool

// Append stores and verifies the given Header(s).
// It requires them to be adjacent and in ascending order,
// as it applies them contiguously on top of the current head height.
// It returns the amount of successfully applied headers,
// so caller can understand what given header was invalid, if any.
Append(context.Context, ...H) error

// GetRange returns the range [from:to).
Expand Down
11 changes: 2 additions & 9 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,6 @@ func (s *Store[H]) Append(ctx context.Context, headers ...H) error {
// collect valid headers
verified := make([]H, 0, lh)
for i, h := range headers {
// currently store requires all headers to be appended sequentially and adjacently
// TODO(@Wondertan): Further pruning friendly Store design should reevaluate this requirement
if h.Height() != head.Height()+1 {
return &header.ErrNonAdjacent{
Head: head.Height(),
Attempted: h.Height(),
}
}

err = head.Verify(h)
if err != nil {
Expand All @@ -358,7 +350,8 @@ func (s *Store[H]) Append(ctx context.Context, headers ...H) error {
// otherwise, stop the loop and apply headers appeared to be valid
break
}
verified, head = append(verified, h), h
verified = append(verified, h)
head = h
}

onWrite := func() {
Expand Down
7 changes: 1 addition & 6 deletions sync/sync_head.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,8 @@ func (s *Syncer[H]) subjectiveHead(ctx context.Context) (H, error) {

// setSubjectiveHead takes already validated head and sets it as the new sync target.
func (s *Syncer[H]) setSubjectiveHead(ctx context.Context, netHead H) {
// TODO(@Wondertan): Right now, we can only store adjacent headers, instead we should:
// * Allow storing any valid header here in Store
// * Remove ErrNonAdjacent
// * Remove writeHead from the canonical store implementation
err := s.storeHeaders(ctx, netHead)
var nonAdj *header.ErrNonAdjacent
if err != nil && !errors.As(err, &nonAdj) {
if err != nil {
// might be a storage error or something else, but we can still try to continue processing netHead
log.Errorw("storing new network header",
"height", netHead.Height(),
Expand Down

0 comments on commit 6ee77e4

Please sign in to comment.