miner: re-use basefee and big.Int in loop (#34783)
Some checks are pending
/ Windows Build (push) Waiting to run
/ Docker Image (push) Waiting to run
/ Linux Build (push) Waiting to run
/ Linux Build (arm) (push) Waiting to run
/ Keeper Build (push) Waiting to run

This commit is contained in:
cui 2026-05-14 19:45:49 +08:00 committed by GitHub
parent da34eb59fd
commit 31bb680997
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -601,10 +601,14 @@ func (miner *Miner) fillTransactions(ctx context.Context, interrupt *atomic.Int3
// totalFees computes total consumed miner fees in Wei. Block transactions and receipts have to have the same order. // totalFees computes total consumed miner fees in Wei. Block transactions and receipts have to have the same order.
func totalFees(block *types.Block, receipts []*types.Receipt) *big.Int { func totalFees(block *types.Block, receipts []*types.Receipt) *big.Int {
baseFee := block.BaseFee()
feesWei := new(big.Int) feesWei := new(big.Int)
var gasUsed, product big.Int
for i, tx := range block.Transactions() { for i, tx := range block.Transactions() {
minerFee, _ := tx.EffectiveGasTip(block.BaseFee()) minerFee, _ := tx.EffectiveGasTip(baseFee)
feesWei.Add(feesWei, new(big.Int).Mul(new(big.Int).SetUint64(receipts[i].GasUsed), minerFee)) gasUsed.SetUint64(receipts[i].GasUsed)
product.Mul(&gasUsed, minerFee)
feesWei.Add(feesWei, &product)
} }
return feesWei return feesWei
} }