@@ -10,6 +10,11 @@ import (
10
10
"github.com/celestiaorg/go-header"
11
11
)
12
12
13
+ // TODO:
14
+ // * Refactor tests
15
+ // * Write tests for estimation
16
+ // * Ensure sync always happen on start
17
+
13
18
// subjectiveTail returns the current Tail header.
14
19
// Lazily fetching it if it doesn't exist locally or moving it to a different height.
15
20
// Moving is done if either parameters are changed or tail moved outside a pruning window.
@@ -30,11 +35,10 @@ func (s *Syncer[H]) subjectiveTail(ctx context.Context, head H) (H, error) {
30
35
fetched = true
31
36
}
32
37
} else if tailHeight , outdated := s .isTailHeightOutdated (tail ); outdated {
33
- // hack for the case with tailHeight > store.Height avoiding heightSub
34
- storeCtx , cancel := context .WithTimeout (ctx , time .Second )
35
- tail , err = s .store .GetByHeight (storeCtx , tailHeight )
36
- cancel ()
37
- if err != nil {
38
+ if tailHeight <= s .store .Height () {
39
+ tail , err = s .store .GetByHeight (ctx , tailHeight )
40
+ }
41
+ if err != nil || tailHeight != tail .Height () {
38
42
tail , err = s .getter .GetByHeight (ctx , tailHeight )
39
43
if err != nil {
40
44
return tail , fmt .Errorf ("getting SyncFromHeight tail(%d): %w" , tailHeight , err )
@@ -52,7 +56,7 @@ func (s *Syncer[H]) subjectiveTail(ctx context.Context, head H) (H, error) {
52
56
fetched = true
53
57
} else {
54
58
// have a known Tail - estimate basing on it.
55
- cutoffTime := head .Time ().UTC ().Add (- s .Params .TrustingPeriod )
59
+ cutoffTime := head .Time ().UTC ().Add (- s .Params .PruningWindow )
56
60
diff := cutoffTime .Sub (tail .Time ().UTC ())
57
61
if diff <= 0 {
58
62
// current tail is relevant as is
0 commit comments