Skip to content

Commit

Permalink
(feat): implement --parallelevm.enforce to force using block-stm
Browse files Browse the repository at this point in the history
  • Loading branch information
manav2401 committed Jan 8, 2025
1 parent 2c45319 commit b1aeb1c
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 5 deletions.
13 changes: 10 additions & 3 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ type BlockChain struct {
processor Processor // Block transaction processor interface
parallelProcessor Processor // Parallel block transaction processor interface
parallelSpeculativeProcesses int // Number of parallel speculative processes
enforceParallelProcessor bool
forker *ForkChoice
vmConfig vm.Config
logger *tracing.Hooks
Expand Down Expand Up @@ -549,7 +550,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
}

// NewParallelBlockChain , similar to NewBlockChain, creates a new blockchain object, but with a parallel state processor
func NewParallelBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis, overrides *ChainOverrides, engine consensus.Engine, vmConfig vm.Config, shouldPreserve func(header *types.Header) bool, txLookupLimit *uint64, checker ethereum.ChainValidator, numprocs int) (*BlockChain, error) {
func NewParallelBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis, overrides *ChainOverrides, engine consensus.Engine, vmConfig vm.Config, shouldPreserve func(header *types.Header) bool, txLookupLimit *uint64, checker ethereum.ChainValidator, numprocs int, enforce bool) (*BlockChain, error) {
bc, err := NewBlockChain(db, cacheConfig, genesis, overrides, engine, vmConfig, shouldPreserve, txLookupLimit, checker)

if err != nil {
Expand All @@ -567,6 +568,7 @@ func NewParallelBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis

bc.parallelProcessor = NewParallelStateProcessor(chainConfig, bc, engine)
bc.parallelSpeculativeProcesses = numprocs
bc.enforceParallelProcessor = enforce

return bc, nil
}
Expand Down Expand Up @@ -602,7 +604,12 @@ func (bc *BlockChain) ProcessBlock(block *types.Block, parent *types.Header) (_
parallel bool
}

resultChan := make(chan Result, 2)
var resultChanLen int = 2
if bc.enforceParallelProcessor {
log.Info("Processing block using Block STM only", "number", block.NumberU64())
resultChanLen = 1
}
resultChan := make(chan Result, resultChanLen)

processorCount := 0

Expand All @@ -629,7 +636,7 @@ func (bc *BlockChain) ProcessBlock(block *types.Block, parent *types.Header) (_
}()
}

if bc.processor != nil {
if bc.processor != nil && !bc.enforceParallelProcessor {
statedb, err := state.New(parent.Root, bc.stateCache, bc.snaps)
if err != nil {
return nil, nil, 0, nil, 0, err
Expand Down
1 change: 1 addition & 0 deletions core/parallel_state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
type ParallelEVMConfig struct {
Enable bool
SpeculativeProcesses int
Enforce bool
}

// StateProcessor is a basic Processor, which takes care of transitioning
Expand Down
2 changes: 1 addition & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
// check if Parallel EVM is enabled
// if enabled, use parallel state processor
if config.ParallelEVM.Enable {
eth.blockchain, err = core.NewParallelBlockChain(chainDb, cacheConfig, config.Genesis, &overrides, eth.engine, vmConfig, eth.shouldPreserve, &config.TxLookupLimit, checker, config.ParallelEVM.SpeculativeProcesses)
eth.blockchain, err = core.NewParallelBlockChain(chainDb, cacheConfig, config.Genesis, &overrides, eth.engine, vmConfig, eth.shouldPreserve, &config.TxLookupLimit, checker, config.ParallelEVM.SpeculativeProcesses, config.ParallelEVM.Enforce)
} else {
eth.blockchain, err = core.NewBlockChain(chainDb, cacheConfig, config.Genesis, &overrides, eth.engine, vmConfig, eth.shouldPreserve, &config.TxLookupLimit, checker)
}
Expand Down
4 changes: 4 additions & 0 deletions internal/cli/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,8 @@ type ParallelEVMConfig struct {
Enable bool `hcl:"enable,optional" toml:"enable,optional"`

SpeculativeProcesses int `hcl:"procs,optional" toml:"procs,optional"`

Enforce bool `hcl:"enforce,optional" toml:"enforce,optional"`
}

func DefaultConfig() *Config {
Expand Down Expand Up @@ -794,6 +796,7 @@ func DefaultConfig() *Config {
ParallelEVM: &ParallelEVMConfig{
Enable: true,
SpeculativeProcesses: 8,
Enforce: false,
},
}
}
Expand Down Expand Up @@ -1196,6 +1199,7 @@ func (c *Config) buildEth(stack *node.Node, accountManager *accounts.Manager) (*

n.ParallelEVM.Enable = c.ParallelEVM.Enable
n.ParallelEVM.SpeculativeProcesses = c.ParallelEVM.SpeculativeProcesses
n.ParallelEVM.Enforce = c.ParallelEVM.Enforce
n.RPCReturnDataLimit = c.RPCReturnDataLimit

if c.Ancient != "" {
Expand Down
7 changes: 7 additions & 0 deletions internal/cli/server/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,13 @@ func (c *Command) Flags(config *Config) *flagset.Flagset {
Value: &c.cliConfig.ParallelEVM.SpeculativeProcesses,
Default: c.cliConfig.ParallelEVM.SpeculativeProcesses,
})
f.BoolFlag(&flagset.BoolFlag{
Name: "parallelevm.enforce",
Usage: "Enforce block processing via Block STM",
Value: &c.cliConfig.ParallelEVM.Enforce,
Default: c.cliConfig.ParallelEVM.Enforce,
})

f.Uint64Flag(&flagset.Uint64Flag{
Name: "dev.gaslimit",
Usage: "Initial block gas limit",
Expand Down
2 changes: 1 addition & 1 deletion miner/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ func BenchmarkBorMiningBlockSTMMetadata(b *testing.B) {
db2 := rawdb.NewMemoryDatabase()
back.genesis.MustCommit(db2, triedb.NewDatabase(db2, triedb.HashDefaults))

chain, _ := core.NewParallelBlockChain(db2, nil, back.genesis, nil, engine, vm.Config{}, nil, nil, nil, 8)
chain, _ := core.NewParallelBlockChain(db2, nil, back.genesis, nil, engine, vm.Config{}, nil, nil, nil, 8, false)
defer chain.Stop()

// Ignore empty commit here for less noise.
Expand Down

0 comments on commit b1aeb1c

Please sign in to comment.