From 1f38f2316541f9521113264c97bf5ceaae9f93ab Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Wed, 10 Feb 2021 17:46:56 -0800 Subject: [PATCH 1/6] init --- Cargo.lock | 3 +- pallets/stake/Cargo.toml | 2 - pallets/stake/src/lib.rs | 87 +++++++++++++++++++++------------------- 3 files changed, 46 insertions(+), 46 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fd38b68597..90f2429b36 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3986,7 +3986,7 @@ dependencies = [ ] [[package]] -name = "moonbase-alphanet" +name = "moonbeam" version = "0.1.0" dependencies = [ "ansi_term 0.12.1", @@ -9508,7 +9508,6 @@ dependencies = [ "frame-support", "frame-system", "pallet-balances", - "pallet-staking", "parity-scale-codec", "serde", "sp-core", diff --git a/pallets/stake/Cargo.toml b/pallets/stake/Cargo.toml index ed1ac7fd14..f54bf650f3 100644 --- a/pallets/stake/Cargo.toml +++ b/pallets/stake/Cargo.toml @@ -10,7 +10,6 @@ author-inherent = { path = "../author-inherent", default-features = false } frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } frame-system = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } -pallet-staking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } parity-scale-codec = { version = "2.0.0", default-features = false, features = ["derive"] } serde = { version = "1.0.101", optional = true } sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } @@ -27,7 +26,6 @@ std = [ "frame-support/std", "frame-system/std", "pallet-balances/std", - "pallet-staking/std", "parity-scale-codec/std", "serde", "sp-std/std", diff --git a/pallets/stake/src/lib.rs b/pallets/stake/src/lib.rs index 94d3d18f33..57fdfbbde9 100644 --- a/pallets/stake/src/lib.rs +++ b/pallets/stake/src/lib.rs @@ -61,8 +61,7 @@ use frame_support::{ traits::{Currency, EnsureOrigin, Get, Imbalance, ReservableCurrency}, }; use frame_system::{ensure_signed, Config as System}; -use pallet_staking::{Exposure, IndividualExposure}; -use parity_scale_codec::{Decode, Encode, HasCompact}; +use parity_scale_codec::{Decode, Encode}; use set::OrderedSet; use sp_runtime::{ traits::{AtLeast32BitUnsigned, Zero}, @@ -105,15 +104,6 @@ impl PartialEq for Bond { } } -impl Into> for Bond { - fn into(self) -> IndividualExposure { - IndividualExposure { - who: self.owner, - value: self.amount, - } - } -} - #[derive(Copy, Clone, PartialEq, Eq, Encode, Decode, RuntimeDebug)] /// The activity status of the validator pub enum ValidatorStatus { @@ -131,7 +121,18 @@ impl Default for ValidatorStatus { } } +#[derive(Default, Encode, Decode, RuntimeDebug)] +/// Snapshot of validator state at the start of the round for which they are selected +pub struct ValidatorSnapshot { + pub id: AccountId, + pub fee: Perbill, + pub bond: Balance, + pub nominators: Vec>, + pub total: Balance, +} + #[derive(Encode, Decode, RuntimeDebug)] +/// Global validator state with commission fee, bonded stake, and nominations pub struct Validator { pub id: AccountId, pub fee: Perbill, @@ -256,12 +257,14 @@ impl< } } -impl Into> for Validator { - fn into(self) -> Exposure { - Exposure { - total: self.total, - own: self.bond, - others: self.nominators.0.into_iter().map(|x| x.into()).collect(), +impl From> for ValidatorSnapshot { + fn from(other: Validator) -> ValidatorSnapshot { + ValidatorSnapshot { + id: other.id, + fee: other.fee, + bond: other.bond, + nominators: other.nominators.0, + total: other.total, } } } @@ -540,7 +543,7 @@ decl_storage! { /// Exposure at stake per round, per validator AtStake: double_map hasher(blake2_128_concat) RoundIndex, - hasher(blake2_128_concat) T::AccountId => Exposure>; + hasher(blake2_128_concat) T::AccountId => ValidatorSnapshot>; /// Snapshot of total staked in this round; used to determine round issuance Staked: map hasher(blake2_128_concat) RoundIndex => BalanceOf; @@ -1095,28 +1098,28 @@ impl Module { if amt_due <= T::Currency::minimum_balance() { continue; } - if let Some(state) = >::get(&val) { - if state.nominators.0.is_empty() { - // solo validator with no nominators - mint(amt_due, val.clone()); + // Take the snapshot of block author and nominations + let state = >::take(round_to_payout, &val); + if state.nominators.is_empty() { + // solo validator with no nominators + mint(amt_due, val.clone()); + } else { + // pay validator first; commission + due_portion + let val_pct = Perbill::from_rational_approximation(state.bond, state.total); + let commission = state.fee * amt_due; + let val_due = if commission > T::Currency::minimum_balance() { + amt_due -= commission; + (val_pct * amt_due) + commission } else { - // pay validator first; commission + due_portion - let val_pct = Perbill::from_rational_approximation(state.bond, state.total); - let commission = state.fee * amt_due; - let val_due = if commission > T::Currency::minimum_balance() { - amt_due -= commission; - (val_pct * amt_due) + commission - } else { - // commission is negligible so not applied - val_pct * amt_due - }; - mint(val_due, val.clone()); - // pay nominators due portion - for Bond { owner, amount } in state.nominators.0 { - let percent = Perbill::from_rational_approximation(amount, state.total); - let due = percent * amt_due; - mint(due, owner); - } + // commission is negligible so not applied + val_pct * amt_due + }; + mint(val_due, val.clone()); + // pay nominators due portion + for Bond { owner, amount } in state.nominators { + let percent = Perbill::from_rational_approximation(amount, state.total); + let due = percent * amt_due; + mint(due, owner); } } } @@ -1176,12 +1179,12 @@ impl Module { .take(max_validators) .map(|x| x.owner) .collect::>(); - // snapshot exposure for round + // snapshot exposure for round for weighting reward distribution for account in validators.iter() { let state = >::get(&account) - .expect("all members of CandidateQ must be viable candidates by construction; qed"); + .expect("all members of CandidateQ must be candidates"); let amount = state.total; - let exposure: Exposure> = state.into(); + let exposure: ValidatorSnapshot> = state.into(); >::insert(next, account, exposure); all_validators += 1u32; total += amount; From 809cb4f0379affea9643121fa5a31eb9e94db411 Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Thu, 11 Feb 2021 08:59:16 -0800 Subject: [PATCH 2/6] unit test --- pallets/stake/src/tests.rs | 230 +++++++++++++++++++++++++++---------- 1 file changed, 171 insertions(+), 59 deletions(-) diff --git a/pallets/stake/src/tests.rs b/pallets/stake/src/tests.rs index 173840d6fd..1778568937 100644 --- a/pallets/stake/src/tests.rs +++ b/pallets/stake/src/tests.rs @@ -21,7 +21,7 @@ use mock::*; use sp_runtime::DispatchError; #[test] -fn genesis_works() { +fn geneses() { two_validators_four_nominators().execute_with(|| { assert!(Sys::events().is_empty()); // validators @@ -69,7 +69,7 @@ fn genesis_works() { } #[test] -fn online_offline_behaves() { +fn online_offline_works() { two_validators_four_nominators().execute_with(|| { roll_to(4); assert_noop!( @@ -124,7 +124,7 @@ fn online_offline_behaves() { } #[test] -fn join_validator_candidates_works() { +fn join_validator_candidates() { two_validators_four_nominators().execute_with(|| { assert_noop!( Stake::join_candidates(Origin::signed(1), Perbill::from_percent(2), 11u128,), @@ -204,7 +204,6 @@ fn validator_exit_executes_after_delay() { #[test] fn validator_selection_chooses_top_candidates() { five_validators_no_nominators().execute_with(|| { - roll_to(4); roll_to(8); // should choose top MaxValidators (5), in order let expected = vec![ @@ -273,9 +272,8 @@ fn validator_selection_chooses_top_candidates() { } #[test] -fn exit_queue_works() { +fn exit_queue() { five_validators_no_nominators().execute_with(|| { - roll_to(4); roll_to(8); // should choose top MaxValidators (5), in order let mut expected = vec![ @@ -339,7 +337,6 @@ fn exit_queue_works() { #[test] fn payout_distribution_to_solo_validators() { five_validators_no_nominators().execute_with(|| { - roll_to(4); roll_to(8); // should choose top MaxValidators (5), in order let mut expected = vec![ @@ -354,7 +351,7 @@ fn payout_distribution_to_solo_validators() { // ~ set block author as 1 for all blocks this round set_author(2, 1, 100); roll_to(16); - // pay total issuance (=10) to 1 + // pay total issuance to 1 let mut new = vec![ RawEvent::ValidatorChosen(3, 1, 100), RawEvent::ValidatorChosen(3, 2, 90), @@ -438,53 +435,8 @@ fn payout_distribution_to_solo_validators() { } #[test] -fn payout_distribution_to_nominators() { - five_validators_five_nominators().execute_with(|| { - roll_to(4); - roll_to(8); - // chooses top MaxValidators (5), in order - let mut expected = vec![ - RawEvent::ValidatorChosen(2, 1, 50), - RawEvent::ValidatorChosen(2, 2, 40), - RawEvent::ValidatorChosen(2, 4, 20), - RawEvent::ValidatorChosen(2, 3, 20), - RawEvent::ValidatorChosen(2, 5, 10), - RawEvent::NewRound(5, 2, 5, 140), - ]; - assert_eq!(events(), expected); - // ~ set block author as 1 for all blocks this round - set_author(2, 1, 100); - roll_to(16); - // distribute total issuance (=10) to validator 1 and its nominators 6, 7, 19 - // -> NOTE that no fee is taken because validators at genesis set default 2% fee - // and 2% of 10 is ~0 by the Perbill arithmetic - let mut new = vec![ - RawEvent::ValidatorChosen(3, 1, 50), - RawEvent::ValidatorChosen(3, 2, 40), - RawEvent::ValidatorChosen(3, 4, 20), - RawEvent::ValidatorChosen(3, 3, 20), - RawEvent::ValidatorChosen(3, 5, 10), - RawEvent::NewRound(10, 3, 5, 140), - RawEvent::Rewarded(1, 20), - RawEvent::Rewarded(6, 10), - RawEvent::Rewarded(7, 10), - RawEvent::Rewarded(10, 10), - RawEvent::ValidatorChosen(4, 1, 50), - RawEvent::ValidatorChosen(4, 2, 40), - RawEvent::ValidatorChosen(4, 4, 20), - RawEvent::ValidatorChosen(4, 3, 20), - RawEvent::ValidatorChosen(4, 5, 10), - RawEvent::NewRound(15, 4, 5, 140), - ]; - expected.append(&mut new); - assert_eq!(events(), expected); - }); -} - -#[test] -fn pays_validator_commission() { +fn validator_commission() { one_validator_two_nominators().execute_with(|| { - roll_to(4); roll_to(8); // chooses top MaxValidators (5), in order let mut expected = vec![ @@ -541,7 +493,6 @@ fn pays_validator_commission() { #[test] fn multiple_nominations() { five_validators_five_nominators().execute_with(|| { - roll_to(4); roll_to(8); // chooses top MaxValidators (5), in order let mut expected = vec![ @@ -694,7 +645,7 @@ fn multiple_nominations() { } #[test] -fn validators_bond_more_less() { +fn validators_bond() { five_validators_five_nominators().execute_with(|| { roll_to(4); assert_noop!( @@ -744,7 +695,7 @@ fn validators_bond_more_less() { } #[test] -fn nominators_bond_more_less() { +fn nominators_bond() { five_validators_five_nominators().execute_with(|| { roll_to(4); assert_noop!( @@ -795,9 +746,8 @@ fn nominators_bond_more_less() { } #[test] -fn switch_nomination_works() { +fn switch_nomination() { five_validators_five_nominators().execute_with(|| { - roll_to(4); roll_to(8); let mut expected = vec![ RawEvent::ValidatorChosen(2, 1, 50), @@ -880,3 +830,165 @@ fn switch_nomination_works() { assert_eq!(events(), expected); }); } + +#[test] +fn revoke_nomination_or_leave_nominators() { + assert!(true); +} + +#[test] +fn payouts_follow_nomination_changes() { + five_validators_five_nominators().execute_with(|| { + roll_to(8); + // chooses top MaxValidators (5), in order + let mut expected = vec![ + RawEvent::ValidatorChosen(2, 1, 50), + RawEvent::ValidatorChosen(2, 2, 40), + RawEvent::ValidatorChosen(2, 4, 20), + RawEvent::ValidatorChosen(2, 3, 20), + RawEvent::ValidatorChosen(2, 5, 10), + RawEvent::NewRound(5, 2, 5, 140), + ]; + assert_eq!(events(), expected); + // ~ set block author as 1 for all blocks this round + set_author(2, 1, 100); + roll_to(16); + // distribute total issuance to validator 1 and its nominators 6, 7, 19 + let mut new = vec![ + RawEvent::ValidatorChosen(3, 1, 50), + RawEvent::ValidatorChosen(3, 2, 40), + RawEvent::ValidatorChosen(3, 4, 20), + RawEvent::ValidatorChosen(3, 3, 20), + RawEvent::ValidatorChosen(3, 5, 10), + RawEvent::NewRound(10, 3, 5, 140), + RawEvent::Rewarded(1, 20), + RawEvent::Rewarded(6, 10), + RawEvent::Rewarded(7, 10), + RawEvent::Rewarded(10, 10), + RawEvent::ValidatorChosen(4, 1, 50), + RawEvent::ValidatorChosen(4, 2, 40), + RawEvent::ValidatorChosen(4, 4, 20), + RawEvent::ValidatorChosen(4, 3, 20), + RawEvent::ValidatorChosen(4, 5, 10), + RawEvent::NewRound(15, 4, 5, 140), + ]; + expected.append(&mut new); + assert_eq!(events(), expected); + // ~ set block author as 1 for all blocks this round + set_author(3, 1, 100); + set_author(4, 1, 100); + // 1. ensure nominators are paid for 2 rounds after they leave + assert_noop!( + Stake::leave_nominators(Origin::signed(66)), + Error::::NominatorDNE + ); + assert_ok!(Stake::leave_nominators(Origin::signed(6))); + roll_to(21); + // keep paying 6 (note: inflation is in terms of total issuance so that's why 1 is 21) + let mut new2 = vec![ + RawEvent::NominatorLeftValidator(6, 1, 10, 40), + RawEvent::NominatorLeft(6, 10), + RawEvent::Rewarded(1, 21), + RawEvent::Rewarded(6, 10), + RawEvent::Rewarded(7, 10), + RawEvent::Rewarded(10, 10), + RawEvent::ValidatorChosen(5, 2, 40), + RawEvent::ValidatorChosen(5, 1, 40), + RawEvent::ValidatorChosen(5, 4, 20), + RawEvent::ValidatorChosen(5, 3, 20), + RawEvent::ValidatorChosen(5, 5, 10), + RawEvent::NewRound(20, 5, 5, 130), + ]; + expected.append(&mut new2); + assert_eq!(events(), expected); + // 6 won't be paid for this round because they left already + set_author(5, 1, 100); + roll_to(26); + // keep paying 6 + let mut new3 = vec![ + RawEvent::Rewarded(1, 22), + RawEvent::Rewarded(6, 11), + RawEvent::Rewarded(7, 11), + RawEvent::Rewarded(10, 11), + RawEvent::ValidatorChosen(6, 2, 40), + RawEvent::ValidatorChosen(6, 1, 40), + RawEvent::ValidatorChosen(6, 4, 20), + RawEvent::ValidatorChosen(6, 3, 20), + RawEvent::ValidatorChosen(6, 5, 10), + RawEvent::NewRound(25, 6, 5, 130), + ]; + expected.append(&mut new3); + assert_eq!(events(), expected); + set_author(6, 1, 100); + roll_to(31); + // no more paying 6 + let mut new4 = vec![ + RawEvent::Rewarded(1, 29), + RawEvent::Rewarded(7, 14), + RawEvent::Rewarded(10, 14), + RawEvent::ValidatorChosen(7, 2, 40), + RawEvent::ValidatorChosen(7, 1, 40), + RawEvent::ValidatorChosen(7, 4, 20), + RawEvent::ValidatorChosen(7, 3, 20), + RawEvent::ValidatorChosen(7, 5, 10), + RawEvent::NewRound(30, 7, 5, 130), + ]; + expected.append(&mut new4); + assert_eq!(events(), expected); + set_author(7, 1, 100); + // 2. ensure new nominations do not dilute old ones for last 2 rounds + assert_noop!( + Stake::nominate_new(Origin::signed(6), 2, 10), + Error::::NominatorDNE + ); + assert_ok!(Stake::nominate_new(Origin::signed(8), 1, 10)); + roll_to(36); + // new nomination is not rewarded yet + let mut new5 = vec![ + RawEvent::ValidatorNominated(8, 10, 1, 50), + RawEvent::Rewarded(1, 30), + RawEvent::Rewarded(7, 15), + RawEvent::Rewarded(10, 15), + RawEvent::ValidatorChosen(8, 1, 50), + RawEvent::ValidatorChosen(8, 2, 40), + RawEvent::ValidatorChosen(8, 4, 20), + RawEvent::ValidatorChosen(8, 3, 20), + RawEvent::ValidatorChosen(8, 5, 10), + RawEvent::NewRound(35, 8, 5, 140), + ]; + expected.append(&mut new5); + assert_eq!(events(), expected); + set_author(8, 1, 100); + roll_to(41); + // new nomination is still not rewarded yet + let mut new6 = vec![ + RawEvent::Rewarded(1, 32), + RawEvent::Rewarded(7, 16), + RawEvent::Rewarded(10, 16), + RawEvent::ValidatorChosen(9, 1, 50), + RawEvent::ValidatorChosen(9, 2, 40), + RawEvent::ValidatorChosen(9, 4, 20), + RawEvent::ValidatorChosen(9, 3, 20), + RawEvent::ValidatorChosen(9, 5, 10), + RawEvent::NewRound(40, 9, 5, 140), + ]; + expected.append(&mut new6); + assert_eq!(events(), expected); + roll_to(46); + // new nomination is rewarded for first time, 2 rounds after joining (`BondDuration` = 2) + let mut new7 = vec![ + RawEvent::Rewarded(1, 27), + RawEvent::Rewarded(7, 13), + RawEvent::Rewarded(8, 13), + RawEvent::Rewarded(10, 13), + RawEvent::ValidatorChosen(10, 1, 50), + RawEvent::ValidatorChosen(10, 2, 40), + RawEvent::ValidatorChosen(10, 4, 20), + RawEvent::ValidatorChosen(10, 3, 20), + RawEvent::ValidatorChosen(10, 5, 10), + RawEvent::NewRound(45, 10, 5, 140), + ]; + expected.append(&mut new7); + assert_eq!(events(), expected); + }); +} From 604c388d5b3e50a3a6ed31e6b50ae51517c59651 Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Thu, 11 Feb 2021 09:11:41 -0800 Subject: [PATCH 3/6] test leave nomination and revoke nomination --- pallets/stake/src/tests.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/pallets/stake/src/tests.rs b/pallets/stake/src/tests.rs index 1778568937..7bab01dafb 100644 --- a/pallets/stake/src/tests.rs +++ b/pallets/stake/src/tests.rs @@ -833,7 +833,33 @@ fn switch_nomination() { #[test] fn revoke_nomination_or_leave_nominators() { - assert!(true); + five_validators_five_nominators().execute_with(|| { + roll_to(4); + assert_noop!( + Stake::revoke_nomination(Origin::signed(1), 2), + Error::::NominatorDNE + ); + assert_noop!( + Stake::revoke_nomination(Origin::signed(6), 2), + Error::::NominationDNE + ); + // must leave set of nominators if total bonds below MinNominatorStk + assert_noop!( + Stake::revoke_nomination(Origin::signed(6), 1), + Error::::NomBondBelowMin + ); + assert_noop!( + Stake::leave_nominators(Origin::signed(1)), + Error::::NominatorDNE + ); + assert_ok!(Stake::leave_nominators(Origin::signed(6))); + assert_noop!( + Stake::revoke_nomination(Origin::signed(8), 2), + Error::::NomBondBelowMin + ); + assert_ok!(Stake::nominate_new(Origin::signed(8), 1, 10)); + assert_ok!(Stake::revoke_nomination(Origin::signed(8), 2)); + }); } #[test] From 96b85be6a622ec81c35e5e85f69c2aaef25063d8 Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Thu, 11 Feb 2021 09:23:07 -0800 Subject: [PATCH 4/6] bump spec version and add compact annotations on balance fields --- pallets/stake/src/lib.rs | 22 +++++++++++++--------- runtime/src/lib.rs | 2 +- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/pallets/stake/src/lib.rs b/pallets/stake/src/lib.rs index 57fdfbbde9..2d4b83684e 100644 --- a/pallets/stake/src/lib.rs +++ b/pallets/stake/src/lib.rs @@ -72,6 +72,7 @@ use sp_std::{cmp::Ordering, prelude::*}; #[derive(Default, Clone, Encode, Decode, RuntimeDebug)] pub struct Bond { pub owner: AccountId, + #[codec(compact)] pub amount: Balance, } @@ -124,10 +125,11 @@ impl Default for ValidatorStatus { #[derive(Default, Encode, Decode, RuntimeDebug)] /// Snapshot of validator state at the start of the round for which they are selected pub struct ValidatorSnapshot { - pub id: AccountId, pub fee: Perbill, + #[codec(compact)] pub bond: Balance, pub nominators: Vec>, + #[codec(compact)] pub total: Balance, } @@ -136,8 +138,10 @@ pub struct ValidatorSnapshot { pub struct Validator { pub id: AccountId, pub fee: Perbill, + #[codec(compact)] pub bond: Balance, pub nominators: OrderedSet>, + #[codec(compact)] pub total: Balance, pub state: ValidatorStatus, } @@ -260,7 +264,6 @@ impl< impl From> for ValidatorSnapshot { fn from(other: Validator) -> ValidatorSnapshot { ValidatorSnapshot { - id: other.id, fee: other.fee, bond: other.bond, nominators: other.nominators.0, @@ -272,6 +275,7 @@ impl From> for ValidatorSnapshot { #[derive(Encode, Decode, RuntimeDebug)] pub struct Nominator { pub nominations: OrderedSet>, + #[codec(compact)] pub total: Balance, } @@ -664,7 +668,7 @@ decl_module! { fn join_candidates( origin, fee: Perbill, - bond: BalanceOf, + #[compact] bond: BalanceOf, ) -> DispatchResult { let acc = ensure_signed(origin)?; ensure!(!Self::is_candidate(&acc),Error::::CandidateExists); @@ -746,7 +750,7 @@ decl_module! { } /// Bond more for validator candidates #[weight = 0] - fn candidate_bond_more(origin, more: BalanceOf) -> DispatchResult { + fn candidate_bond_more(origin, #[compact] more: BalanceOf) -> DispatchResult { let validator = ensure_signed(origin)?; let mut state = >::get(&validator).ok_or(Error::::CandidateDNE)?; ensure!(!state.is_leaving(),Error::::CannotActivateIfLeaving); @@ -763,7 +767,7 @@ decl_module! { } /// Bond less for validator candidates #[weight = 0] - fn candidate_bond_less(origin, less: BalanceOf) -> DispatchResult { + fn candidate_bond_less(origin, #[compact] less: BalanceOf) -> DispatchResult { let validator = ensure_signed(origin)?; let mut state = >::get(&validator).ok_or(Error::::CandidateDNE)?; ensure!(!state.is_leaving(),Error::::CannotActivateIfLeaving); @@ -783,7 +787,7 @@ decl_module! { fn join_nominators( origin, validator: T::AccountId, - amount: BalanceOf, + #[compact] amount: BalanceOf, ) -> DispatchResult { let acc = ensure_signed(origin)?; ensure!(amount >= T::MinNominatorStk::get(), Error::::NomBondBelowMin); @@ -811,7 +815,7 @@ decl_module! { fn nominate_new( origin, validator: T::AccountId, - amount: BalanceOf, + #[compact] amount: BalanceOf, ) -> DispatchResult { let acc = ensure_signed(origin)?; ensure!(amount >= T::MinNomination::get(), Error::::NominationBelowMin); @@ -891,7 +895,7 @@ decl_module! { fn nominator_bond_more( origin, candidate: T::AccountId, - more: BalanceOf + #[compact] more: BalanceOf ) -> DispatchResult { let nominator = ensure_signed(origin)?; let mut nominations = >::get(&nominator).ok_or(Error::::NominatorDNE)?; @@ -916,7 +920,7 @@ decl_module! { fn nominator_bond_less( origin, candidate: T::AccountId, - less: BalanceOf + #[compact] less: BalanceOf ) -> DispatchResult { let nominator = ensure_signed(origin)?; let mut nominations = >::get(&nominator).ok_or(Error::::NominatorDNE)?; diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index dbd08ce22f..c5a1b1f094 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -115,7 +115,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("moonbeam"), impl_name: create_runtime_str!("moonbeam"), authoring_version: 3, - spec_version: 19, + spec_version: 20, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 2, From b0962965ad0df8331bba7f3e9b8627b2389cadab Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Thu, 11 Feb 2021 13:03:06 -0800 Subject: [PATCH 5/6] revert using compact because requires changes to polkadot js types --- pallets/stake/src/lib.rs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/pallets/stake/src/lib.rs b/pallets/stake/src/lib.rs index 2d4b83684e..b225e9eb27 100644 --- a/pallets/stake/src/lib.rs +++ b/pallets/stake/src/lib.rs @@ -72,7 +72,6 @@ use sp_std::{cmp::Ordering, prelude::*}; #[derive(Default, Clone, Encode, Decode, RuntimeDebug)] pub struct Bond { pub owner: AccountId, - #[codec(compact)] pub amount: Balance, } @@ -126,10 +125,8 @@ impl Default for ValidatorStatus { /// Snapshot of validator state at the start of the round for which they are selected pub struct ValidatorSnapshot { pub fee: Perbill, - #[codec(compact)] pub bond: Balance, pub nominators: Vec>, - #[codec(compact)] pub total: Balance, } @@ -138,10 +135,8 @@ pub struct ValidatorSnapshot { pub struct Validator { pub id: AccountId, pub fee: Perbill, - #[codec(compact)] pub bond: Balance, pub nominators: OrderedSet>, - #[codec(compact)] pub total: Balance, pub state: ValidatorStatus, } @@ -275,7 +270,6 @@ impl From> for ValidatorSnapshot { #[derive(Encode, Decode, RuntimeDebug)] pub struct Nominator { pub nominations: OrderedSet>, - #[codec(compact)] pub total: Balance, } @@ -668,7 +662,7 @@ decl_module! { fn join_candidates( origin, fee: Perbill, - #[compact] bond: BalanceOf, + bond: BalanceOf, ) -> DispatchResult { let acc = ensure_signed(origin)?; ensure!(!Self::is_candidate(&acc),Error::::CandidateExists); @@ -750,7 +744,7 @@ decl_module! { } /// Bond more for validator candidates #[weight = 0] - fn candidate_bond_more(origin, #[compact] more: BalanceOf) -> DispatchResult { + fn candidate_bond_more(origin, more: BalanceOf) -> DispatchResult { let validator = ensure_signed(origin)?; let mut state = >::get(&validator).ok_or(Error::::CandidateDNE)?; ensure!(!state.is_leaving(),Error::::CannotActivateIfLeaving); @@ -767,7 +761,7 @@ decl_module! { } /// Bond less for validator candidates #[weight = 0] - fn candidate_bond_less(origin, #[compact] less: BalanceOf) -> DispatchResult { + fn candidate_bond_less(origin, less: BalanceOf) -> DispatchResult { let validator = ensure_signed(origin)?; let mut state = >::get(&validator).ok_or(Error::::CandidateDNE)?; ensure!(!state.is_leaving(),Error::::CannotActivateIfLeaving); @@ -787,7 +781,7 @@ decl_module! { fn join_nominators( origin, validator: T::AccountId, - #[compact] amount: BalanceOf, + amount: BalanceOf, ) -> DispatchResult { let acc = ensure_signed(origin)?; ensure!(amount >= T::MinNominatorStk::get(), Error::::NomBondBelowMin); @@ -815,7 +809,7 @@ decl_module! { fn nominate_new( origin, validator: T::AccountId, - #[compact] amount: BalanceOf, + amount: BalanceOf, ) -> DispatchResult { let acc = ensure_signed(origin)?; ensure!(amount >= T::MinNomination::get(), Error::::NominationBelowMin); @@ -895,7 +889,7 @@ decl_module! { fn nominator_bond_more( origin, candidate: T::AccountId, - #[compact] more: BalanceOf + more: BalanceOf ) -> DispatchResult { let nominator = ensure_signed(origin)?; let mut nominations = >::get(&nominator).ok_or(Error::::NominatorDNE)?; @@ -920,7 +914,7 @@ decl_module! { fn nominator_bond_less( origin, candidate: T::AccountId, - #[compact] less: BalanceOf + less: BalanceOf ) -> DispatchResult { let nominator = ensure_signed(origin)?; let mut nominations = >::get(&nominator).ok_or(Error::::NominatorDNE)?; From e08f0f76d2d9b499ccadca896db42d5e99d31bbc Mon Sep 17 00:00:00 2001 From: Amar Singh Date: Thu, 11 Feb 2021 13:07:06 -0800 Subject: [PATCH 6/6] Update runtime/src/lib.rs --- runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index c5a1b1f094..b95961af1b 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -115,7 +115,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("moonbeam"), impl_name: create_runtime_str!("moonbeam"), authoring_version: 3, - spec_version: 20, + spec_version: 21, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 2,