diff --git a/Cargo.lock b/Cargo.lock index d5970f50481a6e295f0dbfb04ba7c962c1d0874b..b83d12e3835a81ff1ee997cd915eb582fc138bdb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -854,29 +854,6 @@ dependencies = [ "sp-std", ] -[[package]] -name = "common-runtime-except-gdev" -version = "0.8.0-dev" -dependencies = [ - "common-runtime", - "frame-support", - "frame-system", - "pallet-certification", - "pallet-identity", - "pallet-session", - "pallet-ud-accounts-storage", - "parity-scale-codec", - "scale-info", - "serde", - "smallvec", - "sp-arithmetic", - "sp-consensus-babe", - "sp-core", - "sp-runtime", - "sp-staking", - "sp-std", -] - [[package]] name = "concurrent-queue" version = "1.2.2" @@ -1884,7 +1861,6 @@ name = "g1-runtime" version = "3.0.0" dependencies = [ "common-runtime", - "common-runtime-except-gdev", "frame-benchmarking", "frame-executive", "frame-support", @@ -1946,6 +1922,8 @@ dependencies = [ "frame-system-benchmarking", "frame-system-rpc-runtime-api", "hex-literal", + "pallet-authority-discovery", + "pallet-authorship", "pallet-babe", "pallet-balances", "pallet-certification", @@ -1953,10 +1931,14 @@ dependencies = [ "pallet-duniter-wot", "pallet-grandpa", "pallet-identity", + "pallet-im-online", "pallet-membership", "pallet-multisig", + "pallet-offences", "pallet-scheduler", + "pallet-session", "pallet-sudo", + "pallet-timestamp", "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", "pallet-ud-accounts-storage", @@ -2117,7 +2099,6 @@ name = "gtest-runtime" version = "3.0.0" dependencies = [ "common-runtime", - "common-runtime-except-gdev", "frame-benchmarking", "frame-executive", "frame-support", diff --git a/Cargo.toml b/Cargo.toml index 8730f7bd23b9cd2b83e6b95f9d3e9f996da78eb1..daa258c22ddd50ac61b5ee8645b0b52b25ca425a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -108,7 +108,6 @@ members = [ 'pallets/universal-dividend', 'primitives/membership', 'runtime/common', - 'runtime/common-except-gdev', 'runtime/gdev', ] diff --git a/node/src/chain_spec/gdev.rs b/node/src/chain_spec/gdev.rs index 63ba7addf32549f1faf2001972cb56b858eaf654..be77cd5588933b69d72b4d171fbd1a6974b6773c 100644 --- a/node/src/chain_spec/gdev.rs +++ b/node/src/chain_spec/gdev.rs @@ -15,19 +15,31 @@ // along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>. use super::*; +use common_runtime::constants::*; use common_runtime::entities::IdtyName; use gdev_runtime::{ - AccountId, BalancesConfig, CertConfig, GenesisConfig, GenesisParameters, GrandpaConfig, - IdentityConfig, IdtyValue, MembershipConfig, ParametersConfig, SudoConfig, SystemConfig, - UdAccountsStorageConfig, UniversalDividendConfig, WASM_BINARY, + opaque::SessionKeys, AccountId, BabeConfig, BalancesConfig, CertConfig, GenesisConfig, + GenesisParameters, IdentityConfig, IdtyValue, ImOnlineId, MembershipConfig, ParametersConfig, + SessionConfig, SudoConfig, SystemConfig, UdAccountsStorageConfig, UniversalDividendConfig, + WASM_BINARY, }; use maplit::btreemap; use sc_service::ChainType; +use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; +use sp_consensus_babe::AuthorityId as BabeId; use sp_core::sr25519; use sp_finality_grandpa::AuthorityId as GrandpaId; use sp_membership::MembershipData; use std::collections::BTreeMap; +pub type AuthorityKeys = ( + AccountId, + BabeId, + GrandpaId, + ImOnlineId, + AuthorityDiscoveryId, +); + pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig>; const TOKEN_DECIMALS: usize = 2; @@ -36,8 +48,14 @@ const TOKEN_SYMBOL: &str = "ÄžD"; // const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; /// Generate an authority keys. -pub fn get_authority_keys_from_seed(s: &str) -> GrandpaId { - get_from_seed::<GrandpaId>(s) +pub fn get_authority_keys_from_seed(s: &str) -> AuthorityKeys { + ( + get_account_id_from_seed::<sr25519::Public>(s), + get_from_seed::<BabeId>(s), + get_from_seed::<GrandpaId>(s), + get_from_seed::<ImOnlineId>(s), + get_from_seed::<AuthorityDiscoveryId>(s), + ) } pub fn development_chain_spec() -> Result<ChainSpec, String> { @@ -86,15 +104,9 @@ pub fn development_chain_spec() -> Result<ChainSpec, String> { )) } -fn get_env_u32(env_var_name: &'static str, default_value: u32) -> u32 { - std::env::var(env_var_name) - .map_or(Ok(default_value), |s| s.parse()) - .unwrap_or_else(|_| panic!("{} must be a number", env_var_name)) -} - fn devnet_genesis( wasm_binary: &[u8], - initial_authorities: Vec<GrandpaId>, + initial_authorities: Vec<AuthorityKeys>, initial_identities: BTreeMap<IdtyName, AccountId>, root_key: AccountId, _enable_println: bool, @@ -130,11 +142,27 @@ fn devnet_genesis( wot_min_cert_for_create_idty_right: 2, }, }, + authority_discovery: Default::default(), balances: BalancesConfig { balances: Default::default(), }, - grandpa: GrandpaConfig { - authorities: initial_authorities.iter().map(|x| (x.clone(), 1)).collect(), + babe: BabeConfig { + authorities: Vec::with_capacity(0), + epoch_config: Some(BABE_GENESIS_EPOCH_CONFIG), + }, + grandpa: Default::default(), + im_online: Default::default(), + session: SessionConfig { + keys: initial_authorities + .iter() + .map(|x| { + ( + x.0.clone(), + x.0.clone(), + session_keys(x.1.clone(), x.2.clone(), x.3.clone(), x.4.clone()), + ) + }) + .collect::<Vec<_>>(), }, sudo: SudoConfig { // Assign network admin rights. @@ -179,3 +207,23 @@ fn devnet_genesis( }, } } + +fn get_env_u32(env_var_name: &'static str, default_value: u32) -> u32 { + std::env::var(env_var_name) + .map_or(Ok(default_value), |s| s.parse()) + .unwrap_or_else(|_| panic!("{} must be a number", env_var_name)) +} + +fn session_keys( + babe: BabeId, + grandpa: GrandpaId, + im_online: ImOnlineId, + authority_discovery: AuthorityDiscoveryId, +) -> SessionKeys { + SessionKeys { + babe, + grandpa, + im_online, + authority_discovery, + } +} diff --git a/node/src/chain_spec/gtest.rs b/node/src/chain_spec/gtest.rs index 40f17388058ab667527807e70ee394b196c145a6..185da92ef3fe124a9e3890294bec94c01261924d 100644 --- a/node/src/chain_spec/gtest.rs +++ b/node/src/chain_spec/gtest.rs @@ -103,7 +103,6 @@ pub fn development_chain_spec() -> Result<ChainSpec, String> { )) } - fn devnet_genesis( wasm_binary: &[u8], initial_authorities: Vec<AuthorityKeys>, diff --git a/runtime/common-except-gdev/Cargo.toml b/runtime/common-except-gdev/Cargo.toml deleted file mode 100644 index e8ab258a22bfaa0b6f1e5ae2cad66199c58b9e38..0000000000000000000000000000000000000000 --- a/runtime/common-except-gdev/Cargo.toml +++ /dev/null @@ -1,99 +0,0 @@ -[package] -name = 'common-runtime-except-gdev' -description = 'Common code shared between all runtimes except gdev' -license = 'GPL-3.0-only' -version = '0.8.0-dev' -authors = ['Axiom-Team Developers <https://axiom-team.fr>'] -edition = '2018' - -[features] -runtime-benchmarks = [ - 'frame-support/runtime-benchmarks', - 'frame-system/runtime-benchmarks', - 'pallet-certification/runtime-benchmarks', - 'pallet-identity/runtime-benchmarks', - 'pallet-ud-accounts-storage/runtime-benchmarks', - 'common-runtime/runtime-benchmarks', - 'sp-runtime/runtime-benchmarks', -] -std = [ - 'codec/std', - 'frame-support/std', - 'frame-system/std', - 'pallet-certification/std', - 'pallet-identity/std', - 'pallet-ud-accounts-storage/std', - 'common-runtime/std', - 'serde', - 'sp-arithmetic/std', - 'sp-core/std', - 'sp-runtime/std', - 'sp-std/std' -] - -[dependencies] -common-runtime = { path = '../common', default-features = false } -pallet-certification = { path = '../../pallets/certification', default-features = false } -pallet-identity = { path = '../../pallets/identity', default-features = false } -pallet-ud-accounts-storage = { path = '../../pallets/ud-accounts-storage', default-features = false } -smallvec = "1.6.1" - -# substrate -scale-info = { version = "1.0", default-features = false, features = ["derive"] } - -[dependencies.codec] -default-features = false -features = ['derive'] -package = 'parity-scale-codec' -version = '2.3.1' - -[dependencies.frame-support] -default-features = false -git = 'https://github.com/librelois/substrate.git' -branch = 'duniter-monthly-2022-01' - -[dependencies.frame-system] -default-features = false -git = 'https://github.com/librelois/substrate.git' -branch = 'duniter-monthly-2022-01' - -[dependencies.pallet-session] -default-features = false -features = ["historical"] -git = 'https://github.com/librelois/substrate.git' -branch = 'duniter-monthly-2022-01' - -[dependencies.serde] -version = "1.0.101" -optional = true -features = ["derive"] - -[dependencies.sp-arithmetic] -default-features = false -git = 'https://github.com/librelois/substrate.git' -branch = 'duniter-monthly-2022-01' - -[dependencies.sp-consensus-babe] -default-features = false -git = 'https://github.com/librelois/substrate.git' -branch = 'duniter-monthly-2022-01' - -[dependencies.sp-core] -default-features = false -git = 'https://github.com/librelois/substrate.git' -branch = 'duniter-monthly-2022-01' - -[dependencies.sp-runtime] -default-features = false -git = 'https://github.com/librelois/substrate.git' -branch = 'duniter-monthly-2022-01' - -[dependencies.sp-staking] -default-features = false -git = 'https://github.com/librelois/substrate.git' -branch = 'duniter-monthly-2022-01' - -[dependencies.sp-std] -default-features = false -git = 'https://github.com/librelois/substrate.git' -branch = 'duniter-monthly-2022-01' diff --git a/runtime/common-except-gdev/src/apis.rs b/runtime/common-except-gdev/src/apis.rs deleted file mode 100644 index c49a39b4cc188193e14c1f13379122c3dbf9ef4c..0000000000000000000000000000000000000000 --- a/runtime/common-except-gdev/src/apis.rs +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright 2021 Axiom-Team -// -// This file is part of Substrate-Libre-Currency. -// -// Substrate-Libre-Currency is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, version 3 of the License. -// -// Substrate-Libre-Currency 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 Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>. - -#[macro_export] -macro_rules! runtime_apis { - {$($custom:tt)*} => { - common_runtime::runtime_apis! { - $($custom)* - - impl sp_authority_discovery::AuthorityDiscoveryApi<Block> for Runtime { - fn authorities() -> Vec<sp_authority_discovery::AuthorityId> { - AuthorityDiscovery::authorities() - } - } - - impl sp_consensus_babe::BabeApi<Block> for Runtime { - fn configuration() -> sp_consensus_babe::BabeGenesisConfiguration { - // The choice of `c` parameter (where `1 - c` represents the - // probability of a slot being empty), is done in accordance to the - // slot duration and expected target block time, for safely - // resisting network delays of maximum two seconds. - // <https://research.web3.foundation/en/latest/polkadot/BABE/Babe/#6-practical-results> - sp_consensus_babe::BabeGenesisConfiguration { - slot_duration: Babe::slot_duration(), - epoch_length: EpochDuration::get(), - c: BABE_GENESIS_EPOCH_CONFIG.c, - genesis_authorities: Babe::authorities().to_vec(), - randomness: Babe::randomness(), - allowed_slots: BABE_GENESIS_EPOCH_CONFIG.allowed_slots, - } - } - - fn current_epoch_start() -> sp_consensus_babe::Slot { - Babe::current_epoch_start() - } - - fn current_epoch() -> sp_consensus_babe::Epoch { - Babe::current_epoch() - } - - fn next_epoch() -> sp_consensus_babe::Epoch { - Babe::next_epoch() - } - - fn generate_key_ownership_proof( - _slot: sp_consensus_babe::Slot, - authority_id: sp_consensus_babe::AuthorityId, - ) -> Option<sp_consensus_babe::OpaqueKeyOwnershipProof> { - use codec::Encode; - - Historical::prove((sp_consensus_babe::KEY_TYPE, authority_id)) - .map(|p| p.encode()) - .map(sp_consensus_babe::OpaqueKeyOwnershipProof::new) - } - - fn submit_report_equivocation_unsigned_extrinsic( - equivocation_proof: sp_consensus_babe::EquivocationProof<<Block as BlockT>::Header>, - key_owner_proof: sp_consensus_babe::OpaqueKeyOwnershipProof, - ) -> Option<()> { - let key_owner_proof = key_owner_proof.decode()?; - - Babe::submit_unsigned_equivocation_report( - equivocation_proof, - key_owner_proof, - ) - } - } - } - }; -} diff --git a/runtime/common-except-gdev/src/lib.rs b/runtime/common-except-gdev/src/lib.rs deleted file mode 100644 index 1527b2c314fea0ed210407d4126c4ca0555a7a0b..0000000000000000000000000000000000000000 --- a/runtime/common-except-gdev/src/lib.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2021 Axiom-Team -// -// This file is part of Substrate-Libre-Currency. -// -// Substrate-Libre-Currency is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, version 3 of the License. -// -// Substrate-Libre-Currency 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 Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>. - -#![cfg_attr(not(feature = "std"), no_std)] - -pub mod apis; -pub mod pallets_config; diff --git a/runtime/common-except-gdev/src/pallets_config.rs b/runtime/common-except-gdev/src/pallets_config.rs deleted file mode 100644 index 2e0696073bce7d15e6caa0acb0d2277dc7e5a50d..0000000000000000000000000000000000000000 --- a/runtime/common-except-gdev/src/pallets_config.rs +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright 2021 Axiom-Team -// -// This file is part of Substrate-Libre-Currency. -// -// Substrate-Libre-Currency is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, version 3 of the License. -// -// Substrate-Libre-Currency 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 Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>. - -#[macro_export] -macro_rules! pallets_config { - {$($custom:tt)*} => { - common_runtime::pallets_config!{ - $($custom)* - - impl pallet_authority_discovery::Config for Runtime { - type MaxAuthorities = MaxAuthorities; - } - impl pallet_authorship::Config for Runtime { - type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Babe>; - type UncleGenerations = UncleGenerations; - type FilterUncle = (); - type EventHandler = ImOnline; - } - impl pallet_babe::Config for Runtime { - type EpochDuration = EpochDuration; - type ExpectedBlockTime = ExpectedBlockTime; - - // session module is the trigger - type EpochChangeTrigger = pallet_babe::ExternalTrigger; - - type DisabledValidators = Session; - - type KeyOwnerProofSystem = Historical; - - type KeyOwnerProof = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<( - KeyTypeId, - pallet_babe::AuthorityId, - )>>::Proof; - - type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<( - KeyTypeId, - pallet_babe::AuthorityId, - )>>::IdentificationTuple; - - type HandleEquivocation = - pallet_babe::EquivocationHandler<Self::KeyOwnerIdentification, Offences, ReportLongevity>; - - type WeightInfo = (); - - type MaxAuthorities = MaxAuthorities; - } - - impl pallet_im_online::Config for Runtime { - type AuthorityId = ImOnlineId; - type Event = Event; - type ValidatorSet = Historical; - type NextSessionRotation = Babe; - type ReportUnresponsiveness = Offences; - type UnsignedPriority = ImOnlineUnsignedPriority; - type WeightInfo = (); - type MaxKeys = MaxKeys; - type MaxPeerInHeartbeats = MaxPeerInHeartbeats; - type MaxPeerDataEncodingSize = MaxPeerDataEncodingSize; - } - impl pallet_offences::Config for Runtime { - type Event = Event; - type IdentificationTuple = pallet_session::historical::IdentificationTuple<Self>; - type OnOffenceHandler = (); - } - impl pallet_session::Config for Runtime { - type Event = Event; - type ValidatorId = AccountId; - type ValidatorIdOf = sp_runtime::traits::ConvertInto; - type ShouldEndSession = Babe; - type NextSessionRotation = Babe; - type SessionManager = pallet_session::historical::NoteHistoricalRoot<Self, SessionManagerImpl>; - type SessionHandler = <opaque::SessionKeys as OpaqueKeys>::KeyTypeIdProviders; - type Keys = opaque::SessionKeys; - type WeightInfo = (); - } - impl pallet_session::historical::Config for Runtime { - type FullIdentification = ValidatorFullIdentification; - type FullIdentificationOf = FullIdentificationOfImpl; - } - impl pallet_timestamp::Config for Runtime { - type Moment = u64; - type OnTimestampSet = Babe; - type MinimumPeriod = MinimumPeriod; - type WeightInfo = (); - } - } - }; -} diff --git a/runtime/common/src/apis.rs b/runtime/common/src/apis.rs index dba0901a1233ce3c8e8af9008878dbf7f3487b15..88dd18485c8ff7c8f775c274428676488fb2a0f3 100644 --- a/runtime/common/src/apis.rs +++ b/runtime/common/src/apis.rs @@ -20,6 +20,65 @@ macro_rules! runtime_apis { impl_runtime_apis! { $($custom)* + impl sp_authority_discovery::AuthorityDiscoveryApi<Block> for Runtime { + fn authorities() -> Vec<sp_authority_discovery::AuthorityId> { + AuthorityDiscovery::authorities() + } + } + + impl sp_consensus_babe::BabeApi<Block> for Runtime { + fn configuration() -> sp_consensus_babe::BabeGenesisConfiguration { + // The choice of `c` parameter (where `1 - c` represents the + // probability of a slot being empty), is done in accordance to the + // slot duration and expected target block time, for safely + // resisting network delays of maximum two seconds. + // <https://research.web3.foundation/en/latest/polkadot/BABE/Babe/#6-practical-results> + sp_consensus_babe::BabeGenesisConfiguration { + slot_duration: Babe::slot_duration(), + epoch_length: EpochDuration::get(), + c: BABE_GENESIS_EPOCH_CONFIG.c, + genesis_authorities: Babe::authorities().to_vec(), + randomness: Babe::randomness(), + allowed_slots: BABE_GENESIS_EPOCH_CONFIG.allowed_slots, + } + } + + fn current_epoch_start() -> sp_consensus_babe::Slot { + Babe::current_epoch_start() + } + + fn current_epoch() -> sp_consensus_babe::Epoch { + Babe::current_epoch() + } + + fn next_epoch() -> sp_consensus_babe::Epoch { + Babe::next_epoch() + } + + fn generate_key_ownership_proof( + _slot: sp_consensus_babe::Slot, + authority_id: sp_consensus_babe::AuthorityId, + ) -> Option<sp_consensus_babe::OpaqueKeyOwnershipProof> { + use codec::Encode; + + Historical::prove((sp_consensus_babe::KEY_TYPE, authority_id)) + .map(|p| p.encode()) + .map(sp_consensus_babe::OpaqueKeyOwnershipProof::new) + } + + fn submit_report_equivocation_unsigned_extrinsic( + equivocation_proof: sp_consensus_babe::EquivocationProof<<Block as BlockT>::Header>, + key_owner_proof: sp_consensus_babe::OpaqueKeyOwnershipProof, + ) -> Option<()> { + let key_owner_proof = key_owner_proof.decode()?; + + Babe::submit_unsigned_equivocation_report( + equivocation_proof, + key_owner_proof, + ) + } + } + impl sp_api::Core<Block> for Runtime { fn version() -> RuntimeVersion { VERSION diff --git a/runtime/common/src/pallets_config.rs b/runtime/common/src/pallets_config.rs index 322ac1723408c6b584309cdd0329eeb447959ccd..6df203d7366e83016a027da7a37d7271c07d1c8e 100644 --- a/runtime/common/src/pallets_config.rs +++ b/runtime/common/src/pallets_config.rs @@ -109,7 +109,45 @@ macro_rules! pallets_config { type NoPreimagePostponement = (); } - // MONEY // + // BLOCK CREATION // + + impl pallet_babe::Config for Runtime { + type EpochDuration = EpochDuration; + type ExpectedBlockTime = ExpectedBlockTime; + + // session module is the trigger + type EpochChangeTrigger = pallet_babe::ExternalTrigger; + + type DisabledValidators = Session; + + type KeyOwnerProofSystem = Historical; + + type KeyOwnerProof = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<( + KeyTypeId, + pallet_babe::AuthorityId, + )>>::Proof; + + type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<( + KeyTypeId, + pallet_babe::AuthorityId, + )>>::IdentificationTuple; + + type HandleEquivocation = + pallet_babe::EquivocationHandler<Self::KeyOwnerIdentification, Offences, ReportLongevity>; + + type WeightInfo = (); + + type MaxAuthorities = MaxAuthorities; + } + + impl pallet_timestamp::Config for Runtime { + type Moment = u64; + type OnTimestampSet = Babe; + type MinimumPeriod = MinimumPeriod; + type WeightInfo = (); + } + + // MONEY MANAGEMENT // impl pallet_balances::Config for Runtime { type MaxLocks = MaxLocks; @@ -135,6 +173,49 @@ macro_rules! pallets_config { // CONSENSUS // + impl pallet_authority_discovery::Config for Runtime { + type MaxAuthorities = MaxAuthorities; + } + impl pallet_authorship::Config for Runtime { + type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Babe>; + type UncleGenerations = UncleGenerations; + type FilterUncle = (); + type EventHandler = ImOnline; + } + + impl pallet_im_online::Config for Runtime { + type AuthorityId = ImOnlineId; + type Event = Event; + type ValidatorSet = Historical; + type NextSessionRotation = Babe; + type ReportUnresponsiveness = Offences; + type UnsignedPriority = ImOnlineUnsignedPriority; + type WeightInfo = (); + type MaxKeys = MaxKeys; + type MaxPeerInHeartbeats = MaxPeerInHeartbeats; + type MaxPeerDataEncodingSize = MaxPeerDataEncodingSize; + } + impl pallet_offences::Config for Runtime { + type Event = Event; + type IdentificationTuple = pallet_session::historical::IdentificationTuple<Self>; + type OnOffenceHandler = (); + } + impl pallet_session::Config for Runtime { + type Event = Event; + type ValidatorId = AccountId; + type ValidatorIdOf = sp_runtime::traits::ConvertInto; + type ShouldEndSession = Babe; + type NextSessionRotation = Babe; + type SessionManager = pallet_session::historical::NoteHistoricalRoot<Self, SessionManagerImpl>; + type SessionHandler = <opaque::SessionKeys as OpaqueKeys>::KeyTypeIdProviders; + type Keys = opaque::SessionKeys; + type WeightInfo = (); + } + impl pallet_session::historical::Config for Runtime { + type FullIdentification = ValidatorFullIdentification; + type FullIdentificationOf = FullIdentificationOfImpl; + } + impl pallet_grandpa::Config for Runtime { type Event = Event; type Call = Call; @@ -156,7 +237,7 @@ macro_rules! pallets_config { type MaxAuthorities = MaxAuthorities; } - // UTILITY // + // UTILITIES // impl pallet_utility::Config for Runtime { type Event = Event; @@ -165,7 +246,7 @@ macro_rules! pallets_config { type WeightInfo = pallet_utility::weights::SubstrateWeight<Self>; } - // MONEYÂ CREATION // + // UNIVERSALÂ DIVIDEND // impl pallet_universal_dividend::Config for Runtime { type Currency = pallet_balances::Pallet<Runtime>; diff --git a/runtime/g1/Cargo.toml b/runtime/g1/Cargo.toml index 10bba58dc8a49d3b9366eff5c83a3423916258b6..46997fc48a690aaa064e54b978a2461ab559a855 100644 --- a/runtime/g1/Cargo.toml +++ b/runtime/g1/Cargo.toml @@ -49,7 +49,6 @@ std = [ 'pallet-transaction-payment-rpc-runtime-api/std', 'pallet-transaction-payment/std', 'common-runtime/std', - 'common-runtime-except-gdev/std', 'serde', 'sp-api/std', 'sp-arithmetic/std', @@ -69,7 +68,6 @@ std = [ [dependencies] common-runtime = { path = "../common", default-features = false } -common-runtime-except-gdev = { path = "../common-except-gdev", default-features = false } pallet-certification = { path = '../../pallets/certification', default-features = false } pallet-duniter-wot = { path = '../../pallets/duniter-wot', default-features = false } pallet-identity = { path = '../../pallets/identity', default-features = false } diff --git a/runtime/g1/src/lib.rs b/runtime/g1/src/lib.rs index a01f9216ec711fb71190cacaa9c52651dd39bca7..1011efef896853e4f930e6192c606bdbbd553126 100644 --- a/runtime/g1/src/lib.rs +++ b/runtime/g1/src/lib.rs @@ -144,7 +144,7 @@ impl frame_support::traits::Contains<Call> for BaseCallFilter { } } -common_runtime_except_gdev::pallets_config! { +common_runtime::pallets_config! { impl pallet_sudo::Config for Runtime { type Event = Event; type Call = Call; @@ -219,4 +219,4 @@ where // // Specific impls provided to the `runtime_apis!` macro. // } // ``` -common_runtime_except_gdev::runtime_apis! {} +common_runtime::runtime_apis! {} diff --git a/runtime/g1/src/parameters.rs b/runtime/g1/src/parameters.rs index a3326f3487ce692578c274245c5fac6a75cc9384..3bf2b125af0a4a51edb6adae6b535dadfdd6ae7c 100644 --- a/runtime/g1/src/parameters.rs +++ b/runtime/g1/src/parameters.rs @@ -29,7 +29,6 @@ parameter_types! { pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength ::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO); pub const SS58Prefix: u16 = 42; - pub const UncleGenerations: u32 = 0; } /*************/ @@ -41,6 +40,11 @@ parameter_types! { pub const MaxAuthorities: u32 = 100; } +// Authorship +parameter_types! { + pub const UncleGenerations: u32 = 0; +} + // Timestamp parameter_types! { pub const MinimumPeriod: u64 = SLOT_DURATION / 2; diff --git a/runtime/gdev/Cargo.toml b/runtime/gdev/Cargo.toml index f5e9dc5afe37353d2955c535f64119bff3a43e99..3fc51dc0ec56e2ad73289007bb3e02f12098e534 100644 --- a/runtime/gdev/Cargo.toml +++ b/runtime/gdev/Cargo.toml @@ -33,17 +33,21 @@ std = [ 'frame-support/std', 'frame-system-rpc-runtime-api/std', 'frame-system/std', + 'pallet-authority-discovery/std', 'pallet-babe/std', 'pallet-balances/std', 'pallet-certification/std', 'pallet-duniter-test-parameters/std', 'pallet-duniter-wot/std', + 'pallet-grandpa/std', 'pallet-identity/std', 'pallet-membership/std', - 'pallet-grandpa/std', + 'pallet-im-online/std', 'pallet-multisig/std', + 'pallet-session/std', 'pallet-sudo/std', 'pallet-universal-dividend/std', + 'pallet-timestamp/std', 'pallet-transaction-payment-rpc-runtime-api/std', 'pallet-transaction-payment/std', 'common-runtime/std', @@ -120,6 +124,16 @@ branch = 'duniter-monthly-2022-01' optional = true version = '0.3.1' +[dependencies.pallet-authority-discovery] +default-features = false +git = 'https://github.com/librelois/substrate.git' +branch = 'duniter-monthly-2022-01' + +[dependencies.pallet-authorship] +default-features = false +git = 'https://github.com/librelois/substrate.git' +branch = 'duniter-monthly-2022-01' + [dependencies.pallet-babe] default-features = false git = 'https://github.com/librelois/substrate.git' @@ -135,6 +149,16 @@ default-features = false git = 'https://github.com/librelois/substrate.git' branch = 'duniter-monthly-2022-01' +[dependencies.pallet-im-online] +default-features = false +git = 'https://github.com/librelois/substrate.git' +branch = 'duniter-monthly-2022-01' + +[dependencies.pallet-offences] +default-features = false +git = 'https://github.com/librelois/substrate.git' +branch = 'duniter-monthly-2022-01' + [dependencies.pallet-multisig] default-features = false git = 'https://github.com/librelois/substrate.git' @@ -145,11 +169,22 @@ default-features = false git = 'https://github.com/librelois/substrate.git' branch = 'duniter-monthly-2022-01' +[dependencies.pallet-session] +default-features = false +features = ["historical"] +git = 'https://github.com/librelois/substrate.git' +branch = 'duniter-monthly-2022-01' + [dependencies.pallet-sudo] default-features = false git = 'https://github.com/librelois/substrate.git' branch = 'duniter-monthly-2022-01' +[dependencies.pallet-timestamp] +default-features = false +git = 'https://github.com/librelois/substrate.git' +branch = 'duniter-monthly-2022-01' + [dependencies.pallet-transaction-payment] default-features = false git = 'https://github.com/librelois/substrate.git' diff --git a/runtime/gdev/src/lib.rs b/runtime/gdev/src/lib.rs index 29a570f0410cb8cc5dae20c0841ead64076e1686..0e7a068d444e464322751fe09220d877402075a0 100644 --- a/runtime/gdev/src/lib.rs +++ b/runtime/gdev/src/lib.rs @@ -26,24 +26,29 @@ pub mod parameters; pub use self::parameters::*; pub use common_runtime::{ - constants::*, handlers::OnMembershipEventHandler, AccountId, Address, Balance, BlockNumber, - Hash, Header, IdtyIndex, IdtyNameValidatorImpl, Index, Signature, + constants::*, entities::ValidatorFullIdentification, handlers::OnMembershipEventHandler, + AccountId, Address, Balance, BlockNumber, FullIdentificationOfImpl, Hash, Header, IdtyIndex, + IdtyNameValidatorImpl, Index, Signature, }; pub use pallet_balances::Call as BalancesCall; pub use pallet_duniter_test_parameters::Parameters as GenesisParameters; pub use pallet_identity::{IdtyStatus, IdtyValue}; +pub use pallet_im_online::sr25519::AuthorityId as ImOnlineId; +use pallet_session::historical as session_historical; +pub use pallet_timestamp::Call as TimestampCall; +use pallet_transaction_payment::CurrencyAdapter; pub use pallet_universal_dividend; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; -pub use sp_runtime::{Perbill, Permill}; +pub use sp_runtime::{KeyTypeId, Perbill, Permill}; +use common_runtime::SessionManagerImpl; use frame_system::EnsureRoot; use pallet_grandpa::fg_primitives; use pallet_grandpa::{AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList}; -use pallet_transaction_payment::CurrencyAdapter; use sp_api::impl_runtime_apis; -use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; -use sp_runtime::traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, NumberFor}; +use sp_core::OpaqueMetadata; +use sp_runtime::traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, NumberFor, OpaqueKeys}; use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, transaction_validity::{TransactionSource, TransactionValidity}, @@ -71,6 +76,9 @@ pub mod opaque { impl_opaque_keys! { pub struct SessionKeys { pub grandpa: Grandpa, + pub babe: Babe, + pub im_online: ImOnline, + pub authority_discovery: AuthorityDiscovery, } } } @@ -117,6 +125,7 @@ pub type SignedExtra = ( frame_system::CheckWeight<Runtime>, pallet_transaction_payment::ChargeTransactionPayment<Runtime>, ); + /// Executive: handles dispatch to the various modules. pub type Executive = frame_executive::Executive< Runtime, @@ -134,7 +143,7 @@ impl frame_support::traits::Contains<Call> for BaseCallFilter { Call::Membership( pallet_membership::Call::claim_membership { .. } | pallet_membership::Call::revoke_membership { .. } - ) + ) | Call::Session(_) ) } } @@ -182,22 +191,33 @@ construct_runtime!( System: frame_system::{Pallet, Call, Config, Storage, Event<T>} = 0, Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event<T>} = 1, + // Block creation + Babe: pallet_babe::{Pallet, Call, Storage, Config, ValidateUnsigned} = 2, + Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 3, + // Test parameters - Parameters: pallet_duniter_test_parameters::{Pallet, Config<T>, Storage} = 2, + Parameters: pallet_duniter_test_parameters::{Pallet, Config<T>, Storage} = 4, + // Money management Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>} = 5, TransactionPayment: pallet_transaction_payment::{Pallet, Storage} = 32, - // Consensus support. - Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event} = 10, + // Consensus support + Authorship: pallet_authorship::{Pallet, Call, Storage} = 10, + Offences: pallet_offences::{Pallet, Storage, Event} = 11, + Historical: session_historical::{Pallet} = 12, + Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>} = 13, + Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event} = 14, + ImOnline: pallet_im_online::{Pallet, Call, Storage, Event<T>, ValidateUnsigned, Config<T>} = 15, + AuthorityDiscovery: pallet_authority_discovery::{Pallet, Config} = 16, - // Governance stuff. + // Governance stuff Sudo: pallet_sudo::{Pallet, Call, Config<T>, Storage, Event<T>} = 20, - // Cunning utilities. + // Cunning utilities Utility: pallet_utility::{Pallet, Call, Event} = 30, - // Universal dividend. + // Universal dividend UdAccountsStorage: pallet_ud_accounts_storage::{Pallet, Config<T>, Storage} = 40, UniversalDividend: pallet_universal_dividend::{Pallet, Call, Config<T>, Storage, Event<T>} = 41, @@ -207,11 +227,19 @@ construct_runtime!( Membership: pallet_membership::<Instance1>::{Pallet, Call, Config<T>, Storage, Event<T>} = 52, Cert: pallet_certification::<Instance1>::{Pallet, Call, Config<T>, Storage, Event<T>} = 53, - // Multisig dispatch. + // Multisig dispatch Multisig: pallet_multisig::{Pallet, Call, Storage, Event<T>} = 60, } ); +impl<C> frame_system::offchain::SendTransactionTypes<C> for Runtime +where + Call: From<C>, +{ + type Extrinsic = UncheckedExtrinsic; + type OverarchingCall = Call; +} + // All of our runtimes share most of their Runtime API implementations. // We use a macro to implement this common part and add runtime-specific additional implementations. // This macro expands to : @@ -222,42 +250,4 @@ construct_runtime!( // // Specific impls provided to the `runtime_apis!` macro. // } // ``` -common_runtime::runtime_apis! { - impl sp_authority_discovery::AuthorityDiscoveryApi<Block> for Runtime { - fn authorities() -> Vec<sp_authority_discovery::AuthorityId> { - unimplemented!() - } - } - - impl sp_consensus_babe::BabeApi<Block> for Runtime { - fn configuration() -> sp_consensus_babe::BabeGenesisConfiguration { - unimplemented!() - } - - fn current_epoch_start() -> sp_consensus_babe::Slot { - unimplemented!() - } - - fn current_epoch() -> sp_consensus_babe::Epoch { - unimplemented!() - } - - fn next_epoch() -> sp_consensus_babe::Epoch { - unimplemented!() - } - - fn generate_key_ownership_proof( - _slot: sp_consensus_babe::Slot, - _authority_id: sp_consensus_babe::AuthorityId, - ) -> Option<sp_consensus_babe::OpaqueKeyOwnershipProof> { - unimplemented!() - } - - fn submit_report_equivocation_unsigned_extrinsic( - _equivocation_proof: sp_consensus_babe::EquivocationProof<<Block as BlockT>::Header>, - _key_owner_proof: sp_consensus_babe::OpaqueKeyOwnershipProof, - ) -> Option<()> { - unimplemented!() - } - } -} +common_runtime::runtime_apis! {} diff --git a/runtime/gdev/src/parameters.rs b/runtime/gdev/src/parameters.rs index 19638d39d84c9b8ed7bd89bd08c309b52c5434a1..83ed87e36d4664e89ad5fb2e43ad91de792225e8 100644 --- a/runtime/gdev/src/parameters.rs +++ b/runtime/gdev/src/parameters.rs @@ -19,6 +19,7 @@ use common_runtime::{Balance, BlockNumber}; use frame_support::parameter_types; use frame_support::weights::constants::WEIGHT_PER_SECOND; use sp_arithmetic::Permill; +use sp_runtime::transaction_validity::TransactionPriority; parameter_types! { pub const BlockHashCount: BlockNumber = 2400; @@ -30,17 +31,51 @@ parameter_types! { pub const SS58Prefix: u16 = 42; } +/*************/ +/* CONSENSUS */ +/*************/ + +// Authority discovery +parameter_types! { + pub const MaxAuthorities: u32 = 32; +} + +// Authorship +parameter_types! { + pub const UncleGenerations: u32 = 0; +} + +// Timestamp +parameter_types! { + pub const MinimumPeriod: u64 = SLOT_DURATION / 2; +} + +// Babe +pub const EPOCH_DURATION_IN_SLOTS: BlockNumber = HOURS; +parameter_types! { + pub const EpochDuration: u64 = EPOCH_DURATION_IN_SLOTS as u64; + pub const ExpectedBlockTime: u64 = MILLISECS_PER_BLOCK; + pub const ReportLongevity: u64 = 168 * EpochDuration::get(); +} + +// ImOnline +parameter_types! { + pub const ImOnlineUnsignedPriority: TransactionPriority = TransactionPriority::max_value(); + pub const MaxKeys: u32 = 10_000; + pub const MaxPeerInHeartbeats: u32 = 10_000; + pub const MaxPeerDataEncodingSize: u32 = 1_000; +} + +/*********/ +/* MONEY */ +/*********/ + // Balances frame_support::parameter_types! { pub const ExistentialDeposit: Balance = 500; pub const MaxLocks: u32 = 50; } -// Consensus -parameter_types! { - pub const MaxAuthorities: u32 = 10; -} - // Transaction payment frame_support::parameter_types! { pub const TransactionByteFee: Balance = 0; diff --git a/runtime/gtest/Cargo.toml b/runtime/gtest/Cargo.toml index 307d4537ef32d5f366de6ab5045e35a7c08be7fd..2d685e77a3a2b346885525f2ec46b98185dff03e 100644 --- a/runtime/gtest/Cargo.toml +++ b/runtime/gtest/Cargo.toml @@ -49,7 +49,6 @@ std = [ 'pallet-transaction-payment-rpc-runtime-api/std', 'pallet-transaction-payment/std', 'common-runtime/std', - 'common-runtime-except-gdev/std', 'serde', 'sp-api/std', 'sp-arithmetic/std', @@ -69,7 +68,6 @@ std = [ [dependencies] common-runtime = { path = "../common", default-features = false } -common-runtime-except-gdev = { path = "../common-except-gdev", default-features = false } pallet-certification = { path = '../../pallets/certification', default-features = false } pallet-duniter-wot = { path = '../../pallets/duniter-wot', default-features = false } pallet-identity = { path = '../../pallets/identity', default-features = false } diff --git a/runtime/gtest/src/lib.rs b/runtime/gtest/src/lib.rs index db641384d70cd3bbd14e0f4feefbbaf2e836ed5d..2e743168934b6aca300c21423837900c0a385e54 100644 --- a/runtime/gtest/src/lib.rs +++ b/runtime/gtest/src/lib.rs @@ -122,6 +122,7 @@ pub type SignedExtra = ( frame_system::CheckWeight<Runtime>, pallet_transaction_payment::ChargeTransactionPayment<Runtime>, ); + /// Executive: handles dispatch to the various modules. pub type Executive = frame_executive::Executive< Runtime, @@ -144,7 +145,7 @@ impl frame_support::traits::Contains<Call> for BaseCallFilter { } } -common_runtime_except_gdev::pallets_config! { +common_runtime::pallets_config! { impl pallet_sudo::Config for Runtime { type Event = Event; type Call = Call; @@ -162,9 +163,8 @@ construct_runtime!( System: frame_system::{Pallet, Call, Config, Storage, Event<T>} = 0, Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event<T>} = 1, - // Babe must be before session. + // Block creation Babe: pallet_babe::{Pallet, Call, Storage, Config, ValidateUnsigned} = 2, - Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 3, // Money management @@ -219,4 +219,4 @@ where // // Specific impls provided to the `runtime_apis!` macro. // } // ``` -common_runtime_except_gdev::runtime_apis! {} +common_runtime::runtime_apis! {} diff --git a/runtime/gtest/src/parameters.rs b/runtime/gtest/src/parameters.rs index b72844fcad881ffd4e032a6a884d57ef8ad0b7ed..2674ee5652126d4ffd431fed7f9e14904146b442 100644 --- a/runtime/gtest/src/parameters.rs +++ b/runtime/gtest/src/parameters.rs @@ -29,7 +29,6 @@ parameter_types! { pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength ::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO); pub const SS58Prefix: u16 = 42; - pub const UncleGenerations: u32 = 0; } /*************/ @@ -41,6 +40,11 @@ parameter_types! { pub const MaxAuthorities: u32 = 32; } +// Authorship +parameter_types! { + pub const UncleGenerations: u32 = 0; +} + // Timestamp parameter_types! { pub const MinimumPeriod: u64 = SLOT_DURATION / 2;