Skip to content

Commit 65a3e3a

Browse files
committed
refine logs/metrics
1 parent abe56c1 commit 65a3e3a

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

sync/sync_head.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,14 @@ func (s *Syncer[H]) Tail(ctx context.Context) (H, error) {
7070
case errors.Is(err, header.ErrEmptyStore):
7171
// Store is empty, likely the first start - initialize.
7272
log.Info("empty store, initializing...")
73-
// TODO(@Wondertan): Requesting the head directly from the network instead of
74-
// calling general Head path. This is a temporary solution needed to ensure Tail is written to the store first
75-
// before Head. To be reworked by bsync.
73+
// TODO(@Wondertan): Copying the initialization logic here instead of calling the general Head path.
74+
// This is a temporary solution needed to ensure Tail is written to the store first before Head.
75+
// To be reworked by bsync.
7676
head, err := s.head.Head(ctx)
7777
if err != nil {
7878
return head, fmt.Errorf("requesting network head: %w", err)
7979
}
80+
s.metrics.subjectiveInitialization(s.ctx)
8081

8182
switch {
8283
case s.Params.SyncFromHash != nil:
@@ -111,9 +112,13 @@ func (s *Syncer[H]) Tail(ctx context.Context) (H, error) {
111112
return tail, fmt.Errorf("applying head from trusted peers: %w", err)
112113
}
113114

114-
log.Infof("initialized with Tail %d and Head %d", tail.Height(), head.Height())
115-
116-
// TODO: Make sure all the metrics for this alternative subjective init path are added
115+
log.Infow(
116+
"subjective initialization finished",
117+
"tail_height",
118+
tail.Height(),
119+
"head_height",
120+
head.Height(),
121+
)
117122

118123
case !tail.IsZero() && !s.isTailActual(tail):
119124
// Configured Tail has changed - get a new one and resolve the diff
@@ -152,7 +157,7 @@ func (s *Syncer[H]) Tail(ctx context.Context) (H, error) {
152157

153158
switch {
154159
case currentTail.Height() > newTail.Height():
155-
log.Infow(
160+
log.Infof(
156161
"tail header changed from %d to %d, syncing the diff...",
157162
currentTail,
158163
newTail,
@@ -165,8 +170,8 @@ func (s *Syncer[H]) Tail(ctx context.Context) (H, error) {
165170
return tail, fmt.Errorf("syncing the diff between old and new Tail: %w", err)
166171
}
167172
case currentTail.Height() < newTail.Height():
168-
log.Infow(
169-
"Tail header changed from %d to %d, pruning the diff...",
173+
log.Infof(
174+
"tail header changed from %d to %d, pruning the diff...",
170175
currentTail,
171176
newTail,
172177
)

0 commit comments

Comments
 (0)