-
Notifications
You must be signed in to change notification settings - Fork 26
feat(sync): maintain tail #265
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
Changes from all commits
115af45
c698d74
f87e8b4
f97fe87
9faaccd
96b450b
d37c42b
70f65de
df446ed
5d59427
d83e15d
cb71de0
eb96e98
88e6f69
a99d7ac
630ffa3
31d7e13
6613081
8dec451
2931553
0b91ae8
b413137
86cd2fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,24 +48,41 @@ func (s *syncStore[H]) Append(ctx context.Context, headers ...H) error { | |
} | ||
|
||
head, err := s.Head(ctx) | ||
if err != nil && !errors.Is(err, context.Canceled) { | ||
panic(err) | ||
if errors.Is(err, header.ErrEmptyStore) { | ||
// short-circuit for an initialization path | ||
if err := s.Store.Append(ctx, headers...); err != nil { | ||
return err | ||
} | ||
|
||
s.head.Store(&headers[len(headers)-1]) | ||
return nil | ||
} | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, h := range headers { | ||
if h.Height() != head.Height()+1 { | ||
return &errNonAdjacent{ | ||
Head: head.Height(), | ||
Attempted: h.Height(), | ||
// TODO(@Wondertan): As store evolved, certain invariants it had were removed. | ||
// However, Syncer has yet to be refactored to not assume those invariants and until then | ||
// this method is a shim that allows using store with old assumptions. | ||
// To be reworked by bsync. | ||
if headers[0].Height() >= head.Height() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we extract into separate func here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, we could There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't see much value from doing this tbh, so ignoring |
||
for _, h := range headers { | ||
if h.Height() != head.Height()+1 { | ||
return &errNonAdjacent{ | ||
Head: head.Height(), | ||
Attempted: h.Height(), | ||
} | ||
} | ||
|
||
head = h | ||
} | ||
head = h | ||
|
||
s.head.Store(&head) | ||
} | ||
|
||
if err := s.Store.Append(ctx, headers...); err != nil { | ||
return err | ||
} | ||
|
||
s.head.Store(&headers[len(headers)-1]) | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay so this will make it so that we do not have to manually initialise the store via nodebuilder in celestia-node in order to kick off header syncing - syncer will do it for us here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's was the purpose behind doing #243