@@ -14,7 +14,8 @@ import (
14
14
// * Flush
15
15
16
16
// subjectiveTail returns the current Tail header.
17
- // It ensures the Tail is actual and valid according to Parameters.
17
+ // Lazily fetching it if it doesn't exist locally or moving it to a different height.
18
+ // Moving is done if either parameters are changed or tail moved outside a pruning window.
18
19
func (s * Syncer [H ]) subjectiveTail (ctx context.Context , head H ) (H , error ) {
19
20
tail , err := s .store .Tail (ctx )
20
21
if err != nil && ! errors .Is (err , header .ErrEmptyStore ) {
@@ -32,7 +33,7 @@ func (s *Syncer[H]) subjectiveTail(ctx context.Context, head H) (H, error) {
32
33
fetched = true
33
34
}
34
35
} else if tailHeight , outdated := s .isTailHeightOutdated (tail ); outdated {
35
- // hack for the case with necessary tail in the future avoiding heightSub
36
+ // hack for the case with tailHeight > store.Height avoiding heightSub
36
37
storeCtx , cancel := context .WithTimeout (ctx , time .Second )
37
38
tail , err = s .store .GetByHeight (storeCtx , tailHeight )
38
39
cancel ()
@@ -95,6 +96,9 @@ func (s *Syncer[H]) subjectiveTail(ctx context.Context, head H) (H, error) {
95
96
return tail , nil
96
97
}
97
98
99
+ // moveTail moves the Tail to be the given header.
100
+ // It will prune the store if the new Tail is higher than the old one or
101
+ // sync up if the new Tail is lower than the old one.
98
102
func (s * Syncer [H ]) moveTail (ctx context.Context , new H ) error {
99
103
old , err := s .store .Tail (ctx )
100
104
if errors .Is (err , header .ErrEmptyStore ) {
0 commit comments