From 5ad042373379b882293c2996ce96d67f0dc0b25d Mon Sep 17 00:00:00 2001 From: Amlandeep Bhadra Date: Tue, 27 Jun 2023 10:44:11 -0400 Subject: [PATCH 1/3] correct test case and revert original Event hash check --- state/convert_test.go | 9 +++++++++ state/process.go | 18 +++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/state/convert_test.go b/state/convert_test.go index 7720686..b40339b 100644 --- a/state/convert_test.go +++ b/state/convert_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/onflow/flow-go/model/flow" + "github.com/onflow/flow/protobuf/go/flow/entities" "github.com/onflow/rosetta/access" "github.com/onflow/rosetta/config" "github.com/stretchr/testify/assert" @@ -121,6 +122,14 @@ func TestDeriveEventsHash(t *testing.T) { } } hash := deriveEventsHash(spork, colEvents) + eventHashes = append(eventHashes, hash) + } + var execResult *entities.ExecutionResult + execResult, err = client.ExecutionResultForBlockID(ctx, block.Id) + assert.NoError(t, err) + for idx, eventHash := range eventHashes { + chunk := execResult.Chunks[idx] + assert.Equal(t, eventHash[:], chunk.EventCollection) } } } diff --git a/state/process.go b/state/process.go index 7c8d2eb..9db9939 100644 --- a/state/process.go +++ b/state/process.go @@ -304,7 +304,7 @@ outer: skipCache = true continue } - for idx, _ := range eventHashes { + for idx, eventHash := range eventHashes { chunk := execResult.Chunks[idx] if chunk == nil { log.Errorf( @@ -314,14 +314,14 @@ outer: skipCache = true continue outer } - //if !bytes.Equal(chunk.EventCollection, eventHash[:]) { - // log.Errorf( - // "Got mismatching event hash within chunk at offset %d of block %x at height %d: expected %x (from events), got %x (from execution result)", - // idx, hash, height, eventHash[:], chunk.EventCollection, - // ) - // skipCache = true - // continue outer - //} + if !bytes.Equal(chunk.EventCollection, eventHash[:]) { + log.Errorf( + "Got mismatching event hash within chunk at offset %d of block %x at height %d: expected %x (from events), got %x (from execution result)", + idx, hash, height, eventHash[:], chunk.EventCollection, + ) + skipCache = true + continue outer + } } var resultID flow.Identifier var resultIDV5 flow.Identifier From 4cc7002c2f36cdb25294c16a66007e69b9ce1922 Mon Sep 17 00:00:00 2001 From: Amlandeep Bhadra Date: Tue, 26 Sep 2023 12:40:40 -0400 Subject: [PATCH 2/3] push --- state/convert_test.go | 4 ++-- state/process.go | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/state/convert_test.go b/state/convert_test.go index b40339b..4d915b4 100644 --- a/state/convert_test.go +++ b/state/convert_test.go @@ -79,8 +79,8 @@ func TestVerifyExecutionResultHash(t *testing.T) { } func TestDeriveEventsHash(t *testing.T) { - var startBlockHeight uint64 = 55114467 - var endBlockHeight uint64 = 55114469 + var startBlockHeight uint64 = 55114469 + var endBlockHeight uint64 = 55114478 ctx := context.Background() spork, err := createSpork(ctx) if err != nil { diff --git a/state/process.go b/state/process.go index 9db9939..49f09b4 100644 --- a/state/process.go +++ b/state/process.go @@ -338,8 +338,6 @@ outer: continue } sealedResult, foundOk := i.sealedResults[string(hash)] - // NOTE(tav): Skip the execution result check for the root block of - // a spork as it is self-sealed. if spork.Prev != nil && height == spork.RootBlock { sealedResult, foundOk = string(resultID[:]), true } From 30b2f1b46be04b0e57db1556ca3ce0edd3ca4496 Mon Sep 17 00:00:00 2001 From: Amlandeep Bhadra Date: Tue, 3 Oct 2023 12:34:05 -0400 Subject: [PATCH 3/3] modify event hash testy --- state/convert_test.go | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/state/convert_test.go b/state/convert_test.go index 4d915b4..3a7be1b 100644 --- a/state/convert_test.go +++ b/state/convert_test.go @@ -1,6 +1,7 @@ package state import ( + "bytes" "context" "testing" @@ -89,24 +90,30 @@ func TestDeriveEventsHash(t *testing.T) { client := spork.AccessNodes.Client() for blockHeight := startBlockHeight; blockHeight < endBlockHeight; blockHeight++ { block, err := client.BlockByHeight(ctx, blockHeight) + txns, err := client.TransactionsByBlockID(ctx, block.Id) + assert.NoError(t, err) + txnResults, err := client.TransactionResultsByBlockID(ctx, block.Id) assert.NoError(t, err) cols := []*collectionData{} - eventHashes := []flow.Identifier{} - txnIndex := -1 - for _, col := range block.CollectionGuarantees { - colData := &collectionData{} - info, err := client.CollectionByID(ctx, col.CollectionId) - assert.NoError(t, err) - for _, txnHash := range info.TransactionIds { - info, err := client.Transaction(ctx, txnHash) - assert.NoError(t, err) - txnResult, err := client.TransactionResult(ctx, block.Id, uint32(txnIndex)) - txnIndex++ - colData.txns = append(colData.txns, info) - colData.txnResults = append(colData.txnResults, txnResult) + col := &collectionData{} + cols = append(cols, col) + prev := []byte{} + txnLen := len(txns) + for idx, result := range txnResults { + if idx != 0 { + if !bytes.Equal(result.CollectionId, prev) { + col = &collectionData{} + cols = append(cols, col) + } } - cols = append(cols, colData) + if idx < txnLen { + col.txns = append(col.txns, txns[idx]) + } + col.txnResults = append(col.txnResults, result) + prev = result.CollectionId } + cols[len(cols)-1].system = true + eventHashes := []flow.Identifier{} for _, col := range cols { colEvents := []flowEvent{} for _, txnResult := range col.txnResults {