@@ -12,6 +12,7 @@ import (
1212 _ "github.com/onflow/cadence/stdlib" // imported for side-effects only
1313 "github.com/onflow/crypto"
1414 "github.com/onflow/crypto/hash"
15+ "github.com/onflow/flow-go/engine/common/rpc/convert"
1516 "github.com/onflow/flow-go/model/fingerprint"
1617 "github.com/onflow/flow-go/model/flow"
1718 "github.com/onflow/flow-go/storage/merkle"
@@ -22,26 +23,20 @@ import (
2223 "github.com/onflow/rosetta/log"
2324)
2425
25- func convertExecutionResult (hash []byte , height uint64 , result * entities.ExecutionResult ) (flowExecutionResult , bool ) {
26+ func convertExecutionResult (sporkVersion int , hash []byte , height uint64 , result * entities.ExecutionResult ) (flowExecutionResult , bool ) {
2627 // todo: add V6 version branching here directly after mainnet23 spork
2728 exec := flowExecutionResult {
2829 BlockID : toFlowIdentifier (result .BlockId ),
2930 ExecutionDataID : toFlowIdentifier (result .ExecutionDataId ),
3031 PreviousResultID : toFlowIdentifier (result .PreviousResultId ),
3132 }
3233 for _ , chunk := range result .Chunks {
33- exec .Chunks = append (exec .Chunks , & flow.Chunk {
34- ChunkBody : flow.ChunkBody {
35- BlockID : toFlowIdentifier (chunk .BlockId ),
36- CollectionIndex : uint (chunk .CollectionIndex ),
37- EventCollection : toFlowIdentifier (chunk .EventCollection ),
38- NumberOfTransactions : uint64 (chunk .NumberOfTransactions ),
39- StartState : flow .StateCommitment (toFlowIdentifier (chunk .StartState )),
40- TotalComputationUsed : chunk .TotalComputationUsed ,
41- },
42- EndState : flow .StateCommitment (toFlowIdentifier (chunk .EndState )),
43- Index : chunk .Index ,
44- })
34+ convertedChunk , err := convertChunk (sporkVersion , chunk )
35+ if err != nil {
36+ log .Errorf ("Failed to convert chunk in block %x at height %d: %v" , hash , height , err )
37+ return flowExecutionResult {}, false
38+ }
39+ exec .Chunks = append (exec .Chunks , convertedChunk )
4540 }
4641 for _ , ev := range result .ServiceEvents {
4742 eventType := flow .ServiceEventType (ev .Type )
@@ -58,6 +53,25 @@ func convertExecutionResult(hash []byte, height uint64, result *entities.Executi
5853 return exec , true
5954}
6055
56+ func convertChunk (sporkVersion int , protobufChunk * entities.Chunk ) (* flow.Chunk , error ) {
57+ if sporkVersion < 7 {
58+ chunk , err := convert .MessageToChunk (protobufChunk )
59+ if err != nil {
60+ return nil , err
61+ }
62+ // Protocol State v1: ServiceEventCount field not yet added.
63+ // Access Nodes running up-to-date software encode nil ServiceEventCount fields in a detectable way,
64+ // but we assume that we are querying historical Access Nodes that are running prior software versions.
65+ // In this case, the new Protobuf field is automatically set to 0.
66+ // See https://github.com/onflow/flow-go/pull/6744 for additional context
67+ chunk .ServiceEventCount = nil
68+ return chunk , nil
69+ }
70+
71+ // Protocol State v2+
72+ return convert .MessageToChunk (protobufChunk )
73+ }
74+
6175func decodeEvent (typ string , evt * entities.Event , hash []byte , height uint64 ) (cadence.Event , error ) {
6276 val , err := decodePayload (evt .Payload )
6377 if err != nil {
@@ -431,7 +445,7 @@ func verifyBlockHash(spork *config.Spork, hash []byte, height uint64, hdr *entit
431445
432446 var resultIDs []flow.Identifier
433447 for _ , src := range block .ExecutionResultList {
434- exec , ok := convertExecutionResult (hash , height , src )
448+ exec , ok := convertExecutionResult (spork . Version , hash , height , src )
435449 if ok {
436450 resultIDs = append (resultIDs , deriveExecutionResult (spork , exec ))
437451 }
0 commit comments