Skip to content

Commit 3d325d0

Browse files
authored
blobGasPrice should be marshalled as hex (#10551)
This fixes Hive test failures like ``` << (0f4f36d6) {"jsonrpc":"2.0","id":155,"result":{"blobGasPrice":"1","blobGasUsed":"0xc0000","blockHash":"0xdee5398befed018be8f4307ab6f7d4b0f06449880852b1f31d0c5c0820a74de1","blockNumber":"0x1","contractAddress":null,"cumulativeGasUsed":"0x5208","effectiveGasPrice":"0x6fc23ac0","from":"0xf4266f827277b31341deb04983e39c9bc4d66234","gasUsed":"0x5208","logs":[],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","status":"0x1","to":"0x0000000000000000000000000000000000020000","transactionHash":"0x3fb55776c54797702eccbb4fec222204f37eec3c6c87603cd5eb37e86111bee4","transactionIndex":"0x0","type":"0x3"}} FAIL (Parallel Blob Transactions): Unexpected error on TransactionReceipt: json: cannot unmarshal hex string without 0x prefix into Go struct field Receipt.blobGasPrice of type *hexutil.Big, expected=<None> ```
1 parent 4613567 commit 3d325d0

File tree

3 files changed

+8
-78
lines changed

3 files changed

+8
-78
lines changed

eth/ethutils/receipt.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ func MarshalReceipt(
5353
}
5454

5555
if !chainConfig.IsLondon(header.Number.Uint64()) {
56-
fields["effectiveGasPrice"] = hexutil.Uint64(txn.GetPrice().Uint64())
56+
fields["effectiveGasPrice"] = (*hexutil.Big)(txn.GetPrice().ToBig())
5757
} else {
5858
baseFee, _ := uint256.FromBig(header.BaseFee)
5959
gasPrice := new(big.Int).Add(header.BaseFee, txn.GetEffectiveGasTip(baseFee).ToBig())
60-
fields["effectiveGasPrice"] = hexutil.Uint64(gasPrice.Uint64())
60+
fields["effectiveGasPrice"] = (*hexutil.Big)(gasPrice)
6161
}
6262

6363
// Assign receipt status.
@@ -81,7 +81,7 @@ func MarshalReceipt(
8181
if err != nil {
8282
log.Error(err.Error())
8383
}
84-
fields["blobGasPrice"] = blobGasPrice
84+
fields["blobGasPrice"] = (*hexutil.Big)(blobGasPrice.ToBig())
8585
fields["blobGasUsed"] = hexutil.Uint64(misc.GetBlobGasUsed(numBlobs))
8686
}
8787
}

turbo/jsonrpc/eth_receipts.go

