Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
miner: remove replaced txs from contributing to bundle value
Browse files Browse the repository at this point in the history
  • Loading branch information
bsh98 committed Jan 31, 2023
1 parent e1ba33b commit 947f59a
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1865,18 +1865,6 @@ func (w *worker) computeBundleGas(env *environment, bundle types.MevBundle, stat
return simulatedBundle{}, err
}

txInPendingPool := false
txHash := tx.Hash()
if accountTxs, ok := pendingTxs[from]; ok {
// check if tx is in pending pool
for _, accountTx := range accountTxs {
if accountTx.Hash() == txHash {
txInPendingPool = true
break
}
}
}

gasUsed := new(big.Int).SetUint64(receipt.GasUsed)
gasPrice, err := tx.EffectiveGasTip(env.header.BaseFee)
if err != nil {
Expand All @@ -1888,6 +1876,33 @@ func (w *worker) computeBundleGas(env *environment, bundle types.MevBundle, stat
coinbaseDelta.Sub(coinbaseDelta, gasFeesTx)
ethSentToCoinbase.Add(ethSentToCoinbase, coinbaseDelta)

txInPendingPool := false
txNonce := tx.Nonce()
txHash := tx.Hash()
if accountTxs, ok := pendingTxs[from]; ok {
// Check if tx is in (or was in) pending pool.
for _, accountTx := range accountTxs {
if accountTx.Nonce() == txNonce && accountTx.Hash() == txHash {
// Bundle includes a transaction from the mempool.
txInPendingPool = true
break
} else if accountTx.Nonce() == txNonce && accountTx.Hash() != txHash {
// Bundle is attempting to replace a transaction from the mempool.
txTipValue := new(big.Int).Add(gasFeesTx, coinbaseDelta)
txTipGasPrice := new(big.Int).Div(txTipValue, gasUsed)
accountTxTipGasPrice := accountTx.EffectiveGasTipValue(env.header.BaseFee)
if txTipGasPrice.Cmp(accountTxTipGasPrice) != 1 {
// Replacement underpriced, so don't count the gas fees towards the bundle value.
// This could mean that the transaction was already replaced in the mempool.
// This prevents incentivising bundles to include replaced transactions.
txInPendingPool = true
break
}

}
}
}

if !txInPendingPool {
// If tx is not in pending pool, count the gas fees
gasFees.Add(gasFees, gasFeesTx)
Expand Down

0 comments on commit 947f59a

Please sign in to comment.