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
+6
View File
@@ -35,6 +35,7 @@ sp-block-builder = { path = "../../../primitives/block-builder", default-feature
sp-genesis-builder = { version = "0.1.0-dev", default-features = false, path = "../../../primitives/genesis-builder" }
sp-inherents = { path = "../../../primitives/inherents", default-features = false}
node-primitives = { path = "../primitives", default-features = false}
sp-mixnet = { path = "../../../primitives/mixnet", default-features = false }
sp-offchain = { path = "../../../primitives/offchain", default-features = false}
sp-core = { path = "../../../primitives/core", default-features = false}
sp-std = { path = "../../../primitives/std", default-features = false}
@@ -88,6 +89,7 @@ pallet-identity = { path = "../../../frame/identity", default-features = false}
pallet-lottery = { path = "../../../frame/lottery", default-features = false}
pallet-membership = { path = "../../../frame/membership", default-features = false}
pallet-message-queue = { path = "../../../frame/message-queue", default-features = false}
pallet-mixnet = { path = "../../../frame/mixnet", default-features = false }
pallet-mmr = { path = "../../../frame/merkle-mountain-range", default-features = false}
pallet-multisig = { path = "../../../frame/multisig", default-features = false}
pallet-nfts = { path = "../../../frame/nfts", default-features = false}
@@ -185,6 +187,7 @@ std = [
"pallet-lottery/std",
"pallet-membership/std",
"pallet-message-queue/std",
"pallet-mixnet/std",
"pallet-mmr/std",
"pallet-multisig/std",
"pallet-nft-fractionalization/std",
@@ -235,6 +238,7 @@ std = [
"sp-genesis-builder/std",
"sp-inherents/std",
"sp-io/std",
"sp-mixnet/std",
"sp-offchain/std",
"sp-runtime/std",
"sp-session/std",
@@ -281,6 +285,7 @@ runtime-benchmarks = [
"pallet-lottery/runtime-benchmarks",
"pallet-membership/runtime-benchmarks",
"pallet-message-queue/runtime-benchmarks",
"pallet-mixnet/runtime-benchmarks",
"pallet-mmr/runtime-benchmarks",
"pallet-multisig/runtime-benchmarks",
"pallet-nft-fractionalization/runtime-benchmarks",
@@ -354,6 +359,7 @@ try-runtime = [
"pallet-lottery/try-runtime",
"pallet-membership/try-runtime",
"pallet-message-queue/try-runtime",
"pallet-mixnet/try-runtime",
"pallet-mmr/try-runtime",
"pallet-multisig/try-runtime",
"pallet-nft-fractionalization/try-runtime",
+44 -1
View File
@@ -589,6 +589,7 @@ impl_opaque_keys! {
pub babe: Babe,
pub im_online: ImOnline,
pub authority_discovery: AuthorityDiscovery,
pub mixnet: Mixnet,
}
}
@@ -1048,7 +1049,7 @@ impl pallet_democracy::Config for Runtime {
pallet_collective::EnsureProportionAtLeast<AccountId, TechnicalCollective, 2, 3>;
type InstantOrigin =
pallet_collective::EnsureProportionAtLeast<AccountId, TechnicalCollective, 1, 1>;
type InstantAllowed = frame_support::traits::ConstBool<true>;
type InstantAllowed = ConstBool<true>;
type FastTrackVotingPeriod = FastTrackVotingPeriod;
// To cancel a proposal which has been passed, 2/3 of the council must agree to it.
type CancellationOrigin =
@@ -2028,6 +2029,29 @@ impl pallet_broker::Config for Runtime {
type PriceAdapter = pallet_broker::Linear;
}
parameter_types! {
pub const MixnetNumCoverToCurrentBlocks: BlockNumber = 3;
pub const MixnetNumRequestsToCurrentBlocks: BlockNumber = 3;
pub const MixnetNumCoverToPrevBlocks: BlockNumber = 3;
pub const MixnetNumRegisterStartSlackBlocks: BlockNumber = 3;
pub const MixnetNumRegisterEndSlackBlocks: BlockNumber = 3;
pub const MixnetRegistrationPriority: TransactionPriority = ImOnlineUnsignedPriority::get() - 1;
}
impl pallet_mixnet::Config for Runtime {
type MaxAuthorities = MaxAuthorities;
type MaxExternalAddressSize = ConstU32<128>;
type MaxExternalAddressesPerMixnode = ConstU32<16>;
type NextSessionRotation = Babe;
type NumCoverToCurrentBlocks = MixnetNumCoverToCurrentBlocks;
type NumRequestsToCurrentBlocks = MixnetNumRequestsToCurrentBlocks;
type NumCoverToPrevBlocks = MixnetNumCoverToPrevBlocks;
type NumRegisterStartSlackBlocks = MixnetNumRegisterStartSlackBlocks;
type NumRegisterEndSlackBlocks = MixnetNumRegisterEndSlackBlocks;
type RegistrationPriority = MixnetRegistrationPriority;
type MinMixnodes = ConstU32<7>; // Low to allow small testing networks
}
construct_runtime!(
pub struct Runtime
{
@@ -2104,6 +2128,7 @@ construct_runtime!(
SafeMode: pallet_safe_mode,
Statement: pallet_statement,
Broker: pallet_broker,
Mixnet: pallet_mixnet,
}
);
@@ -2663,6 +2688,24 @@ impl_runtime_apis! {
}
}
impl sp_mixnet::runtime_api::MixnetApi<Block> for Runtime {
fn session_status() -> sp_mixnet::types::SessionStatus {
Mixnet::session_status()
}
fn prev_mixnodes() -> Result<Vec<sp_mixnet::types::Mixnode>, sp_mixnet::types::MixnodesErr> {
Mixnet::prev_mixnodes()
}
fn current_mixnodes() -> Result<Vec<sp_mixnet::types::Mixnode>, sp_mixnet::types::MixnodesErr> {
Mixnet::current_mixnodes()
}
fn maybe_register(session_index: sp_mixnet::types::SessionIndex, mixnode: sp_mixnet::types::Mixnode) -> bool {
Mixnet::maybe_register(session_index, mixnode)
}
}
impl sp_session::SessionKeys<Block> for Runtime {
fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
SessionKeys::generate(seed)