Skip to content

Commit

Permalink
fix receipt json marshaling/unmarshaling
Browse files Browse the repository at this point in the history
Signed-off-by: Roberto Bayardo <roberto.bayardo@coinbase.com>
  • Loading branch information
roberto-bayardo committed Oct 25, 2023
1 parent 29cd9a3 commit 622226d
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 47 deletions.
92 changes: 50 additions & 42 deletions core/types/gen_receipt_json.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions core/types/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,13 @@ type receiptMarshaling struct {
BlockNumber *hexutil.Big
TransactionIndex hexutil.Uint

// Optimism: extend receipts with their L1 price (if a rollup tx)
L1GasPrice *hexutil.Big
L1GasUsed *hexutil.Big
L1Fee *hexutil.Big
FeeScalar *big.Float
// Optimism
L1GasPrice *hexutil.Big
L1GasUsed *hexutil.Big
L1Fee *hexutil.Big
FeeScalar *big.Float
DepositNonce *hexutil.Uint64
DepositReceiptVersion *hexutil.Uint64
}

// receiptRLP is the consensus encoding of a receipt.
Expand Down
12 changes: 12 additions & 0 deletions core/types/receipt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,18 @@ func TestReceiptJSON(t *testing.T) {
if err != nil {
t.Fatal("error unmarshaling receipt from json:", err)
}

// Make sure marshal/unmarshal doesn't affect receipt hash root computation by comparing
// the output of EncodeIndex
rsBefore := Receipts([]*Receipt{receipts[i]})
rsAfter := Receipts([]*Receipt{&r})

encBefore, encAfter := bytes.Buffer{}, bytes.Buffer{}
rsBefore.EncodeIndex(0, &encBefore)
rsAfter.EncodeIndex(0, &encAfter)
if !bytes.Equal(encBefore.Bytes(), encAfter.Bytes()) {
t.Errorf("%v: EncodeIndex differs after JSON marshal/unmarshal", i)
}
}
}

Expand Down

0 comments on commit 622226d

Please sign in to comment.