1
// Copyright 2019-2025 PureStake Inc.
2
// This file is part of Moonbeam.
3

            
4
// Moonbeam is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8

            
9
// Moonbeam is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13

            
14
use std::path::PathBuf;
15
// You should have received a copy of the GNU General Public License
16
// along with Moonbeam.  If not, see <http://www.gnu.org/licenses/>.
17
use primitive_types::H256;
18
use std::str::FromStr;
19

            
20
pub use polkadot_omni_node_lib::cli::AuthoringPolicy;
21

            
22
pub mod account_key;
23

            
24
/// Block authoring scheme to be used by the dev service.
25
#[derive(Debug, Copy, Clone)]
26
pub enum Sealing {
27
	/// Author a block immediately upon receiving a transaction into the transaction pool
28
	Instant,
29
	/// Author a block upon receiving an RPC command
30
	Manual,
31
	/// Author blocks at a regular interval specified in milliseconds
32
	Interval(u64),
33
}
34

            
35
impl FromStr for Sealing {
36
	type Err = String;
37

            
38
932
	fn from_str(s: &str) -> Result<Self, Self::Err> {
39
932
		Ok(match s {
40
932
			"instant" => Self::Instant,
41
926
			"manual" => Self::Manual,
42
			s => {
43
				let millis =
44
					u64::from_str_radix(s, 10).map_err(|_| "couldn't decode sealing param")?;
45
				Self::Interval(millis)
46
			}
47
		})
48
932
	}
49
}
50

            
51
#[derive(Debug, PartialEq, Clone)]
52
pub enum EthApi {
53
	Txpool,
54
	Debug,
55
	Trace,
56
}
57

            
58
impl FromStr for EthApi {
59
	type Err = String;
60

            
61
926
	fn from_str(s: &str) -> Result<Self, Self::Err> {
62
926
		Ok(match s {
63
926
			"txpool" => Self::Txpool,
64
			"debug" => Self::Debug,
65
			"trace" => Self::Trace,
66
			_ => {
67
				return Err(format!(
68
					"`{}` is not recognized as a supported Ethereum Api",
69
					s
70
				))
71
			}
72
		})
73
926
	}
74
}
75

            
76
/// Available frontier backend types.
77
#[derive(Debug, Copy, Clone, Default, clap::ValueEnum)]
78
pub enum FrontierBackendType {
79
	/// Either RocksDb or ParityDb as per inherited from the global backend settings.
80
	#[default]
81
	KeyValue,
82
	/// Sql database with custom log indexing.
83
	Sql,
84
}
85

            
86
/// Defines the frontier backend configuration.
87
pub enum FrontierBackendConfig {
88
	KeyValue,
89
	Sql {
90
		pool_size: u32,
91
		num_ops_timeout: u32,
92
		thread_count: u32,
93
		cache_size: u64,
94
	},
95
}
96

            
97
impl Default for FrontierBackendConfig {
98
	fn default() -> FrontierBackendConfig {
99
		FrontierBackendConfig::KeyValue
100
	}
101
}
102

            
103
pub struct RpcConfig {
104
	pub ethapi: Vec<EthApi>,
105
	pub ethapi_max_permits: u32,
106
	pub ethapi_trace_max_count: u32,
107
	pub ethapi_trace_cache_duration: u64,
108
	pub eth_log_block_cache: usize,
109
	pub eth_statuses_cache: usize,
110
	pub fee_history_limit: u64,
111
	pub max_past_logs: u32,
112
	pub max_block_range: u32,
113
	pub relay_chain_rpc_urls: Vec<url::Url>,
114
	pub tracing_raw_max_memory_usage: usize,
115
	pub frontier_backend_config: FrontierBackendConfig,
116
	pub no_prometheus_prefix: bool,
117
}
118

            
119
#[derive(Clone)]
120
pub struct LazyLoadingConfig {
121
	pub state_rpc: url::Url,
122
	pub from_block: Option<H256>,
123
	pub state_overrides_path: Option<PathBuf>,
124
	pub runtime_override: Option<PathBuf>,
125
	pub delay_between_requests: u32,
126
	pub max_retries_per_request: u32,
127
}
128
/// Extra args that are passed when creating a new node spec.
129
#[derive(Clone)]
130
pub struct NodeExtraArgs {
131
	/// The authoring policy to use.
132
	///
133
	/// Can be used to influence details of block production.
134
	pub authoring_policy: AuthoringPolicy,
135

            
136
	/// If set, each `PoV` build by the node will be exported to this folder.
137
	pub export_pov: Option<PathBuf>,
138

            
139
	/// The maximum percentage of the maximum PoV size that the collator can use.
140
	/// It will be removed once <https://github.com/paritytech/polkadot-sdk/issues/6020> is fixed.
141
	pub max_pov_percentage: Option<u32>,
142

            
143
	/// Enable the legacy block import strategy
144
	pub legacy_block_import_strategy: bool,
145
}