Skip to content

Commit 26055fd

Browse files
committed
Add flashbots support for eip-1559
1 parent 7ffbaac commit 26055fd

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

miner/multi_worker.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ func (w *multiWorker) isRunning() bool {
4343
return false
4444
}
4545

46+
// pendingBlockAndReceipts returns pending block and corresponding receipts from the `regularWorker`
47+
func (w *multiWorker) pendingBlockAndReceipts() (*types.Block, types.Receipts) {
48+
// return a snapshot to avoid contention on currentMu mutex
49+
return w.regularWorker.pendingBlockAndReceipts()
50+
}
51+
52+
func (w *multiWorker) setGasCeil(ceil uint64) {
53+
for _, worker := range w.workers {
54+
worker.setGasCeil(ceil)
55+
}
56+
}
57+
4658
func (w *multiWorker) setExtra(extra []byte) {
4759
for _, worker := range w.workers {
4860
worker.setExtra(extra)

miner/worker.go

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,11 @@ func (w *worker) updateSnapshot() {
808808
func (w *worker) commitTransaction(tx *types.Transaction, coinbase common.Address) ([]*types.Log, error) {
809809
snap := w.current.state.Snapshot()
810810

811+
gasPrice, err := tx.EffectiveGasTip(w.current.header.BaseFee)
812+
if err != nil {
813+
return nil, err
814+
}
815+
811816
receipt, err := core.ApplyTransaction(w.chainConfig, w.chain, &coinbase, w.current.gasPool, w.current.state, w.current.header, tx, &w.current.header.GasUsed, *w.chain.GetVMConfig())
812817
if err != nil {
813818
w.current.state.RevertToSnapshot(snap)
@@ -817,7 +822,7 @@ func (w *worker) commitTransaction(tx *types.Transaction, coinbase common.Addres
817822
w.current.receipts = append(w.current.receipts, receipt)
818823

819824
gasUsed := new(big.Int).SetUint64(receipt.GasUsed)
820-
w.current.profit.Add(w.current.profit, gasUsed.Mul(gasUsed, tx.GasPrice()))
825+
w.current.profit.Add(w.current.profit, gasUsed.Mul(gasUsed, gasPrice))
821826

822827
return receipt.Logs, nil
823828
}
@@ -874,7 +879,7 @@ func (w *worker) commitBundle(txs types.Transactions, coinbase common.Address, i
874879
return true
875880
}
876881
// Start executing the transaction
877-
w.current.state.Prepare(tx.Hash(), common.Hash{}, w.current.tcount)
882+
w.current.state.Prepare(tx.Hash(), w.current.tcount)
878883

879884
logs, err := w.commitTransaction(tx, coinbase)
880885
switch {
@@ -1365,7 +1370,21 @@ func (w *worker) computeBundleGas(bundle types.MevBundle, parent *types.Block, h
13651370
ethSentToCoinbase := new(big.Int)
13661371

13671372
for i, tx := range bundle.Txs {
1368-
state.Prepare(tx.Hash(), common.Hash{}, i+currentTxCount)
1373+
if header.BaseFee != nil && tx.Type() == 2 {
1374+
// Sanity check for extremely large numbers
1375+
if tx.GasFeeCap().BitLen() > 256 {
1376+
return simulatedBundle{}, core.ErrFeeCapVeryHigh
1377+
}
1378+
if tx.GasTipCap().BitLen() > 256 {
1379+
return simulatedBundle{}, core.ErrTipVeryHigh
1380+
}
1381+
// Ensure gasFeeCap is greater than or equal to gasTipCap.
1382+
if tx.GasFeeCapIntCmp(tx.GasTipCap()) < 0 {
1383+
return simulatedBundle{}, core.ErrTipAboveFeeCap
1384+
}
1385+
}
1386+
1387+
state.Prepare(tx.Hash(), i+currentTxCount)
13691388
coinbaseBalanceBefore := state.GetBalance(w.coinbase)
13701389

13711390
receipt, err := core.ApplyTransaction(w.chainConfig, w.chain, &w.coinbase, gasPool, state, header, tx, &tempGasUsed, *w.chain.GetVMConfig())
@@ -1397,7 +1416,11 @@ func (w *worker) computeBundleGas(bundle types.MevBundle, parent *types.Block, h
13971416
}
13981417

13991418
gasUsed := new(big.Int).SetUint64(receipt.GasUsed)
1400-
gasFeesTx := gasUsed.Mul(gasUsed, tx.GasPrice())
1419+
gasPrice, err := tx.EffectiveGasTip(header.BaseFee)
1420+
if err != nil {
1421+
return simulatedBundle{}, err
1422+
}
1423+
gasFeesTx := gasUsed.Mul(gasUsed, gasPrice)
14011424
coinbaseBalanceAfter := state.GetBalance(w.coinbase)
14021425
coinbaseDelta := big.NewInt(0).Sub(coinbaseBalanceAfter, coinbaseBalanceBefore)
14031426
coinbaseDelta.Sub(coinbaseDelta, gasFeesTx)

0 commit comments

Comments
 (0)