Skip to content

Commit

Permalink
blobGasPrice should be marshalled as hex (#10551)
Browse files Browse the repository at this point in the history
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>
```
  • Loading branch information
yperbasis authored May 30, 2024
1 parent 4613567 commit 3d325d0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 78 deletions.
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

0 comments on commit 3d325d0

Please sign in to comment.