Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions core/state_prefetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ const checkInterval = 10
// from disk. Transactions are executed in parallel to fully leverage the
// SSD's read performance.
type statePrefetcher struct {
config *params.ChainConfig // Chain configuration options
chain *HeaderChain // Canonical block chain
config *params.ChainConfig // Chain configuration options
chain *HeaderChain // Canonical block chain
mevEnabled bool // Indicate whether MEV is enabled
}

// NewStatePrefetcher initialises a new statePrefetcher.
Expand All @@ -52,6 +53,11 @@ func NewStatePrefetcher(config *params.ChainConfig, chain *HeaderChain) *statePr
}
}

// EnableMevMode enables MEV mode for this prefetcher.
func (p *statePrefetcher) EnableMevMode() {
p.mevEnabled = true
}

// Prefetch processes the state changes according to the Ethereum rules by running
// the transaction messages using the statedb, but any changes are discarded. The
// only goal is to warm the state caches.
Expand Down Expand Up @@ -285,8 +291,14 @@ func (p *statePrefetcher) PrefetchMining(txs TransactionsByPriceAndNonce, header
signer = types.MakeSigner(p.config, header.Number, header.Time)
)

txCh := make(chan *types.Transaction, 2*prefetchMiningThread)
for i := 0; i < prefetchMiningThread; i++ {
// When MEV is not enabled, use more threads for local mining
threadCount := prefetchMiningThread
if !p.mevEnabled {
threadCount = max(prefetchMiningThread, 3*runtime.NumCPU()/5)
}

txCh := make(chan *types.Transaction, 2*threadCount)
Comment thread
buddh0 marked this conversation as resolved.
for i := 0; i < threadCount; i++ {
go func(startCh <-chan *types.Transaction, stopCh <-chan struct{}) {
newStatedb := statedb.CopyDoPrefetch()
evm := vm.NewEVM(NewEVMBlockContext(header, p.chain, nil), newStatedb, p.config, cfg)
Expand Down
6 changes: 5 additions & 1 deletion miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,12 @@ type worker struct {

func newWorker(config *minerconfig.Config, engine consensus.Engine, eth Backend, mux *event.TypeMux) *worker {
chainConfig := eth.BlockChain().Config()
prefetcher := core.NewStatePrefetcher(chainConfig, eth.BlockChain().HeadChain())
if config.Mev.Enabled != nil && *config.Mev.Enabled {
prefetcher.EnableMevMode()
}
worker := &worker{
prefetcher: core.NewStatePrefetcher(chainConfig, eth.BlockChain().HeadChain()),
prefetcher: prefetcher,
config: config,
chainConfig: chainConfig,
engine: engine,
Expand Down