Skip to content

Commit

Permalink
Sort EVM tx events based on their TransactionIndex first and their Ev…
Browse files Browse the repository at this point in the history
…entIndex after
  • Loading branch information
m-Peter committed Nov 15, 2024
1 parent 1ee0b67 commit fe346c4
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion services/ingestion/event_subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,16 @@ func (r *RPCEventSubscriber) backfillSporkFromHeight(ctx context.Context, fromCa
}

// append the transaction events to the block events
blocks[i].Events = append(blocks[i].Events, transactions[i].Events...)
// first we sort all the events in the block, by their TransactionIndex,
// and then we also sort events in the same transaction, by their EventIndex.
txEvents := transactions[i].Events
sort.Slice(txEvents, func(i, j int) bool {
if txEvents[i].TransactionIndex != txEvents[j].TransactionIndex {
return txEvents[i].TransactionIndex < txEvents[j].TransactionIndex
}
return txEvents[i].EventIndex < txEvents[j].EventIndex
})
blocks[i].Events = append(blocks[i].Events, txEvents...)

evmEvents := models.NewBlockEvents(blocks[i])
eventsChan <- evmEvents
Expand Down

0 comments on commit fe346c4

Please sign in to comment.