Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ethapi/receipt: Use hexutil for JSON marshalling #315

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions core/types/gen_receipt_json.go

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

19 changes: 15 additions & 4 deletions core/types/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ type Receipt struct {
L1GasUsed *big.Int `json:"l1GasUsed,omitempty"` // Present from pre-bedrock
L1Fee *big.Int `json:"l1Fee,omitempty"` // Present from pre-bedrock
FeeScalar *big.Float `json:"l1FeeScalar,omitempty"` // Present from pre-bedrock to Ecotone. Nil after Ecotone
L1BaseFeeScalar *uint32 `json:"l1BaseFeeScalar,omitempty"` // Always nil prior to the Ecotone hardfork
L1BlobBaseFeeScalar *uint32 `json:"l1BlobBaseFeeScalar,omitempty"` // Always nil prior to the Ecotone hardfork
L1BaseFeeScalar *uint64 `json:"l1BaseFeeScalar,omitempty"` // Always nil prior to the Ecotone hardfork
L1BlobBaseFeeScalar *uint64 `json:"l1BlobBaseFeeScalar,omitempty"` // Always nil prior to the Ecotone hardfork
}

type receiptMarshaling struct {
Expand All @@ -108,9 +108,12 @@ type receiptMarshaling struct {

// Optimism
L1GasPrice *hexutil.Big
L1BlobBaseFee *hexutil.Big
L1GasUsed *hexutil.Big
L1Fee *hexutil.Big
FeeScalar *big.Float
L1BaseFeeScalar *hexutil.Uint64
L1BlobBaseFeeScalar *hexutil.Uint64
DepositNonce *hexutil.Uint64
DepositReceiptVersion *hexutil.Uint64
}
Expand Down Expand Up @@ -585,9 +588,17 @@ func (rs Receipts) DeriveFields(config *params.ChainConfig, hash common.Hash, nu
rs[i].L1BlobBaseFee = gasParams.l1BlobBaseFee
rs[i].L1Fee, rs[i].L1GasUsed = gasParams.costFunc(txs[i].RollupCostData())
rs[i].FeeScalar = gasParams.feeScalar
rs[i].L1BaseFeeScalar = gasParams.l1BaseFeeScalar
rs[i].L1BlobBaseFeeScalar = gasParams.l1BlobBaseFeeScalar
rs[i].L1BaseFeeScalar = u32ptrTou64ptr(gasParams.l1BaseFeeScalar)
rs[i].L1BlobBaseFeeScalar = u32ptrTou64ptr(gasParams.l1BlobBaseFeeScalar)
}
}
return nil
}

func u32ptrTou64ptr(a *uint32) *uint64 {
if a == nil {
return nil
}
b := uint64(*a)
return &b
}
8 changes: 4 additions & 4 deletions core/types/receipt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ func clearComputedFieldsOnLogs(logs []*Log) []*Log {
return l
}

func getOptimismEcotoneTxReceipts(l1AttributesPayload []byte, l1GasPrice, l1BlobGasPrice, l1GasUsed, l1Fee *big.Int, baseFeeScalar, blobBaseFeeScalar *uint32) ([]*Transaction, []*Receipt) {
func getOptimismEcotoneTxReceipts(l1AttributesPayload []byte, l1GasPrice, l1BlobGasPrice, l1GasUsed, l1Fee *big.Int, baseFeeScalar, blobBaseFeeScalar *uint64) ([]*Transaction, []*Receipt) {
// Create a few transactions to have receipts for
txs := Transactions{
NewTx(&DepositTx{
Expand Down Expand Up @@ -868,9 +868,9 @@ func TestDeriveOptimismEcotoneTxReceipts(t *testing.T) {
// Ecotone style l1 attributes with baseFeeScalar=2, blobBaseFeeScalar=3, baseFee=1000*1e6, blobBaseFee=10*1e6
payload := common.Hex2Bytes("440a5e20000000020000000300000000000004d200000000000004d200000000000004d2000000000000000000000000000000000000000000000000000000003b9aca00000000000000000000000000000000000000000000000000000000000098968000000000000000000000000000000000000000000000000000000000000004d200000000000000000000000000000000000000000000000000000000000004d2")
// the parameters we use below are defined in rollup_test.go
baseFeeScalarUint32 := uint32(baseFeeScalar.Uint64())
blobBaseFeeScalarUint32 := uint32(blobBaseFeeScalar.Uint64())
txs, receipts := getOptimismEcotoneTxReceipts(payload, baseFee, blobBaseFee, ecotoneGas, ecotoneFee, &baseFeeScalarUint32, &blobBaseFeeScalarUint32)
baseFeeScalarUint64 := baseFeeScalar.Uint64()
blobBaseFeeScalarUint64 := blobBaseFeeScalar.Uint64()
txs, receipts := getOptimismEcotoneTxReceipts(payload, baseFee, blobBaseFee, ecotoneGas, ecotoneFee, &baseFeeScalarUint64, &blobBaseFeeScalarUint64)

// Re-derive receipts.
baseFee := big.NewInt(1000)
Expand Down
Loading