@@ -61,6 +61,13 @@ func (s *Syncer[H]) Tail(ctx context.Context) (H, error) {
61
61
tail , err := s .store .Tail (ctx )
62
62
switch {
63
63
case errors .Is (err , header .ErrEmptyStore ):
64
+ // TODO(@Wondertan): This is a temporary solution requesting the head directly from the network instead of
65
+ // calling general Head path. This is needed to ensure Tail is written to the store first.
66
+ head , err := s .head .Head (ctx )
67
+ if err != nil {
68
+ return head , err
69
+ }
70
+
64
71
switch {
65
72
case s .Params .SyncFromHash != nil :
66
73
tail , err = s .getter .Get (ctx , s .Params .SyncFromHash )
@@ -73,23 +80,23 @@ func (s *Syncer[H]) Tail(ctx context.Context) (H, error) {
73
80
return tail , fmt .Errorf ("getting tail header(%d): %w" , s .Params .SyncFromHeight , err )
74
81
}
75
82
default :
76
- head , err := s .Head (ctx )
77
- if err != nil {
78
- return head , err
79
- }
80
-
81
83
tailHeight := estimateTail (head , s .Params .blockTime , s .Params .TrustingPeriod )
82
84
tail , err = s .getter .GetByHeight (ctx , tailHeight )
83
85
if err != nil {
84
86
return tail , fmt .Errorf ("getting estimated tail header(%d): %w" , tailHeight , err )
85
87
}
86
88
}
87
89
88
- err = s .store .Store . Append (ctx , tail )
90
+ err = s .store .Append (ctx , tail )
89
91
if err != nil {
90
92
return tail , fmt .Errorf ("appending tail header: %w" , err )
91
93
}
92
94
95
+ err = s .incomingNetworkHead (ctx , head )
96
+ if err != nil {
97
+ return tail , fmt .Errorf ("applying head from trusted peers: %w" , err )
98
+ }
99
+
93
100
case ! s .isTailActual (tail ):
94
101
if s .Params .SyncFromHash != nil {
95
102
tail , err = s .getter .Get (ctx , s .Params .SyncFromHash )
0 commit comments