internal/ethapi: eth api changes needed #27928 (#1818)

This commit is contained in:
Daniel Liu 2025-12-08 15:26:40 +08:00 committed by GitHub
parent 8664487b0c
commit 0c2b0f3234
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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