Skip to content
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

[GPoS] Clear stakers should not remove online validators #108

Closed
badkk opened this issue Apr 23, 2020 · 0 comments · Fixed by #111
Closed

[GPoS] Clear stakers should not remove online validators #108

badkk opened this issue Apr 23, 2020 · 0 comments · Fixed by #111
Assignees
Labels
A4-enhancement PR for refactor, better api or improve performance

Comments

@badkk
Copy link
Member

badkk commented Apr 23, 2020

Problem

If chain in a danger situation(corner case), it won't update any staking related data structures(minimum validator protection)

<tee::Module<T>>::update_identities();
Self::clear_stakers();
let validators: Vec<(T::AccountId, Validations<T::AccountId>)> =
<Validators<T>>::iter().collect();
let validator_count = validators.len();
let minimum_validator_count = Self::minimum_validator_count().max(1) as usize;
if validator_count < minimum_validator_count {
// There were not enough validators for even our minimal level of functionality.
// This is bad.
// We should probably disable all functionality except for block production
// and let the chain keep producing blocks until we can decide on a sufficiently
// substantial set.
// TODO: #2494(paritytech/substrate)
return None;
}

However, we should not clear online validator's stakers, cause rewards based on staker(snapshot) status:
// 2. Staking payout
let current_era = Self::current_era().unwrap_or(0);
let total_staking_payout = Self::staking_rewards_in_era(current_era);
let total_stakes = Self::total_stakes();
<Stakers<T>>::iter().for_each(|(v, e)| {
let staking_reward = Perbill::from_rational_approximation(to_num(e.total), to_num(total_stakes)) * total_staking_payout;
total_imbalance.subsume(Self::reward_validator(&v, staking_reward));
});

Proposal

We can zip Stakers with Validators, remove those offline validator's staker

@badkk badkk added betanet🐜 A4-enhancement PR for refactor, better api or improve performance labels Apr 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A4-enhancement PR for refactor, better api or improve performance
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants