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::{cli::BuildSpecCmd, service::node_builder::Sealing},
20
};
21

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

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

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

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

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

            
45
#[derive(Debug, Parser)]
46
#[group(skip)]
47
pub struct RunCmd {
48
    #[clap(flatten)]
49
    pub base: cumulus_client_cli::RunCmd,
50

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

            
55
    #[clap(flatten)]
56
    pub eth: EthRpcArguments,
57

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

            
65
impl std::ops::Deref for RunCmd {
66
    type Target = cumulus_client_cli::RunCmd;
67

            
68
320
    fn deref(&self) -> &Self::Target {
69
320
        &self.base
70
320
    }
71
}
72

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

            
79
    #[clap(flatten)]
80
    pub eth: EthRpcArguments,
81
}
82

            
83
/// Common subcommands enum configured with frontier build spec.
84
pub type BaseSubcommand = node_common::cli::Subcommand<BuildSpecCmdFrontier>;
85

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

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

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

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

            
122
    /// Optional parachain id that should be used to build chain spec.
123
    #[arg(long)]
124
    pub para_id: Option<u32>,
125

            
126
    /// Relay chain arguments
127
    #[arg(raw = true)]
128
    pub relay_chain_args: Vec<String>,
129
}
130

            
131
#[derive(Debug, Clone, clap::Args)]
132
pub struct BuildSpecCmdExtraFields {
133
    /// List of bootnodes to add to chain spec
134
    #[arg(long)]
135
    pub add_bootnode: Vec<String>,
136

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

            
143
pub type BuildSpecCmdFrontier = BuildSpecCmd<BuildSpecCmdExtraFields>;
144

            
145
#[derive(Clone)]
146
pub struct RpcConfig {
147
    pub eth_log_block_cache: usize,
148
    pub eth_statuses_cache: usize,
149
    pub fee_history_limit: u64,
150
    pub max_past_logs: u32,
151
    pub max_block_range: u32,
152
}