Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

correct test case and revert original Event hash check #42

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 32 additions & 16 deletions state/convert_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package state

import (
"bytes"
"context"
"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"
Expand Down Expand Up @@ -78,8 +80,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 {
Expand All @@ -88,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 {
Expand All @@ -121,6 +129,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)
}
}
}
Expand Down
20 changes: 9 additions & 11 deletions state/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -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
}
Expand Down