Skip to content

Commit 38482d2

Browse files
committed
Improve error handling in RPCBlockTrackingSubscriber subscription
1 parent 723299f commit 38482d2

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

services/ingestion/block_tracking_subscriber.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,11 @@ func (r *RPCBlockTrackingSubscriber) subscribe(ctx context.Context, height uint6
117117
)
118118
if err != nil {
119119
eventsChan <- models.NewBlockEventsError(
120-
fmt.Errorf("failed to subscribe to events by block height: %d, with: %w", height, err),
120+
fmt.Errorf(
121+
"failed to subscribe for finalized block headers on height: %d, with: %w",
122+
height,
123+
err,
124+
),
121125
)
122126
return eventsChan
123127
}
@@ -146,7 +150,6 @@ func (r *RPCBlockTrackingSubscriber) subscribe(ctx context.Context, height uint6
146150
}
147151

148152
var blockEvents flow.BlockEvents
149-
150153
for _, eventType := range blocksFilter(r.chain).EventTypes {
151154
evts, err := r.client.GetEventsForHeightRange(
152155
ctx,
@@ -155,10 +158,24 @@ func (r *RPCBlockTrackingSubscriber) subscribe(ctx context.Context, height uint6
155158
blockHeader.Height,
156159
)
157160
if err != nil {
161+
eventsChan <- models.NewBlockEventsError(
162+
fmt.Errorf(
163+
"failed to fetch EVM events for height: %d, with: %w",
164+
blockHeader.Height,
165+
err,
166+
),
167+
)
158168
return
159169
}
160170

161171
if len(evts) != 1 {
172+
eventsChan <- models.NewBlockEventsError(
173+
fmt.Errorf(
174+
"received unexpected number of EVM events for height: %d, got: %d, expected: 1",
175+
blockHeader.Height,
176+
len(evts),
177+
),
178+
)
162179
return
163180
}
164181
blockEvent := evts[0]
@@ -203,7 +220,11 @@ func (r *RPCBlockTrackingSubscriber) subscribe(ctx context.Context, height uint6
203220
)
204221
if err != nil {
205222
eventsChan <- models.NewBlockEventsError(
206-
fmt.Errorf("failed to subscribe to events by block height: %d, with: %w", height, err),
223+
fmt.Errorf(
224+
"failed to subscribe for finalized block headers on height: %d, with: %w",
225+
height,
226+
err,
227+
),
207228
)
208229
return
209230
}

0 commit comments

Comments
 (0)