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

blobGasPrice should be marshalled as hex #10551

Merged
merged 2 commits into from
May 30, 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
6 changes: 3 additions & 3 deletions eth/ethutils/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ func MarshalReceipt(
}

if !chainConfig.IsLondon(header.Number.Uint64()) {
fields["effectiveGasPrice"] = hexutil.Uint64(txn.GetPrice().Uint64())
fields["effectiveGasPrice"] = (*hexutil.Big)(txn.GetPrice().ToBig())
} else {
baseFee, _ := uint256.FromBig(header.BaseFee)
gasPrice := new(big.Int).Add(header.BaseFee, txn.GetEffectiveGasTip(baseFee).ToBig())
fields["effectiveGasPrice"] = hexutil.Uint64(gasPrice.Uint64())
fields["effectiveGasPrice"] = (*hexutil.Big)(gasPrice)
}

// Assign receipt status.
Expand All @@ -81,7 +81,7 @@ func MarshalReceipt(
if err != nil {
log.Error(err.Error())
}
fields["blobGasPrice"] = blobGasPrice
fields["blobGasPrice"] = (*hexutil.Big)(blobGasPrice.ToBig())
fields["blobGasUsed"] = hexutil.Uint64(misc.GetBlobGasUsed(numBlobs))
}
}
Expand Down
77 changes: 3 additions & 74 deletions turbo/jsonrpc/eth_receipts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,26 @@ package jsonrpc
import (
"context"
"fmt"
"math/big"

"github.com/holiman/uint256"
"github.com/ledgerwatch/erigon-lib/common/hexutil"
"github.com/ledgerwatch/erigon/cmd/state/exec3"

"github.com/RoaringBitmap/roaring"
"github.com/ledgerwatch/log/v3"

"github.com/ledgerwatch/erigon-lib/chain"
"github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon-lib/kv/bitmapdb"
"github.com/ledgerwatch/erigon-lib/kv/iter"
"github.com/ledgerwatch/erigon-lib/kv/order"
"github.com/ledgerwatch/erigon-lib/kv/rawdbv3"
"github.com/ledgerwatch/erigon/eth/ethutils"
bortypes "github.com/ledgerwatch/erigon/polygon/bor/types"

"github.com/ledgerwatch/erigon/consensus/misc"
"github.com/ledgerwatch/erigon/cmd/state/exec3"
"github.com/ledgerwatch/erigon/core"
"github.com/ledgerwatch/erigon/core/rawdb"
"github.com/ledgerwatch/erigon/core/state"
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/core/vm"
"github.com/ledgerwatch/erigon/eth/ethutils"
"github.com/ledgerwatch/erigon/eth/filters"
bortypes "github.com/ledgerwatch/erigon/polygon/bor/types"
"github.com/ledgerwatch/erigon/rpc"
"github.com/ledgerwatch/erigon/turbo/rpchelper"
"github.com/ledgerwatch/erigon/turbo/transactions"
Expand Down Expand Up @@ -570,71 +564,6 @@ func (api *APIImpl) GetBlockReceipts(ctx context.Context, numberOrHash rpc.Block
return result, nil
}

func marshalReceipt(receipt *types.Receipt, txn types.Transaction, chainConfig *chain.Config, header *types.Header, txnHash common.Hash, signed bool) map[string]interface{} {
var chainId *big.Int
switch t := txn.(type) {
case *types.LegacyTx:
if t.Protected() {
chainId = types.DeriveChainId(&t.V).ToBig()
}
default:
chainId = txn.GetChainID().ToBig()
}

var from common.Address
if signed {
signer := types.LatestSignerForChainID(chainId)
from, _ = txn.Sender(*signer)
}

fields := map[string]interface{}{
"blockHash": receipt.BlockHash,
"blockNumber": hexutil.Uint64(receipt.BlockNumber.Uint64()),
"transactionHash": txnHash,
"transactionIndex": hexutil.Uint64(receipt.TransactionIndex),
"from": from,
"to": txn.GetTo(),
"type": hexutil.Uint(txn.Type()),
"gasUsed": hexutil.Uint64(receipt.GasUsed),
"cumulativeGasUsed": hexutil.Uint64(receipt.CumulativeGasUsed),
"contractAddress": nil,
"logs": receipt.Logs,
"logsBloom": types.CreateBloom(types.Receipts{receipt}),
}

if !chainConfig.IsLondon(header.Number.Uint64()) {
fields["effectiveGasPrice"] = hexutil.Uint64(txn.GetPrice().Uint64())
} else {
baseFee, _ := uint256.FromBig(header.BaseFee)
gasPrice := new(big.Int).Add(header.BaseFee, txn.GetEffectiveGasTip(baseFee).ToBig())
fields["effectiveGasPrice"] = hexutil.Uint64(gasPrice.Uint64())
}
// Assign receipt status.
fields["status"] = hexutil.Uint64(receipt.Status)
if receipt.Logs == nil {
fields["logs"] = [][]*types.Log{}
}
// If the ContractAddress is 20 0x0 bytes, assume it is not a contract creation
if receipt.ContractAddress != (common.Address{}) {
fields["contractAddress"] = receipt.ContractAddress
}
// Set derived blob related fields
numBlobs := len(txn.GetBlobHashes())
if numBlobs > 0 {
if header.ExcessBlobGas == nil {
log.Warn("excess blob gas not set when trying to marshal blob tx")
} else {
blobGasPrice, err := misc.GetBlobGasPrice(chainConfig, *header.ExcessBlobGas)
if err != nil {
log.Error(err.Error())
}
fields["blobGasPrice"] = blobGasPrice
fields["blobGasUsed"] = hexutil.Uint64(misc.GetBlobGasUsed(numBlobs))
}
}
return fields
}

// MapTxNum2BlockNumIter - enrich iterator by TxNumbers, adding more info:
// - blockNum
// - txIndex in block: -1 means first system tx
Expand Down
3 changes: 2 additions & 1 deletion turbo/jsonrpc/otterscan_search_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/ledgerwatch/erigon-lib/kv/rawdbv3"
"github.com/ledgerwatch/erigon/cmd/state/exec3"
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/eth/ethutils"
"github.com/ledgerwatch/log/v3"
)

Expand Down Expand Up @@ -102,7 +103,7 @@ func (api *OtterscanAPIImpl) buildSearchResults(ctx context.Context, tx kv.Tempo
receipt.Status = types.ReceiptStatusSuccessful
}

mReceipt := marshalReceipt(receipt, txn, chainConfig, header, txn.Hash(), true)
mReceipt := ethutils.MarshalReceipt(receipt, txn, chainConfig, header, txn.Hash(), true)
mReceipt["timestamp"] = header.Time
receipts = append(receipts, mReceipt)

Expand Down
Loading