stratus/eth/executor/
executor_config.rs

1use std::cmp::max;
2use std::str::FromStr;
3use std::sync::Arc;
4
5use clap::Parser;
6use display_json::DebugAsJson;
7use revm::primitives::hardfork::SpecId;
8
9use crate::eth::executor::Executor;
10use crate::eth::miner::Miner;
11use crate::eth::storage::StratusStorage;
12
13#[derive(Parser, DebugAsJson, Clone, serde::Serialize)]
14pub struct ExecutorConfig {
15    /// Chain ID of the network.
16    #[arg(long = "executor-chain-id", alias = "chain-id", env = "EXECUTOR_CHAIN_ID")]
17    pub executor_chain_id: u64,
18
19    /// Number of EVM instances to run.
20    #[arg(long = "executor-evms", alias = "evms", env = "EXECUTOR_EVMS", default_value = "30")]
21    pub executor_evms: usize,
22
23    #[arg(long = "executor-call-present-evms", env = "EXECUTOR_CALL_PRESENT_EVMS")]
24    pub executor_call_present_evms: Option<usize>,
25
26    #[arg(long = "executor-call-past-evms", env = "EXECUTOR_CALL_PAST_EVMS")]
27    pub executor_call_past_evms: Option<usize>,
28
29    #[arg(long = "executor-inspector-evms", env = "EXECUTOR_INSPECTOR_EVMS")]
30    pub executor_inspector_evms: Option<usize>,
31
32    /// Should reject contract transactions and calls to accounts that are not contracts?
33    #[arg(
34        long = "executor-reject-not-contract",
35        alias = "reject-not-contract",
36        env = "EXECUTOR_REJECT_NOT_CONTRACT",
37        default_value = "true"
38    )]
39    pub executor_reject_not_contract: bool,
40
41    #[arg(long = "executor-evm-spec", env = "EXECUTOR_EVM_SPEC", default_value = "Cancun", value_parser = parse_evm_spec)]
42    pub executor_evm_spec: SpecId,
43}
44
45fn parse_evm_spec(input: &str) -> anyhow::Result<SpecId> {
46    SpecId::from_str(input).map_err(|err| anyhow::anyhow!("unknown hard fork: {:?}", err))
47}
48
49impl ExecutorConfig {
50    /// Initializes Executor.
51    ///
52    /// Note: Should be called only after async runtime is initialized.
53    pub fn init(&self, storage: Arc<StratusStorage>, miner: Arc<Miner>) -> Arc<Executor> {
54        let mut config = self.clone();
55        config.executor_evms = max(config.executor_evms, 1);
56        tracing::info!(?config, "creating executor");
57
58        let executor = Executor::new(storage, miner, config);
59        Arc::new(executor)
60    }
61}