Skip to content

Commit bd3b7b6

Browse files
committed
updates after rebase
1 parent f070c5a commit bd3b7b6

File tree

6 files changed

+68
-96
lines changed

6 files changed

+68
-96
lines changed

common/primitives/src/capacity.rs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ use frame_support::traits::tokens::Balance;
44
use scale_info::TypeInfo;
55
use sp_api::Decode;
66
use sp_runtime::DispatchError;
7-
use sp_runtime::traits::{AtLeast32BitUnsigned, MaybeDisplay};
8-
use crate::node::{AccountId, Era, Hash};
97

108
/// A trait for checking that a target MSA can be staked to.
119
pub trait TargetValidator {
@@ -67,35 +65,3 @@ pub enum StakingType {
6765
/// and token for the account holder
6866
ProviderBoost,
6967
}
70-
71-
72-
pub trait StakingRewardsProvider {
73-
type Balance: Balance;
74-
/// Return the size of the reward pool for the given era, in token
75-
/// Errors:
76-
/// - EraOutOfRange when `era` is prior to the history retention limit, or greater than the current Era.
77-
fn reward_pool_size(era: Era) -> Self::Balance;
78-
79-
/// Return the total unclaimed reward in token for `accountId` for `fromEra` --> `toEra`, inclusive
80-
/// Errors:
81-
/// - NotAStakingAccount
82-
/// - EraOutOfRange when fromEra or toEra are prior to the history retention limit, or greater than the current Era.
83-
fn staking_reward_total(accountId: AccountId, fromEra: Era, toEra: Era);
84-
85-
/// Validate a payout claim for `accountId`, using `proof` and the provided `payload` StakingRewardClaim.
86-
/// Returns whether the claim passes validation. Accounts must first pass `payoutEligible` test.
87-
/// Errors:
88-
/// - NotAStakingAccount
89-
/// - MaxUnlockingChunksExceeded
90-
/// - All other conditions that would prevent a reward from being claimed return 'false'
91-
fn validate_staking_reward_claim(accountId: AccountId, proof: Hash, payload: StakingRewardClaim) -> bool;
92-
93-
/// Return whether `accountId` can claim a reward. Staking accounts may not claim a reward more than once
94-
/// per Era, may not claim rewards before a complete Era has been staked, and may not claim more rewards past
95-
/// the number of `MaxUnlockingChunks`.
96-
/// Errors:
97-
/// - NotAStakingAccount
98-
/// - MaxUnlockingChunksExceeded
99-
/// - All other conditions that would prevent a reward from being claimed return 'false'
100-
fn payout_eligible(accountId: AccountIdOf<T>) -> bool;
101-
}

pallets/capacity/src/lib.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,19 @@ pub use common_primitives::{
7070

7171
#[cfg(feature = "runtime-benchmarks")]
7272
use common_primitives::benchmarks::RegisterProviderBenchmarkHelper;
73-
use common_primitives::{
74-
capacity::StakingType,
75-
node::{RewardEra},
76-
};
73+
use common_primitives::capacity::StakingType;
7774

7875
pub use pallet::*;
7976
pub use types::*;
8077
pub use weights::*;
78+
8179
pub mod types;
8280

8381
#[cfg(feature = "runtime-benchmarks")]
8482
mod benchmarking;
8583

8684
#[cfg(test)]
8785
mod tests;
88-
mod tests;
8986

9087
pub mod weights;
9188

@@ -96,9 +93,9 @@ const STAKING_ID: LockIdentifier = *b"netstkng";
9693
#[frame_support::pallet]
9794
pub mod pallet {
9895
use super::*;
99-
use codec::EncodeLike;
96+
use codec::EncodeLike;
10097

101-
use common_primitives::capacity::{StakingType};
98+
use common_primitives::capacity::StakingType;
10299
use frame_support::{pallet_prelude::*, Twox64Concat};
103100
use frame_system::pallet_prelude::*;
104101
use sp_runtime::traits::{AtLeast32BitUnsigned, MaybeDisplay};
@@ -768,13 +765,6 @@ impl<T: Config> Pallet<T> {
768765
}
769766
}
770767

771-
/// Returns whether `account_id` may claim and and be paid token rewards.
772-
pub fn payout_eligible(account_id: T::AccountId) -> bool {
773-
let _staking_account =
774-
Self::get_staking_account_for(account_id).ok_or(Error::<T>::StakingAccountNotFound);
775-
false
776-
}
777-
778768
fn start_new_reward_era_if_needed(current_block: T::BlockNumber) -> Weight {
779769
let current_era_info: RewardEraInfo<T::RewardEra, T::BlockNumber> = Self::get_current_era(); // 1r
780770
if current_block.saturating_sub(current_era_info.started_at) >= T::EraLength::get().into() {
Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,51 @@
1-
use super::{mock::*,
2-
testing_utils::{run_to_block, system_run_to_block, setup_provider}};
3-
use crate::{CurrentEraInfo, RewardEraInfo, StakingRewardPool, RewardPoolInfo};
1+
use super::{
2+
mock::*,
3+
testing_utils::{run_to_block, system_run_to_block},
4+
};
5+
use crate::{Config, CurrentEraInfo, RewardEraInfo, RewardPoolInfo, StakingRewardPool};
6+
use sp_core::Get;
47

58
#[test]
6-
fn start_new_era_if_needed_updates_reward_pool_and_era_info() {
9+
fn start_new_era_if_needed_updates_era_info_and_limits_reward_pool_size() {
710
new_test_ext().execute_with(|| {
811
CurrentEraInfo::<Test>::set(RewardEraInfo { era_index: 1, started_at: 0 });
9-
StakingRewardPool::<Test>::insert(1, RewardPoolInfo {
10-
total_staked_token: 10_000,
11-
total_reward_pool: 1_000,
12-
unclaimed_balance: 1_000,
13-
});
12+
StakingRewardPool::<Test>::insert(
13+
1,
14+
RewardPoolInfo {
15+
total_staked_token: 10_000,
16+
total_reward_pool: 1_000,
17+
unclaimed_balance: 1_000,
18+
},
19+
);
20+
system_run_to_block(9);
21+
for i in 1..4 {
22+
let block_decade = i * 10;
23+
run_to_block(block_decade);
24+
25+
let current_era_info = CurrentEraInfo::<Test>::get();
26+
27+
let expected_era = i + 1;
28+
assert_eq!(current_era_info.era_index, expected_era);
29+
assert_eq!(current_era_info.started_at, block_decade);
30+
let past_eras_max: u32 = <Test as Config>::StakingRewardsPastErasMax::get();
31+
assert!(StakingRewardPool::<Test>::count().le(&past_eras_max));
32+
system_run_to_block(block_decade + 9);
33+
}
34+
})
35+
}
36+
37+
#[test]
38+
fn start_new_era_if_needed_updates_reward_pool() {
39+
new_test_ext().execute_with(|| {
40+
CurrentEraInfo::<Test>::set(RewardEraInfo { era_index: 1, started_at: 0 });
41+
StakingRewardPool::<Test>::insert(
42+
1,
43+
RewardPoolInfo {
44+
total_staked_token: 10_000,
45+
total_reward_pool: 1_000,
46+
unclaimed_balance: 1_000,
47+
},
48+
);
1449
system_run_to_block(8);
1550

1651
// TODO: Provider boost, after staking updates reward pool info
@@ -21,22 +56,19 @@ fn start_new_era_if_needed_updates_reward_pool_and_era_info() {
2156

2257
system_run_to_block(9);
2358
run_to_block(10);
24-
let mut current_era_info = CurrentEraInfo::<Test>::get();
25-
assert_eq!(current_era_info.era_index, 2u32);
26-
assert_eq!(current_era_info.started_at, 10u32);
27-
2859
assert_eq!(StakingRewardPool::<Test>::count(), 2);
2960
let current_reward_pool_info = StakingRewardPool::<Test>::get(2).unwrap();
30-
assert_eq!(current_reward_pool_info, RewardPoolInfo {
31-
total_staked_token: 10_000,
32-
total_reward_pool: 1_000,
33-
unclaimed_balance: 1_000,
34-
});
61+
assert_eq!(
62+
current_reward_pool_info,
63+
RewardPoolInfo {
64+
total_staked_token: 10_000,
65+
total_reward_pool: 1_000,
66+
unclaimed_balance: 1_000,
67+
}
68+
);
3569

36-
system_run_to_block(19);
37-
run_to_block(20);
38-
current_era_info = CurrentEraInfo::<Test>::get();
39-
assert_eq!(current_era_info.era_index, 3u32);
40-
assert_eq!(current_era_info.started_at, 20u32);
41-
})
70+
// TODO: after staking updates reward pool info
71+
// system_run_to_block(19);
72+
// run_to_block(20);
73+
});
4274
}

pallets/capacity/src/tests/stake_and_deposit_tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::{mock::*, testing_utils::*};
22
use crate::{BalanceOf, CapacityDetails, Error, Event, StakingAccountDetails};
33
use common_primitives::{
44
capacity::{
5-
Nontransferable,
5+
Nontransferable, StakingType,
66
StakingType::{MaximumCapacity, ProviderBoost},
77
},
88
msa::MessageSourceId,
@@ -389,7 +389,7 @@ fn increase_stake_and_issue_capacity_errors_with_overflow() {
389389
&mut staking_account,
390390
&target,
391391
&overflow_amount,
392-
&StakingType::ProviderBoost,
392+
&ProviderBoost,
393393
),
394394
ArithmeticError::Overflow
395395
);
@@ -479,8 +479,8 @@ fn assert_successful_increase_stake_with_type(
479479
fn increase_stake_and_issue_capacity_happy_path() {
480480
new_test_ext().execute_with(|| {
481481
assert_successful_increase_stake_with_type(1, MaximumCapacity, 550, 550, 55);
482-
assert_successful_increase_stake_with_type(2, StakingType::ProviderBoost, 550, 550, 3);
483-
assert_successful_increase_stake_with_type(2, StakingType::ProviderBoost, 6666, 7216, 36);
482+
assert_successful_increase_stake_with_type(2, ProviderBoost, 550, 550, 3);
483+
assert_successful_increase_stake_with_type(2, ProviderBoost, 6666, 7216, 36);
484484
});
485485
}
486486

pallets/capacity/src/types.rs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
//! Types for the Capacity Pallet
22
use super::*;
3-
use codec::{Decode, Encode, EncodeLike, MaxEncodedLen};
3+
use codec::{Decode, Encode, MaxEncodedLen};
44
use frame_support::{
55
log::warn, BoundedVec, EqNoBound, PartialEqNoBound, RuntimeDebug, RuntimeDebugNoBound,
66
};
77
use scale_info::TypeInfo;
8-
use sp_runtime::traits::{AtLeast32BitUnsigned, CheckedAdd, CheckedSub, Saturating, Zero};
8+
use sp_runtime::traits::{CheckedAdd, CheckedSub, Saturating, Zero};
99

1010
use common_primitives::capacity::StakingType;
1111
#[cfg(any(feature = "runtime-benchmarks", test))]
1212
use sp_std::vec::Vec;
13-
use common_primitives::node::{AccountId, Hash};
1413

1514
/// The type used for storing information about staking details.
1615
#[derive(
@@ -372,27 +371,13 @@ pub trait StakingRewardsProvider<T: Config> {
372371
TypeInfo,
373372
MaxEncodedLen,
374373
)]
375-
pub struct RewardEraInfo<RewardEra, BlockNumber>
376-
where
377-
RewardEra: AtLeast32BitUnsigned + EncodeLike,
378-
{
374+
pub struct RewardEraInfo<RewardEra, BlockNumber> {
379375
/// the index of this era
380376
pub era_index: RewardEra,
381377
/// the starting block of this era
382378
pub started_at: BlockNumber,
383379
}
384380

385-
/// The information needed to track a Reward Era
386-
#[derive(
387-
PartialEq, Eq, Clone, Default, PartialOrd, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen,
388-
)]
389-
pub struct RewardEraInfo<RewardEra, BlockNumber> {
390-
/// the index of this era
391-
pub current_era: RewardEra,
392-
/// the starting block of this era
393-
pub era_start: BlockNumber,
394-
}
395-
396381
/// Needed data about a RewardPool for a given RewardEra.
397382
/// The total_reward_pool balance for the previous era is set when a new era starts,
398383
/// based on total staked token at the end of the previous era, and remains unchanged.

runtime/frequency/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ pub use common_runtime::{
7878
};
7979
use frame_support::traits::Contains;
8080

81-
use common_primitives::capacity::StakingRewardsProvider;
8281
#[cfg(feature = "try-runtime")]
8382
use frame_support::traits::TryStateSelect;
8483

@@ -740,7 +739,7 @@ use pallet_frequency_tx_payment::Call as FrequencyPaymentCall;
740739
use pallet_handles::Call as HandlesCall;
741740
use pallet_messages::Call as MessagesCall;
742741
use pallet_msa::Call as MsaCall;
743-
use pallet_stateful_storage::{types::ItemAction::Delete, Call as StatefulStorageCall};
742+
use pallet_stateful_storage::Call as StatefulStorageCall;
744743

745744
pub struct CapacityEligibleCalls;
746745
impl GetStableWeight<RuntimeCall, Weight> for CapacityEligibleCalls {

0 commit comments

Comments
 (0)