From 0c2b0f323403726c3d0d630d3c94c1700bd20514 Mon Sep 17 00:00:00 2001 From: Daniel Liu <139250065@qq.com> Date: Mon, 8 Dec 2025 15:26:40 +0800 Subject: [PATCH] internal/ethapi: eth api changes needed #27928 (#1818) --- internal/ethapi/api.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 587522fc34..ca8471a187 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1711,12 +1711,7 @@ func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber // if the transaction has been mined, compute the effective gas price if baseFee != nil && blockHash != (common.Hash{}) { // price = min(tip, gasFeeCap - baseFee) + baseFee - price := new(big.Int).Add(tx.GasTipCap(), baseFee) - txGasFeeCap := tx.GasFeeCap() - if price.Cmp(txGasFeeCap) > 0 { - price = txGasFeeCap - } - result.GasPrice = (*hexutil.Big)(price) + result.GasPrice = (*hexutil.Big)(effectiveGasPrice(tx, baseFee)) } else { result.GasPrice = (*hexutil.Big)(tx.GasFeeCap()) } @@ -1724,6 +1719,18 @@ func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber return result } +// effectiveGasPrice computes the transaction gas fee, based on the given basefee value. +// +// price = min(gasTipCap + baseFee, gasFeeCap) +func effectiveGasPrice(tx *types.Transaction, baseFee *big.Int) *big.Int { + fee := tx.GasTipCap() + fee = fee.Add(fee, baseFee) + if tx.GasFeeCapIntCmp(fee) < 0 { + return tx.GasFeeCap() + } + return fee +} + // newRPCPendingTransaction returns a pending transaction that will serialize to the RPC representation func newRPCPendingTransaction(tx *types.Transaction, current *types.Header, config *params.ChainConfig) *RPCTransaction { var baseFee *big.Int