mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
internal/ethapi: optimize calculating effective price
Seems better to have this in a dedicated function, and we can also avoid creating multiple temp bigints.
This commit is contained in:
parent
caa4ffb848
commit
b55a7da151
1 changed files with 15 additions and 5 deletions
|
|
@ -1470,11 +1470,11 @@ 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(gasTipCap + baseFee, gasFeeCap)
|
||||
price := math.BigMin(new(big.Int).Add(tx.GasTipCap(), baseFee), tx.GasFeeCap())
|
||||
result.GasPrice = (*hexutil.Big)(price)
|
||||
result.GasPrice = (*hexutil.Big)(effectiveGasPrice(tx, baseFee))
|
||||
} else {
|
||||
result.GasPrice = (*hexutil.Big)(tx.GasFeeCap())
|
||||
}
|
||||
|
||||
case types.BlobTxType:
|
||||
al := tx.AccessList()
|
||||
yparity := hexutil.Uint64(v.Sign())
|
||||
|
|
@ -1485,9 +1485,7 @@ func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber
|
|||
result.GasTipCap = (*hexutil.Big)(tx.GasTipCap())
|
||||
// if the transaction has been mined, compute the effective gas price
|
||||
if baseFee != nil && blockHash != (common.Hash{}) {
|
||||
// price = min(gasTipCap + baseFee, gasFeeCap)
|
||||
price := math.BigMin(new(big.Int).Add(tx.GasTipCap(), baseFee), tx.GasFeeCap())
|
||||
result.GasPrice = (*hexutil.Big)(price)
|
||||
result.GasPrice = (*hexutil.Big)(effectiveGasPrice(tx, baseFee))
|
||||
} else {
|
||||
result.GasPrice = (*hexutil.Big)(tx.GasFeeCap())
|
||||
}
|
||||
|
|
@ -1497,6 +1495,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.GasTipCapIntCmp(fee) < 0 {
|
||||
return tx.GasTipCap()
|
||||
}
|
||||
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 (
|
||||
|
|
|
|||
Loading…
Reference in a new issue