Skip to content

Commit

Permalink
Merge pull request #4562 from onflow/fxamacker/fix-incomplete-events-…
Browse files Browse the repository at this point in the history
…in-gcp-uploader

Fix missing events in block data uploaded to GCP
  • Loading branch information
fxamacker authored Jul 14, 2023
2 parents 72b4db9 + 6fe26d1 commit f1d5a06
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
7 changes: 4 additions & 3 deletions engine/execution/ingestion/uploader/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
18 changes: 15 additions & 3 deletions engine/execution/ingestion/uploader/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)
Expand Down

0 comments on commit f1d5a06

Please sign in to comment.