mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-14 07:53:47 +00:00
feat(api): add L1 fee to eth_getTransactionReceipt (#244)
* Update api.go * fmt * revert changes * add l1fee to receipt in transaction processor * decoder * fmt * fmt * add encoding, test * fmt * removed duplicate l1 fee calc, added gen receipt * remove dup l1feecalc * lint * add omitempty * bump version --------- Co-authored-by: Péter Garamvölgyi <th307q@gmail.com> Co-authored-by: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com> Co-authored-by: Péter Garamvölgyi <peter@scroll.io>
This commit is contained in:
parent
4da184ea60
commit
a74b35e86f
7 changed files with 69 additions and 2 deletions
|
|
@ -623,6 +623,7 @@ type storedReceiptRLP struct {
|
||||||
PostStateOrStatus []byte
|
PostStateOrStatus []byte
|
||||||
CumulativeGasUsed uint64
|
CumulativeGasUsed uint64
|
||||||
Logs []*types.LogForStorage
|
Logs []*types.LogForStorage
|
||||||
|
L1Fee *big.Int
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReceiptLogs is a barebone version of ReceiptForStorage which only keeps
|
// ReceiptLogs is a barebone version of ReceiptForStorage which only keeps
|
||||||
|
|
|
||||||
|
|
@ -139,6 +139,7 @@ func applyTransaction(msg types.Message, config *params.ChainConfig, bc ChainCon
|
||||||
receipt.BlockHash = blockHash
|
receipt.BlockHash = blockHash
|
||||||
receipt.BlockNumber = blockNumber
|
receipt.BlockNumber = blockNumber
|
||||||
receipt.TransactionIndex = uint(statedb.TxIndex())
|
receipt.TransactionIndex = uint(statedb.TxIndex())
|
||||||
|
receipt.L1Fee = result.L1Fee
|
||||||
return receipt, err
|
return receipt, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,8 @@ func (r Receipt) MarshalJSON() ([]byte, error) {
|
||||||
BlockHash common.Hash `json:"blockHash,omitempty"`
|
BlockHash common.Hash `json:"blockHash,omitempty"`
|
||||||
BlockNumber *hexutil.Big `json:"blockNumber,omitempty"`
|
BlockNumber *hexutil.Big `json:"blockNumber,omitempty"`
|
||||||
TransactionIndex hexutil.Uint `json:"transactionIndex"`
|
TransactionIndex hexutil.Uint `json:"transactionIndex"`
|
||||||
|
ReturnValue []byte `json:"returnValue,omitempty"`
|
||||||
|
L1Fee *big.Int `json:"l1Fee" gencodec:"required"`
|
||||||
}
|
}
|
||||||
var enc Receipt
|
var enc Receipt
|
||||||
enc.Type = hexutil.Uint64(r.Type)
|
enc.Type = hexutil.Uint64(r.Type)
|
||||||
|
|
@ -42,6 +44,8 @@ func (r Receipt) MarshalJSON() ([]byte, error) {
|
||||||
enc.BlockHash = r.BlockHash
|
enc.BlockHash = r.BlockHash
|
||||||
enc.BlockNumber = (*hexutil.Big)(r.BlockNumber)
|
enc.BlockNumber = (*hexutil.Big)(r.BlockNumber)
|
||||||
enc.TransactionIndex = hexutil.Uint(r.TransactionIndex)
|
enc.TransactionIndex = hexutil.Uint(r.TransactionIndex)
|
||||||
|
enc.ReturnValue = r.ReturnValue
|
||||||
|
enc.L1Fee = r.L1Fee
|
||||||
return json.Marshal(&enc)
|
return json.Marshal(&enc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -60,6 +64,8 @@ func (r *Receipt) UnmarshalJSON(input []byte) error {
|
||||||
BlockHash *common.Hash `json:"blockHash,omitempty"`
|
BlockHash *common.Hash `json:"blockHash,omitempty"`
|
||||||
BlockNumber *hexutil.Big `json:"blockNumber,omitempty"`
|
BlockNumber *hexutil.Big `json:"blockNumber,omitempty"`
|
||||||
TransactionIndex *hexutil.Uint `json:"transactionIndex"`
|
TransactionIndex *hexutil.Uint `json:"transactionIndex"`
|
||||||
|
ReturnValue []byte `json:"returnValue,omitempty"`
|
||||||
|
L1Fee *big.Int `json:"l1Fee" gencodec:"required"`
|
||||||
}
|
}
|
||||||
var dec Receipt
|
var dec Receipt
|
||||||
if err := json.Unmarshal(input, &dec); err != nil {
|
if err := json.Unmarshal(input, &dec); err != nil {
|
||||||
|
|
@ -106,5 +112,12 @@ func (r *Receipt) UnmarshalJSON(input []byte) error {
|
||||||
if dec.TransactionIndex != nil {
|
if dec.TransactionIndex != nil {
|
||||||
r.TransactionIndex = uint(*dec.TransactionIndex)
|
r.TransactionIndex = uint(*dec.TransactionIndex)
|
||||||
}
|
}
|
||||||
|
if dec.ReturnValue != nil {
|
||||||
|
r.ReturnValue = dec.ReturnValue
|
||||||
|
}
|
||||||
|
if dec.L1Fee == nil {
|
||||||
|
return errors.New("missing required field 'l1Fee' for Receipt")
|
||||||
|
}
|
||||||
|
r.L1Fee = dec.L1Fee
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,9 @@ type Receipt struct {
|
||||||
|
|
||||||
// The value of evm execution result.
|
// The value of evm execution result.
|
||||||
ReturnValue []byte `json:"returnValue,omitempty"`
|
ReturnValue []byte `json:"returnValue,omitempty"`
|
||||||
|
|
||||||
|
// Scroll rollup
|
||||||
|
L1Fee *big.Int `json:"l1Fee,omitempty" gencodec:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type receiptMarshaling struct {
|
type receiptMarshaling struct {
|
||||||
|
|
@ -98,6 +101,14 @@ type storedReceiptRLP struct {
|
||||||
PostStateOrStatus []byte
|
PostStateOrStatus []byte
|
||||||
CumulativeGasUsed uint64
|
CumulativeGasUsed uint64
|
||||||
Logs []*LogForStorage
|
Logs []*LogForStorage
|
||||||
|
L1Fee *big.Int
|
||||||
|
}
|
||||||
|
|
||||||
|
// v5StoredReceiptRLP is the storage encoding of a receipt used in database version 5.
|
||||||
|
type v5StoredReceiptRLP struct {
|
||||||
|
PostStateOrStatus []byte
|
||||||
|
CumulativeGasUsed uint64
|
||||||
|
Logs []*LogForStorage
|
||||||
}
|
}
|
||||||
|
|
||||||
// v4StoredReceiptRLP is the storage encoding of a receipt used in database version 4.
|
// v4StoredReceiptRLP is the storage encoding of a receipt used in database version 4.
|
||||||
|
|
@ -295,6 +306,7 @@ func (r *ReceiptForStorage) EncodeRLP(w io.Writer) error {
|
||||||
PostStateOrStatus: (*Receipt)(r).statusEncoding(),
|
PostStateOrStatus: (*Receipt)(r).statusEncoding(),
|
||||||
CumulativeGasUsed: r.CumulativeGasUsed,
|
CumulativeGasUsed: r.CumulativeGasUsed,
|
||||||
Logs: make([]*LogForStorage, len(r.Logs)),
|
Logs: make([]*LogForStorage, len(r.Logs)),
|
||||||
|
L1Fee: r.L1Fee,
|
||||||
}
|
}
|
||||||
for i, log := range r.Logs {
|
for i, log := range r.Logs {
|
||||||
enc.Logs[i] = (*LogForStorage)(log)
|
enc.Logs[i] = (*LogForStorage)(log)
|
||||||
|
|
@ -319,7 +331,10 @@ func (r *ReceiptForStorage) DecodeRLP(s *rlp.Stream) error {
|
||||||
if err := decodeV3StoredReceiptRLP(r, blob); err == nil {
|
if err := decodeV3StoredReceiptRLP(r, blob); err == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return decodeV4StoredReceiptRLP(r, blob)
|
if err := decodeV4StoredReceiptRLP(r, blob); err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return decodeV5StoredReceiptRLP(r, blob)
|
||||||
}
|
}
|
||||||
|
|
||||||
func decodeStoredReceiptRLP(r *ReceiptForStorage, blob []byte) error {
|
func decodeStoredReceiptRLP(r *ReceiptForStorage, blob []byte) error {
|
||||||
|
|
@ -336,6 +351,25 @@ func decodeStoredReceiptRLP(r *ReceiptForStorage, blob []byte) error {
|
||||||
r.Logs[i] = (*Log)(log)
|
r.Logs[i] = (*Log)(log)
|
||||||
}
|
}
|
||||||
r.Bloom = CreateBloom(Receipts{(*Receipt)(r)})
|
r.Bloom = CreateBloom(Receipts{(*Receipt)(r)})
|
||||||
|
r.L1Fee = stored.L1Fee
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeV5StoredReceiptRLP(r *ReceiptForStorage, blob []byte) error {
|
||||||
|
var stored v5StoredReceiptRLP
|
||||||
|
if err := rlp.DecodeBytes(blob, &stored); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := (*Receipt)(r).setStatus(stored.PostStateOrStatus); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
r.CumulativeGasUsed = stored.CumulativeGasUsed
|
||||||
|
r.Logs = make([]*Log, len(stored.Logs))
|
||||||
|
for i, log := range stored.Logs {
|
||||||
|
r.Logs[i] = (*Log)(log)
|
||||||
|
}
|
||||||
|
r.Bloom = CreateBloom(Receipts{(*Receipt)(r)})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,10 @@ func TestLegacyReceiptDecoding(t *testing.T) {
|
||||||
"StoredReceiptRLP",
|
"StoredReceiptRLP",
|
||||||
encodeAsStoredReceiptRLP,
|
encodeAsStoredReceiptRLP,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"V5StoredReceiptRLP",
|
||||||
|
encodeAsV5StoredReceiptRLP,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"V4StoredReceiptRLP",
|
"V4StoredReceiptRLP",
|
||||||
encodeAsV4StoredReceiptRLP,
|
encodeAsV4StoredReceiptRLP,
|
||||||
|
|
@ -175,6 +179,19 @@ func encodeAsStoredReceiptRLP(want *Receipt) ([]byte, error) {
|
||||||
PostStateOrStatus: want.statusEncoding(),
|
PostStateOrStatus: want.statusEncoding(),
|
||||||
CumulativeGasUsed: want.CumulativeGasUsed,
|
CumulativeGasUsed: want.CumulativeGasUsed,
|
||||||
Logs: make([]*LogForStorage, len(want.Logs)),
|
Logs: make([]*LogForStorage, len(want.Logs)),
|
||||||
|
L1Fee: want.L1Fee,
|
||||||
|
}
|
||||||
|
for i, log := range want.Logs {
|
||||||
|
stored.Logs[i] = (*LogForStorage)(log)
|
||||||
|
}
|
||||||
|
return rlp.EncodeToBytes(stored)
|
||||||
|
}
|
||||||
|
|
||||||
|
func encodeAsV5StoredReceiptRLP(want *Receipt) ([]byte, error) {
|
||||||
|
stored := &v5StoredReceiptRLP{
|
||||||
|
PostStateOrStatus: want.statusEncoding(),
|
||||||
|
CumulativeGasUsed: want.CumulativeGasUsed,
|
||||||
|
Logs: make([]*LogForStorage, len(want.Logs)),
|
||||||
}
|
}
|
||||||
for i, log := range want.Logs {
|
for i, log := range want.Logs {
|
||||||
stored.Logs[i] = (*LogForStorage)(log)
|
stored.Logs[i] = (*LogForStorage)(log)
|
||||||
|
|
|
||||||
|
|
@ -1579,6 +1579,7 @@ func (s *PublicTransactionPoolAPI) GetTransactionReceipt(ctx context.Context, ha
|
||||||
"logs": receipt.Logs,
|
"logs": receipt.Logs,
|
||||||
"logsBloom": receipt.Bloom,
|
"logsBloom": receipt.Bloom,
|
||||||
"type": hexutil.Uint(tx.Type()),
|
"type": hexutil.Uint(tx.Type()),
|
||||||
|
"l1Fee": receipt.L1Fee,
|
||||||
}
|
}
|
||||||
// Assign the effective gas price paid
|
// Assign the effective gas price paid
|
||||||
if !s.b.ChainConfig().IsLondon(bigblock) {
|
if !s.b.ChainConfig().IsLondon(bigblock) {
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import (
|
||||||
const (
|
const (
|
||||||
VersionMajor = 3 // Major version component of the current release
|
VersionMajor = 3 // Major version component of the current release
|
||||||
VersionMinor = 1 // Minor version component of the current release
|
VersionMinor = 1 // Minor version component of the current release
|
||||||
VersionPatch = 0 // Patch version component of the current release
|
VersionPatch = 1 // Patch version component of the current release
|
||||||
VersionMeta = "alpha" // Version metadata to append to the version string
|
VersionMeta = "alpha" // Version metadata to append to the version string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue