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
    /// Id of the parachain this collator collates for.
42
    #[arg(long)]
43
    pub parachain_id: Option<u32>,
44

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

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

            
56
impl std::ops::Deref for RunCmd {
57
    type Target = cumulus_client_cli::RunCmd;
58

            
59
292
    fn deref(&self) -> &Self::Target {
60
292
        &self.base
61
292
    }
62
}
63

            
64
pub type FrontierSubcommand = Subcommand<BuildSpecCmdFrontier>;
65

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

            
76
    #[command(flatten)]
77
    pub run: RunCmd,
78

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

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

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

            
98
    /// Optional parachain id that should be used to build chain spec.
99
    #[arg(long)]
100
    pub para_id: Option<u32>,
101

            
102
    /// Relay chain arguments, optionally followed by "--" and container chain arguments
103
    #[arg(raw = true)]
104
    extra_args: Vec<String>,
105
}
106

            
107
impl Cli {
108
146
    pub fn relaychain_args(&self) -> &[String] {
109
146
        let (relay_chain_args, _) = self.split_extra_args_at_first_dashdash();
110
146

            
111
146
        relay_chain_args
112
146
    }
113

            
114
    pub fn container_chain_args(&self) -> &[String] {
115
        let (_, container_chain_args) = self.split_extra_args_at_first_dashdash();
116

            
117
        container_chain_args
118
    }
119

            
120
146
    fn split_extra_args_at_first_dashdash(&self) -> (&[String], &[String]) {
121
146
        let index_of_dashdash = self.extra_args.iter().position(|x| *x == "--");
122

            
123
146
        if let Some(i) = index_of_dashdash {
124
            let (container_chain_args, extra_extra) = self.extra_args.split_at(i);
125
            (&extra_extra[1..], container_chain_args)
126
        } else {
127
            // Only relay chain args
128
146
            (&self.extra_args, &[])
129
        }
130
146
    }
131
}
132

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

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

            
145
pub type BuildSpecCmdFrontier = BuildSpecCmd<BuildSpecCmdExtraFields>;
146

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