diff --git a/.github/workflows/run_linters.yml b/.github/workflows/run_linters.yml index 4679b4133..971c33d6a 100644 --- a/.github/workflows/run_linters.yml +++ b/.github/workflows/run_linters.yml @@ -71,7 +71,7 @@ jobs: curl -s https://sh.rustup.rs -sSf | sh -s -- -y source ${HOME}/.cargo/env rustup toolchain install nightly - rustup default nightly + rustup default nightly-2022-07-10-x86_64-unknown-linux-gnu cargo install taplo-cli - name: Run yamllint uses: actionshub/yamllint@main diff --git a/CHANGELOG.md b/CHANGELOG.md index aed4e64f3..1e2c51ac1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### Features - [\#576](https://github.com/Manta-Network/Manta/pull/576) Unfilter xtokens.transfer_multicurrencies and bump MaxAssetsForTransfer to 2. +- [\#646](https://github.com/Manta-Network/Manta/pull/646) Add collator session keys for future nimbus consensus and a vrf placeholder ### Improvements - [\#449](https://github.com/Manta-Network/Manta/pull/449) Remove strip from CI, and add strip profile to production. diff --git a/Cargo.lock b/Cargo.lock index 51ffa77e2..778c8798f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1157,6 +1157,7 @@ dependencies = [ "pallet-asset-manager", "pallet-assets", "pallet-aura", + "pallet-author-inherent", "pallet-authorship", "pallet-balances", "pallet-collective", @@ -1182,8 +1183,10 @@ dependencies = [ "scale-info", "serde", "serde_json", + "session-key-primitives", "smallvec", "sp-api", + "sp-application-crypto", "sp-arithmetic", "sp-block-builder", "sp-consensus-aura", @@ -2535,6 +2538,7 @@ dependencies = [ "pallet-asset-manager", "pallet-assets", "pallet-aura", + "pallet-author-inherent", "pallet-authorship", "pallet-balances", "pallet-collective", @@ -2561,8 +2565,10 @@ dependencies = [ "runtime-common", "scale-info", "serde", + "session-key-primitives", "smallvec", "sp-api", + "sp-application-crypto", "sp-arithmetic", "sp-block-builder", "sp-consensus-aura", @@ -5021,6 +5027,7 @@ dependencies = [ "sc-transaction-pool", "sc-transaction-pool-api", "serde", + "session-key-primitives", "sp-api", "sp-block-builder", "sp-blockchain", @@ -5168,7 +5175,6 @@ dependencies = [ "parity-scale-codec", "scale-info", "smallvec", - "sp-consensus-aura", "sp-core", "sp-io", "sp-runtime", @@ -5223,6 +5229,7 @@ dependencies = [ "runtime-common", "scale-info", "serde", + "session-key-primitives", "smallvec", "sp-api", "sp-block-builder", @@ -5635,6 +5642,23 @@ dependencies = [ "log", ] +[[package]] +name = "nimbus-primitives" +version = "0.9.0" +source = "git+https://github.com/manta-network/nimbus.git?branch=polkadot-v0.9.22#84161bc6e71ee10ea34a50bb839b2c24f64760a5" +dependencies = [ + "async-trait", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-api", + "sp-application-crypto", + "sp-inherents", + "sp-runtime", + "sp-std", +] + [[package]] name = "nix" version = "0.22.3" @@ -5994,6 +6018,26 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-author-inherent" +version = "0.9.0" +source = "git+https://github.com/manta-network/nimbus.git?branch=polkadot-v0.9.22#84161bc6e71ee10ea34a50bb839b2c24f64760a5" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "nimbus-primitives", + "parity-scale-codec", + "scale-info", + "sp-api", + "sp-application-crypto", + "sp-authorship", + "sp-inherents", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-authority-discovery" version = "4.0.0-dev" @@ -10617,6 +10661,20 @@ dependencies = [ "syn", ] +[[package]] +name = "session-key-primitives" +version = "3.2.0" +dependencies = [ + "manta-primitives", + "nimbus-primitives", + "parity-scale-codec", + "scale-info", + "sp-application-crypto", + "sp-consensus-aura", + "sp-core", + "sp-runtime", +] + [[package]] name = "sha-1" version = "0.8.2" diff --git a/Cargo.toml b/Cargo.toml index 3c47115e7..9fff46070 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,8 @@ members = [ 'runtime/calamari', 'runtime/dolphin', 'runtime/common', - 'primitives', + 'primitives/manta', + 'primitives/session-keys', ] resolver = "2" diff --git a/node/Cargo.toml b/node/Cargo.toml index 0bbda9559..86774abf3 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -46,7 +46,7 @@ sc-network = { git = "https://github.com/paritytech/substrate.git", branch = "po sc-rpc = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.22" } sc-rpc-api = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.22" } sc-service = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.22" } -sc-sysinfo = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } +sc-sysinfo = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" } sc-telemetry = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.22" } sc-tracing = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.22" } sc-transaction-pool = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.22" } @@ -91,9 +91,10 @@ xcm = { git = "https://github.com/paritytech/polkadot.git", branch = "release-v0 # Self dependencies calamari-runtime = { path = '../runtime/calamari' } dolphin-runtime = { path = '../runtime/dolphin' } -manta-primitives = { path = '../primitives' } +manta-primitives = { path = '../primitives/manta' } manta-runtime = { path = '../runtime/manta' } pallet-manta-pay = { path = '../pallets/manta-pay', features = ["rpc", "runtime"] } +session-key-primitives = { path = '../primitives/session-keys' } [build-dependencies] substrate-build-script-utils = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.22" } diff --git a/node/src/chain_specs/calamari.rs b/node/src/chain_specs/calamari.rs index d96cffe13..c540c4f8b 100644 --- a/node/src/chain_specs/calamari.rs +++ b/node/src/chain_specs/calamari.rs @@ -18,8 +18,10 @@ use super::*; use crate::command::CALAMARI_PARACHAIN_ID; -use calamari_runtime::{CouncilConfig, DemocracyConfig, GenesisConfig, TechnicalCommitteeConfig}; -use manta_primitives::helpers::{get_account_id_from_seed, get_collator_keys_from_seed}; +use calamari_runtime::{ + opaque::SessionKeys, CouncilConfig, DemocracyConfig, GenesisConfig, TechnicalCommitteeConfig, +}; +use session_key_primitives::helpers::{get_account_id_from_seed, get_collator_keys_from_seed}; /// Calamari Protocol Identifier pub const CALAMARI_PROTOCOL_ID: &str = "calamari"; @@ -39,8 +41,12 @@ pub type CalamariChainSpec = sc_service::GenericChainSpec calamari_runtime::opaque::SessionKeys { - calamari_runtime::opaque::SessionKeys { aura: keys } +pub fn calamari_session_keys(keys: AuraId) -> SessionKeys { + SessionKeys { + aura: keys.clone(), + nimbus: session_key_primitives::nimbus::dummy_key_from(keys.clone()), + vrf: session_key_primitives::vrf::dummy_key_from(keys), + } } /// Returns the [`Properties`] for the Calamari parachain. @@ -65,7 +71,7 @@ pub fn calamari_development_config() -> CalamariChainSpec { calamari_dev_genesis( vec![( get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed("Alice"), + SessionKeys::new(get_collator_keys_from_seed("Alice")).aura, )], vec![ get_account_id_from_seed::("Alice"), @@ -98,23 +104,23 @@ pub fn calamari_local_config() -> CalamariChainSpec { vec![ ( get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed("Alice"), + SessionKeys::new(get_collator_keys_from_seed("Alice")).aura, ), ( get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed("Bob"), + SessionKeys::new(get_collator_keys_from_seed("Bob")).aura, ), ( get_account_id_from_seed::("Charlie"), - get_collator_keys_from_seed("Charlie"), + SessionKeys::new(get_collator_keys_from_seed("Charlie")).aura, ), ( get_account_id_from_seed::("Dave"), - get_collator_keys_from_seed("Dave"), + SessionKeys::new(get_collator_keys_from_seed("Dave")).aura, ), ( get_account_id_from_seed::("Eve"), - get_collator_keys_from_seed("Eve"), + SessionKeys::new(get_collator_keys_from_seed("Eve")).aura, ), ], vec![ diff --git a/node/src/chain_specs/dolphin.rs b/node/src/chain_specs/dolphin.rs index 9ca6684ee..f5a214f26 100644 --- a/node/src/chain_specs/dolphin.rs +++ b/node/src/chain_specs/dolphin.rs @@ -18,8 +18,10 @@ use super::*; use crate::command::DOLPHIN_PARACHAIN_ID; -use dolphin_runtime::{CouncilConfig, DemocracyConfig, GenesisConfig, TechnicalCommitteeConfig}; -use manta_primitives::helpers::{get_account_id_from_seed, get_collator_keys_from_seed}; +use dolphin_runtime::{ + opaque::SessionKeys, CouncilConfig, DemocracyConfig, GenesisConfig, TechnicalCommitteeConfig, +}; +use session_key_primitives::helpers::{get_account_id_from_seed, get_collator_keys_from_seed}; /// Dolphin Protocol Identifier pub const DOLPHIN_PROTOCOL_ID: &str = "dolphin"; @@ -39,8 +41,12 @@ pub type DolphinChainSpec = sc_service::GenericChainSpec dolphin_runtime::opaque::SessionKeys { - dolphin_runtime::opaque::SessionKeys { aura: keys } +pub fn dolphin_session_keys(keys: AuraId) -> SessionKeys { + SessionKeys { + aura: keys.clone(), + nimbus: session_key_primitives::nimbus::dummy_key_from(keys.clone()), + vrf: session_key_primitives::vrf::dummy_key_from(keys), + } } /// Returns the [`Properties`] for the Dolphin parachain. @@ -62,7 +68,7 @@ pub fn dolphin_development_config() -> DolphinChainSpec { dolphin_dev_genesis( vec![( get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed("Alice"), + SessionKeys::new(get_collator_keys_from_seed("Alice")).aura, )], get_account_id_from_seed::("Alice"), vec![ @@ -96,23 +102,23 @@ pub fn dolphin_local_config() -> DolphinChainSpec { vec![ ( get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed("Alice"), + SessionKeys::new(get_collator_keys_from_seed("Alice")).aura, ), ( get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed("Bob"), + SessionKeys::new(get_collator_keys_from_seed("Bob")).aura, ), ( get_account_id_from_seed::("Charlie"), - get_collator_keys_from_seed("Charlie"), + SessionKeys::new(get_collator_keys_from_seed("Charlie")).aura, ), ( get_account_id_from_seed::("Dave"), - get_collator_keys_from_seed("Dave"), + SessionKeys::new(get_collator_keys_from_seed("Dave")).aura, ), ( get_account_id_from_seed::("Eve"), - get_collator_keys_from_seed("Eve"), + SessionKeys::new(get_collator_keys_from_seed("Eve")).aura, ), ], get_account_id_from_seed::("Alice"), diff --git a/node/src/chain_specs/manta.rs b/node/src/chain_specs/manta.rs index ddd07fc46..cf4d57ad9 100644 --- a/node/src/chain_specs/manta.rs +++ b/node/src/chain_specs/manta.rs @@ -18,8 +18,8 @@ use super::*; use crate::command::MANTA_PARACHAIN_ID; -use manta_primitives::helpers::{get_account_id_from_seed, get_collator_keys_from_seed}; - +use manta_runtime::opaque::SessionKeys; +use session_key_primitives::helpers::{get_account_id_from_seed, get_collator_keys_from_seed}; /// Manta Protocol Identifier pub const MANTA_PROTOCOL_ID: &str = "manta"; @@ -38,8 +38,8 @@ pub type MantaChainSpec = sc_service::GenericChainSpec manta_runtime::opaque::SessionKeys { - manta_runtime::opaque::SessionKeys { aura: keys } +pub fn manta_session_keys(keys: AuraId) -> SessionKeys { + SessionKeys { aura: keys } } /// Returns the [`Properties`] for the Manta parachain. @@ -61,7 +61,7 @@ pub fn manta_development_config() -> MantaChainSpec { manta_dev_genesis( vec![( get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed("Alice"), + get_collator_keys_from_seed("Alice").0, )], get_account_id_from_seed::("Alice"), vec![ @@ -95,11 +95,11 @@ pub fn manta_local_config() -> MantaChainSpec { vec![ ( get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed("Alice"), + get_collator_keys_from_seed("Alice").0, ), ( get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed("Bob"), + get_collator_keys_from_seed("Bob").0, ), ], get_account_id_from_seed::("Alice"), diff --git a/node/src/chain_specs/mod.rs b/node/src/chain_specs/mod.rs index 7aa5bcb10..147c5b21f 100644 --- a/node/src/chain_specs/mod.rs +++ b/node/src/chain_specs/mod.rs @@ -23,11 +23,12 @@ use manta_primitives::{ constants, - types::{AccountId, AuraId, Balance}, + types::{AccountId, Balance}, }; use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup}; use sc_service::{ChainType, Properties}; use serde::{Deserialize, Serialize}; +use session_key_primitives::AuraId; use sp_core::sr25519; pub mod calamari; diff --git a/node/src/command.rs b/node/src/command.rs index d3ee1c5b8..c6b8359db 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -25,16 +25,16 @@ use crate::{ use codec::Encode; use cumulus_client_service::genesis::generate_genesis_block; use cumulus_primitives_core::ParaId; -use log::info; - use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE}; -use manta_primitives::types::{AuraId, Header}; +use log::info; +use manta_primitives::types::Header; use polkadot_parachain::primitives::AccountIdConversion; use sc_cli::{ ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, NetworkParams, RuntimeVersion, SharedParams, SubstrateCli, }; use sc_service::config::{BasePath, PrometheusConfig}; +use session_key_primitives::AuraId; use sp_core::hexdisplay::HexDisplay; use sp_runtime::{generic, traits::Block as BlockT, OpaqueExtrinsic}; use std::{io::Write, net::SocketAddr}; diff --git a/pallets/asset-manager/Cargo.toml b/pallets/asset-manager/Cargo.toml index 197b8f9da..597f1b789 100644 --- a/pallets/asset-manager/Cargo.toml +++ b/pallets/asset-manager/Cargo.toml @@ -13,7 +13,7 @@ frame-benchmarking = { git = 'https://github.com/paritytech/substrate.git', bran frame-support = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22", default-features = false } frame-system = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22", default-features = false } log = { version = "0.4.0", default-features = false } -manta-primitives = { path = "../../primitives", default-features = false } +manta-primitives = { path = "../../primitives/manta", default-features = false } scale-info = { version = "2.0.0", default-features = false, features = ["derive"] } sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22", default-features = false } sp-std = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22", default-features = false } diff --git a/pallets/manta-pay/Cargo.toml b/pallets/manta-pay/Cargo.toml index e4f878051..27aa5dcf5 100644 --- a/pallets/manta-pay/Cargo.toml +++ b/pallets/manta-pay/Cargo.toml @@ -96,7 +96,7 @@ manta-accounting = { git = "https://github.com/manta-network/manta-rs.git", tag manta-crypto = { git = "https://github.com/manta-network/manta-rs.git", tag = "v0.5.1", default-features = false } manta-parameters = { git = "https://github.com/manta-network/manta-rs.git", tag = "v0.5.1", default-features = false } manta-pay = { git = "https://github.com/manta-network/manta-rs.git", tag = "v0.5.1", default-features = false, features = ["groth16", "scale"] } -manta-primitives = { path = "../../primitives", default-features = false } +manta-primitives = { path = "../../primitives/manta", default-features = false } manta-util = { git = "https://github.com/manta-network/manta-rs.git", tag = "v0.5.1", default-features = false } [dev-dependencies] diff --git a/pallets/tx-pause/Cargo.toml b/pallets/tx-pause/Cargo.toml index 60ff5ed6f..cbf3d88ed 100644 --- a/pallets/tx-pause/Cargo.toml +++ b/pallets/tx-pause/Cargo.toml @@ -17,7 +17,7 @@ sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "po sp-std = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22", default-features = false } [dev-dependencies] -manta-primitives = { path = '../../primitives' } +manta-primitives = { path = '../../primitives/manta' } pallet-balances = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" } sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" } sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22" } diff --git a/primitives/Cargo.toml b/primitives/manta/Cargo.toml similarity index 92% rename from primitives/Cargo.toml rename to primitives/manta/Cargo.toml index 85b758586..b95c0553e 100644 --- a/primitives/Cargo.toml +++ b/primitives/manta/Cargo.toml @@ -23,7 +23,6 @@ manta-accounting = { git = "https://github.com/manta-network/manta-rs.git", tag frame-benchmarking = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.22", default-features = false, optional = true } frame-support = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.22" } frame-system = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.22" } -sp-consensus-aura = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.22" } sp-core = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.22" } sp-io = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.22" } sp-runtime = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.22" } @@ -42,7 +41,6 @@ runtime-benchmarks = [ ] std = [ 'codec/std', - 'sp-consensus-aura/std', 'scale-info/std', 'sp-io/std', 'sp-std/std', @@ -50,7 +48,6 @@ std = [ 'log/std', 'frame-support/std', 'frame-system/std', - 'sp-consensus-aura/std', 'sp-core/std', 'sp-runtime/std', 'xcm-executor/std', diff --git a/primitives/src/assets.rs b/primitives/manta/src/assets.rs similarity index 100% rename from primitives/src/assets.rs rename to primitives/manta/src/assets.rs diff --git a/primitives/src/constants.rs b/primitives/manta/src/constants.rs similarity index 100% rename from primitives/src/constants.rs rename to primitives/manta/src/constants.rs diff --git a/primitives/src/lib.rs b/primitives/manta/src/lib.rs similarity index 95% rename from primitives/src/lib.rs rename to primitives/manta/src/lib.rs index 8430a6a7c..7ac86c79c 100644 --- a/primitives/src/lib.rs +++ b/primitives/manta/src/lib.rs @@ -23,6 +23,3 @@ pub mod assets; pub mod constants; pub mod types; pub mod xcm; - -#[cfg(feature = "std")] -pub mod helpers; diff --git a/primitives/src/types.rs b/primitives/manta/src/types.rs similarity index 95% rename from primitives/src/types.rs rename to primitives/manta/src/types.rs index 9d13d037d..dd28805f3 100644 --- a/primitives/src/types.rs +++ b/primitives/manta/src/types.rs @@ -48,9 +48,6 @@ pub type Block = sp_runtime::generic::Block /// Digest item type. pub type DigestItem = sp_runtime::generic::DigestItem; -// Aura consensus authority. -pub type AuraId = sp_consensus_aura::sr25519::AuthorityId; - // Moment pub type Moment = u64; diff --git a/primitives/src/xcm.rs b/primitives/manta/src/xcm.rs similarity index 100% rename from primitives/src/xcm.rs rename to primitives/manta/src/xcm.rs diff --git a/primitives/session-keys/Cargo.toml b/primitives/session-keys/Cargo.toml new file mode 100644 index 000000000..a27b3f1f7 --- /dev/null +++ b/primitives/session-keys/Cargo.toml @@ -0,0 +1,30 @@ +[package] +authors = ['Manta Network'] +description = "Primitives for session keys" +edition = "2021" +license = 'GPL-3.0' +name = "session-key-primitives" +version = "3.2.0" + +[dependencies] +manta-primitives = { path = "../manta", default-features = false } +nimbus-primitives = { git = "https://github.com/manta-network/nimbus.git", branch = "polkadot-v0.9.22", default-features = false } +parity-scale-codec = { version = "3.1.2", default-features = false, features = ["derive"] } +scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } +sp-application-crypto = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22", default-features = false } +sp-consensus-aura = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.22" } +sp-core = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.22" } +sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.22", default-features = false } + +[features] +default = ["std"] +std = [ + "manta-primitives/std", + "nimbus-primitives/std", + "parity-scale-codec/std", + "scale-info/std", + "sp-application-crypto/std", + "sp-runtime/std", + 'sp-core/std', + 'sp-consensus-aura/std', +] diff --git a/primitives/session-keys/src/aura.rs b/primitives/session-keys/src/aura.rs new file mode 100644 index 000000000..091ab0c4f --- /dev/null +++ b/primitives/session-keys/src/aura.rs @@ -0,0 +1,18 @@ +// Copyright 2020-2022 Manta Network. +// This file is part of Manta. +// +// Manta 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. +// +// Manta 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 Manta. If not, see . + +// Aura consensus authority. +pub type AuraId = sp_consensus_aura::sr25519::AuthorityId; diff --git a/primitives/src/helpers.rs b/primitives/session-keys/src/helpers.rs similarity index 80% rename from primitives/src/helpers.rs rename to primitives/session-keys/src/helpers.rs index 9cb5fdea9..a7cd0e818 100644 --- a/primitives/src/helpers.rs +++ b/primitives/session-keys/src/helpers.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Manta. If not, see . -use crate::types::{AccountId, AuraId, Signature}; +//! Helper methods to generate dummy keys used in testing + +use crate::{AuraId, NimbusId, VrfId}; +use manta_primitives::types::{AccountId, Signature}; use sp_core::{Pair, Public}; use sp_runtime::traits::{IdentifyAccount, Verify}; @@ -28,8 +31,12 @@ pub fn get_pair_from_seed(seed: &str) -> AuraId { - get_pair_from_seed::(seed) +pub fn get_collator_keys_from_seed(seed: &str) -> (AuraId, NimbusId, VrfId) { + ( + get_pair_from_seed::(seed), + get_pair_from_seed::(seed), + get_pair_from_seed::(seed), + ) } type AccountPublic = ::Signer; diff --git a/primitives/session-keys/src/lib.rs b/primitives/session-keys/src/lib.rs new file mode 100644 index 000000000..a0725a6fb --- /dev/null +++ b/primitives/session-keys/src/lib.rs @@ -0,0 +1,28 @@ +// Copyright 2020-2022 Manta Network. +// This file is part of Manta. +// +// Manta 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. +// +// Manta 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 Manta. If not, see . + +//! Primitives for session keys +#![cfg_attr(not(feature = "std"), no_std)] + +pub mod aura; +pub use aura::AuraId; +pub mod nimbus; +pub use nimbus::NimbusId; +pub mod vrf; +pub use vrf::VrfId; + +#[cfg(feature = "std")] +pub mod helpers; diff --git a/primitives/session-keys/src/nimbus.rs b/primitives/session-keys/src/nimbus.rs new file mode 100644 index 000000000..770e55ddf --- /dev/null +++ b/primitives/session-keys/src/nimbus.rs @@ -0,0 +1,31 @@ +// Copyright 2020-2022 Manta Network. +// This file is part of Manta. +// +// Manta 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. +// +// Manta 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 Manta. If not, see . + +//! Helpers for handling nimbus keys +#![cfg_attr(not(feature = "std"), no_std)] + +use crate::AuraId; +use sp_application_crypto::{sr25519, UncheckedFrom}; + +pub type NimbusId = nimbus_primitives::NimbusId; + +/// Reinterprets Aura public key as a NimbusId +/// NO CORRESPONDING PRIVATE KEY TO THAT KEY WILL EXIST +pub fn dummy_key_from(aura_id: AuraId) -> NimbusId { + let aura_as_sr25519: sr25519::Public = aura_id.into(); + let sr25519_as_bytes: [u8; 32] = aura_as_sr25519.into(); + sr25519::Public::unchecked_from(sr25519_as_bytes).into() +} diff --git a/primitives/session-keys/src/vrf.rs b/primitives/session-keys/src/vrf.rs new file mode 100644 index 000000000..56bb87d50 --- /dev/null +++ b/primitives/session-keys/src/vrf.rs @@ -0,0 +1,68 @@ +// Copyright 2020-2022 Manta Network. +// This file is part of Manta. +// +// Manta 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. +// +// Manta 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 Manta. If not, see . + +//! VRF Key type, which is sr25519 +use crate::AuraId; +use sp_application_crypto::{sr25519, KeyTypeId, UncheckedFrom}; +use sp_runtime::{BoundToRuntimeAppPublic, ConsensusEngineId}; + +/// Struct to implement `BoundToRuntimeAppPublic` by assigning Public = VrfId +pub struct VrfSessionKey; + +impl BoundToRuntimeAppPublic for VrfSessionKey { + type Public = VrfId; +} + +/// Reinterprets Aura public key as a VRFId. +/// NO CORRESPONDING PRIVATE KEY TO THAT KEY WILL EXIST +pub fn dummy_key_from(aura_id: AuraId) -> VrfId { + let aura_as_sr25519: sr25519::Public = aura_id.into(); + let sr25519_as_bytes: [u8; 32] = aura_as_sr25519.into(); + sr25519::Public::unchecked_from(sr25519_as_bytes).into() +} + +/// The ConsensusEngineId for VRF keys +pub const VRF_ENGINE_ID: ConsensusEngineId = *b"rand"; + +/// The KeyTypeId used for VRF keys +pub const VRF_KEY_ID: KeyTypeId = KeyTypeId(VRF_ENGINE_ID); + +// The strongly-typed crypto wrappers to be used by VRF in the keystore +mod vrf_crypto { + use sp_application_crypto::{app_crypto, sr25519}; + app_crypto!(sr25519, crate::vrf::VRF_KEY_ID); +} + +/// A vrf public key. +pub type VrfId = vrf_crypto::Public; + +/// A vrf signature. +pub type VrfSignature = vrf_crypto::Signature; + +sp_application_crypto::with_pair! { + /// A vrf key pair + pub type VrfPair = vrf_crypto::Pair; +} + +#[test] +fn creating_dummy_vrf_id_from_aura_id_is_sane() { + for x in 0u8..10u8 { + let aura_id: AuraId = sr25519::Public::unchecked_from([x; 32]).into(); + let expected_vrf_id: VrfId = sr25519::Public::unchecked_from([x; 32]).into(); + let aura_to_vrf_id: VrfId = dummy_key_from(aura_id); + assert_eq!(expected_vrf_id, aura_to_vrf_id); + } +} diff --git a/runtime/calamari/Cargo.toml b/runtime/calamari/Cargo.toml index cb64707cf..536a9ae48 100644 --- a/runtime/calamari/Cargo.toml +++ b/runtime/calamari/Cargo.toml @@ -17,6 +17,7 @@ smallvec = "1.8.0" # Substrate primitives sp-api = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.22" } +sp-application-crypto = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.22" } sp-arithmetic = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.22" } sp-block-builder = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.22" } sp-consensus-aura = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.22" } @@ -69,6 +70,9 @@ cumulus-primitives-timestamp = { git = 'https://github.com/paritytech/cumulus.gi cumulus-primitives-utility = { git = 'https://github.com/paritytech/cumulus.git', default-features = false, branch = "polkadot-v0.9.22" } parachain-info = { git = 'https://github.com/paritytech/cumulus.git', default-features = false, branch = "polkadot-v0.9.22" } +# Nimbus Dependencies +pallet-author-inherent = { git = "https://github.com/manta-network/nimbus.git", branch = "polkadot-v0.9.22", default-features = false } + # Polkadot dependencies pallet-xcm = { git = 'https://github.com/paritytech/polkadot.git', default-features = false, branch = "release-v0.9.22" } polkadot-parachain = { git = 'https://github.com/paritytech/polkadot.git', default-features = false, branch = "release-v0.9.22" } @@ -84,10 +88,11 @@ orml-xtokens = { git = "https://github.com/manta-network/open-runtime-module-lib # Self dependencies calamari-vesting = { path = '../../pallets/vesting', default-features = false } manta-collator-selection = { path = '../../pallets/collator-selection', default-features = false } -manta-primitives = { path = '../../primitives', default-features = false } +manta-primitives = { path = '../../primitives/manta', default-features = false } pallet-asset-manager = { path = '../../pallets/asset-manager', default-features = false } pallet-tx-pause = { path = '../../pallets/tx-pause', default-features = false } runtime-common = { path = '../common', default-features = false } +session-key-primitives = { path = '../../primitives/session-keys', default-features = false } [package.metadata.docs.rs] targets = ['x86_64-unknown-linux-gnu'] @@ -181,6 +186,7 @@ std = [ 'pallet-transaction-payment-rpc-runtime-api/std', 'pallet-timestamp/std', 'pallet-session/std', + 'sp-application-crypto/std', 'pallet-xcm/std', 'pallet-transaction-payment/std', 'pallet-treasury/std', @@ -199,6 +205,8 @@ std = [ "cumulus-primitives-core/std", "cumulus-primitives-timestamp/std", "cumulus-primitives-utility/std", + "pallet-author-inherent/std", + 'session-key-primitives/std', 'xcm/std', 'xcm-builder/std', 'xcm-executor/std', diff --git a/runtime/calamari/src/lib.rs b/runtime/calamari/src/lib.rs index ce95fc64d..4fa5fd8f8 100644 --- a/runtime/calamari/src/lib.rs +++ b/runtime/calamari/src/lib.rs @@ -52,9 +52,10 @@ use frame_system::{ }; use manta_primitives::{ constants::{time::*, STAKING_PALLET_ID, TREASURY_PALLET_ID}, - types::{AccountId, AuraId, Balance, BlockNumber, Hash, Header, Index, Signature}, + types::{AccountId, Balance, BlockNumber, Hash, Header, Index, Signature}, }; use runtime_common::{prod_or_fast, BlockHashCount, SlowAdjustingFeeUpdate}; +use session_key_primitives::{AuraId, NimbusId, VrfId}; use sp_runtime::{Perbill, Permill}; #[cfg(any(feature = "std", test))] @@ -67,6 +68,7 @@ pub mod currency; pub mod fee; pub mod impls; pub mod migrations; +mod nimbus_session_adapter; pub mod xcm_config; use currency::*; @@ -88,9 +90,32 @@ pub mod opaque { pub type Block = generic::Block; /// Opaque block identifier type. pub type BlockId = generic::BlockId; + + use nimbus_session_adapter::{AuthorInherentWithNoOpSession, VrfWithNoOpSession}; + impl_opaque_keys! { + pub struct OldSessionKeys { + pub aura: Aura, + } + } impl_opaque_keys! { pub struct SessionKeys { pub aura: Aura, + pub nimbus: AuthorInherentWithNoOpSession, + pub vrf: VrfWithNoOpSession, + } + } + impl SessionKeys { + pub fn new(tuple: (AuraId, NimbusId, VrfId)) -> SessionKeys { + let (aura, nimbus, vrf) = tuple; + SessionKeys { aura, nimbus, vrf } + } + } + + pub fn transform_session_keys(_v: AccountId, old: OldSessionKeys) -> SessionKeys { + SessionKeys { + aura: old.aura.clone(), + nimbus: session_key_primitives::nimbus::dummy_key_from(old.aura.clone()), + vrf: session_key_primitives::vrf::dummy_key_from(old.aura), } } } @@ -750,8 +775,48 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsReversedWithSystemFirst, - (), + UpgradeSessionKeys, >; +// When this is removed, should also remove `OldSessionKeys`. +pub struct UpgradeSessionKeys; +impl frame_support::traits::OnRuntimeUpgrade for UpgradeSessionKeys { + fn on_runtime_upgrade() -> frame_support::weights::Weight { + use opaque::transform_session_keys; + // transform_session_keys runs translate() on NextKeys and on QueuedKeys which is (at worst or faster than) 1 read 1 write + let validator_set_len: u64 = Session::queued_keys().len().try_into().unwrap(); + + Session::upgrade_keys::(transform_session_keys); + + core::cmp::max( + Perbill::from_percent(50) * BlockWeights::default().max_block as u64, + ::DbWeight::get() + .reads_writes(2 * validator_set_len, validator_set_len * 2), + ) + } + #[cfg(feature = "try_runtime")] + fn pre_runtime_upgrade() -> frame_support::weights::Weight { + // get aura keys + let owners_and_aura_keys = Session::queued_keys(); + Self::set_temp_storage(owners_and_aura_keys, "aura_keys"); + 0 + } + #[cfg(feature = "try_runtime")] + fn post_runtime_upgrade() -> frame_support::weights::Weight { + // ensure aura keys have not changed + let pre_migration_keys = Self::get_temp_storage(owners_and_aura_keys, "aura_keys"); + let new_owners_and_aura_keys = Session::queued_keys(); + + for it in pre_migration_keys + .iter() + .zip(new_owners_and_aura_keys.iter()) + { + let ((old_owner, old_key), (new_owner, new_key)) = iter; + ensure!(old_owner == new_owner, "owner changed"); + ensure!(old_key.aura == new_key.aura, "key changed"); + } + 0 + } +} #[cfg(feature = "runtime-benchmarks")] #[macro_use] diff --git a/runtime/calamari/src/nimbus_session_adapter.rs b/runtime/calamari/src/nimbus_session_adapter.rs new file mode 100644 index 000000000..3dce3ae87 --- /dev/null +++ b/runtime/calamari/src/nimbus_session_adapter.rs @@ -0,0 +1,78 @@ +// Copyright 2020-2022 Manta Network. +// This file is part of Manta. +// +// Manta 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. +// +// Manta 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 Manta. If not, see . + +use crate::AccountId; +use frame_support::traits::OneSessionHandler; +use frame_system::Config; +use pallet_author_inherent::Pallet as AuthorInherent; +use session_key_primitives::vrf::VrfSessionKey; +use sp_application_crypto::BoundToRuntimeAppPublic; + +/// This adapts pallet AuthorInherent to be compatible with pallet session +/// making it suitable as a SessionKey entry +pub struct AuthorInherentWithNoOpSession(pub AuthorInherent); + +impl BoundToRuntimeAppPublic for AuthorInherentWithNoOpSession { + type Public = as BoundToRuntimeAppPublic>::Public; +} + +impl OneSessionHandler for AuthorInherentWithNoOpSession { + type Key = as BoundToRuntimeAppPublic>::Public; + + fn on_genesis_session<'a, I: 'a>(_: I) + where + I: Iterator, + { + } + + fn on_new_session<'a, I: 'a>(_: bool, _: I, _: I) + where + I: Iterator, + { + } + + fn on_disabled(_: u32) {} + + fn on_before_session_ending() {} +} + +/// This adapts VrfSessionKey to be compatible with pallet session +/// making it suitable as a SessionKey entry +pub struct VrfWithNoOpSession(pub VrfSessionKey); + +impl BoundToRuntimeAppPublic for VrfWithNoOpSession { + type Public = ::Public; +} + +impl OneSessionHandler for VrfWithNoOpSession { + type Key = ::Public; + + fn on_genesis_session<'a, I: 'a>(_: I) + where + I: Iterator, + { + } + + fn on_new_session<'a, I: 'a>(_: bool, _: I, _: I) + where + I: Iterator, + { + } + + fn on_disabled(_: u32) {} + + fn on_before_session_ending() {} +} diff --git a/runtime/calamari/tests/common/mock.rs b/runtime/calamari/tests/common/mock.rs index c4f1ce63d..f01263c92 100644 --- a/runtime/calamari/tests/common/mock.rs +++ b/runtime/calamari/tests/common/mock.rs @@ -16,6 +16,7 @@ use crate::common::*; +use calamari_runtime::opaque::SessionKeys; pub use calamari_runtime::{ assets_config::CalamariAssetConfig, currency::KMA, Call, CollatorSelection, Democracy, Runtime, Scheduler, Session, System, TransactionPayment, @@ -23,13 +24,13 @@ pub use calamari_runtime::{ use frame_support::traits::{GenesisBuild, OnFinalize, OnInitialize}; use manta_primitives::{ assets::AssetConfig, - helpers::{get_account_id_from_seed, get_collator_keys_from_seed}, - types::{AccountId, AuraId, Balance}, + types::{AccountId, Balance}, }; +use session_key_primitives::helpers::{get_account_id_from_seed, get_collator_keys_from_seed}; use sp_core::sr25519; pub struct ExtBuilder { balances: Vec<(AccountId, Balance)>, - authorities: Vec<(AccountId, AuraId)>, + authorities: Vec<(AccountId, SessionKeys)>, invulnerables: Vec, desired_candidates: u32, safe_xcm_version: Option, @@ -45,7 +46,7 @@ impl Default for ExtBuilder { )], authorities: vec![( get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed("Alice"), + SessionKeys::new(get_collator_keys_from_seed("Alice")), )], invulnerables: vec![get_account_id_from_seed::("Alice")], safe_xcm_version: None, @@ -60,7 +61,7 @@ impl ExtBuilder { self } - pub fn with_authorities(mut self, authorities: Vec<(AccountId, AuraId)>) -> Self { + pub fn with_authorities(mut self, authorities: Vec<(AccountId, SessionKeys)>) -> Self { self.authorities = authorities; self } @@ -103,11 +104,11 @@ impl ExtBuilder { .authorities .iter() .cloned() - .map(|(acc, aura)| { + .map(|(acc, session_keys)| { ( - acc.clone(), // account id - acc, // validator id - calamari_runtime::opaque::SessionKeys { aura }, // session keys + acc.clone(), // account id + acc, // validator id + session_keys, // session keys ) }) .collect(), diff --git a/runtime/calamari/tests/integration_tests.rs b/runtime/calamari/tests/integration_tests.rs index 568421a53..59c5b648a 100644 --- a/runtime/calamari/tests/integration_tests.rs +++ b/runtime/calamari/tests/integration_tests.rs @@ -34,6 +34,7 @@ pub use calamari_runtime::{ Runtime, TechnicalCommittee, Timestamp, Treasury, Utility, VotingPeriod, }; +use calamari_runtime::opaque::SessionKeys; use frame_support::{ assert_err, assert_ok, codec::Encode, @@ -49,9 +50,9 @@ use manta_primitives::{ AssetConfig, AssetLocation, AssetRegistrarMetadata, FungibleLedger, FungibleLedgerError, }, constants::time::{DAYS, HOURS}, - helpers::{get_account_id_from_seed, get_collator_keys_from_seed}, types::{AccountId, Header}, }; +use session_key_primitives::helpers::{get_account_id_from_seed, get_collator_keys_from_seed}; use xcm::{ opaque::latest::{ Junction::{PalletInstance, Parachain}, @@ -351,7 +352,10 @@ fn balances_operations_should_work() { (charlie.clone(), INITIAL_BALANCE), (dave.clone(), INITIAL_BALANCE), ]) - .with_authorities(vec![(alice.clone(), get_collator_keys_from_seed("Alice"))]) + .with_authorities(vec![( + alice.clone(), + SessionKeys::new(get_collator_keys_from_seed("Alice")), + )]) .with_collators(vec![alice.clone()], 0) .build() .execute_with(|| { @@ -459,7 +463,10 @@ fn reward_fees_to_block_author_and_treasury() { (bob.clone(), INITIAL_BALANCE), (charlie.clone(), INITIAL_BALANCE), ]) - .with_authorities(vec![(alice.clone(), get_collator_keys_from_seed("Alice"))]) + .with_authorities(vec![( + alice.clone(), + SessionKeys::new(get_collator_keys_from_seed("Alice")), + )]) .with_collators(vec![alice.clone()], desired_candidates) .build() .execute_with(|| { @@ -551,8 +558,8 @@ fn advance_session_assertions(session_index: &mut u32, advance_by: u32) { fn session_and_collator_selection_work() { let alice = get_account_id_from_seed::("Alice"); let bob = get_account_id_from_seed::("Bob"); - let alice_aura = get_collator_keys_from_seed("Alice"); - let bob_aura = get_collator_keys_from_seed("Bob"); + let alice_session_keys = SessionKeys::new(get_collator_keys_from_seed("Alice")); + let bob_session_keys = SessionKeys::new(get_collator_keys_from_seed("Bob")); let desired_candidates = 1; ExtBuilder::default() @@ -567,10 +574,11 @@ fn session_and_collator_selection_work() { assert_eq!(CollatorSelection::candidates(), vec![]); // Create and bond session keys to Bob's account. - let keys = calamari_runtime::opaque::SessionKeys { - aura: bob_aura.clone(), - }; - assert_ok!(Session::set_keys(Origin::signed(bob.clone()), keys, vec![])); + assert_ok!(Session::set_keys( + Origin::signed(bob.clone()), + bob_session_keys.clone(), + vec![] + )); assert_ok!(CollatorSelection::register_candidate( root_origin(), @@ -585,12 +593,7 @@ fn session_and_collator_selection_work() { assert_eq!(CollatorSelection::candidates(), vec![candidate]); assert_eq!( Session::queued_keys(), - vec![( - alice.clone(), - calamari_runtime::opaque::SessionKeys { - aura: alice_aura.clone(), - } - )] + vec![(alice.clone(), alice_session_keys.clone())] ); assert_eq!(Session::validators(), vec![alice.clone()]); @@ -604,18 +607,8 @@ fn session_and_collator_selection_work() { assert_eq!( Session::queued_keys(), vec![ - ( - alice.clone(), - calamari_runtime::opaque::SessionKeys { - aura: alice_aura.clone(), - } - ), - ( - bob.clone(), - calamari_runtime::opaque::SessionKeys { - aura: bob_aura.clone(), - } - ) + (alice.clone(), alice_session_keys.clone()), + (bob.clone(), bob_session_keys.clone()) ] ); assert_eq!(Session::validators(), vec![alice.clone()]); @@ -650,9 +643,9 @@ fn batched_registration_of_collator_candidates_works() { let alice = get_account_id_from_seed::("Alice"); let bob = get_account_id_from_seed::("Bob"); let charlie = get_account_id_from_seed::("Charlie"); - let alice_aura = get_collator_keys_from_seed("Alice"); - let bob_aura = get_collator_keys_from_seed("Bob"); - let charlie_aura = get_collator_keys_from_seed("Charlie"); + let alice_session_keys = SessionKeys::new(get_collator_keys_from_seed("Alice")); + let bob_session_keys = SessionKeys::new(get_collator_keys_from_seed("Bob")); + let charlie_session_keys = SessionKeys::new(get_collator_keys_from_seed("Charlie")); let desired_candidates = 2; ExtBuilder::default() @@ -664,17 +657,15 @@ fn batched_registration_of_collator_candidates_works() { .with_collators(vec![alice.clone()], desired_candidates) .build() .execute_with(|| { - let keys = calamari_runtime::opaque::SessionKeys { - aura: bob_aura.clone(), - }; - assert_ok!(Session::set_keys(Origin::signed(bob.clone()), keys, vec![])); + assert_ok!(Session::set_keys( + Origin::signed(bob.clone()), + bob_session_keys.clone(), + vec![] + )); - let keys = calamari_runtime::opaque::SessionKeys { - aura: charlie_aura.clone(), - }; assert_ok!(Session::set_keys( Origin::signed(charlie.clone()), - keys, + charlie_session_keys.clone(), vec![] )); @@ -706,12 +697,7 @@ fn batched_registration_of_collator_candidates_works() { ); assert_eq!( Session::queued_keys(), - vec![( - alice.clone(), - calamari_runtime::opaque::SessionKeys { - aura: alice_aura.clone(), - } - ),] + vec![(alice.clone(), alice_session_keys.clone()),] ); assert_eq!(Session::validators(), vec![alice.clone()]); @@ -719,24 +705,9 @@ fn batched_registration_of_collator_candidates_works() { run_to_block(session_index * Period::get()); let all_collator_pairs = vec![ - ( - alice.clone(), - calamari_runtime::opaque::SessionKeys { - aura: alice_aura.clone(), - }, - ), - ( - bob.clone(), - calamari_runtime::opaque::SessionKeys { - aura: bob_aura.clone(), - }, - ), - ( - charlie.clone(), - calamari_runtime::opaque::SessionKeys { - aura: charlie_aura.clone(), - }, - ), + (alice.clone(), alice_session_keys.clone()), + (bob.clone(), bob_session_keys.clone()), + (charlie.clone(), charlie_session_keys.clone()), ]; assert_eq!(Session::queued_keys(), all_collator_pairs); diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 8ff929178..04f55862f 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -14,7 +14,7 @@ pallet-transaction-payment = { git = 'https://github.com/paritytech/substrate.gi sp-runtime = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.22", default-features = false } # Self dependencies -manta-primitives = { path = '../../primitives', default-features = false } +manta-primitives = { path = '../../primitives/manta', default-features = false } [dev-dependencies] syn = { version = "=1.0.96" } # Workaround until polkadot-v0.9.24 for https://github.com/paritytech/substrate/issues/11706 diff --git a/runtime/dolphin/Cargo.toml b/runtime/dolphin/Cargo.toml index c8617663b..a465eb51d 100644 --- a/runtime/dolphin/Cargo.toml +++ b/runtime/dolphin/Cargo.toml @@ -17,6 +17,7 @@ smallvec = "1.8.0" # Substrate primitives sp-api = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.22" } +sp-application-crypto = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.22" } sp-arithmetic = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.22" } sp-block-builder = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.22" } sp-consensus-aura = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.22" } @@ -70,6 +71,9 @@ cumulus-primitives-timestamp = { git = 'https://github.com/paritytech/cumulus.gi cumulus-primitives-utility = { git = 'https://github.com/paritytech/cumulus.git', default-features = false, branch = "polkadot-v0.9.22" } parachain-info = { git = 'https://github.com/paritytech/cumulus.git', default-features = false, branch = "polkadot-v0.9.22" } +# Nimbus Dependencies +pallet-author-inherent = { git = "https://github.com/manta-network/nimbus.git", branch = "polkadot-v0.9.22", default-features = false } + # Polkadot dependencies pallet-xcm = { git = 'https://github.com/paritytech/polkadot.git', default-features = false, branch = "release-v0.9.22" } polkadot-core-primitives = { git = 'https://github.com/paritytech/polkadot.git', default-features = false, branch = "release-v0.9.22" } @@ -81,11 +85,12 @@ xcm-executor = { git = 'https://github.com/paritytech/polkadot.git', default-fea # Self dependencies manta-collator-selection = { path = '../../pallets/collator-selection', default-features = false } -manta-primitives = { path = '../../primitives', default-features = false } +manta-primitives = { path = '../../primitives/manta', default-features = false } pallet-asset-manager = { path = '../../pallets/asset-manager', default-features = false } pallet-manta-pay = { path = '../../pallets/manta-pay', default-features = false, features = ["runtime"] } pallet-tx-pause = { path = '../../pallets/tx-pause', default-features = false } runtime-common = { path = '../common', default-features = false } +session-key-primitives = { path = '../../primitives/session-keys', default-features = false } # Third party (vendored) dependencies orml-traits = { git = "https://github.com/manta-network/open-runtime-module-library.git", default-features = false, rev = "cc26ffa" } @@ -197,7 +202,10 @@ std = [ "cumulus-primitives-core/std", "cumulus-primitives-timestamp/std", "cumulus-primitives-utility/std", + "pallet-author-inherent/std", + 'session-key-primitives/std', 'xcm/std', + 'sp-application-crypto/std', 'xcm-builder/std', 'xcm-executor/std', 'polkadot-primitives/std', diff --git a/runtime/dolphin/src/lib.rs b/runtime/dolphin/src/lib.rs index ffb6d0c54..09bf97a56 100644 --- a/runtime/dolphin/src/lib.rs +++ b/runtime/dolphin/src/lib.rs @@ -53,9 +53,10 @@ use frame_system::{ }; use manta_primitives::{ constants::{time::*, STAKING_PALLET_ID, TREASURY_PALLET_ID}, - types::{AccountId, AuraId, Balance, BlockNumber, Hash, Header, Index, Signature}, + types::{AccountId, Balance, BlockNumber, Hash, Header, Index, Signature}, }; use runtime_common::{prod_or_fast, BlockHashCount, SlowAdjustingFeeUpdate}; +use session_key_primitives::{AuraId, NimbusId, VrfId}; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; @@ -65,6 +66,7 @@ pub mod assets_config; pub mod currency; pub mod fee; pub mod impls; +mod nimbus_session_adapter; pub mod xcm_config; use currency::*; @@ -86,9 +88,32 @@ pub mod opaque { pub type Block = generic::Block; /// Opaque block identifier type. pub type BlockId = generic::BlockId; + + use nimbus_session_adapter::{AuthorInherentWithNoOpSession, VrfWithNoOpSession}; + impl_opaque_keys! { + pub struct OldSessionKeys { + pub aura: Aura, + } + } impl_opaque_keys! { pub struct SessionKeys { pub aura: Aura, + pub nimbus: AuthorInherentWithNoOpSession, + pub vrf: VrfWithNoOpSession, + } + } + impl SessionKeys { + pub fn new(tuple: (AuraId, NimbusId, VrfId)) -> SessionKeys { + let (aura, nimbus, vrf) = tuple; + SessionKeys { aura, nimbus, vrf } + } + } + + pub fn transform_session_keys(_v: AccountId, old: OldSessionKeys) -> SessionKeys { + SessionKeys { + aura: old.aura.clone(), + nimbus: session_key_primitives::nimbus::dummy_key_from(old.aura.clone()), + vrf: session_key_primitives::vrf::dummy_key_from(old.aura), } } } @@ -737,7 +762,48 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsReversedWithSystemFirst, + UpgradeSessionKeys, >; +// When this is removed, should also remove `OldSessionKeys`. +pub struct UpgradeSessionKeys; +impl frame_support::traits::OnRuntimeUpgrade for UpgradeSessionKeys { + fn on_runtime_upgrade() -> frame_support::weights::Weight { + use opaque::transform_session_keys; + // transform_session_keys runs translate() on NextKeys and on QueuedKeys which is (at worst or faster than) 1 read 1 write + let validator_set_len: u64 = Session::queued_keys().len().try_into().unwrap(); + + Session::upgrade_keys::(transform_session_keys); + + core::cmp::max( + Perbill::from_percent(50) * BlockWeights::default().max_block as u64, + ::DbWeight::get() + .reads_writes(2 * validator_set_len, validator_set_len * 2), + ) + } + #[cfg(feature = "try_runtime")] + fn pre_runtime_upgrade() -> frame_support::weights::Weight { + // get aura keys + let owners_and_aura_keys = Session::queued_keys(); + Self::set_temp_storage(owners_and_aura_keys, "aura_keys"); + 0 + } + #[cfg(feature = "try_runtime")] + fn post_runtime_upgrade() -> frame_support::weights::Weight { + // ensure aura keys have not changed + let pre_migration_keys = Self::get_temp_storage(owners_and_aura_keys, "aura_keys"); + let new_owners_and_aura_keys = Session::queued_keys(); + + for it in pre_migration_keys + .iter() + .zip(new_owners_and_aura_keys.iter()) + { + let ((old_owner, old_key), (new_owner, new_key)) = iter; + ensure!(old_owner == new_owner, "owner changed"); + ensure!(old_key.aura == new_key.aura, "key changed"); + } + 0 + } +} #[cfg(feature = "runtime-benchmarks")] #[macro_use] diff --git a/runtime/dolphin/src/nimbus_session_adapter.rs b/runtime/dolphin/src/nimbus_session_adapter.rs new file mode 100644 index 000000000..65237e86d --- /dev/null +++ b/runtime/dolphin/src/nimbus_session_adapter.rs @@ -0,0 +1,81 @@ +// Copyright 2020-2022 Manta Network. +// This file is part of Manta. +// +// Manta 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. +// +// Manta 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 Manta. If not, see . + +//! This file contains wrappers for Nimbus to make them compatible with pallet session traits, +//! but has No-Op implementations on everything so as to not change behavior of the running chain just yet + +use crate::AccountId; +use frame_support::traits::OneSessionHandler; +use frame_system::Config; +use pallet_author_inherent::Pallet as AuthorInherent; +use session_key_primitives::vrf::VrfSessionKey; +use sp_application_crypto::BoundToRuntimeAppPublic; + +/// This adapts pallet AuthorInherent to be compatible with pallet session +/// making it suitable as a SessionKey entry +pub struct AuthorInherentWithNoOpSession(pub AuthorInherent); + +impl BoundToRuntimeAppPublic for AuthorInherentWithNoOpSession { + type Public = as BoundToRuntimeAppPublic>::Public; +} + +impl OneSessionHandler for AuthorInherentWithNoOpSession { + type Key = as BoundToRuntimeAppPublic>::Public; + + fn on_genesis_session<'a, I: 'a>(_: I) + where + I: Iterator, + { + } + + fn on_new_session<'a, I: 'a>(_: bool, _: I, _: I) + where + I: Iterator, + { + } + + fn on_disabled(_: u32) {} + + fn on_before_session_ending() {} +} + +/// This adapts VrfSessionKey to be compatible with pallet session +/// making it suitable as a SessionKey entry +pub struct VrfWithNoOpSession(pub VrfSessionKey); + +impl BoundToRuntimeAppPublic for VrfWithNoOpSession { + type Public = ::Public; +} + +impl OneSessionHandler for VrfWithNoOpSession { + type Key = ::Public; + + fn on_genesis_session<'a, I: 'a>(_: I) + where + I: Iterator, + { + } + + fn on_new_session<'a, I: 'a>(_: bool, _: I, _: I) + where + I: Iterator, + { + } + + fn on_disabled(_: u32) {} + + fn on_before_session_ending() {} +} diff --git a/runtime/manta/Cargo.toml b/runtime/manta/Cargo.toml index 4d58d1936..fb5c6e4c4 100644 --- a/runtime/manta/Cargo.toml +++ b/runtime/manta/Cargo.toml @@ -74,9 +74,10 @@ xcm-builder = { git = 'https://github.com/paritytech/polkadot.git', default-feat xcm-executor = { git = 'https://github.com/paritytech/polkadot.git', default-features = false, branch = "release-v0.9.22" } # Self dependencies -manta-primitives = { path = '../../primitives', default-features = false } +manta-primitives = { path = '../../primitives/manta', default-features = false } pallet-tx-pause = { path = '../../pallets/tx-pause', default-features = false } runtime-common = { path = '../common', default-features = false } +session-key-primitives = { path = '../../primitives/session-keys', default-features = false } [package.metadata.docs.rs] targets = ['x86_64-unknown-linux-gnu'] @@ -160,5 +161,6 @@ std = [ 'xcm-executor/std', 'polkadot-primitives/std', 'pallet-collator-selection/std', + 'session-key-primitives/std', 'pallet-tx-pause/std', ] diff --git a/runtime/manta/src/lib.rs b/runtime/manta/src/lib.rs index 27d1ab9e0..2a713aa36 100644 --- a/runtime/manta/src/lib.rs +++ b/runtime/manta/src/lib.rs @@ -53,9 +53,10 @@ use frame_system::{ }; use manta_primitives::{ constants::{time::*, STAKING_PALLET_ID}, - types::{AccountId, AuraId, Balance, BlockNumber, Hash, Header, Index, Signature}, + types::{AccountId, Balance, BlockNumber, Hash, Header, Index, Signature}, }; use runtime_common::{prod_or_fast, BlockHashCount, SlowAdjustingFeeUpdate}; +use session_key_primitives::AuraId; use sp_runtime::Perbill; #[cfg(any(feature = "std", test))] @@ -102,6 +103,13 @@ pub mod opaque { pub aura: Aura, } } + impl SessionKeys { + /// Generates a [`SessionKey`], discarding key types that are not currently used. + #[inline] + pub fn new((aura, _, _): (AuraId, T, U)) -> Self { + Self { aura } + } + } } // Weights used in the runtime.