Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce parallel evm via flag #1425

Merged
merged 6 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions builder/files/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ syncmode = "full"
# [parallelevm]
# enable = true
# procs = 8
# enforce = false

# [pprof]
# pprof = false
Expand Down
13 changes: 10 additions & 3 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
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 @@ -551,7 +552,7 @@
}

// 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) {

Check warning on line 555 in core/blockchain.go

View check run for this annotation

Codecov / codecov/patch

core/blockchain.go#L555

Added line #L555 was not covered by tests
cffls marked this conversation as resolved.
Show resolved Hide resolved
bc, err := NewBlockChain(db, cacheConfig, genesis, overrides, engine, vmConfig, shouldPreserve, txLookupLimit, checker)

if err != nil {
Expand All @@ -569,6 +570,7 @@

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

Check warning on line 573 in core/blockchain.go

View check run for this annotation

Codecov / codecov/patch

core/blockchain.go#L573

Added line #L573 was not covered by tests

return bc, nil
}
Expand Down Expand Up @@ -604,7 +606,12 @@
parallel bool
}

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

processorCount := 0

Expand All @@ -631,7 +638,7 @@
}()
}

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
11 changes: 8 additions & 3 deletions core/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,23 @@ func testBlockChainImport(chain types.Blocks, blockchain *BlockChain) error {
func TestParallelBlockChainImport(t *testing.T) {
t.Parallel()

testParallelBlockChainImport(t, rawdb.HashScheme)
testParallelBlockChainImport(t, rawdb.PathScheme)
testParallelBlockChainImport(t, rawdb.HashScheme, false)
testParallelBlockChainImport(t, rawdb.PathScheme, false)

testParallelBlockChainImport(t, rawdb.HashScheme, true)
testParallelBlockChainImport(t, rawdb.PathScheme, true)
}

func testParallelBlockChainImport(t *testing.T, scheme string) {
func testParallelBlockChainImport(t *testing.T, scheme string, enforceParallelProcessor bool) {
db, _, blockchain, err := newCanonical(ethash.NewFaker(), 10, true, scheme)
blockchain.parallelProcessor = NewParallelStateProcessor(blockchain.chainConfig, blockchain, blockchain.engine)

if err != nil {
t.Fatalf("failed to make new canonical chain: %v", err)
}

// If required, enforce parallel block processing and skip serial processing completely
blockchain.enforceParallelProcessor = enforceParallelProcessor
defer blockchain.Stop()

block := blockchain.GetBlockByHash(blockchain.CurrentBlock().Hash())
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
5 changes: 5 additions & 0 deletions docs/cli/example_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ devfakeauthor = false # Run miner without validator set authorization
period = 0 # Block period to use in developer mode (0 = mine only if transaction pending)
gaslimit = 11500000 # Initial block gas limit

[parallelevm]
enable = true # Enables parallel execution using Block STM
procs = 8 # Number of speculative processes (cores) in Block STM
enforce = false # Use only Block STM for execution and skip serial execution

[pprof]
pprof = false # Enable the pprof HTTP server
port = 6060 # pprof HTTP server listening port
Expand Down
10 changes: 6 additions & 4 deletions docs/cli/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The ```bor server``` command runs the Bor client.

- ```eth.requiredblocks```: Comma separated block number-to-hash mappings to require for peering (<number>=<hash>)

- ```ethstats```: Reporting URL of an ethstats service (nodename:secret@host:port)
- ```ethstats```: Reporting URL of a ethstats service (nodename:secret@host:port)

- ```gcmode```: Blockchain garbage collection mode ("full", "archive") (default: full)

Expand All @@ -66,6 +66,8 @@ The ```bor server``` command runs the Bor client.

- ```parallelevm.enable```: Enable Block STM (default: true)

- ```parallelevm.enforce```: Enforce block processing via Block STM (default: false)

- ```parallelevm.procs```: Number of speculative processes (cores) in Block STM (default: 8)

- ```pprof```: Enable the pprof HTTP server (default: false)
Expand Down Expand Up @@ -148,7 +150,7 @@ The ```bor server``` command runs the Bor client.

- ```graphql```: Enable GraphQL on the HTTP-RPC server. Note that GraphQL can only be started if an HTTP server is started as well. (default: false)

- ```graphql.corsdomain```: Comma separated list of domains from which to accept cross-origin requests (browser enforced) (default: localhost)
- ```graphql.corsdomain```: Comma separated list of domains from which to accept cross origin requests (browser enforced) (default: localhost)
manav2401 marked this conversation as resolved.
Show resolved Hide resolved

- ```graphql.vhosts```: Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard. (default: localhost)

Expand All @@ -158,7 +160,7 @@ The ```bor server``` command runs the Bor client.

- ```http.api```: API's offered over the HTTP-RPC interface (default: eth,net,web3,txpool,bor)

- ```http.corsdomain```: Comma separated list of domains from which to accept cross-origin requests (browser enforced) (default: localhost)
- ```http.corsdomain```: Comma separated list of domains from which to accept cross origin requests (browser enforced) (default: localhost)

- ```http.ep-requesttimeout```: Request Timeout for rpc execution pool for HTTP requests (default: 0s)

Expand Down Expand Up @@ -310,4 +312,4 @@ The ```bor server``` command runs the Bor client.

- ```txpool.pricelimit```: Minimum gas price limit to enforce for acceptance into the pool (default: 25000000000)

- ```txpool.rejournal```: Time interval to regenerate the local transaction journal (default: 1h0m0s)
- ```txpool.rejournal```: Time interval to regenerate the local transaction journal (default: 1h0m0s)
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 @@
// 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)

Check warning on line 261 in eth/backend.go

View check run for this annotation

Codecov / codecov/patch

eth/backend.go#L261

Added line #L261 was not covered by tests
} 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 @@ -1199,6 +1202,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
1 change: 1 addition & 0 deletions internal/cli/server/testdata/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ devfakeauthor = false
[parallelevm]
enable = true
procs = 8
enforce = false

[pprof]
pprof = false
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
5 changes: 5 additions & 0 deletions packaging/templates/mainnet-v1/archive/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ gcmode = "archive"
# period = 0
# gaslimit = 11500000

# [parallelevm]
# enable = true
# procs = 8
# enforce = false

# [pprof]
# pprof = false
# port = 6060
Expand Down
5 changes: 5 additions & 0 deletions packaging/templates/mainnet-v1/sentry/sentry/bor/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ syncmode = "full"
# period = 0
# gaslimit = 11500000

# [parallelevm]
# enable = true
# procs = 8
# enforce = false

# [pprof]
# pprof = false
# port = 6060
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ syncmode = "full"
# period = 0
# gaslimit = 11500000

# [parallelevm]
# enable = true
# procs = 8
# enforce = false

# [pprof]
# pprof = false
# port = 6060
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ syncmode = "full"
# period = 0
# gaslimit = 11500000

# [parallelevm]
# enable = true
# procs = 8
# enforce = false

# [pprof]
# pprof = false
# port = 6060
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ syncmode = "full"
# period = 0
# gaslimit = 11500000

# [parallelevm]
# enable = true
# procs = 8
# enforce = false

# [pprof]
# pprof = false
# port = 6060
Expand Down
5 changes: 5 additions & 0 deletions packaging/templates/mainnet-v1/without-sentry/bor/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ syncmode = "full"
# period = 0
# gaslimit = 11500000

# [parallelevm]
# enable = true
# procs = 8
# enforce = false

# [pprof]
# pprof = false
# port = 6060
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ syncmode = "full"
# period = 0
# gaslimit = 11500000

# [parallelevm]
# enable = true
# procs = 8
# enforce = false

# [pprof]
# pprof = false
# port = 6060
Expand Down
5 changes: 5 additions & 0 deletions packaging/templates/testnet-amoy/archive/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ gcmode = "archive"
# period = 0
# gaslimit = 11500000

# [parallelevm]
# enable = true
# procs = 8
# enforce = false

# [pprof]
# pprof = false
# port = 6060
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ syncmode = "full"
# period = 0
# gaslimit = 11500000

# [parallelevm]
# enable = true
# procs = 8
# enforce = false

# [pprof]
# pprof = false
# port = 6060
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ syncmode = "full"
# period = 0
# gaslimit = 11500000

# [parallelevm]
# enable = true
# procs = 8
# enforce = false

# [pprof]
# pprof = false
# port = 6060
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ syncmode = "full"
# period = 0
# gaslimit = 11500000

# [parallelevm]
# enable = true
# procs = 8
# enforce = false

# pprof = false
# port = 6060
# addr = "127.0.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ syncmode = "full"
# period = 0
# gaslimit = 11500000

# [parallelevm]
# enable = true
# procs = 8
# enforce = false

# pprof = false
# port = 6060
# addr = "127.0.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ syncmode = "full"
# period = 0
# gaslimit = 11500000

# [parallelevm]
# enable = true
# procs = 8
# enforce = false

# [pprof]
# pprof = false
# port = 6060
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ syncmode = "full"
# period = 0
# gaslimit = 11500000

# [parallelevm]
# enable = true
# procs = 8
# enforce = false

# [pprof]
# pprof = false
# port = 6060
Expand Down
Loading