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:
Max Wolff 2023-03-27 18:08:57 -07:00 committed by GitHub
parent 4da184ea60
commit a74b35e86f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 69 additions and 2 deletions

View file

@ -623,6 +623,7 @@ type storedReceiptRLP struct {
PostStateOrStatus []byte
CumulativeGasUsed uint64
Logs []*types.LogForStorage
L1Fee *big.Int
}
// ReceiptLogs is a barebone version of ReceiptForStorage which only keeps

View file

@ -139,6 +139,7 @@ func applyTransaction(msg types.Message, config *params.ChainConfig, bc ChainCon
receipt.BlockHash = blockHash
receipt.BlockNumber = blockNumber
receipt.TransactionIndex = uint(statedb.TxIndex())
receipt.L1Fee = result.L1Fee
return receipt, err
}

View file

@ -28,6 +28,8 @@ func (r Receipt) MarshalJSON() ([]byte, error) {
BlockHash common.Hash `json:"blockHash,omitempty"`
BlockNumber *hexutil.Big `json:"blockNumber,omitempty"`
TransactionIndex hexutil.Uint `json:"transactionIndex"`
ReturnValue []byte `json:"returnValue,omitempty"`
L1Fee *big.Int `json:"l1Fee" gencodec:"required"`
}
var enc Receipt
enc.Type = hexutil.Uint64(r.Type)
@ -42,6 +44,8 @@ func (r Receipt) MarshalJSON() ([]byte, error) {
enc.BlockHash = r.BlockHash
enc.BlockNumber = (*hexutil.Big)(r.BlockNumber)
enc.TransactionIndex = hexutil.Uint(r.TransactionIndex)
enc.ReturnValue = r.ReturnValue
enc.L1Fee = r.L1Fee
return json.Marshal(&enc)
}
@ -60,6 +64,8 @@ func (r *Receipt) UnmarshalJSON(input []byte) error {
BlockHash *common.Hash `json:"blockHash,omitempty"`
BlockNumber *hexutil.Big `json:"blockNumber,omitempty"`
TransactionIndex *hexutil.Uint `json:"transactionIndex"`
ReturnValue []byte `json:"returnValue,omitempty"`
L1Fee *big.Int `json:"l1Fee" gencodec:"required"`
}
var dec Receipt
if err := json.Unmarshal(input, &dec); err != nil {
@ -106,5 +112,12 @@ func (r *Receipt) UnmarshalJSON(input []byte) error {
if dec.TransactionIndex != nil {
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
}

View file

@ -73,6 +73,9 @@ type Receipt struct {
// The value of evm execution result.
ReturnValue []byte `json:"returnValue,omitempty"`
// Scroll rollup
L1Fee *big.Int `json:"l1Fee,omitempty" gencodec:"required"`
}
type receiptMarshaling struct {
@ -98,6 +101,14 @@ type storedReceiptRLP struct {
PostStateOrStatus []byte
CumulativeGasUsed uint64
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.
@ -295,6 +306,7 @@ func (r *ReceiptForStorage) EncodeRLP(w io.Writer) error {
PostStateOrStatus: (*Receipt)(r).statusEncoding(),
CumulativeGasUsed: r.CumulativeGasUsed,
Logs: make([]*LogForStorage, len(r.Logs)),
L1Fee: r.L1Fee,
}
for i, log := range r.Logs {
enc.Logs[i] = (*LogForStorage)(log)
@ -319,7 +331,10 @@ func (r *ReceiptForStorage) DecodeRLP(s *rlp.Stream) error {
if err := decodeV3StoredReceiptRLP(r, blob); err == 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 {
@ -336,6 +351,25 @@ func decodeStoredReceiptRLP(r *ReceiptForStorage, blob []byte) error {
r.Logs[i] = (*Log)(log)
}
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
}

View file

@ -100,6 +100,10 @@ func TestLegacyReceiptDecoding(t *testing.T) {
"StoredReceiptRLP",
encodeAsStoredReceiptRLP,
},
{
"V5StoredReceiptRLP",
encodeAsV5StoredReceiptRLP,
},
{
"V4StoredReceiptRLP",
encodeAsV4StoredReceiptRLP,
@ -175,6 +179,19 @@ func encodeAsStoredReceiptRLP(want *Receipt) ([]byte, error) {
PostStateOrStatus: want.statusEncoding(),
CumulativeGasUsed: want.CumulativeGasUsed,
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 {
stored.Logs[i] = (*LogForStorage)(log)

View file

@ -1579,6 +1579,7 @@ func (s *PublicTransactionPoolAPI) GetTransactionReceipt(ctx context.Context, ha
"logs": receipt.Logs,
"logsBloom": receipt.Bloom,
"type": hexutil.Uint(tx.Type()),
"l1Fee": receipt.L1Fee,
}
// Assign the effective gas price paid
if !s.b.ChainConfig().IsLondon(bigblock) {

View file

@ -24,7 +24,7 @@ import (
const (
VersionMajor = 3 // Major 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
)