From 8cb71bd982963407a7014992d4720253a4b31f71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Tue, 14 Jan 2020 20:11:42 +0100 Subject: [PATCH] Add `pallet-society` and `pallet-recovery` to substrate node (#4622) * Add `pallet-society` and `pallet-recovery` to substrate node * Add `OnReapAccount` * Fixes and replaces nicks with identity --- Cargo.lock | 4 +- bin/node/runtime/Cargo.toml | 8 +++- bin/node/runtime/src/lib.rs | 73 +++++++++++++++++++++++++++++++------ 3 files changed, 70 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 086df23fd2a57..e5648c89d9354 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3174,13 +3174,15 @@ dependencies = [ "pallet-elections-phragmen 2.0.0", "pallet-finality-tracker 2.0.0", "pallet-grandpa 2.0.0", + "pallet-identity 2.0.0", "pallet-im-online 2.0.0", "pallet-indices 2.0.0", "pallet-membership 2.0.0", - "pallet-nicks 2.0.0", "pallet-offences 2.0.0", "pallet-randomness-collective-flip 2.0.0", + "pallet-recovery 2.0.0", "pallet-session 2.0.0", + "pallet-society 2.0.0", "pallet-staking 2.0.0", "pallet-staking-reward-curve 2.0.0", "pallet-sudo 2.0.0", diff --git a/bin/node/runtime/Cargo.toml b/bin/node/runtime/Cargo.toml index a8f26d13cba40..c434c72120271 100644 --- a/bin/node/runtime/Cargo.toml +++ b/bin/node/runtime/Cargo.toml @@ -48,14 +48,16 @@ pallet-finality-tracker = { version = "2.0.0", default-features = false, path = pallet-grandpa = { version = "2.0.0", default-features = false, path = "../../../frame/grandpa" } pallet-im-online = { version = "2.0.0", default-features = false, path = "../../../frame/im-online" } pallet-indices = { version = "2.0.0", default-features = false, path = "../../../frame/indices" } +pallet-identity = { version = "2.0.0", default-features = false, path = "../../../frame/identity" } pallet-membership = { version = "2.0.0", default-features = false, path = "../../../frame/membership" } -pallet-nicks = { version = "2.0.0", default-features = false, path = "../../../frame/nicks" } pallet-offences = { version = "2.0.0", default-features = false, path = "../../../frame/offences" } pallet-randomness-collective-flip = { version = "2.0.0", default-features = false, path = "../../../frame/randomness-collective-flip" } +pallet-recovery = { version = "2.0.0", default-features = false, path = "../../../frame/recovery" } pallet-session = { version = "2.0.0", features = ["historical"], path = "../../../frame/session", default-features = false } pallet-staking = { version = "2.0.0", features = ["migrate"], path = "../../../frame/staking", default-features = false } pallet-staking-reward-curve = { version = "2.0.0", path = "../../../frame/staking/reward-curve" } pallet-sudo = { version = "2.0.0", default-features = false, path = "../../../frame/sudo" } +pallet-society = { version = "2.0.0", default-features = false, path = "../../../frame/society" } pallet-timestamp = { version = "2.0.0", default-features = false, path = "../../../frame/timestamp" } pallet-treasury = { version = "2.0.0", default-features = false, path = "../../../frame/treasury" } pallet-utility = { version = "2.0.0", default-features = false, path = "../../../frame/utility" } @@ -91,7 +93,7 @@ std = [ "pallet-indices/std", "sp-inherents/std", "pallet-membership/std", - "pallet-nicks/std", + "pallet-identity/std", "node-primitives/std", "sp-offchain/std", "pallet-offences/std", @@ -119,4 +121,6 @@ std = [ "sp-transaction-pool/std", "pallet-utility/std", "sp-version/std", + "pallet-society/std", + "pallet-recovery/std", ] diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 4266ad7459e65..e5e453fcaff04 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -80,8 +80,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to equal spec_version. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 203, - impl_version: 203, + spec_version: 204, + impl_version: 204, apis: RUNTIME_API_VERSIONS, }; @@ -174,7 +174,7 @@ parameter_types! { impl pallet_balances::Trait for Runtime { type Balance = Balance; type OnFreeBalanceZero = ((Staking, Contracts), Session); - type OnReapAccount = System; + type OnReapAccount = (System, Recovery); type OnNewAccount = Indices; type Event = Event; type DustRemoval = (); @@ -488,19 +488,22 @@ impl pallet_finality_tracker::Trait for Runtime { } parameter_types! { - pub const ReservationFee: Balance = 1 * DOLLARS; - pub const MinLength: usize = 3; - pub const MaxLength: usize = 16; + pub const BasicDeposit: Balance = 10 * DOLLARS; // 258 bytes on-chain + pub const FieldDeposit: Balance = 250 * CENTS; // 66 bytes on-chain + pub const SubAccountDeposit: Balance = 2 * DOLLARS; // 53 bytes on-chain + pub const MaximumSubAccounts: u32 = 100; } -impl pallet_nicks::Trait for Runtime { +impl pallet_identity::Trait for Runtime { type Event = Event; type Currency = Balances; - type ReservationFee = ReservationFee; type Slashed = Treasury; - type ForceOrigin = pallet_collective::EnsureMember; - type MinLength = MinLength; - type MaxLength = MaxLength; + type BasicDeposit = BasicDeposit; + type FieldDeposit = FieldDeposit; + type SubAccountDeposit = SubAccountDeposit; + type MaximumSubAccounts = MaximumSubAccounts; + type RegistrarOrigin = pallet_collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>; + type ForceOrigin = pallet_collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>; } impl frame_system::offchain::CreateTransaction for Runtime { @@ -543,6 +546,50 @@ impl frame_system::offchain::CreateTransaction for } } +parameter_types! { + pub const ConfigDepositBase: Balance = 5 * DOLLARS; + pub const FriendDepositFactor: Balance = 50 * CENTS; + pub const MaxFriends: u16 = 9; + pub const RecoveryDeposit: Balance = 5 * DOLLARS; +} + +impl pallet_recovery::Trait for Runtime { + type Event = Event; + type Call = Call; + type Currency = Balances; + type ConfigDepositBase = ConfigDepositBase; + type FriendDepositFactor = FriendDepositFactor; + type MaxFriends = MaxFriends; + type RecoveryDeposit = RecoveryDeposit; +} + +parameter_types! { + pub const CandidateDeposit: Balance = 10 * DOLLARS; + pub const WrongSideDeduction: Balance = 2 * DOLLARS; + pub const MaxStrikes: u32 = 10; + pub const RotationPeriod: BlockNumber = 80 * HOURS; + pub const PeriodSpend: Balance = 500 * DOLLARS; + pub const MaxLockDuration: BlockNumber = 36 * 30 * DAYS; + pub const ChallengePeriod: BlockNumber = 7 * DAYS; + pub const MaxMembers: u32 = 999; +} + +impl pallet_society::Trait for Runtime { + type Event = Event; + type Currency = Balances; + type Randomness = RandomnessCollectiveFlip; + type CandidateDeposit = CandidateDeposit; + type WrongSideDeduction = WrongSideDeduction; + type MaxStrikes = MaxStrikes; + type PeriodSpend = PeriodSpend; + type MembershipChanged = (); + type RotationPeriod = RotationPeriod; + type MaxLockDuration = MaxLockDuration; + type FounderSetOrigin = pallet_collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>; + type SuspensionJudgementOrigin = pallet_society::EnsureFounder; + type ChallengePeriod = ChallengePeriod; +} + construct_runtime!( pub enum Runtime where Block = Block, @@ -573,7 +620,9 @@ construct_runtime!( AuthorityDiscovery: pallet_authority_discovery::{Module, Call, Config}, Offences: pallet_offences::{Module, Call, Storage, Event}, RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage}, - Nicks: pallet_nicks::{Module, Call, Storage, Event}, + Identity: pallet_identity::{Module, Call, Storage, Event}, + Society: pallet_society::{Module, Call, Storage, Event}, + Recovery: pallet_recovery::{Module, Call, Storage, Event}, } );