Skip to content

Commit 0974579

Browse files
authored
Merge pull request #664 from onflow/mpeter/handle-missing-evm-block-event
Handle ingestion of missing `EVM.BlockExecuted` event in backfill process
2 parents 6727d4a + a22b951 commit 0974579

File tree

4 files changed

+431
-50
lines changed

4 files changed

+431
-50
lines changed

models/events.go

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,6 @@ type CadenceEvents struct {
4646

4747
// NewCadenceEvents decodes the events into evm types.
4848
func NewCadenceEvents(events flow.BlockEvents) (*CadenceEvents, error) {
49-
// first we sort all the events in the block, by their TransactionIndex,
50-
// and then we also sort events in the same transaction, by their EventIndex.
51-
sort.Slice(events.Events, func(i, j int) bool {
52-
if events.Events[i].TransactionIndex != events.Events[j].TransactionIndex {
53-
return events.Events[i].TransactionIndex < events.Events[j].TransactionIndex
54-
}
55-
return events.Events[i].EventIndex < events.Events[j].EventIndex
56-
})
57-
5849
e, err := decodeCadenceEvents(events)
5950
if err != nil {
6051
return nil, err
@@ -219,11 +210,41 @@ type BlockEvents struct {
219210
Err error
220211
}
221212

222-
func NewBlockEvents(events flow.BlockEvents) BlockEvents {
223-
blockEvents, err := NewCadenceEvents(events)
213+
// NewMultiBlockEvents will decode any possible `EVM.TransactionExecuted` &
214+
// `EVM.BlockExecuted` events and populate the resulting `Block`, `Transaction` &
215+
// `Receipt` values.
216+
// The `EVM.TransactionExecuted` events are expected to be properly sorted by
217+
// the caller.
218+
// Use this method when dealing with `flow.BlockEvents` from multiple Flow blocks.
219+
// The `EVM.TransactionExecuted` events could be produced at a Flow block, that
220+
// comes prior to the Flow block that produced the `EVM.BlockExecuted` event.
221+
func NewMultiBlockEvents(events flow.BlockEvents) BlockEvents {
222+
cdcEvents, err := NewCadenceEvents(events)
223+
return BlockEvents{
224+
Events: cdcEvents,
225+
Err: err,
226+
}
227+
}
228+
229+
// NewSingleBlockEvents will decode any possible `EVM.TransactionExecuted` &
230+
// `EVM.BlockExecuted` events and populate the resulting `Block`, `Transaction` &
231+
// `Receipt` values.
232+
// The `EVM.TransactionExecuted` events will be sorted by `TransactionIndex` &
233+
// `EventIndex`, prior to decoding.
234+
// Use this method when dealing with `flow.BlockEvents` from a single Flow block.
235+
func NewSingleBlockEvents(events flow.BlockEvents) BlockEvents {
236+
// first we sort all the events in the block, by their TransactionIndex,
237+
// and then we also sort events in the same transaction, by their EventIndex.
238+
sort.Slice(events.Events, func(i, j int) bool {
239+
if events.Events[i].TransactionIndex != events.Events[j].TransactionIndex {
240+
return events.Events[i].TransactionIndex < events.Events[j].TransactionIndex
241+
}
242+
return events.Events[i].EventIndex < events.Events[j].EventIndex
243+
})
224244

245+
cdcEvents, err := NewCadenceEvents(events)
225246
return BlockEvents{
226-
Events: blockEvents,
247+
Events: cdcEvents,
227248
Err: err,
228249
}
229250
}

0 commit comments

Comments
 (0)