Mixnet integration (#1346)

See #1345, <https://github.com/paritytech/substrate/pull/14207>.

This adds all the necessary mixnet components, and puts them together in
the "kitchen-sink" node/runtime. The components added are:

- A pallet (`frame/mixnet`). This is responsible for determining the
current mixnet session and phase, and the mixnodes to use in each
session. It provides a function that validators can call to register a
mixnode for the next session. The logic of this pallet is very similar
to that of the `im-online` pallet.
- A service (`client/mixnet`). This implements the core mixnet logic,
building on the `mixnet` crate. The service communicates with other
nodes using notifications sent over the "mixnet" protocol.
- An RPC interface. This currently only supports sending transactions
over the mixnet.

---------

Co-authored-by: David Emett <dave@sp4m.net>
Co-authored-by: Javier Viola <javier@parity.io>
This commit is contained in:
David Emett
2023-10-09 15:56:30 +02:00
committed by GitHub
parent 1dc935c715
commit a808a3a091
52 changed files with 3010 additions and 109 deletions
@@ -0,0 +1,67 @@
// This file is part of Substrate.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use clap::Args;
use sp_core::H256;
use std::str::FromStr;
fn parse_kx_secret(s: &str) -> Result<sc_mixnet::KxSecret, String> {
H256::from_str(s).map(H256::to_fixed_bytes).map_err(|err| err.to_string())
}
/// Parameters used to create the mixnet configuration.
#[derive(Debug, Clone, Args)]
pub struct MixnetParams {
/// Enable the mixnet service.
///
/// This will make the mixnet RPC methods available. If the node is running as a validator, it
/// will also attempt to register and operate as a mixnode.
#[arg(long)]
pub mixnet: bool,
/// The mixnet key-exchange secret to use in session 0.
///
/// Should be 64 hex characters, giving a 32-byte secret.
///
/// WARNING: Secrets provided as command-line arguments are easily exposed. Use of this option
/// should be limited to development and testing.
#[arg(long, value_name = "SECRET", value_parser = parse_kx_secret)]
pub mixnet_session_0_kx_secret: Option<sc_mixnet::KxSecret>,
}
impl MixnetParams {
/// Returns the mixnet configuration, or `None` if the mixnet is disabled.
pub fn config(&self, is_authority: bool) -> Option<sc_mixnet::Config> {
self.mixnet.then(|| {
let mut config = sc_mixnet::Config {
core: sc_mixnet::CoreConfig {
session_0_kx_secret: self.mixnet_session_0_kx_secret,
..Default::default()
},
..Default::default()
};
if !is_authority {
// Only authorities can be mixnodes; don't attempt to register
config.substrate.register = false;
// Only mixnodes need to allow connections from non-mixnodes
config.substrate.num_gateway_slots = 0;
}
config
})
}
}
+5 -3
View File
@@ -19,6 +19,7 @@ mod database_params;
mod import_params;
mod keystore_params;
mod message_params;
mod mixnet_params;
mod network_params;
mod node_key_params;
mod offchain_worker_params;
@@ -39,9 +40,10 @@ use sp_runtime::{
use std::{fmt::Debug, str::FromStr};
pub use crate::params::{
database_params::*, import_params::*, keystore_params::*, message_params::*, network_params::*,
node_key_params::*, offchain_worker_params::*, prometheus_params::*, pruning_params::*,
runtime_params::*, shared_params::*, telemetry_params::*, transaction_pool_params::*,
database_params::*, import_params::*, keystore_params::*, message_params::*, mixnet_params::*,
network_params::*, node_key_params::*, offchain_worker_params::*, prometheus_params::*,
pruning_params::*, runtime_params::*, shared_params::*, telemetry_params::*,
transaction_pool_params::*,
};
/// Parse Ss58AddressFormat