From 6228e63f66fa2c2be96dce2783f39d877b762d6f Mon Sep 17 00:00:00 2001 From: Faye Amacker <33205765+fxamacker@users.noreply.github.com> Date: Fri, 14 Jul 2023 15:33:24 -0500 Subject: [PATCH] Fix missing events in uploaded block data Previously, only last event is included in block data (repeated n times). This commit fixes the bug and includes all events. --- engine/execution/ingestion/uploader/model.go | 7 ++++--- .../execution/ingestion/uploader/model_test.go | 18 +++++++++++++++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/engine/execution/ingestion/uploader/model.go b/engine/execution/ingestion/uploader/model.go index ba01f27ca28..fc39dd08393 100644 --- a/engine/execution/ingestion/uploader/model.go +++ b/engine/execution/ingestion/uploader/model.go @@ -29,9 +29,10 @@ func ComputationResultToBlockData(computationResult *execution.ComputationResult txResults[i] = &AllResults[i] } - events := make([]*flow.Event, 0) - for _, e := range computationResult.AllEvents() { - events = append(events, &e) + eventsList := computationResult.AllEvents() + events := make([]*flow.Event, len(eventsList)) + for i := 0; i < len(eventsList); i++ { + events[i] = &eventsList[i] } trieUpdates := make( diff --git a/engine/execution/ingestion/uploader/model_test.go b/engine/execution/ingestion/uploader/model_test.go index c58979eb44f..5f78824ebe4 100644 --- a/engine/execution/ingestion/uploader/model_test.go +++ b/engine/execution/ingestion/uploader/model_test.go @@ -11,6 +11,7 @@ import ( "github.com/onflow/flow-go/ledger" "github.com/onflow/flow-go/ledger/common/pathfinder" "github.com/onflow/flow-go/ledger/complete" + "github.com/onflow/flow-go/model/flow" "github.com/onflow/flow-go/utils/unittest" ) @@ -29,12 +30,23 @@ func Test_ComputationResultToBlockDataConversion(t *testing.T) { assert.Equal(t, result, *blockData.TxResults[i]) } - // ramtin: warning returned events are not preserving orders, - // but since we are going to depricate this part of logic, - // I'm not going to spend more time fixing this mess + // Since returned events are not preserving orders, + // use map with event.ID() as key to confirm all events + // are included. allEvents := cr.AllEvents() require.Equal(t, len(allEvents), len(blockData.Events)) + eventsInBlockData := make(map[flow.Identifier]flow.Event) + for _, e := range blockData.Events { + eventsInBlockData[e.ID()] = *e + } + + for _, expectedEvent := range allEvents { + event, ok := eventsInBlockData[expectedEvent.ID()] + require.True(t, ok) + require.Equal(t, expectedEvent, event) + } + assert.Equal(t, len(expectedTrieUpdates), len(blockData.TrieUpdates)) assert.Equal(t, cr.CurrentEndState(), blockData.FinalStateCommitment)