Skip to content

Commit bc5064b

Browse files
authored
fix(sync): allow estimation errors (#329)
Another tail determination bug again. When we have both old tail and head, we look into the stored local header timestamps to mitigate estimation errors. However, the assumption was that we could always get the header locally, which is not the case. If the node was offline for long enough, it may be possible that the new estimated tail is above the old head, causing header loading to deadlock on heightSub. The fix here ensures that header loading is only within the current boundaries of the store, and if not, it proceeds with the estimate without checking for errors.
1 parent aa4ae28 commit bc5064b

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

sync/syncer_tail.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,15 @@ func (s *Syncer[H]) renewTail(ctx context.Context, oldTail, head H) (newTail H,
103103
log.Debugw("fetched tail header by height", "height", tailHeight)
104104
}
105105

106-
if err := s.store.Append(ctx, newTail); err != nil {
106+
err = s.store.Append(ctx, newTail)
107+
var errNonAdj *errNonAdjacent
108+
if errors.As(err, &errNonAdj) {
109+
// TODO(@Wondertan): We have to force through the write here
110+
// We don't car if its non-adjacent
111+
// Remove with bsync
112+
err = s.store.Store.Append(ctx, newTail)
113+
}
114+
if err != nil {
107115
return newTail, fmt.Errorf("appending tail header %d: %w", newTail.Height(), err)
108116
}
109117

@@ -235,9 +243,9 @@ func (s *Syncer[H]) findTailHeight(ctx context.Context, oldTail, head H) (uint64
235243
)
236244

237245
newTailHeight := estimatedTailHeight
238-
for {
246+
for newTailHeight > oldTail.Height() && newTailHeight < s.store.Height() {
239247
// store keeps all the headers up to the current head
240-
// to iterate over the headers and find the most accurate tail
248+
// iterate over the headers and find the most accurate tail
241249
newTail, err := s.store.GetByHeight(ctx, newTailHeight)
242250
if err != nil {
243251
return 0, fmt.Errorf(

0 commit comments

Comments
 (0)