Skip to content

Commit 9e71225

Browse files
authored
chore(store|sync): error wrappings (#310)
Preventive measures to help with future debugging
1 parent 0479af3 commit 9e71225

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

store/store.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ func (s *Store[H]) GetByHeight(ctx context.Context, height uint64) (H, error) {
246246
// we subscribe to it
247247
err := s.heightSub.Wait(ctx, height)
248248
if err != nil && !errors.Is(err, errElapsedHeight) {
249-
return zero, err
249+
return zero, fmt.Errorf("awaiting header %d with head %d: %w", height, s.Height(), err)
250250
}
251251
// otherwise, the errElapsedHeight is thrown,
252252
// which means the requested 'height' should be present

sync/syncer_head.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var NetworkHeadRequestTimeout = time.Second * 2
2121
func (s *Syncer[H]) Head(ctx context.Context, _ ...header.HeadOption[H]) (H, error) {
2222
netHead, updated, err := s.networkHead(ctx)
2323
if err != nil {
24-
return netHead, err
24+
return netHead, fmt.Errorf("network head: %w", err)
2525
}
2626
if !updated {
2727
return netHead, nil
@@ -52,7 +52,7 @@ func (s *Syncer[H]) Head(ctx context.Context, _ ...header.HeadOption[H]) (H, err
5252
func (s *Syncer[H]) networkHead(ctx context.Context) (H, bool, error) {
5353
sbjHead, initialized, err := s.subjectiveHead(ctx)
5454
if err != nil {
55-
return sbjHead, false, err
55+
return sbjHead, false, fmt.Errorf("subjective head: %w", err)
5656
}
5757
if isRecent(sbjHead, s.Params.blockTime, s.Params.recencyThreshold) || initialized {
5858
return sbjHead, initialized, nil
@@ -124,15 +124,16 @@ func (s *Syncer[H]) subjectiveHead(ctx context.Context) (H, bool, error) {
124124
"expired_height",
125125
sbjHead.Height(),
126126
)
127+
case err != nil:
128+
return sbjHead, false, fmt.Errorf("local head: %w", err)
127129
default:
128-
// success or unknown error case
129-
return sbjHead, false, err
130+
return sbjHead, false, nil
130131
}
131132

132133
s.metrics.subjectiveInitialization(ctx)
133134
newHead, err := s.head.Head(ctx)
134135
if err != nil {
135-
return newHead, false, err
136+
return newHead, false, fmt.Errorf("exchange head: %w", err)
136137
}
137138
// still check if even the newly requested head is expired
138139
if isExpired(newHead, s.Params.TrustingPeriod) {

0 commit comments

Comments
 (0)