From a7b30b1b5d7aabfab4f51f1279b359e9465d8e90 Mon Sep 17 00:00:00 2001 From: librelois <c@elo.tf> Date: Sun, 25 Jul 2021 19:01:47 +0200 Subject: [PATCH] feat: impl real parameters for g1 and g1-test --- runtime/g1/src/lib.rs | 57 +++-------------------------- runtime/g1/src/parameters.rs | 64 +++++++++++++++++++++++++++++++++ runtime/gdev/src/lib.rs | 39 ++------------------ runtime/gdev/src/parameters.rs | 59 ++++++++++++++++++++++++++++++ runtime/gtest/src/lib.rs | 53 ++------------------------- runtime/gtest/src/parameters.rs | 64 +++++++++++++++++++++++++++++++++ 6 files changed, 198 insertions(+), 138 deletions(-) create mode 100644 runtime/g1/src/parameters.rs create mode 100644 runtime/gdev/src/parameters.rs create mode 100644 runtime/gtest/src/parameters.rs diff --git a/runtime/g1/src/lib.rs b/runtime/g1/src/lib.rs index 5801ba073..f250effcb 100644 --- a/runtime/g1/src/lib.rs +++ b/runtime/g1/src/lib.rs @@ -22,6 +22,9 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); +mod parameters; + +pub use self::parameters::*; pub use common_runtime::{ constants::*, entities::{IdtyData, IdtyDid, IdtyRight, Planet}, @@ -78,15 +81,6 @@ pub use frame_support::{ pub mod opaque { use super::*; - pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic; - - /// Opaque block header type. - pub type Header = generic::Header<BlockNumber, BlakeTwo256>; - /// Opaque block type. - pub type Block = generic::Block<Header, UncheckedExtrinsic>; - /// Opaque block identifier type. - pub type BlockId = generic::BlockId<Block>; - impl_opaque_keys! { pub struct SessionKeys { pub aura: Aura, @@ -99,8 +93,8 @@ pub mod opaque { // https://substrate.dev/docs/en/knowledgebase/runtime/upgrades#runtime-versioning #[sp_version::runtime_version] pub const VERSION: RuntimeVersion = RuntimeVersion { - spec_name: create_runtime_str!("lc-core"), - impl_name: create_runtime_str!("lc-core"), + spec_name: create_runtime_str!("g1"), + impl_name: create_runtime_str!("g1"), authoring_version: 1, // The version of the runtime specification. A full node will not attempt to use its native // runtime in substitute for the on-chain Wasm runtime unless all of `spec_name`, @@ -211,10 +205,6 @@ impl pallet_grandpa::Config for Runtime { type WeightInfo = (); } -parameter_types! { - pub const MinimumPeriod: u64 = SLOT_DURATION / 2; -} - impl pallet_timestamp::Config for Runtime { /// A timestamp: milliseconds since the unix epoch. type Moment = u64; @@ -223,18 +213,12 @@ impl pallet_timestamp::Config for Runtime { type WeightInfo = (); } -parameter_types! { - pub const ExistentialDeposit: Balance = 500; - pub const MaxLocks: u32 = 50; -} - impl pallet_balances::Config for Runtime { type MaxLocks = MaxLocks; type MaxReserves = (); type ReserveIdentifier = [u8; 8]; /// The type for recording an account's balance. type Balance = Balance; - /// The ubiquitous event type. type Event = Event; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; @@ -242,10 +226,6 @@ impl pallet_balances::Config for Runtime { type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>; } -parameter_types! { - pub const TransactionByteFee: Balance = 0; -} - impl pallet_transaction_payment::Config for Runtime { type OnChargeTransaction = CurrencyAdapter<Balances, ()>; type TransactionByteFee = TransactionByteFee; @@ -260,16 +240,6 @@ impl pallet_sudo::Config for Runtime { // PALLET IDENTITY -const IDTY_CREATE_PERIOD: BlockNumber = 100; - -parameter_types! { - pub const ConfirmPeriod: BlockNumber = 12 * HOURS; - pub const MaxInactivityPeriod: BlockNumber = YEARS; - pub const MaxNoRightPeriod: BlockNumber = YEARS; - pub const IdtyRenewablePeriod: BlockNumber = 6 * MONTHS; - pub const ValidationPeriod: BlockNumber = 2 * MONTHS; -} - /// Configure the pallet identity impl pallet_identity::Config for Runtime { type ConfirmPeriod = ConfirmPeriod; @@ -292,16 +262,6 @@ impl pallet_identity::Config for Runtime { // PALLET CERTIFICATION -const MIN_STRONG_CERT_FOR_UD: u32 = 2; -const MIN_STRONG_CERT_FOR_STRONG_CERT: u32 = 3; - -parameter_types! { - pub const CertPeriod: BlockNumber = 15; - pub const MaxByIssuer: u8 = 100; - pub const StrongCertRenewablePeriod: BlockNumber = 50;//6 * MONTHS; - pub const ValidityPeriod: BlockNumber = 200;//2 * YEARS; -} - /// Configure the pallet certification impl pallet_certification::Config for Runtime { type AddCertOrigin = AddStrongCertOrigin<Runtime>; @@ -319,13 +279,6 @@ impl pallet_certification::Config for Runtime { // PALLET UNIVERSAL DIVIDEND -parameter_types! { - pub const SquareMoneyGrowthRate: Permill = Permill::one(); - pub const UdCreationPeriod: BlockNumber = 20; - pub const UdReevalPeriod: Balance = 10; - pub const UdReevalPeriodInBlocks: BlockNumber = 20 * 10; -} - pub struct UdAccountsProvider; impl Get<u64> for UdAccountsProvider { fn get() -> u64 { diff --git a/runtime/g1/src/parameters.rs b/runtime/g1/src/parameters.rs new file mode 100644 index 000000000..3738ac605 --- /dev/null +++ b/runtime/g1/src/parameters.rs @@ -0,0 +1,64 @@ +// 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/>. + +use common_runtime::constants::*; +use common_runtime::{Balance, BlockNumber}; +use frame_support::parameter_types; +use sp_arithmetic::Permill; + +// Timestamp +parameter_types! { + pub const MinimumPeriod: u64 = SLOT_DURATION / 2; +} + +// Balances +frame_support::parameter_types! { + pub const ExistentialDeposit: Balance = 500; + pub const MaxLocks: u32 = 50; +} + +// Transaction payment +frame_support::parameter_types! { + pub const TransactionByteFee: Balance = 0; +} + +// Identity +pub const IDTY_CREATE_PERIOD: BlockNumber = 100; +frame_support::parameter_types! { + pub const ConfirmPeriod: BlockNumber = 3 * DAYS; + pub const MaxInactivityPeriod: BlockNumber = YEARS; + pub const MaxNoRightPeriod: BlockNumber = YEARS; + pub const IdtyRenewablePeriod: BlockNumber = 6 * MONTHS; + pub const ValidationPeriod: BlockNumber = YEARS; +} + +// Certification +pub const MIN_STRONG_CERT_FOR_UD: u32 = 5; +pub const MIN_STRONG_CERT_FOR_STRONG_CERT: u32 = 5; +parameter_types! { + pub const CertPeriod: BlockNumber = 5 * DAYS; + pub const MaxByIssuer: u8 = 100; + pub const StrongCertRenewablePeriod: BlockNumber = 6 * MONTHS; + pub const ValidityPeriod: BlockNumber = 2 * YEARS; +} + +// Universal dividend +parameter_types! { + pub const SquareMoneyGrowthRate: Permill = Permill::from_parts(2_381_440); // 0.002_381_440 = 0.0488^2 + pub const UdCreationPeriod: BlockNumber = DAYS; + pub const UdReevalPeriod: Balance = 182; + pub const UdReevalPeriodInBlocks: BlockNumber = 2_620_800; // 86400 * 182 / 6 +} diff --git a/runtime/gdev/src/lib.rs b/runtime/gdev/src/lib.rs index 3c2c98e23..48cc6c06e 100644 --- a/runtime/gdev/src/lib.rs +++ b/runtime/gdev/src/lib.rs @@ -22,6 +22,9 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); +mod parameters; + +pub use self::parameters::*; pub use common_runtime::{ constants::*, entities::{IdtyData, IdtyDid, IdtyRight, Planet}, @@ -196,11 +199,6 @@ impl pallet_grandpa::Config for Runtime { type WeightInfo = (); } -parameter_types! { - pub const ExistentialDeposit: Balance = 500; - pub const MaxLocks: u32 = 50; -} - impl pallet_balances::Config for Runtime { type MaxLocks = MaxLocks; type MaxReserves = (); @@ -215,10 +213,6 @@ impl pallet_balances::Config for Runtime { type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>; } -parameter_types! { - pub const TransactionByteFee: Balance = 0; -} - impl pallet_transaction_payment::Config for Runtime { type OnChargeTransaction = CurrencyAdapter<Balances, ()>; type TransactionByteFee = TransactionByteFee; @@ -233,16 +227,6 @@ impl pallet_sudo::Config for Runtime { // PALLET IDENTITY -const IDTY_CREATE_PERIOD: BlockNumber = 100; - -parameter_types! { - pub const ConfirmPeriod: BlockNumber = 12 * HOURS; - pub const MaxInactivityPeriod: BlockNumber = YEARS; - pub const MaxNoRightPeriod: BlockNumber = YEARS; - pub const IdtyRenewablePeriod: BlockNumber = 6 * MONTHS; - pub const ValidationPeriod: BlockNumber = 2 * MONTHS; -} - /// Configure the pallet identity impl pallet_identity::Config for Runtime { type ConfirmPeriod = ConfirmPeriod; @@ -265,16 +249,6 @@ impl pallet_identity::Config for Runtime { // PALLET CERTIFICATION -const MIN_STRONG_CERT_FOR_UD: u32 = 2; -const MIN_STRONG_CERT_FOR_STRONG_CERT: u32 = 3; - -parameter_types! { - pub const CertPeriod: BlockNumber = 15; - pub const MaxByIssuer: u8 = 100; - pub const StrongCertRenewablePeriod: BlockNumber = 50;//6 * MONTHS; - pub const ValidityPeriod: BlockNumber = 200;//2 * YEARS; -} - /// Configure the pallet certification impl pallet_certification::Config for Runtime { type AddCertOrigin = AddStrongCertOrigin<Runtime>; @@ -292,13 +266,6 @@ impl pallet_certification::Config for Runtime { // PALLET UNIVERSAL DIVIDEND -parameter_types! { - pub const SquareMoneyGrowthRate: Permill = Permill::one(); - pub const UdCreationPeriod: BlockNumber = 20; - pub const UdReevalPeriod: Balance = 10; - pub const UdReevalPeriodInBlocks: BlockNumber = 20 * 10; -} - pub struct UdAccountsProvider; impl Get<u64> for UdAccountsProvider { fn get() -> u64 { diff --git a/runtime/gdev/src/parameters.rs b/runtime/gdev/src/parameters.rs new file mode 100644 index 000000000..d1c1e5afb --- /dev/null +++ b/runtime/gdev/src/parameters.rs @@ -0,0 +1,59 @@ +// 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/>. + +use common_runtime::constants::*; +use common_runtime::{Balance, BlockNumber}; +use frame_support::parameter_types; +use sp_arithmetic::Permill; + +// Balances +frame_support::parameter_types! { + pub const ExistentialDeposit: Balance = 500; + pub const MaxLocks: u32 = 50; +} + +// Transaction payment +frame_support::parameter_types! { + pub const TransactionByteFee: Balance = 0; +} + +// Identity +pub const IDTY_CREATE_PERIOD: BlockNumber = 100; +frame_support::parameter_types! { + pub const ConfirmPeriod: BlockNumber = 12 * HOURS; + pub const MaxInactivityPeriod: BlockNumber = YEARS; + pub const MaxNoRightPeriod: BlockNumber = YEARS; + pub const IdtyRenewablePeriod: BlockNumber = 6 * MONTHS; + pub const ValidationPeriod: BlockNumber = 2 * MONTHS; +} + +// Certification +pub const MIN_STRONG_CERT_FOR_UD: u32 = 2; +pub const MIN_STRONG_CERT_FOR_STRONG_CERT: u32 = 3; +parameter_types! { + pub const CertPeriod: BlockNumber = 15; + pub const MaxByIssuer: u8 = 100; + pub const StrongCertRenewablePeriod: BlockNumber = 50;//6 * MONTHS; + pub const ValidityPeriod: BlockNumber = 200;//2 * YEARS; +} + +// Universal dividend +parameter_types! { + pub const SquareMoneyGrowthRate: Permill = Permill::one(); + pub const UdCreationPeriod: BlockNumber = 20; + pub const UdReevalPeriod: Balance = 10; + pub const UdReevalPeriodInBlocks: BlockNumber = 20 * 10; +} diff --git a/runtime/gtest/src/lib.rs b/runtime/gtest/src/lib.rs index ee9e25bf8..c1c42611b 100644 --- a/runtime/gtest/src/lib.rs +++ b/runtime/gtest/src/lib.rs @@ -22,6 +22,9 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); +mod parameters; + +pub use self::parameters::*; pub use common_runtime::{ constants::*, entities::{IdtyData, IdtyDid, IdtyRight, Planet}, @@ -78,15 +81,6 @@ pub use frame_support::{ pub mod opaque { use super::*; - pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic; - - /// Opaque block header type. - pub type Header = generic::Header<BlockNumber, BlakeTwo256>; - /// Opaque block type. - pub type Block = generic::Block<Header, UncheckedExtrinsic>; - /// Opaque block identifier type. - pub type BlockId = generic::BlockId<Block>; - impl_opaque_keys! { pub struct SessionKeys { pub aura: Aura, @@ -211,10 +205,6 @@ impl pallet_grandpa::Config for Runtime { type WeightInfo = (); } -parameter_types! { - pub const MinimumPeriod: u64 = SLOT_DURATION / 2; -} - impl pallet_timestamp::Config for Runtime { /// A timestamp: milliseconds since the unix epoch. type Moment = u64; @@ -223,18 +213,12 @@ impl pallet_timestamp::Config for Runtime { type WeightInfo = (); } -parameter_types! { - pub const ExistentialDeposit: Balance = 500; - pub const MaxLocks: u32 = 50; -} - impl pallet_balances::Config for Runtime { type MaxLocks = MaxLocks; type MaxReserves = (); type ReserveIdentifier = [u8; 8]; /// The type for recording an account's balance. type Balance = Balance; - /// The ubiquitous event type. type Event = Event; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; @@ -242,10 +226,6 @@ impl pallet_balances::Config for Runtime { type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>; } -parameter_types! { - pub const TransactionByteFee: Balance = 0; -} - impl pallet_transaction_payment::Config for Runtime { type OnChargeTransaction = CurrencyAdapter<Balances, ()>; type TransactionByteFee = TransactionByteFee; @@ -260,16 +240,6 @@ impl pallet_sudo::Config for Runtime { // PALLET IDENTITY -const IDTY_CREATE_PERIOD: BlockNumber = 100; - -parameter_types! { - pub const ConfirmPeriod: BlockNumber = 12 * HOURS; - pub const MaxInactivityPeriod: BlockNumber = YEARS; - pub const MaxNoRightPeriod: BlockNumber = YEARS; - pub const IdtyRenewablePeriod: BlockNumber = 6 * MONTHS; - pub const ValidationPeriod: BlockNumber = 2 * MONTHS; -} - /// Configure the pallet identity impl pallet_identity::Config for Runtime { type ConfirmPeriod = ConfirmPeriod; @@ -292,16 +262,6 @@ impl pallet_identity::Config for Runtime { // PALLET CERTIFICATION -const MIN_STRONG_CERT_FOR_UD: u32 = 2; -const MIN_STRONG_CERT_FOR_STRONG_CERT: u32 = 3; - -parameter_types! { - pub const CertPeriod: BlockNumber = 15; - pub const MaxByIssuer: u8 = 100; - pub const StrongCertRenewablePeriod: BlockNumber = 50;//6 * MONTHS; - pub const ValidityPeriod: BlockNumber = 200;//2 * YEARS; -} - /// Configure the pallet certification impl pallet_certification::Config for Runtime { type AddCertOrigin = AddStrongCertOrigin<Runtime>; @@ -319,13 +279,6 @@ impl pallet_certification::Config for Runtime { // PALLET UNIVERSAL DIVIDEND -parameter_types! { - pub const SquareMoneyGrowthRate: Permill = Permill::one(); - pub const UdCreationPeriod: BlockNumber = 20; - pub const UdReevalPeriod: Balance = 10; - pub const UdReevalPeriodInBlocks: BlockNumber = 20 * 10; -} - pub struct UdAccountsProvider; impl Get<u64> for UdAccountsProvider { fn get() -> u64 { diff --git a/runtime/gtest/src/parameters.rs b/runtime/gtest/src/parameters.rs new file mode 100644 index 000000000..4b44b7081 --- /dev/null +++ b/runtime/gtest/src/parameters.rs @@ -0,0 +1,64 @@ +// 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/>. + +use common_runtime::constants::*; +use common_runtime::{Balance, BlockNumber}; +use frame_support::parameter_types; +use sp_arithmetic::Permill; + +// Timestamp +parameter_types! { + pub const MinimumPeriod: u64 = SLOT_DURATION / 2; +} + +// Balances +frame_support::parameter_types! { + pub const ExistentialDeposit: Balance = 500; + pub const MaxLocks: u32 = 50; +} + +// Transaction payment +frame_support::parameter_types! { + pub const TransactionByteFee: Balance = 0; +} + +// Identity +pub const IDTY_CREATE_PERIOD: BlockNumber = 100; +frame_support::parameter_types! { + pub const ConfirmPeriod: BlockNumber = DAYS; + pub const MaxInactivityPeriod: BlockNumber = 73 * DAYS; + pub const MaxNoRightPeriod: BlockNumber = 73 * DAYS; + pub const IdtyRenewablePeriod: BlockNumber = 12 * DAYS; + pub const ValidationPeriod: BlockNumber = 73 * DAYS; +} + +// Certification +pub const MIN_STRONG_CERT_FOR_UD: u32 = 5; +pub const MIN_STRONG_CERT_FOR_STRONG_CERT: u32 = 5; +parameter_types! { + pub const CertPeriod: BlockNumber = DAYS; + pub const MaxByIssuer: u8 = 100; + pub const StrongCertRenewablePeriod: BlockNumber = 12 * DAYS; + pub const ValidityPeriod: BlockNumber = 146 * DAYS; +} + +// Universal dividend +parameter_types! { + pub const SquareMoneyGrowthRate: Permill = Permill::from_parts(2_381_440); // 0.002_381_440 = 0.0488^2 + pub const UdCreationPeriod: BlockNumber = DAYS; + pub const UdReevalPeriod: Balance = 7; + pub const UdReevalPeriodInBlocks: BlockNumber = 100800; // 86400 *7 / 6 +} -- GitLab