core/types: rename to calcEffectiveGasTip

This commit is contained in:
lightclient 2025-05-05 15:59:42 -06:00
parent 1a1c1a4718
commit 8d6ca2e5ba
No known key found for this signature in database
GPG key ID: 657913021EF45A6A
2 changed files with 11 additions and 9 deletions

View file

@ -356,11 +356,13 @@ func (tx *Transaction) GasTipCapIntCmp(other *big.Int) int {
// the actual negative value, _and_ ErrGasFeeCapTooLow // the actual negative value, _and_ ErrGasFeeCapTooLow
func (tx *Transaction) EffectiveGasTip(baseFee *big.Int) (*big.Int, error) { func (tx *Transaction) EffectiveGasTip(baseFee *big.Int) (*big.Int, error) {
dst := new(big.Int) dst := new(big.Int)
err := tx.effectiveGasTipInto(dst, baseFee) err := tx.calcEffectiveGasTip(dst, baseFee)
return dst, err return dst, err
} }
func (tx *Transaction) effectiveGasTipInto(dst *big.Int, baseFee *big.Int) error { // calcEffectiveGasTip calculates the effective gas tip of the transaction and
// saves the result to dst.
func (tx *Transaction) calcEffectiveGasTip(dst *big.Int, baseFee *big.Int) error {
if baseFee == nil { if baseFee == nil {
dst.Set(tx.inner.gasTipCap()) dst.Set(tx.inner.gasTipCap())
return nil return nil
@ -385,10 +387,10 @@ func (tx *Transaction) EffectiveGasTipCmp(other *Transaction, baseFee *big.Int)
if baseFee == nil { if baseFee == nil {
return tx.GasTipCapCmp(other) return tx.GasTipCapCmp(other)
} }
txTip := new(big.Int) // Use more efficient internal method.
otherTip := new(big.Int) txTip, otherTip := new(big.Int), new(big.Int)
tx.effectiveGasTipInto(txTip, baseFee) tx.calcEffectiveGasTip(txTip, baseFee)
other.effectiveGasTipInto(otherTip, baseFee) other.calcEffectiveGasTip(otherTip, baseFee)
return txTip.Cmp(otherTip) return txTip.Cmp(otherTip)
} }
@ -398,7 +400,7 @@ func (tx *Transaction) EffectiveGasTipIntCmp(other *big.Int, baseFee *big.Int) i
return tx.GasTipCapIntCmp(other) return tx.GasTipCapIntCmp(other)
} }
txTip := new(big.Int) txTip := new(big.Int)
tx.effectiveGasTipInto(txTip, baseFee) tx.calcEffectiveGasTip(txTip, baseFee)
return txTip.Cmp(other) return txTip.Cmp(other)
} }

View file

@ -625,7 +625,7 @@ func BenchmarkEffectiveGasTip(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
dst := new(big.Int) dst := new(big.Int)
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
err := tx.effectiveGasTipInto(dst, baseFee) err := tx.calcEffectiveGasTip(dst, baseFee)
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
} }
@ -675,7 +675,7 @@ func TestEffectiveGasTipInto(t *testing.T) {
// Get result from new method // Get result from new method
dst := new(big.Int) dst := new(big.Int)
newErr := tx.effectiveGasTipInto(dst, baseFee) newErr := tx.calcEffectiveGasTip(dst, baseFee)
// Compare results // Compare results
if (origErr != nil) != (newErr != nil) { if (origErr != nil) != (newErr != nil) {