Skip to content

Commit

Permalink
fix polygon trx index for combined system transaction when there are …
Browse files Browse the repository at this point in the history
…no other transaction in block

* fix compare-rpc test --> a dangling 'hack' was preventing the discovery of that bug
* added tests to catch this case specifically
* the blocks will need to be patched or reprocessed
  • Loading branch information
sduchesneau committed Sep 28, 2023
1 parent 61f8d7f commit f730faa
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
10 changes: 5 additions & 5 deletions codec/postprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
Expand Down Expand Up @@ -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,
Expand All @@ -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++
Expand Down
28 changes: 28 additions & 0 deletions codec/postprocess_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func TestCombinePolygonSystemTransactions(t *testing.T) {
expectedSystemTrxBeginOrdinal uint64
expectedSystemTrxEndOrdinal uint64
expectedSystemTrx bool
expectedSystemTrxIndex uint32
expectedCalls []*pbeth.Call
}{
{
Expand All @@ -75,6 +76,7 @@ func TestCombinePolygonSystemTransactions(t *testing.T) {
0,
0,
false,
0,
nil,
},
{
Expand All @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -146,6 +167,7 @@ func TestCombinePolygonSystemTransactions(t *testing.T) {
1,
30,
true,
1,
[]*pbeth.Call{
call(1, 0, 0, 2, 29),

Expand All @@ -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 {
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,6 @@
"from": "fffffffffffffffffffffffffffffffffffffffe",
"gasLimit": "9223372036854775807",
"hash": "958e5726dd1fa45d3f56d56733d86edd09fefebd1a64efccd9b74de65f7a1de0",
"index": 1,
"input": "23c2a2b40000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000019ff00000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000000b8f8b6d906822710940375b2fc7140977c9c76d45421564e354ed42277d9078227109442eefcda06ead475cde3731b8eb138e88cd0bac3d901822710945973918275c01f50555d44e92c9d9b353cadad54d905822710947fcd58c2d53d980b247f1612fdba93e9a76193e6d90482271094b702f1c9154ac9c08da247a8e30ee6f2f3373f41d90282271094b8bb158b93c94ed35c1970d610d1e2b34e26652cd90382271094f84c74dea96df0ec22e11e7c33996c73fcc2d822000000000000000000000000000000000000000000000000000000000000000000000000000000b8f8b6d906822710940375b2fc7140977c9c76d45421564e354ed42277d9078227109442eefcda06ead475cde3731b8eb138e88cd0bac3d901822710945973918275c01f50555d44e92c9d9b353cadad54d905822710947fcd58c2d53d980b247f1612fdba93e9a76193e6d90482271094b702f1c9154ac9c08da247a8e30ee6f2f3373f41d90282271094b8bb158b93c94ed35c1970d610d1e2b34e26652cd90382271094f84c74dea96df0ec22e11e7c33996c73fcc2d8220000000000000000",
"receipt": {
"logsBloom": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
Expand All @@ -664,4 +663,4 @@
],
"ver": 3
}
]
]
5 changes: 0 additions & 5 deletions tools/compare-rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit f730faa

Please sign in to comment.