Skip to content

[Storage] Add a sanity check to the events BatchStore for correct order #8454

@peterargue

Description

@peterargue

Currently there is no check within the storage/store/events.go implementation to ensure that events passed to BatchStore are sorted by transaction index/event index and form a continuous sequence. Add this sanity check and return an error if they do not match

combinedEvents := make([]flow.Event, sliceSize)
eventIndex := 0
for _, txEvents := range blockEvents {
for _, event := range txEvents {
combinedEvents[eventIndex] = event
eventIndex++
}
}

the logic would be something like

	combinedEvents := make([]flow.Event, sliceSize)
	globalIndex := 0
	eventIndex := uint32(0)
	txIndex := uint32(0)

	for _, txEvents := range blockEvents {
		for _, event := range txEvents {
			switch event.TransactionIndex {
			case txIndex:
				if event.EventIndex != eventIndex {
					return fmt.Errorf("event index mismatch in transaction %d: expected %d, got %d", txIndex, eventIndex, event.EventIndex)
				}
				eventIndex++
			case txIndex + 1:
				txIndex = event.TransactionIndex
				eventIndex = 0
			default:
				return fmt.Errorf("transaction index mismatch: expected %d, got %d", txIndex, event.TransactionIndex)
			}

			combinedEvents[globalIndex] = event
			globalIndex++
		}
	}

Along with this change, we will need to check the data from the current and past sporks to see if this issue exists to avoid causing an execution halt. We should be able to iterate execution data for each block and inspect the events since execution data is produced in the same order as execution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions