From c5853163b580550a25f0a7cfab6544e4d3bbee5a Mon Sep 17 00:00:00 2001 From: yperbasis Date: Wed, 29 May 2024 17:34:36 +0200 Subject: [PATCH 1/2] blobGasPrice should be marshaled as hex --- turbo/jsonrpc/eth_receipts.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/turbo/jsonrpc/eth_receipts.go b/turbo/jsonrpc/eth_receipts.go index 6916b45bceb..e45005f7a1b 100644 --- a/turbo/jsonrpc/eth_receipts.go +++ b/turbo/jsonrpc/eth_receipts.go @@ -5,30 +5,29 @@ import ( "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/holiman/uint256" "github.com/ledgerwatch/log/v3" "github.com/ledgerwatch/erigon-lib/chain" "github.com/ledgerwatch/erigon-lib/common" + "github.com/ledgerwatch/erigon-lib/common/hexutil" "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/cmd/state/exec3" "github.com/ledgerwatch/erigon/consensus/misc" "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" @@ -603,11 +602,11 @@ func marshalReceipt(receipt *types.Receipt, txn types.Transaction, chainConfig * } 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. fields["status"] = hexutil.Uint64(receipt.Status) @@ -628,7 +627,7 @@ func marshalReceipt(receipt *types.Receipt, txn types.Transaction, chainConfig * if err != nil { log.Error(err.Error()) } - fields["blobGasPrice"] = blobGasPrice + fields["blobGasPrice"] = (*hexutil.Big)(blobGasPrice.ToBig()) fields["blobGasUsed"] = hexutil.Uint64(misc.GetBlobGasUsed(numBlobs)) } } From daf3b18b39fa05ab753ab07768228eb2c8e8bbc1 Mon Sep 17 00:00:00 2001 From: yperbasis Date: Thu, 30 May 2024 09:09:15 +0200 Subject: [PATCH 2/2] remove duplicated marshalReceipt --- eth/ethutils/receipt.go | 6 +-- turbo/jsonrpc/eth_receipts.go | 70 ---------------------------- turbo/jsonrpc/otterscan_search_v3.go | 3 +- 3 files changed, 5 insertions(+), 74 deletions(-) diff --git a/eth/ethutils/receipt.go b/eth/ethutils/receipt.go index 43fa46f168b..2caa571290e 100644 --- a/eth/ethutils/receipt.go +++ b/eth/ethutils/receipt.go @@ -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. @@ -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)) } } diff --git a/turbo/jsonrpc/eth_receipts.go b/turbo/jsonrpc/eth_receipts.go index e45005f7a1b..fde78029fb4 100644 --- a/turbo/jsonrpc/eth_receipts.go +++ b/turbo/jsonrpc/eth_receipts.go @@ -3,15 +3,11 @@ package jsonrpc import ( "context" "fmt" - "math/big" "github.com/RoaringBitmap/roaring" - "github.com/holiman/uint256" "github.com/ledgerwatch/log/v3" - "github.com/ledgerwatch/erigon-lib/chain" "github.com/ledgerwatch/erigon-lib/common" - "github.com/ledgerwatch/erigon-lib/common/hexutil" "github.com/ledgerwatch/erigon-lib/kv" "github.com/ledgerwatch/erigon-lib/kv/bitmapdb" "github.com/ledgerwatch/erigon-lib/kv/iter" @@ -19,7 +15,6 @@ import ( "github.com/ledgerwatch/erigon-lib/kv/rawdbv3" "github.com/ledgerwatch/erigon/cmd/state/exec3" - "github.com/ledgerwatch/erigon/consensus/misc" "github.com/ledgerwatch/erigon/core" "github.com/ledgerwatch/erigon/core/rawdb" "github.com/ledgerwatch/erigon/core/state" @@ -569,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.Big)(txn.GetPrice().ToBig()) - } else { - baseFee, _ := uint256.FromBig(header.BaseFee) - gasPrice := new(big.Int).Add(header.BaseFee, txn.GetEffectiveGasTip(baseFee).ToBig()) - fields["effectiveGasPrice"] = (*hexutil.Big)(gasPrice) - } - // 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"] = (*hexutil.Big)(blobGasPrice.ToBig()) - 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 diff --git a/turbo/jsonrpc/otterscan_search_v3.go b/turbo/jsonrpc/otterscan_search_v3.go index 8c8797aa333..2f54fa3589e 100644 --- a/turbo/jsonrpc/otterscan_search_v3.go +++ b/turbo/jsonrpc/otterscan_search_v3.go @@ -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" ) @@ -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)