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, cli::Subcommand, service::Sealing},
20
    url::Url,
21
};
22

            
23
#[derive(Debug, Parser)]
24
#[group(skip)]
25
pub struct RunCmd {
26
    #[clap(flatten)]
27
    pub base: cumulus_client_cli::RunCmd,
28

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

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

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

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

            
45
    /// Id of the parachain this collator collates for.
46
    #[arg(long)]
47
    pub parachain_id: Option<u32>,
48

            
49
    /// Maximum fee history cache size.
50
    #[arg(long, default_value = "2048")]
51
    pub fee_history_limit: u64,
52

            
53
    /// When blocks should be sealed in the dev service.
54
    ///
55
    /// Options are "instant", "manual", or timer interval in milliseconds
56
    #[arg(long, default_value = "instant")]
57
    pub sealing: Sealing,
58
}
59

            
60
impl std::ops::Deref for RunCmd {
61
    type Target = cumulus_client_cli::RunCmd;
62

            
63
296
    fn deref(&self) -> &Self::Target {
64
296
        &self.base
65
296
    }
66
}
67

            
68
pub type FrontierSubcommand = Subcommand<BuildSpecCmdFrontier>;
69

            
70
#[derive(Debug, clap::Parser)]
71
#[command(
72
    propagate_version = true,
73
    args_conflicts_with_subcommands = true,
74
    subcommand_negates_reqs = true
75
)]
76
pub struct Cli {
77
    #[command(subcommand)]
78
    pub subcommand: Option<FrontierSubcommand>,
79

            
80
    #[command(flatten)]
81
    pub run: RunCmd,
82

            
83
    /// Disable automatic hardware benchmarks.
84
    ///
85
    /// By default these benchmarks are automatically ran at startup and measure
86
    /// the CPU speed, the memory bandwidth and the disk speed.
87
    ///
88
    /// The results are then printed out in the logs, and also sent as part of
89
    /// telemetry, if telemetry is enabled.
90
    #[arg(long)]
91
    pub no_hardware_benchmarks: bool,
92

            
93
    /// Profile id associated with the node, whose assignements will be followed to provide RPC services.
94
    #[arg(long)]
95
    pub rpc_provider_profile_id: Option<u64>,
96

            
97
    /// Endpoints to connect to orchestrator nodes, avoiding to start a local orchestrator node.
98
    /// If this list is empty, a local embeded orchestrator node is started.
99
    #[arg(long)]
100
    pub orchestrator_endpoints: Vec<Url>,
101

            
102
    /// Optional parachain id that should be used to build chain spec.
103
    #[arg(long)]
104
    pub para_id: Option<u32>,
105

            
106
    /// Relay chain arguments, optionally followed by "--" and container chain arguments
107
    #[arg(raw = true)]
108
    extra_args: Vec<String>,
109
}
110

            
111
impl Cli {
112
148
    pub fn relaychain_args(&self) -> &[String] {
113
148
        let (relay_chain_args, _) = self.split_extra_args_at_first_dashdash();
114
148

            
115
148
        relay_chain_args
116
148
    }
117

            
118
    pub fn container_chain_args(&self) -> &[String] {
119
        let (_, container_chain_args) = self.split_extra_args_at_first_dashdash();
120

            
121
        container_chain_args
122
    }
123

            
124
148
    fn split_extra_args_at_first_dashdash(&self) -> (&[String], &[String]) {
125
148
        let index_of_dashdash = self.extra_args.iter().position(|x| *x == "--");
126

            
127
148
        if let Some(i) = index_of_dashdash {
128
            let (container_chain_args, extra_extra) = self.extra_args.split_at(i);
129
            (&extra_extra[1..], container_chain_args)
130
        } else {
131
            // Only relay chain args
132
148
            (&self.extra_args, &[])
133
        }
134
148
    }
135
}
136

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

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

            
149
pub type BuildSpecCmdFrontier = BuildSpecCmd<BuildSpecCmdExtraFields>;
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
}