-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
claim_staking_rewards
extrinsic
#2080
claim_staking_rewards
extrinsic
#2080
Conversation
@@ -40,7 +40,7 @@ fn do_retarget_happy_path() { | |||
let from_amount = 600u64; | |||
let to_amount = 300u64; | |||
let to_msa: MessageSourceId = 2; | |||
let staking_type = ProviderBoost; | |||
let staking_type = StakingType::ProviderBoost; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was about silencing linter warnings.
assert_ok!(new_chunk.try_insert(era.into(), (1000u32 * era).into())); | ||
} | ||
ProviderBoostRewardPools::<T>::set(i, Some(new_chunk)); | ||
fn fill_reward_pool_chunks<T: Config>(current_era: RewardEra) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous version of this function, while it worked for the provider_boost benchmark, did not correctly fill up the reward_pool_chunks, so it caused an EraOutOfRange error in the claim_staking_reward benchmark.
@@ -402,6 +410,10 @@ pub mod pallet { | |||
MaxRetargetsExceeded, | |||
/// Tried to exceed bounds of a some Bounded collection | |||
CollectionBoundExceeded, | |||
/// This origin has nothing staked for ProviderBoost. | |||
NotAProviderBoostAccount, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NotAStakingAccount
was getting a bit overloaded.
/// When this reward expires, i.e. can no longer be claimed | ||
pub expires_at_block: BlockNumber, | ||
/// The total staked in this era as of the current block | ||
pub staked_amount: Balance, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes sense to have the amount they staked in each Reward Info.
// have to save this because calling self.count() after self.0.get_mut produces compiler error | ||
let current_count = self.count(); | ||
|
||
let current_staking_amount = self.get_last_staking_amount(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some code golf.
@@ -77,7 +77,7 @@ mod test { | |||
|
|||
assert_eq!(p, 100_000); | |||
|
|||
assert!(q >= 65_000_000); | |||
assert!(q >= 50_000_000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pulled in from main b/c benchmarks were failing due to too low weight.
pallets/capacity/src/weights.rs
Outdated
// Proof Size summary in bytes: | ||
// Measured: `1592` | ||
// Estimated: `20591` | ||
// Minimum execution time: 90_000_000 picoseconds. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is worst case scenario. Claiming rewards may be able to have some tuning, but also the benchmark should include variation. Created issue #2082 to address this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good, just some nits and questions!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Read through the code and looked good to me!
); | ||
let total_to_mint = Self::do_claim_rewards(&staker)?; | ||
Self::deposit_event(Event::ProviderBoostRewardClaimed { | ||
account: staker.clone(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please check if the clone can be removed from here? It seems at first sight that we might not need to do a clone.
@@ -1024,37 +1053,42 @@ impl<T: Config> Pallet<T> { | |||
Some(provider_boost_history) => { | |||
match provider_boost_history.count() { | |||
0usize => false, | |||
// they staked before the current era, so they have unclaimed rewards. | |||
1usize => provider_boost_history.get_entry_for_era(¤t_era).is_none(), | |||
1usize => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think removing a match statement makes the code a bit more readable:
pub(crate) fn has_unclaimed_rewards(account: &T::AccountId) -> bool {
let current_era = Self::get_current_era().era_index;
if let Some(provider_boost_history) = Self::get_staking_history_for(account) {
let entry_count = provider_boost_history.count();
match entry_count {
0 => false,
1 => {
let previous_era = current_era.saturating_sub(1);
provider_boost_history.get_entry_for_era(&previous_era).is_none() &&
provider_boost_history.get_entry_for_era(¤t_era).is_none()
},
_ => true
}
} else {
false
}
}
.fold(zero_balance, |acc, reward_info| acc.saturating_add(reward_info.earned_amount)) | ||
.into(); | ||
ensure!(total_to_mint.gt(&Zero::zero()), Error::<T>::NothingToClaim); | ||
let _minted_unused = T::Currency::mint_into(&staker, total_to_mint)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need let _minted_unused
if we are not using it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 amazing!
The goal of this PR is to implement the claim_staking_rewards extrinsic, its benchmarks, and tests. Closes #1970
The goal of this PR is to implement the claim_staking_rewards extrinsic, its benchmarks, and tests. Closes #1970
Goal
The goal of this PR is to implement the claim_staking_rewards extrinsic, its benchmarks, and tests.
Closes #1970
Discussion
Also removes a trait function that was complicating things and didn't really belong there.
Checklist