Skip to content

Commit 6d52f06

Browse files
committed
support for non-updated historical access nodes
1 parent 6ff10de commit 6d52f06

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

state/convert.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ import (
2323
"github.com/onflow/rosetta/log"
2424
)
2525

26-
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) {
2727
// todo: add V6 version branching here directly after mainnet23 spork
2828
exec := flowExecutionResult{
2929
BlockID: toFlowIdentifier(result.BlockId),
3030
ExecutionDataID: toFlowIdentifier(result.ExecutionDataId),
3131
PreviousResultID: toFlowIdentifier(result.PreviousResultId),
3232
}
3333
for _, chunk := range result.Chunks {
34-
convertedChunk, err := convert.MessageToChunk(chunk)
34+
convertedChunk, err := convertChunk(sporkVersion, chunk)
3535
if err != nil {
3636
log.Errorf("Failed to convert chunk in block %x at height %d: %v", hash, height, err)
3737
return flowExecutionResult{}, false
@@ -53,6 +53,25 @@ func convertExecutionResult(hash []byte, height uint64, result *entities.Executi
5353
return exec, true
5454
}
5555

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+
5675
func decodeEvent(typ string, evt *entities.Event, hash []byte, height uint64) (cadence.Event, error) {
5776
val, err := decodePayload(evt.Payload)
5877
if err != nil {
@@ -426,7 +445,7 @@ func verifyBlockHash(spork *config.Spork, hash []byte, height uint64, hdr *entit
426445

427446
var resultIDs []flow.Identifier
428447
for _, src := range block.ExecutionResultList {
429-
exec, ok := convertExecutionResult(hash, height, src)
448+
exec, ok := convertExecutionResult(spork.Version, hash, height, src)
430449
if ok {
431450
resultIDs = append(resultIDs, deriveExecutionResult(spork, exec))
432451
}

state/convert_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func TestVerifyExecutionResultHash(t *testing.T) {
6363
sealedResults[string(seal.BlockId)] = string(seal.ResultId)
6464
}
6565
var resultID flow.Identifier
66-
exec, ok := convertExecutionResult(block.Id, blockHeight, execResult)
66+
exec, ok := convertExecutionResult(spork.Version, block.Id, blockHeight, execResult)
6767
if ok {
6868
resultID = deriveExecutionResult(spork, exec)
6969
}
@@ -156,7 +156,7 @@ func TestExecutionResultConsistency_ChunkServiceEventCountField(t *testing.T) {
156156

157157
psv1ProtobufResult, err := convert.ExecutionResultToMessage(psv1Result)
158158
require.NoError(t, err)
159-
psv1RosettaResult, ok := convertExecutionResult(nil, 0, psv1ProtobufResult)
159+
psv1RosettaResult, ok := convertExecutionResult(7, nil, 0, psv1ProtobufResult)
160160
require.True(t, ok)
161161
rosettaResultID := deriveExecutionResultV2(psv1RosettaResult)
162162
assert.Equal(t, psv1Result.ID(), rosettaResultID)
@@ -168,7 +168,7 @@ func TestExecutionResultConsistency_ChunkServiceEventCountField(t *testing.T) {
168168

169169
psv2ProtobufResult, err := convert.ExecutionResultToMessage(psv2Result)
170170
require.NoError(t, err)
171-
psv2RosettaResult, ok := convertExecutionResult(nil, 0, psv2ProtobufResult)
171+
psv2RosettaResult, ok := convertExecutionResult(7, nil, 0, psv2ProtobufResult)
172172
require.True(t, ok)
173173
rosettaResultID := deriveExecutionResultV2(psv2RosettaResult)
174174
assert.Equal(t, psv2Result.ID(), rosettaResultID)

state/process.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ import (
1212
"github.com/onflow/flow-go/model/flow"
1313
flowaccess "github.com/onflow/flow/protobuf/go/flow/access"
1414
"github.com/onflow/flow/protobuf/go/flow/entities"
15+
"google.golang.org/grpc/codes"
16+
"google.golang.org/grpc/status"
17+
1518
"github.com/onflow/rosetta/access"
1619
"github.com/onflow/rosetta/cache"
1720
"github.com/onflow/rosetta/config"
1821
"github.com/onflow/rosetta/crypto"
1922
"github.com/onflow/rosetta/log"
2023
"github.com/onflow/rosetta/model"
2124
"github.com/onflow/rosetta/trace"
22-
"google.golang.org/grpc/codes"
23-
"google.golang.org/grpc/status"
2425
)
2526

2627
var (
@@ -326,7 +327,7 @@ outer:
326327
}
327328
}
328329
var resultID flow.Identifier
329-
exec, convOk := convertExecutionResult(hash, height, execResult)
330+
exec, convOk := convertExecutionResult(spork.Version, hash, height, execResult)
330331
if convOk {
331332
resultID = deriveExecutionResult(spork, exec)
332333
}

0 commit comments

Comments
 (0)