referrerpolicy=no-referrer-when-downgrade

sc_cli/params/
mixnet_params.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5
6// This program is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License
17// along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19use clap::Args;
20use sp_core::H256;
21use std::str::FromStr;
22
23fn parse_kx_secret(s: &str) -> Result<sc_mixnet::KxSecret, String> {
24	H256::from_str(s).map(H256::to_fixed_bytes).map_err(|err| err.to_string())
25}
26
27/// Parameters used to create the mixnet configuration.
28#[derive(Debug, Clone, Args)]
29pub struct MixnetParams {
30	/// Enable the mixnet service.
31	///
32	/// This will make the mixnet RPC methods available. If the node is running as a validator, it
33	/// will also attempt to register and operate as a mixnode.
34	#[arg(long)]
35	pub mixnet: bool,
36
37	/// The mixnet key-exchange secret to use in session 0.
38	///
39	/// Should be 64 hex characters, giving a 32-byte secret.
40	///
41	/// WARNING: Secrets provided as command-line arguments are easily exposed. Use of this option
42	/// should be limited to development and testing.
43	#[arg(long, value_name = "SECRET", value_parser = parse_kx_secret)]
44	pub mixnet_session_0_kx_secret: Option<sc_mixnet::KxSecret>,
45}
46
47impl MixnetParams {
48	/// Returns the mixnet configuration, or `None` if the mixnet is disabled.
49	pub fn config(&self, is_authority: bool) -> Option<sc_mixnet::Config> {
50		self.mixnet.then(|| {
51			let mut config = sc_mixnet::Config {
52				core: sc_mixnet::CoreConfig {
53					session_0_kx_secret: self.mixnet_session_0_kx_secret,
54					..Default::default()
55				},
56				..Default::default()
57			};
58			if !is_authority {
59				// Only authorities can be mixnodes; don't attempt to register
60				config.substrate.register = false;
61				// Only mixnodes need to allow connections from non-mixnodes
62				config.substrate.num_gateway_slots = 0;
63			}
64			config
65		})
66	}
67}