From 8d6ca2e5ba76b7b5b3e23ab498fc1a881705de2b Mon Sep 17 00:00:00 2001 From: lightclient Date: Mon, 5 May 2025 15:59:42 -0600 Subject: [PATCH] core/types: rename to calcEffectiveGasTip --- core/types/transaction.go | 16 +++++++++------- core/types/transaction_test.go | 4 ++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/core/types/transaction.go b/core/types/transaction.go index 05ff14ff31..934feb7353 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -356,11 +356,13 @@ func (tx *Transaction) GasTipCapIntCmp(other *big.Int) int { // the actual negative value, _and_ ErrGasFeeCapTooLow func (tx *Transaction) EffectiveGasTip(baseFee *big.Int) (*big.Int, error) { dst := new(big.Int) - err := tx.effectiveGasTipInto(dst, baseFee) + err := tx.calcEffectiveGasTip(dst, baseFee) 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 { dst.Set(tx.inner.gasTipCap()) return nil @@ -385,10 +387,10 @@ func (tx *Transaction) EffectiveGasTipCmp(other *Transaction, baseFee *big.Int) if baseFee == nil { return tx.GasTipCapCmp(other) } - txTip := new(big.Int) - otherTip := new(big.Int) - tx.effectiveGasTipInto(txTip, baseFee) - other.effectiveGasTipInto(otherTip, baseFee) + // Use more efficient internal method. + txTip, otherTip := new(big.Int), new(big.Int) + tx.calcEffectiveGasTip(txTip, baseFee) + other.calcEffectiveGasTip(otherTip, baseFee) return txTip.Cmp(otherTip) } @@ -398,7 +400,7 @@ func (tx *Transaction) EffectiveGasTipIntCmp(other *big.Int, baseFee *big.Int) i return tx.GasTipCapIntCmp(other) } txTip := new(big.Int) - tx.effectiveGasTipInto(txTip, baseFee) + tx.calcEffectiveGasTip(txTip, baseFee) return txTip.Cmp(other) } diff --git a/core/types/transaction_test.go b/core/types/transaction_test.go index 79100ad535..7d5e2f058a 100644 --- a/core/types/transaction_test.go +++ b/core/types/transaction_test.go @@ -625,7 +625,7 @@ func BenchmarkEffectiveGasTip(b *testing.B) { b.ReportAllocs() dst := new(big.Int) for i := 0; i < b.N; i++ { - err := tx.effectiveGasTipInto(dst, baseFee) + err := tx.calcEffectiveGasTip(dst, baseFee) if err != nil { b.Fatal(err) } @@ -675,7 +675,7 @@ func TestEffectiveGasTipInto(t *testing.T) { // Get result from new method dst := new(big.Int) - newErr := tx.effectiveGasTipInto(dst, baseFee) + newErr := tx.calcEffectiveGasTip(dst, baseFee) // Compare results if (origErr != nil) != (newErr != nil) {