Skip to content

Commit 90675f0

Browse files
zdave-parityzdavepepoviola
authored
Mixnet integration (paritytech#1346)
See paritytech#1345, <paritytech/substrate#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 <[email protected]> Co-authored-by: Javier Viola <[email protected]>
1 parent 0d2b961 commit 90675f0

50 files changed

Lines changed: 2766 additions & 39 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

substrate/bin/node/cli/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ sp-keystore = { path = "../../../primitives/keystore" }
6060
sp-consensus = { path = "../../../primitives/consensus/common" }
6161
sp-transaction-storage-proof = { path = "../../../primitives/transaction-storage-proof" }
6262
sp-io = { path = "../../../primitives/io" }
63+
sp-mixnet = { path = "../../../primitives/mixnet" }
6364
sp-statement-store = { path = "../../../primitives/statement-store" }
6465

6566
# client dependencies
@@ -82,6 +83,7 @@ sc-service = { path = "../../../client/service", default-features = false}
8283
sc-telemetry = { path = "../../../client/telemetry" }
8384
sc-executor = { path = "../../../client/executor" }
8485
sc-authority-discovery = { path = "../../../client/authority-discovery" }
86+
sc-mixnet = { path = "../../../client/mixnet" }
8587
sc-sync-state-rpc = { path = "../../../client/sync-state-rpc" }
8688
sc-sysinfo = { path = "../../../client/sysinfo" }
8789
sc-storage-monitor = { path = "../../../client/storage-monitor" }

substrate/bin/node/cli/benches/block_production.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase {
100100
wasm_runtime_overrides: None,
101101
};
102102

103-
node_cli::service::new_full_base(config, false, |_, _| ())
103+
node_cli::service::new_full_base(config, None, false, |_, _| ())
104104
.expect("creating a full node doesn't fail")
105105
}
106106

substrate/bin/node/cli/benches/transaction_pool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase {
9696
wasm_runtime_overrides: None,
9797
};
9898

99-
node_cli::service::new_full_base(config, false, |_, _| ()).expect("Creates node")
99+
node_cli::service::new_full_base(config, None, false, |_, _| ()).expect("Creates node")
100100
}
101101

