1
// Copyright (C) Moondance Labs Ltd.
2
// This file is part of Tanssi.
3

            
4
// Tanssi 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
// Tanssi 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
// You should have received a copy of the GNU General Public License
15
// along with Tanssi.  If not, see <http://www.gnu.org/licenses/>.
16

            
17
use {
18
    clap::Parser,
19
    node_common::{
20
        cli::{BuildSpecCmd, ExportChainSpecCmd},
21
        service::node_builder::Sealing,
22
    },
23
};
24

            
25
#[derive(Debug, Parser)]
26
pub struct EthRpcArguments {
27
    /// Size in bytes of the LRU cache for block data.
28
    #[arg(long, default_value = "300000000")]
29
    pub eth_log_block_cache: usize,
30

            
31
    /// Size in bytes of the LRU cache for transactions statuses data.
32
    #[arg(long, default_value = "300000000")]
33
    pub eth_statuses_cache: usize,
34

            
35
    /// Maximum number of logs in a query.
36
    #[arg(long, default_value = "10000")]
37
    pub max_past_logs: u32,
38

            
39
    /// Maximum block range to query logs from.
40
    #[arg(long, default_value = "1024")]
41
    pub max_block_range: u32,
42

            
43
    /// Maximum fee history cache size.
44
    #[arg(long, default_value = "2048")]
45
    pub fee_history_limit: u64,
46
}
47

            
48
#[derive(Debug, Parser)]
49
#[group(skip)]
50
pub struct RunCmd {
51
    #[clap(flatten)]
52
    pub base: cumulus_client_cli::RunCmd,
53

            
54
    /// Id of the parachain this collator collates for.
55
    #[arg(long)]
56
    pub parachain_id: Option<u32>,
57

            
58
    #[clap(flatten)]
59
    pub eth: EthRpcArguments,
60

            
61
    /// When blocks should be sealed in the dev service.
62
    ///
63
    /// Options are "instant", "manual", or timer interval in milliseconds
64
    #[arg(long, default_value = "instant")]
65
    pub sealing: Sealing,
66
}
67

            
68
impl std::ops::Deref for RunCmd {
69
    type Target = cumulus_client_cli::RunCmd;
70

            
71
324
    fn deref(&self) -> &Self::Target {
72
324
        &self.base
73
324
    }
74
}
75

            
76
/// Watches for an assignment and provide Ethereum RPC services for assigned chain.
77
#[derive(Debug, Parser)]
78
pub struct DataPreserverCmd {
79
    #[clap(flatten)]
80
    pub base: tc_service_container_chain_data_preserver::DataPreserverCmd,
81

            
82
    #[clap(flatten)]
83
    pub eth: EthRpcArguments,
84
}
85

            
86
/// Common subcommands enum configured with frontier build spec.
87
pub type BaseSubcommand =
88
    node_common::cli::Subcommand<BuildSpecCmdFrontier, ExportChainSpecCmdFrontier>;
89

            
90
/// Custom subcommand enum with `rpc-provider`
91
#[derive(Debug, clap::Subcommand)]
92
pub enum Subcommand {
93
    DataPreserver(DataPreserverCmd),
94
    #[command(flatten)]
95
    Base(BaseSubcommand),
96
}
97

            
98
#[derive(Debug, clap::Parser)]
99
#[command(
100
    propagate_version = true,
101
    args_conflicts_with_subcommands = true,
102
    subcommand_negates_reqs = true
103
)]
104
pub struct Cli {
105
    #[command(subcommand)]
106
    pub subcommand: Option<Subcommand>,
107

            
108
    // ===== WARNING =====
109
    // The following arguments are only parsed if `subcommand` is `None`. They
110
    // get default values when a subcommand is used!
111
    // TODO: Fix usage of those wrong values in subcommands.
112
    // SEE: https://github.com/paritytech/polkadot-sdk/issues/9356
113
    #[command(flatten)]
114
    pub run: RunCmd,
115

            
116
    /// Disable automatic hardware benchmarks.
117
    ///
118
    /// By default these benchmarks are automatically ran at startup and measure
119
    /// the CPU speed, the memory bandwidth and the disk speed.
120
    ///
121
    /// The results are then printed out in the logs, and also sent as part of
122
    /// telemetry, if telemetry is enabled.
123
    #[arg(long)]
124
    pub no_hardware_benchmarks: bool,
125

            
126
    /// Optional parachain id that should be used to build chain spec.
127
    #[arg(long)]
128
    pub para_id: Option<u32>,
129

            
130
    /// Relay chain arguments
131
    #[arg(raw = true)]
132
    pub relay_chain_args: Vec<String>,
133
}
134

            
135
#[derive(Debug, Clone, clap::Args)]
136
pub struct ExtraFields {
137
    /// List of bootnodes to add to chain spec
138
    #[arg(long)]
139
    pub add_bootnode: Vec<String>,
140

            
141
    /// Id of the parachain this spec is for. Note that this overrides the `--chain` param.
142
    #[arg(long, conflicts_with = "chain")]
143
    #[arg(long)]
144
    pub parachain_id: Option<u32>,
145
}
146

            
147
pub type BuildSpecCmdFrontier = BuildSpecCmd<ExtraFields>;
148

            
149
pub type ExportChainSpecCmdFrontier = ExportChainSpecCmd<ExtraFields>;
150

            
151
#[derive(Clone)]
152
pub struct RpcConfig {
153
    pub eth_log_block_cache: usize,
154
    pub eth_statuses_cache: usize,
155
    pub fee_history_limit: u64,
156
    pub max_past_logs: u32,
157
    pub max_block_range: u32,
158
}