Skip to content

Commit

Permalink
Merge pull request #39 from bnb-chain/develop
Browse files Browse the repository at this point in the history
fix: bug in profit calculation (#35)
  • Loading branch information
irrun authored Jul 4, 2024
2 parents e5dfa8e + 5d89879 commit 4ad8bcb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
16 changes: 14 additions & 2 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
12 changes: 11 additions & 1 deletion miner/worker_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,17 @@ 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)

if tx.Type() == types.BlobTxType {
blobFee := new(big.Int).SetUint64(receipt.BlobGasUsed)
blobFee.Mul(blobFee, receipt.BlobGasPrice)
txGasFees.Add(txGasFees, blobFee)
}
bundleGasFees.Add(bundleGasFees, txGasFees)
sysBalanceAfter := state.GetBalance(consensus.SystemAddress)
sysDelta := new(uint256.Int).Sub(sysBalanceAfter, sysBalanceBefore)
Expand Down

0 comments on commit 4ad8bcb

Please sign in to comment.