102102
fn create_accounts(num: usize) -> Vec<sr25519::Pair> {

substrate/bin/node/cli/src/chain_spec.rs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use serde::{Deserialize, Serialize};
3333
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
3434
use sp_consensus_babe::AuthorityId as BabeId;
3535
use sp_core::{crypto::UncheckedInto, sr25519, Pair, Public};
36+
use sp_mixnet::types::AuthorityId as MixnetId;
3637
use sp_runtime::{
3738
traits::{IdentifyAccount, Verify},
3839
Perbill,
@@ -72,8 +73,9 @@ fn session_keys(
7273
babe: BabeId,
7374
im_online: ImOnlineId,
7475
authority_discovery: AuthorityDiscoveryId,
76+
mixnet: MixnetId,
7577
) -> SessionKeys {
76-
SessionKeys { grandpa, babe, im_online, authority_discovery }
78+
SessionKeys { grandpa, babe, im_online, authority_discovery, mixnet }
7779
}
7880

7981
fn staging_testnet_config_genesis() -> RuntimeGenesisConfig {
@@ -93,6 +95,7 @@ fn staging_testnet_config_genesis() -> RuntimeGenesisConfig {
9395
BabeId,
9496
ImOnlineId,
9597
AuthorityDiscoveryId,
98+
MixnetId,
9699
)> = vec![
97100
(
98101
// 5Fbsd6WXDGiLTxunqeK5BATNiocfCqu9bS1yArVjCgeBLkVy
@@ -111,6 +114,9 @@ fn staging_testnet_config_genesis() -> RuntimeGenesisConfig {
111114
// 5EZaeQ8djPcq9pheJUhgerXQZt9YaHnMJpiHMRhwQeinqUW8
112115
array_bytes::hex2array_unchecked("6e7e4eb42cbd2e0ab4cae8708ce5509580b8c04d11f6758dbf686d50fe9f9106")
113116
.unchecked_into(),
117+
// 5EZaeQ8djPcq9pheJUhgerXQZt9YaHnMJpiHMRhwQeinqUW8
118+
array_bytes::hex2array_unchecked("6e7e4eb42cbd2e0ab4cae8708ce5509580b8c04d11f6758dbf686d50fe9f9106")
119+
.unchecked_into(),
114120
),
115121
(
116122
// 5ERawXCzCWkjVq3xz1W5KGNtVx2VdefvZ62Bw1FEuZW4Vny2
@@ -129,6 +135,9 @@ fn staging_testnet_config_genesis() -> RuntimeGenesisConfig {
129135
// 5DhLtiaQd1L1LU9jaNeeu9HJkP6eyg3BwXA7iNMzKm7qqruQ
130136
array_bytes::hex2array_unchecked("482dbd7297a39fa145c570552249c2ca9dd47e281f0c500c971b59c9dcdcd82e")
131137
.unchecked_into(),
138+
// 5DhLtiaQd1L1LU9jaNeeu9HJkP6eyg3BwXA7iNMzKm7qqruQ
139+
array_bytes::hex2array_unchecked("482dbd7297a39fa145c570552249c2ca9dd47e281f0c500c971b59c9dcdcd82e")
140+
.unchecked_into(),
132141
),
133142
(
134143
// 5DyVtKWPidondEu8iHZgi6Ffv9yrJJ1NDNLom3X9cTDi98qp
@@ -147,6 +156,9 @@ fn staging_testnet_config_genesis() -> RuntimeGenesisConfig {
147156
// 5DhKqkHRkndJu8vq7pi2Q5S3DfftWJHGxbEUNH43b46qNspH
148157
array_bytes::hex2array_unchecked("482a3389a6cf42d8ed83888cfd920fec738ea30f97e44699ada7323f08c3380a")
149158
.unchecked_into(),
159+
// 5DhKqkHRkndJu8vq7pi2Q5S3DfftWJHGxbEUNH43b46qNspH
160+
array_bytes::hex2array_unchecked("482a3389a6cf42d8ed83888cfd920fec738ea30f97e44699ada7323f08c3380a")
161+
.unchecked_into(),
150162
),
151163
(
152164
// 5HYZnKWe5FVZQ33ZRJK1rG3WaLMztxWrrNDb1JRwaHHVWyP9
@@ -165,6 +177,9 @@ fn staging_testnet_config_genesis() -> RuntimeGenesisConfig {
165177
// 5C4vDQxA8LTck2xJEy4Yg1hM9qjDt4LvTQaMo4Y8ne43aU6x
166178
array_bytes::hex2array_unchecked("00299981a2b92f878baaf5dbeba5c18d4e70f2a1fcd9c61b32ea18daf38f4378")
167179
.unchecked_into(),
180+
// 5C4vDQxA8LTck2xJEy4Yg1hM9qjDt4LvTQaMo4Y8ne43aU6x
181+
array_bytes::hex2array_unchecked("00299981a2b92f878baaf5dbeba5c18d4e70f2a1fcd9c61b32ea18daf38f4378")
182+
.unchecked_into(),
168183
),
169184
];
170185

@@ -217,14 +232,15 @@ where
217232
/// Helper function to generate stash, controller and session key from seed.
218233
pub fn authority_keys_from_seed(
219234
seed: &str,
220-
) -> (AccountId, AccountId, GrandpaId, BabeId, ImOnlineId, AuthorityDiscoveryId) {
235+
) -> (AccountId, AccountId, GrandpaId, BabeId, ImOnlineId, AuthorityDiscoveryId, MixnetId) {
221236
(
222237
get_account_id_from_seed::<sr25519::Public>(&format!("{}//stash", seed)),
223238
get_account_id_from_seed::<sr25519::Public>(seed),
224239
get_from_seed::<GrandpaId>(seed),
225240
get_from_seed::<BabeId>(seed),
226241
get_from_seed::<ImOnlineId>(seed),
227242
get_from_seed::<AuthorityDiscoveryId>(seed),
243+
get_from_seed::<MixnetId>(seed),
228244
)
229245
}
230246

@@ -237,6 +253,7 @@ pub fn testnet_genesis(
237253
BabeId,
238254
ImOnlineId,
239255
AuthorityDiscoveryId,
256+
MixnetId,
240257
)>,
241258
initial_nominators: Vec<AccountId>,
242259
root_key: AccountId,
@@ -306,7 +323,13 @@ pub fn testnet_genesis(
306323
(
307324
x.0.clone(),
308325
x.0.clone(),
309-
session_keys(x.2.clone(), x.3.clone(), x.4.clone(), x.5.clone()),
326+
session_keys(
327+
x.2.clone(),
328+
x.3.clone(),
329+
x.4.clone(),
330+
x.5.clone(),
331+
x.6.clone(),
332+
),
310333
)
311334
})
312335
.collect::<Vec<_>>(),
@@ -367,6 +390,7 @@ pub fn testnet_genesis(
367390
..Default::default()
368391
},
369392
glutton: Default::default(),
393+
mixnet: Default::default(),
370394
}
371395
}
372396

@@ -475,7 +499,7 @@ pub(crate) mod tests {
475499

476500
sc_service_test::connectivity(integration_test_config_with_two_authorities(), |config| {
477501
let NewFullBase { task_manager, client, network, sync, transaction_pool, .. } =
478-
new_full_base(config, false, |_, _| ())?;
502+
new_full_base(config, None, false, |_, _| ())?;
479503
Ok(sc_service_test::TestNetComponents::new(
480504
task_manager,
481505
client,

substrate/bin/node/cli/src/cli.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ pub struct Cli {
2727
#[clap(flatten)]
2828
pub run: sc_cli::RunCmd,
2929

30+
#[allow(missing_docs)]
31+
#[clap(flatten)]
32+
pub mixnet_params: sc_cli::MixnetParams,
33+
3034
/// Disable automatic hardware benchmarks.
3135
///
3236
/// By default these benchmarks are automatically ran at startup and measure

substrate/bin/node/cli/src/command.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub fn run() -> Result<()> {
111111
},
112112
BenchmarkCmd::Block(cmd) => {
113113
// ensure that we keep the task manager alive
114-
let partial = new_partial(&config)?;
114+
let partial = new_partial(&config, None)?;
115115
cmd.run(partial.client)
116116
},
117117
#[cfg(not(feature = "runtime-benchmarks"))]
@@ -122,15 +122,15 @@ pub fn run() -> Result<()> {
122122
#[cfg(feature = "runtime-benchmarks")]
123123
BenchmarkCmd::Storage(cmd) => {
124124
// ensure that we keep the task manager alive
125-
let partial = new_partial(&config)?;
125+
let partial = new_partial(&config, None)?;
126126
let db = partial.backend.expose_db();
127127
let storage = partial.backend.expose_storage();
128128

129129
cmd.run(config, partial.client, db, storage)
130130
},
131131
BenchmarkCmd::Overhead(cmd) => {
132132
// ensure that we keep the task manager alive
133-
let partial = new_partial(&config)?;
133+
let partial = new_partial(&config, None)?;
134134
let ext_builder = RemarkBuilder::new(partial.client.clone());
135135

136136
cmd.run(
@@ -143,7 +143,7 @@ pub fn run() -> Result<()> {
143143
},
144144
BenchmarkCmd::Extrinsic(cmd) => {
145145
// ensure that we keep the task manager alive
146-
let partial = service::new_partial(&config)?;
146+
let partial = service::new_partial(&config, None)?;
147147
// Register the *Remark* and *TKA* builders.
148148
let ext_factory = ExtrinsicFactory(vec![
149149
Box::new(RemarkBuilder::new(partial.client.clone())),
@@ -178,29 +178,29 @@ pub fn run() -> Result<()> {
178178
let runner = cli.create_runner(cmd)?;
179179
runner.async_run(|config| {
180180
let PartialComponents { client, task_manager, import_queue, .. } =
181-
new_partial(&config)?;
181+
new_partial(&config, None)?;
182182
Ok((cmd.run(client, import_queue), task_manager))
183183
})
184184
},
185185
Some(Subcommand::ExportBlocks(cmd)) => {
186186
let runner = cli.create_runner(cmd)?;
187187
runner.async_run(|config| {
188-
let PartialComponents { client, task_manager, .. } = new_partial(&config)?;
188+
let PartialComponents { client, task_manager, .. } = new_partial(&config, None)?;
189189
Ok((cmd.run(client, config.database), task_manager))
190190
})
191191
},
192192
Some(Subcommand::ExportState(cmd)) => {
193193
let runner = cli.create_runner(cmd)?;
194194
runner.async_run(|config| {
195-
let PartialComponents { client, task_manager, .. } = new_partial(&config)?;
195+
let PartialComponents { client, task_manager, .. } = new_partial(&config, None)?;
196196
Ok((cmd.run(client, config.chain_spec), task_manager))
197197
})
198198
},
199199
Some(Subcommand::ImportBlocks(cmd)) => {
200200
let runner = cli.create_runner(cmd)?;
201201
runner.async_run(|config| {
202202
let PartialComponents { client, task_manager, import_queue, .. } =
203-
new_partial(&config)?;
203+
new_partial(&config, None)?;
204204
Ok((cmd.run(client, import_queue), task_manager))
205205
})
206206
},
@@ -211,7 +211,8 @@ pub fn run() -> Result<()> {
211211
Some(Subcommand::Revert(cmd)) => {
212212
let runner = cli.create_runner(cmd)?;
213213
runner.async_run(|config| {
214-
let PartialComponents { client, task_manager, backend, .. } = new_partial(&config)?;
214+
let PartialComponents { client, task_manager, backend, .. } =
215+
new_partial(&config, None)?;
215216
let aux_revert = Box::new(|client: Arc<FullClient>, backend, blocks| {
216217
sc_consensus_babe::revert(client.clone(), backend, blocks)?;
217218
grandpa::revert(client, blocks)?;

0 commit comments

Comments
 (0)