diff --git a/codec/postprocess.go b/codec/postprocess.go index 27ed1714..fa991a0c 100644 --- a/codec/postprocess.go +++ b/codec/postprocess.go @@ -172,7 +172,7 @@ func CombinePolygonSystemTransactions(traces []*pbeth.TransactionTrace, blockNum var unmergeableSystemTransactions []*pbeth.TransactionTrace normalTransactions := make([]*pbeth.TransactionTrace, 0, len(traces)) - var highestTrxIndex uint32 + highestTrxIndex := int64(-1) // negative so that next one is 0 if no normal transaction is met for _, trace := range traces { if bytes.Equal(trace.From, polygonSystemAddress) { if bytes.Equal(trace.To, polygonStateReceiverAddress) { @@ -185,8 +185,8 @@ func CombinePolygonSystemTransactions(traces []*pbeth.TransactionTrace, blockNum } // no other know case for polygon } - if trace.Index > highestTrxIndex { - highestTrxIndex = trace.Index + if int64(trace.Index) > highestTrxIndex { + highestTrxIndex = int64(trace.Index) } normalTransactions = append(normalTransactions, trace) } @@ -282,7 +282,7 @@ func CombinePolygonSystemTransactions(traces []*pbeth.TransactionTrace, blockNum GasPrice: bigIntZero, GasLimit: 0, Value: bigIntZero, - Index: highestTrxIndex + 1, + Index: uint32(highestTrxIndex + 1), Input: nil, GasUsed: 0, Type: pbeth.TransactionTrace_TRX_TYPE_LEGACY, @@ -302,7 +302,7 @@ func CombinePolygonSystemTransactions(traces []*pbeth.TransactionTrace, blockNum highestTrxIndex++ } for _, tx := range unmergeableSystemTransactions { - tx.Index = highestTrxIndex + 1 + tx.Index = uint32(highestTrxIndex + 1) systemTransactionHashes = append(systemTransactionHashes, tx.Hash) out = append(out, tx) highestTrxIndex++ diff --git a/codec/postprocess_test.go b/codec/postprocess_test.go index 8b6f8679..cf059cfc 100644 --- a/codec/postprocess_test.go +++ b/codec/postprocess_test.go @@ -63,6 +63,7 @@ func TestCombinePolygonSystemTransactions(t *testing.T) { expectedSystemTrxBeginOrdinal uint64 expectedSystemTrxEndOrdinal uint64 expectedSystemTrx bool + expectedSystemTrxIndex uint32 expectedCalls []*pbeth.Call }{ { @@ -75,6 +76,7 @@ func TestCombinePolygonSystemTransactions(t *testing.T) { 0, 0, false, + 0, nil, }, { @@ -90,6 +92,24 @@ func TestCombinePolygonSystemTransactions(t *testing.T) { 1, 4, true, + 2, + []*pbeth.Call{ + call(1, 0, 0, 2, 3), + call(2, 1, 1, 2, 3), + }, + }, + { + "single system trx, no normal trx", + []*pbeth.TransactionTrace{ + systemTrx("cc", 1, 4, []*pbeth.Call{ + call(1, 0, 0, 2, 3), + }), + }, + []string{systemTrxHash}, + 1, + 4, + true, + 0, []*pbeth.Call{ call(1, 0, 0, 2, 3), call(2, 1, 1, 2, 3), @@ -110,6 +130,7 @@ func TestCombinePolygonSystemTransactions(t *testing.T) { 1, 10, true, + 1, []*pbeth.Call{ call(1, 0, 0, 2, 9), call(2, 1, 1, 2, 9), @@ -146,6 +167,7 @@ func TestCombinePolygonSystemTransactions(t *testing.T) { 1, 30, true, + 1, []*pbeth.Call{ call(1, 0, 0, 2, 29), @@ -170,6 +192,11 @@ func TestCombinePolygonSystemTransactions(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { + // our test values have no index set, we set it here to check the combination index result + for i, tx := range test.in { + tx.Index = uint32(i) + } + out, outHashes := CombinePolygonSystemTransactions(test.in, 0, nil) if test.expectedSystemTrx { @@ -193,6 +220,7 @@ func TestCombinePolygonSystemTransactions(t *testing.T) { return } + assert.Equal(t, test.expectedSystemTrxIndex, systemTrx.Index) assert.Equal(t, test.expectedSystemTrxBeginOrdinal, systemTrx.BeginOrdinal) assert.Equal(t, test.expectedSystemTrxEndOrdinal, systemTrx.EndOrdinal) diff --git a/codec/testdata/polygon_calls_after_finalize.dmlog.golden.json b/codec/testdata/polygon_calls_after_finalize.dmlog.golden.json index 0a212954..f8842b38 100644 --- a/codec/testdata/polygon_calls_after_finalize.dmlog.golden.json +++ b/codec/testdata/polygon_calls_after_finalize.dmlog.golden.json @@ -653,7 +653,6 @@ "from": "fffffffffffffffffffffffffffffffffffffffe", "gasLimit": "9223372036854775807", "hash": "958e5726dd1fa45d3f56d56733d86edd09fefebd1a64efccd9b74de65f7a1de0", - "index": 1, "input": "23c2a2b40000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000019ff00000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000000b8f8b6d906822710940375b2fc7140977c9c76d45421564e354ed42277d9078227109442eefcda06ead475cde3731b8eb138e88cd0bac3d901822710945973918275c01f50555d44e92c9d9b353cadad54d905822710947fcd58c2d53d980b247f1612fdba93e9a76193e6d90482271094b702f1c9154ac9c08da247a8e30ee6f2f3373f41d90282271094b8bb158b93c94ed35c1970d610d1e2b34e26652cd90382271094f84c74dea96df0ec22e11e7c33996c73fcc2d822000000000000000000000000000000000000000000000000000000000000000000000000000000b8f8b6d906822710940375b2fc7140977c9c76d45421564e354ed42277d9078227109442eefcda06ead475cde3731b8eb138e88cd0bac3d901822710945973918275c01f50555d44e92c9d9b353cadad54d905822710947fcd58c2d53d980b247f1612fdba93e9a76193e6d90482271094b702f1c9154ac9c08da247a8e30ee6f2f3373f41d90282271094b8bb158b93c94ed35c1970d610d1e2b34e26652cd90382271094f84c74dea96df0ec22e11e7c33996c73fcc2d8220000000000000000", "receipt": { "logsBloom": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" @@ -664,4 +663,4 @@ ], "ver": 3 } -] \ No newline at end of file +] diff --git a/tools/compare-rpc.go b/tools/compare-rpc.go index db3dd335..01cb362c 100644 --- a/tools/compare-rpc.go +++ b/tools/compare-rpc.go @@ -342,11 +342,6 @@ func stripFirehoseTransactionTraces(in []*pbeth.TransactionTrace, hashesWithoutT idx := uint32(0) for _, trace := range in { - if trace.Index != idx { - if idx == uint32(len(in)-1) { - trace.Index = idx // POLYGON BLOCK FIX - } - } if hashesWithoutTo[eth.Hash(trace.Hash).String()] { trace.To = nil // FIXME: we could compute this from nonce+address }