@@ -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,22 +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
- 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 ()
964
977
965
978
gasPrice , err := tx .EffectiveGasTip (env .header .BaseFee )
966
979
if err != nil {
967
980
return nil , err
968
981
}
969
982
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 )
971
992
if err != nil {
972
- env .state .RevertToSnapshot (snap )
973
- env .gasPool .SetGas (gp )
993
+ stateDB .RevertToSnapshot (snapshot )
974
994
return nil , err
975
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
+
976
1008
env .txs = append (env .txs , tx )
977
1009
env .receipts = append (env .receipts , receipt )
978
1010
@@ -1395,6 +1427,7 @@ func (w *worker) generateWork(params *generateParams) (*types.Block, *big.Int, e
1395
1427
log .Warn ("Block building is interrupted" , "allowance" , common .PrettyDuration (w .newpayloadTimeout ))
1396
1428
}
1397
1429
blockBundles = mergedBundles
1430
+ log .Info ("Filled block with transactions" , "time" , time .Since (start ), "gas used" , work .header .GasUsed )
1398
1431
}
1399
1432
block , err := w .engine .FinalizeAndAssemble (w .chain , work .header , work .state , work .txs , work .unclelist (), work .receipts , params .withdrawals )
1400
1433
if err != nil {
@@ -1674,13 +1707,27 @@ func (w *worker) computeBundleGas(env *environment, bundle types.MevBundle, stat
1674
1707
state .Prepare (tx .Hash (), i + currentTxCount )
1675
1708
coinbaseBalanceBefore := state .GetBalance (env .coinbase )
1676
1709
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 )
1678
1718
if err != nil {
1679
1719
return simulatedBundle {}, err
1680
1720
}
1681
1721
if receipt .Status == types .ReceiptStatusFailed && ! containsHash (bundle .RevertingTxHashes , receipt .TxHash ) {
1682
1722
return simulatedBundle {}, errors .New ("failed tx" )
1683
1723
}
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
+ }
1684
1731
1685
1732
totalGasUsed += receipt .GasUsed
1686
1733
0 commit comments