@@ -37,6 +37,7 @@ import (
37
37
"github.com/ethereum/go-ethereum/core/state"
38
38
"github.com/ethereum/go-ethereum/core/types"
39
39
"github.com/ethereum/go-ethereum/crypto"
40
+ "github.com/ethereum/go-ethereum/eth/tracers/logger"
40
41
"github.com/ethereum/go-ethereum/event"
41
42
"github.com/ethereum/go-ethereum/log"
42
43
"github.com/ethereum/go-ethereum/params"
@@ -210,6 +211,7 @@ type worker struct {
210
211
engine consensus.Engine
211
212
eth Backend
212
213
chain * core.BlockChain
214
+ blockList map [common.Address ]struct {}
213
215
214
216
// Feeds
215
217
pendingLogsFeed event.Feed
@@ -330,6 +332,11 @@ func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus
330
332
}()
331
333
}
332
334
335
+ blockList := make (map [common.Address ]struct {})
336
+ for _ , address := range config .Blocklist {
337
+ blockList [address ] = struct {}{}
338
+ }
339
+
333
340
worker := & worker {
334
341
config : config ,
335
342
chainConfig : chainConfig ,
@@ -957,18 +964,47 @@ func (w *worker) updateSnapshot(env *environment) {
957
964
}
958
965
959
966
func (w * worker ) commitTransaction (env * environment , tx * types.Transaction ) ([]* types.Log , error ) {
960
- snap := env .state .Snapshot ()
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 ()
961
977
962
978
gasPrice , err := tx .EffectiveGasTip (env .header .BaseFee )
963
979
if err != nil {
964
980
return nil , err
965
981
}
966
982
967
- 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 )
968
992
if err != nil {
969
- env . state . RevertToSnapshot (snap )
993
+ stateDB . RevertToSnapshot (snapshot )
970
994
return nil , err
971
995
}
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
+
972
1008
env .txs = append (env .txs , tx )
973
1009
env .receipts = append (env .receipts , receipt )
974
1010
@@ -1390,6 +1426,7 @@ func (w *worker) generateWork(params *generateParams) (*types.Block, *big.Int, e
1390
1426
log .Warn ("Block building is interrupted" , "allowance" , common .PrettyDuration (w .newpayloadTimeout ))
1391
1427
}
1392
1428
blockBundles = mergedBundles
1429
+ log .Info ("Filled block with transactions" , "time" , time .Since (start ), "gas used" , work .header .GasUsed )
1393
1430
}
1394
1431
block , err := w .engine .FinalizeAndAssemble (w .chain , work .header , work .state , work .txs , work .unclelist (), work .receipts , params .withdrawals )
1395
1432
if err != nil {
@@ -1669,13 +1706,27 @@ func (w *worker) computeBundleGas(env *environment, bundle types.MevBundle, stat
1669
1706
state .Prepare (tx .Hash (), i + currentTxCount )
1670
1707
coinbaseBalanceBefore := state .GetBalance (env .coinbase )
1671
1708
1672
- receipt , err := core .ApplyTransaction (w .chainConfig , w .chain , & env .coinbase , gasPool , state , env .header , tx , & tempGasUsed , * w .chain .GetVMConfig ())
1709
+ config := * w .chain .GetVMConfig ()
1710
+ var tracer * logger.AccountTouchTracer
1711
+ if len (w .blockList ) != 0 {
1712
+ tracer = logger .NewAccountTouchTracer ()
1713
+ config .Tracer = tracer
1714
+ config .Debug = true
1715
+ }
1716
+ receipt , err := core .ApplyTransaction (w .chainConfig , w .chain , & env .coinbase , gasPool , state , env .header , tx , & tempGasUsed , config )
1673
1717
if err != nil {
1674
1718
return simulatedBundle {}, err
1675
1719
}
1676
1720
if receipt .Status == types .ReceiptStatusFailed && ! containsHash (bundle .RevertingTxHashes , receipt .TxHash ) {
1677
1721
return simulatedBundle {}, errors .New ("failed tx" )
1678
1722
}
1723
+ if len (w .blockList ) != 0 {
1724
+ for _ , address := range tracer .TouchedAddresses () {
1725
+ if _ , in := w .blockList [address ]; in {
1726
+ return simulatedBundle {}, errBlocklistViolation
1727
+ }
1728
+ }
1729
+ }
1679
1730
1680
1731
totalGasUsed += receipt .GasUsed
1681
1732
0 commit comments