@@ -37,6 +37,7 @@ import (
3737 "github.com/ethereum/go-ethereum/core/state"
3838 "github.com/ethereum/go-ethereum/core/types"
3939 "github.com/ethereum/go-ethereum/crypto"
40+ "github.com/ethereum/go-ethereum/eth/tracers/logger"
4041 "github.com/ethereum/go-ethereum/event"
4142 "github.com/ethereum/go-ethereum/log"
4243 "github.com/ethereum/go-ethereum/params"
@@ -210,6 +211,7 @@ type worker struct {
210211 engine consensus.Engine
211212 eth Backend
212213 chain * core.BlockChain
214+ blockList map [common.Address ]struct {}
213215
214216 // Feeds
215217 pendingLogsFeed event.Feed
@@ -330,6 +332,11 @@ func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus
330332 }()
331333 }
332334
335+ blockList := make (map [common.Address ]struct {})
336+ for _ , address := range config .Blocklist {
337+ blockList [address ] = struct {}{}
338+ }
339+
333340 worker := & worker {
334341 config : config ,
335342 chainConfig : chainConfig ,
@@ -957,22 +964,47 @@ func (w *worker) updateSnapshot(env *environment) {
957964}
958965
959966func (w * worker ) commitTransaction (env * environment , tx * types.Transaction ) ([]* types.Log , error ) {
960- var (
961- snap = env .state .Snapshot ()
962- gp = env .gasPool .Gas ()
963- )
967+ gasPool := * env .gasPool
968+ envGasUsed := env .header .GasUsed
969+ var stateDB * state.StateDB
970+ if len (w .blockList ) != 0 {
971+ stateDB = env .state .Copy ()
972+ } else {
973+ stateDB = env .state
974+ }
975+
976+ snapshot := stateDB .Snapshot ()
964977
965978 gasPrice , err := tx .EffectiveGasTip (env .header .BaseFee )
966979 if err != nil {
967980 return nil , err
968981 }
969982
970- receipt , err := core .ApplyTransaction (w .chainConfig , w .chain , & env .coinbase , env .gasPool , env .state , env .header , tx , & env .header .GasUsed , * w .chain .GetVMConfig ())
983+ var tracer * logger.AccountTouchTracer
984+ config := * w .chain .GetVMConfig ()
985+ if len (w .blockList ) != 0 {
986+ tracer = logger .NewAccountTouchTracer ()
987+ config .Tracer = tracer
988+ config .Debug = true
989+ }
990+
991+ receipt , err := core .ApplyTransaction (w .chainConfig , w .chain , & env .coinbase , & gasPool , stateDB , env .header , tx , & envGasUsed , config )
971992 if err != nil {
972- env .state .RevertToSnapshot (snap )
973- env .gasPool .SetGas (gp )
993+ stateDB .RevertToSnapshot (snapshot )
974994 return nil , err
975995 }
996+ if len (w .blockList ) != 0 {
997+ for _ , address := range tracer .TouchedAddresses () {
998+ if _ , in := w .blockList [address ]; in {
999+ return nil , errBlocklistViolation
1000+ }
1001+ }
1002+ }
1003+
1004+ * env .gasPool = gasPool
1005+ env .header .GasUsed = envGasUsed
1006+ env .state = stateDB
1007+
9761008 env .txs = append (env .txs , tx )
9771009 env .receipts = append (env .receipts , receipt )
9781010
@@ -1395,6 +1427,7 @@ func (w *worker) generateWork(params *generateParams) (*types.Block, *big.Int, e
13951427 log .Warn ("Block building is interrupted" , "allowance" , common .PrettyDuration (w .newpayloadTimeout ))
13961428 }
13971429 blockBundles = mergedBundles
1430+ log .Info ("Filled block with transactions" , "time" , time .Since (start ), "gas used" , work .header .GasUsed )
13981431 }
13991432 block , err := w .engine .FinalizeAndAssemble (w .chain , work .header , work .state , work .txs , work .unclelist (), work .receipts , params .withdrawals )
14001433 if err != nil {
@@ -1674,13 +1707,27 @@ func (w *worker) computeBundleGas(env *environment, bundle types.MevBundle, stat
16741707 state .Prepare (tx .Hash (), i + currentTxCount )
16751708 coinbaseBalanceBefore := state .GetBalance (env .coinbase )
16761709
1677- receipt , err := core .ApplyTransaction (w .chainConfig , w .chain , & env .coinbase , gasPool , state , env .header , tx , & tempGasUsed , * w .chain .GetVMConfig ())
1710+ config := * w .chain .GetVMConfig ()
1711+ var tracer * logger.AccountTouchTracer
1712+ if len (w .blockList ) != 0 {
1713+ tracer = logger .NewAccountTouchTracer ()
1714+ config .Tracer = tracer
1715+ config .Debug = true
1716+ }
1717+ receipt , err := core .ApplyTransaction (w .chainConfig , w .chain , & env .coinbase , gasPool , state , env .header , tx , & tempGasUsed , config )
16781718 if err != nil {
16791719 return simulatedBundle {}, err
16801720 }
16811721 if receipt .Status == types .ReceiptStatusFailed && ! containsHash (bundle .RevertingTxHashes , receipt .TxHash ) {
16821722 return simulatedBundle {}, errors .New ("failed tx" )
16831723 }
1724+ if len (w .blockList ) != 0 {
1725+ for _ , address := range tracer .TouchedAddresses () {
1726+ if _ , in := w .blockList [address ]; in {
1727+ return simulatedBundle {}, errBlocklistViolation
1728+ }
1729+ }
1730+ }
16841731
16851732 totalGasUsed += receipt .GasUsed
16861733
0 commit comments