Skip to content

Commit

Permalink
Update recover logic to work properly and fix failing test case
Browse files Browse the repository at this point in the history
  • Loading branch information
m-Peter committed Sep 17, 2024
1 parent 5f3f789 commit 6dd8b6d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
17 changes: 11 additions & 6 deletions services/ingestion/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,18 +329,23 @@ func (r *RPCSubscriber) accumulateEventsMissingBlock(events flow.BlockEvents) mo
// in which case we might miss one of the events (missing transaction), or it can be
// due to a failure from the system transaction which commits an EVM block, which results
// in missing EVM block event but present transactions.
func (r *RPCSubscriber) recover(ctx context.Context, events flow.BlockEvents, err error) models.BlockEvents {
r.logger.Error().Err(err).Msgf(
func (r *RPCSubscriber) recover(
ctx context.Context,
events flow.BlockEvents,
err error,
) models.BlockEvents {
r.logger.Warn().Err(err).Msgf(
"failed to parse EVM block events for Flow height: %d, entering recovery",
events.Height,
)

switch {
case errors.Is(err, errs.ErrMissingTransactions):
return r.fetchMissingData(ctx, events)
case errors.Is(err, errs.ErrMissingBlock):
if errors.Is(err, errs.ErrMissingBlock) || r.recovery {
return r.accumulateEventsMissingBlock(events)
}

if errors.Is(err, errs.ErrMissingTransactions) {
return r.fetchMissingData(ctx, events)
}

return models.NewBlockEventsError(err)
}
7 changes: 4 additions & 3 deletions services/ingestion/subscriber_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,17 @@ func Test_MissingBlockEvent(t *testing.T) {
blockCdc, _, blockEvent, _ := newBlock(i, []gethCommon.Hash{tx.Hash()})

if i == foundBlockHeight {
missingHashes = append(missingHashes, tx.Hash())
blockCdc, _, _, _ = newBlock(i, missingHashes)
}

blockEvents := []flow.Event{
{Value: blockCdc, Type: string(txEvent.Etype)},
{Value: txCdc, Type: string(blockEvent.Etype)},
{Value: txCdc, Type: string(txEvent.Etype)},
{Value: blockCdc, Type: string(blockEvent.Etype)},
}

if i > missingBlockHeight && i < foundBlockHeight {
blockEvents = blockEvents[1:] // remove block
blockEvents = blockEvents[:1] // remove block
missingHashes = append(missingHashes, tx.Hash())
}

Expand Down

0 comments on commit 6dd8b6d

Please sign in to comment.