Lines changed: 3 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,26 @@ package jsonrpc
33
import (
44
"context"
55
"fmt"
6-
"math/big"
7-
8-
"github.com/holiman/uint256"
9-
"github.com/ledgerwatch/erigon-lib/common/hexutil"
10-
"github.com/ledgerwatch/erigon/cmd/state/exec3"
116

127
"github.com/RoaringBitmap/roaring"
138
"github.com/ledgerwatch/log/v3"
149

15-
"github.com/ledgerwatch/erigon-lib/chain"
1610
"github.com/ledgerwatch/erigon-lib/common"
1711
"github.com/ledgerwatch/erigon-lib/kv"
1812
"github.com/ledgerwatch/erigon-lib/kv/bitmapdb"
1913
"github.com/ledgerwatch/erigon-lib/kv/iter"
2014
"github.com/ledgerwatch/erigon-lib/kv/order"
2115
"github.com/ledgerwatch/erigon-lib/kv/rawdbv3"
22-
"github.com/ledgerwatch/erigon/eth/ethutils"
23-
bortypes "github.com/ledgerwatch/erigon/polygon/bor/types"
2416

25-
"github.com/ledgerwatch/erigon/consensus/misc"
17+
"github.com/ledgerwatch/erigon/cmd/state/exec3"
2618
"github.com/ledgerwatch/erigon/core"
2719
"github.com/ledgerwatch/erigon/core/rawdb"
2820
"github.com/ledgerwatch/erigon/core/state"
2921
"github.com/ledgerwatch/erigon/core/types"
3022
"github.com/ledgerwatch/erigon/core/vm"
23+
"github.com/ledgerwatch/erigon/eth/ethutils"
3124
"github.com/ledgerwatch/erigon/eth/filters"
25+
bortypes "github.com/ledgerwatch/erigon/polygon/bor/types"
3226
"github.com/ledgerwatch/erigon/rpc"
3327
"github.com/ledgerwatch/erigon/turbo/rpchelper"
3428
"github.com/ledgerwatch/erigon/turbo/transactions"
@@ -570,71 +564,6 @@ func (api *APIImpl) GetBlockReceipts(ctx context.Context, numberOrHash rpc.Block
570564
return result, nil
571565
}
572566

573-
func marshalReceipt(receipt *types.Receipt, txn types.Transaction, chainConfig *chain.Config, header *types.Header, txnHash common.Hash, signed bool) map[string]interface{} {
574-
var chainId *big.Int
575-
switch t := txn.(type) {
576-
case *types.LegacyTx:
577-
if t.Protected() {
578-
chainId = types.DeriveChainId(&t.V).ToBig()
579-
}
580-
default:
581-
chainId = txn.GetChainID().ToBig()
582-
}
583-
584-
var from common.Address
585-
if signed {
586-
signer := types.LatestSignerForChainID(chainId)
587-
from, _ = txn.Sender(*signer)
588-
}
589-
590-
fields := map[string]interface{}{
591-
"blockHash": receipt.BlockHash,
592-
"blockNumber": hexutil.Uint64(receipt.BlockNumber.Uint64()),
593-
"transactionHash": txnHash,
594-
"transactionIndex": hexutil.Uint64(receipt.TransactionIndex),
595-
"from": from,
596-
"to": txn.GetTo(),
597-
"type": hexutil.Uint(txn.Type()),
598-
"gasUsed": hexutil.Uint64(receipt.GasUsed),
599-
"cumulativeGasUsed": hexutil.Uint64(receipt.CumulativeGasUsed),
600-
"contractAddress": nil,
601-
"logs": receipt.Logs,
602-
"logsBloom": types.CreateBloom(types.Receipts{receipt}),
603-
}
604-
605-
if !chainConfig.IsLondon(header.Number.Uint64()) {
606-
fields["effectiveGasPrice"] = hexutil.Uint64(txn.GetPrice().Uint64())
607-
} else {
608-
baseFee, _ := uint256.FromBig(header.BaseFee)
609-
gasPrice := new(big.Int).Add(header.BaseFee, txn.GetEffectiveGasTip(baseFee).ToBig())
610-
fields["effectiveGasPrice"] = hexutil.Uint64(gasPrice.Uint64())
611-
}
612-
// Assign receipt status.
613-
fields["status"] = hexutil.Uint64(receipt.Status)
614-
if receipt.Logs == nil {
615-
fields["logs"] = [][]*types.Log{}
616-
}
617-
// If the ContractAddress is 20 0x0 bytes, assume it is not a contract creation
618-
if receipt.ContractAddress != (common.Address{}) {
619-
fields["contractAddress"] = receipt.ContractAddress
620-
}
621-
// Set derived blob related fields
622-
numBlobs := len(txn.GetBlobHashes())
623-
if numBlobs > 0 {
624-
if header.ExcessBlobGas == nil {
625-
log.Warn("excess blob gas not set when trying to marshal blob tx")
626-
} else {
627-
blobGasPrice, err := misc.GetBlobGasPrice(chainConfig, *header.ExcessBlobGas)
628-
if err != nil {
629-
log.Error(err.Error())
630-
}
631-
fields["blobGasPrice"] = blobGasPrice
632-
fields["blobGasUsed"] = hexutil.Uint64(misc.GetBlobGasUsed(numBlobs))
633-
}
634-
}
635-
return fields
636-
}
637-
638567
// MapTxNum2BlockNumIter - enrich iterator by TxNumbers, adding more info:
639568
// - blockNum
640569
// - txIndex in block: -1 means first system tx

turbo/jsonrpc/otterscan_search_v3.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/ledgerwatch/erigon-lib/kv/rawdbv3"
1212
"github.com/ledgerwatch/erigon/cmd/state/exec3"
1313
"github.com/ledgerwatch/erigon/core/types"
14+
"github.com/ledgerwatch/erigon/eth/ethutils"
1415
"github.com/ledgerwatch/log/v3"
1516
)
1617

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

105-
mReceipt := marshalReceipt(receipt, txn, chainConfig, header, txn.Hash(), true)
106+
mReceipt := ethutils.MarshalReceipt(receipt, txn, chainConfig, header, txn.Hash(), true)
106107
mReceipt["timestamp"] = header.Time
107108
receipts = append(receipts, mReceipt)
108109

0 commit comments

Comments
 (0)