Skip to content

Commit 4fd8b05

Browse files
authored
core/types: Populate Jovian receipt fields (#710)
* core/types: Move receipt tests OP diff to separate file * core/types: Populate Jovian receipt fields
1 parent 0a1c7b4 commit 4fd8b05

File tree

7 files changed

+594
-618
lines changed

7 files changed

+594
-618
lines changed

core/types/gen_receipt_json.go

Lines changed: 8 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/types/receipt.go

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,16 @@ type Receipt struct {
8686
TransactionIndex uint `json:"transactionIndex"`
8787

8888
// Optimism: extend receipts with L1 and operator fee info
89-
L1GasPrice *big.Int `json:"l1GasPrice,omitempty"` // Present from pre-bedrock. L1 Basefee after Bedrock
90-
L1BlobBaseFee *big.Int `json:"l1BlobBaseFee,omitempty"` // Always nil prior to the Ecotone hardfork
91-
L1GasUsed *big.Int `json:"l1GasUsed,omitempty"` // Present from pre-bedrock, deprecated as of Fjord
92-
L1Fee *big.Int `json:"l1Fee,omitempty"` // Present from pre-bedrock
93-
FeeScalar *big.Float `json:"l1FeeScalar,omitempty"` // Present from pre-bedrock to Ecotone. Nil after Ecotone
94-
L1BaseFeeScalar *uint64 `json:"l1BaseFeeScalar,omitempty"` // Always nil prior to the Ecotone hardfork
95-
L1BlobBaseFeeScalar *uint64 `json:"l1BlobBaseFeeScalar,omitempty"` // Always nil prior to the Ecotone hardfork
96-
OperatorFeeScalar *uint64 `json:"operatorFeeScalar,omitempty"` // Always nil prior to the Isthmus hardfork
97-
OperatorFeeConstant *uint64 `json:"operatorFeeConstant,omitempty"` // Always nil prior to the Isthmus hardfork
89+
L1GasPrice *big.Int `json:"l1GasPrice,omitempty"` // Present from pre-bedrock. L1 Basefee after Bedrock
90+
L1BlobBaseFee *big.Int `json:"l1BlobBaseFee,omitempty"` // Always nil prior to the Ecotone hardfork
91+
L1GasUsed *big.Int `json:"l1GasUsed,omitempty"` // Present from pre-bedrock, deprecated as of Fjord
92+
L1Fee *big.Int `json:"l1Fee,omitempty"` // Present from pre-bedrock
93+
FeeScalar *big.Float `json:"l1FeeScalar,omitempty"` // Present from pre-bedrock to Ecotone. Nil after Ecotone
94+
L1BaseFeeScalar *uint64 `json:"l1BaseFeeScalar,omitempty"` // Always nil prior to the Ecotone hardfork
95+
L1BlobBaseFeeScalar *uint64 `json:"l1BlobBaseFeeScalar,omitempty"` // Always nil prior to the Ecotone hardfork
96+
OperatorFeeScalar *uint64 `json:"operatorFeeScalar,omitempty"` // Always nil prior to the Isthmus hardfork
97+
OperatorFeeConstant *uint64 `json:"operatorFeeConstant,omitempty"` // Always nil prior to the Isthmus hardfork
98+
DAFootprintGasScalar *uint64 `json:"daFootprintGasScalar,omitempty"` // Always nil prior to the Jovian hardfork
9899
}
99100

100101
type receiptMarshaling struct {
@@ -121,6 +122,7 @@ type receiptMarshaling struct {
121122
DepositReceiptVersion *hexutil.Uint64
122123
OperatorFeeScalar *hexutil.Uint64
123124
OperatorFeeConstant *hexutil.Uint64
125+
DAFootprintGasScalar *hexutil.Uint64
124126
}
125127

126128
// receiptRLP is the consensus encoding of a receipt.
@@ -612,26 +614,8 @@ func (rs Receipts) DeriveFields(config *params.ChainConfig, blockHash common.Has
612614
logIndex += uint(len(rs[i].Logs))
613615
}
614616

615-
if config.Optimism != nil && len(txs) >= 2 && config.IsBedrock(new(big.Int).SetUint64(blockNumber)) {
616-
gasParams, err := extractL1GasParams(config, blockTime, txs[0].Data())
617-
if err != nil {
618-
return err
619-
}
620-
for i := 0; i < len(rs); i++ {
621-
if txs[i].IsDepositTx() {
622-
continue
623-
}
624-
rs[i].L1GasPrice = gasParams.l1BaseFee
625-
rs[i].L1BlobBaseFee = gasParams.l1BlobBaseFee
626-
rs[i].L1Fee, rs[i].L1GasUsed = gasParams.costFunc(txs[i].RollupCostData())
627-
rs[i].FeeScalar = gasParams.feeScalar
628-
rs[i].L1BaseFeeScalar = u32ptrTou64ptr(gasParams.l1BaseFeeScalar)
629-
rs[i].L1BlobBaseFeeScalar = u32ptrTou64ptr(gasParams.l1BlobBaseFeeScalar)
630-
if gasParams.operatorFeeScalar != nil && gasParams.operatorFeeConstant != nil && (*gasParams.operatorFeeScalar != 0 || *gasParams.operatorFeeConstant != 0) {
631-
rs[i].OperatorFeeScalar = u32ptrTou64ptr(gasParams.operatorFeeScalar)
632-
rs[i].OperatorFeeConstant = gasParams.operatorFeeConstant
633-
}
634-
}
617+
if config.IsOptimismBedrock(new(big.Int).SetUint64(blockNumber)) && len(txs) >= 2 {
618+
return rs.deriveOPStackFields(config, blockTime, txs)
635619
}
636620
return nil
637621
}

core/types/receipt_opstack.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package types
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/ethereum/go-ethereum/params"
7+
)
8+
9+
// deriveOPStackFields derives the OP Stack specific fields for each receipt.
10+
// It must only be called for blocks with at least one transaction (the L1 attributes deposit).
11+
func (rs Receipts) deriveOPStackFields(config *params.ChainConfig, blockTime uint64, txs []*Transaction) error {
12+
// Exit early if there are only deposit transactions, for which no fields are derived.
13+
if txs[len(txs)-1].IsDepositTx() {
14+
return nil
15+
}
16+
17+
l1AttributesData := txs[0].Data()
18+
gasParams, err := extractL1GasParams(config, blockTime, l1AttributesData)
19+
if err != nil {
20+
return fmt.Errorf("failed to extract L1 gas params: %w", err)
21+
}
22+
23+
var daFootprintGasScalar uint64
24+
isJovian := config.IsJovian(blockTime)
25+
if isJovian {
26+
scalar, err := ExtractDAFootprintGasScalar(l1AttributesData)
27+
if err != nil {
28+
return fmt.Errorf("failed to extract DA footprint gas scalar: %w", err)
29+
}
30+
daFootprintGasScalar = uint64(scalar)
31+
}
32+
33+
for i := range rs {
34+
if txs[i].IsDepositTx() {
35+
continue
36+
}
37+
rs[i].L1GasPrice = gasParams.l1BaseFee
38+
rs[i].L1BlobBaseFee = gasParams.l1BlobBaseFee
39+
rcd := txs[i].RollupCostData()
40+
rs[i].L1Fee, rs[i].L1GasUsed = gasParams.costFunc(rcd)
41+
rs[i].FeeScalar = gasParams.feeScalar
42+
rs[i].L1BaseFeeScalar = u32ptrTou64ptr(gasParams.l1BaseFeeScalar)
43+
rs[i].L1BlobBaseFeeScalar = u32ptrTou64ptr(gasParams.l1BlobBaseFeeScalar)
44+
if gasParams.operatorFeeScalar != nil && gasParams.operatorFeeConstant != nil && (*gasParams.operatorFeeScalar != 0 || *gasParams.operatorFeeConstant != 0) {
45+
rs[i].OperatorFeeScalar = u32ptrTou64ptr(gasParams.operatorFeeScalar)
46+
rs[i].OperatorFeeConstant = gasParams.operatorFeeConstant
47+
}
48+
if isJovian {
49+
rs[i].DAFootprintGasScalar = &daFootprintGasScalar
50+
rs[i].BlobGasUsed = daFootprintGasScalar * rcd.EstimatedDASize().Uint64()
51+
}
52+
}
53+
return nil
54+
}

0 commit comments

Comments
 (0)