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,52 @@
// This file is part of Substrate.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Runtime API for querying mixnet configuration and registering mixnodes.
use super::types::{Mixnode, MixnodesErr, SessionIndex, SessionStatus};
use sp_std::vec::Vec;
sp_api::decl_runtime_apis! {
/// API to query the mixnet session status and mixnode sets, and to register mixnodes.
pub trait MixnetApi {
/// Get the index and phase of the current session.
fn session_status() -> SessionStatus;
/// Get the mixnode set for the previous session.
fn prev_mixnodes() -> Result<Vec<Mixnode>, MixnodesErr>;
/// Get the mixnode set for the current session.
fn current_mixnodes() -> Result<Vec<Mixnode>, MixnodesErr>;
/// Try to register a mixnode for the next session.
///
/// If a registration extrinsic is submitted, `true` is returned. The caller should avoid
/// calling `maybe_register` again for a few blocks, to give the submitted extrinsic a
/// chance to get included.
///
/// With the above exception, `maybe_register` is designed to be called every block. Most
/// of the time it will not do anything, for example:
///
/// - If it is not an appropriate time to submit a registration extrinsic.
/// - If the local node has already registered a mixnode for the next session.
/// - If the local node is not permitted to register a mixnode for the next session.
///
/// `session_index` should match `session_status().current_index`; if it does not, `false`
/// is returned immediately.
fn maybe_register(session_index: SessionIndex, mixnode: Mixnode) -> bool;
}
}