From 4df8d18e6fe626bb5d251dae86d5d478d6bdb4fa Mon Sep 17 00:00:00 2001 From: djye Date: Wed, 26 Jun 2024 15:51:49 +0800 Subject: [PATCH 1/3] fix the bug in profit calculation --- miner/worker.go | 16 ++++++++++++++-- miner/worker_builder.go | 6 +++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/miner/worker.go b/miner/worker.go index 413b9a531d..3ac687b5f2 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -747,7 +747,11 @@ func (w *worker) commitTransaction(env *environment, tx *types.Transaction, rece env.receipts = append(env.receipts, receipt) gasUsed := new(big.Int).SetUint64(receipt.GasUsed) - env.profit.Add(env.profit, gasUsed.Mul(gasUsed, tx.GasPrice())) + effectiveTip, err := tx.EffectiveGasTip(env.header.BaseFee) + if err != nil { + return nil, err + } + env.profit.Add(env.profit, gasUsed.Mul(gasUsed, effectiveTip)) return receipt.Logs, nil } @@ -777,7 +781,15 @@ func (w *worker) commitBlobTransaction(env *environment, tx *types.Transaction, *env.header.BlobGasUsed += receipt.BlobGasUsed gasUsed := new(big.Int).SetUint64(receipt.GasUsed) - env.profit.Add(env.profit, gasUsed.Mul(gasUsed, tx.GasPrice())) + effectiveTip, err := tx.EffectiveGasTip(env.header.BaseFee) + if err != nil { + return nil, err + } + env.profit.Add(env.profit, gasUsed.Mul(gasUsed, effectiveTip)) + + blobFee := new(big.Int).SetUint64(receipt.BlobGasUsed) + blobFee.Mul(blobFee, receipt.BlobGasPrice) + env.profit.Add(env.profit, blobFee) return receipt.Logs, nil } diff --git a/miner/worker_builder.go b/miner/worker_builder.go index 469d267a2e..606fed2a05 100644 --- a/miner/worker_builder.go +++ b/miner/worker_builder.go @@ -441,7 +441,11 @@ func (w *worker) simulateBundle( bundleGasUsed += receipt.GasUsed txGasUsed := new(big.Int).SetUint64(receipt.GasUsed) - txGasFees := new(big.Int).Mul(txGasUsed, tx.GasPrice()) + effectiveTip, err := tx.EffectiveGasTip(env.header.BaseFee) + if err != nil { + return nil, err + } + txGasFees := new(big.Int).Mul(txGasUsed, effectiveTip) bundleGasFees.Add(bundleGasFees, txGasFees) sysBalanceAfter := state.GetBalance(consensus.SystemAddress) sysDelta := new(uint256.Int).Sub(sysBalanceAfter, sysBalanceBefore) From 6fe59d0794a629fedbf2c152dbc53fda971be449 Mon Sep 17 00:00:00 2001 From: djye Date: Wed, 26 Jun 2024 17:33:57 +0800 Subject: [PATCH 2/3] the bundle gas fee needs to include the blob fee --- miner/worker_builder.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/miner/worker_builder.go b/miner/worker_builder.go index 606fed2a05..a635413d29 100644 --- a/miner/worker_builder.go +++ b/miner/worker_builder.go @@ -447,6 +447,12 @@ func (w *worker) simulateBundle( } txGasFees := new(big.Int).Mul(txGasUsed, effectiveTip) bundleGasFees.Add(bundleGasFees, txGasFees) + + if tx.Type() == types.BlobTxType { + blobFee := new(big.Int).SetUint64(receipt.BlobGasUsed) + blobFee.Mul(blobFee, receipt.BlobGasPrice) + bundleGasFees.Add(bundleGasFees, blobFee) + } sysBalanceAfter := state.GetBalance(consensus.SystemAddress) sysDelta := new(uint256.Int).Sub(sysBalanceAfter, sysBalanceBefore) sysDelta.Sub(sysDelta, uint256.MustFromBig(txGasFees)) From 4ce2bd26071809f6dda60b9a210e73fe6f9a41a4 Mon Sep 17 00:00:00 2001 From: djye Date: Wed, 26 Jun 2024 17:39:17 +0800 Subject: [PATCH 3/3] txGasFees also needs to include the blob fee --- miner/worker_builder.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/miner/worker_builder.go b/miner/worker_builder.go index a635413d29..b264180303 100644 --- a/miner/worker_builder.go +++ b/miner/worker_builder.go @@ -446,13 +446,13 @@ func (w *worker) simulateBundle( return nil, err } txGasFees := new(big.Int).Mul(txGasUsed, effectiveTip) - bundleGasFees.Add(bundleGasFees, txGasFees) if tx.Type() == types.BlobTxType { blobFee := new(big.Int).SetUint64(receipt.BlobGasUsed) blobFee.Mul(blobFee, receipt.BlobGasPrice) - bundleGasFees.Add(bundleGasFees, blobFee) + txGasFees.Add(txGasFees, blobFee) } + bundleGasFees.Add(bundleGasFees, txGasFees) sysBalanceAfter := state.GetBalance(consensus.SystemAddress) sysDelta := new(uint256.Int).Sub(sysBalanceAfter, sysBalanceBefore) sysDelta.Sub(sysDelta, uint256.MustFromBig(txGasFees))