mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-19 03:10:48 +00:00
core/types: allow fee comparison with large basefee
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
parent
bb6503f36a
commit
b6e2b3e860
1 changed files with 25 additions and 2 deletions
|
|
@ -396,14 +396,37 @@ func (tx *Transaction) calcEffectiveGasTip(dst *uint256.Int, baseFee *uint256.In
|
|||
return err
|
||||
}
|
||||
|
||||
// EffectiveGasTipValue returns the effective gasTip value for the given base fee,
|
||||
// even if it would be negative. This can be used for sorting purposes.
|
||||
func (tx *Transaction) EffectiveGasTipValue(baseFee *big.Int) *big.Int {
|
||||
// min(gasTipCap, gasFeeCap - baseFee)
|
||||
dst := new(big.Int)
|
||||
if baseFee == nil {
|
||||
dst.Set(tx.inner.gasTipCap())
|
||||
return dst
|
||||
}
|
||||
|
||||
dst.Sub(tx.inner.gasFeeCap(), baseFee) // gasFeeCap - baseFee
|
||||
gasTipCap := tx.inner.gasTipCap()
|
||||
if gasTipCap.Cmp(dst) < 0 { // gasTipCap < (gasFeeCap - baseFee)
|
||||
dst.Set(gasTipCap)
|
||||
}
|
||||
return dst
|
||||
}
|
||||
|
||||
func (tx *Transaction) EffectiveGasTipCmp(other *Transaction, baseFee *uint256.Int) int {
|
||||
if baseFee == nil {
|
||||
return tx.GasTipCapCmp(other)
|
||||
}
|
||||
// Use more efficient internal method.
|
||||
txTip, otherTip := new(uint256.Int), new(uint256.Int)
|
||||
tx.calcEffectiveGasTip(txTip, baseFee)
|
||||
other.calcEffectiveGasTip(otherTip, baseFee)
|
||||
err1 := tx.calcEffectiveGasTip(txTip, baseFee)
|
||||
err2 := other.calcEffectiveGasTip(otherTip, baseFee)
|
||||
if err1 != nil || err2 != nil {
|
||||
// fall back to big int comparison in case of error
|
||||
base := baseFee.ToBig()
|
||||
return tx.EffectiveGasTipValue(base).Cmp(other.EffectiveGasTipValue(base))
|
||||
}
|
||||
return txTip.Cmp(otherTip)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue