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

Add new try-state check invariant for nomination-pools (points >= stake) #5465

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions prdoc/pr_5465.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
title: try-state check invariant for nomination-pools (points >= stake)

doc:
- audience: Runtime Dev
description: |
Adds a new try-state invariant to the nomination pools that checks that for each bonded pool, the pool's points can never be lower than its staked balance.

crates:
- name: pallet-nomination-pools
bump: minor
6 changes: 6 additions & 0 deletions substrate/frame/nomination-pools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3658,6 +3658,7 @@ impl<T: Config> Pallet<T> {
/// * each `member.pool_id` must correspond to an existing `BondedPool.id` (which implies the
/// existence of the reward pool as well).
/// * count of all members must be less than `MaxPoolMembers`.
/// * each `BondedPool.points` must never be lower than the pool's balance.
///
/// Then, considering unbonding members:
///
Expand Down Expand Up @@ -3786,6 +3787,11 @@ impl<T: Config> Pallet<T> {
pool is being destroyed and the depositor is the last member",
);

ensure!(
bonded_pool.points >= bonded_pool.points_to_balance(bonded_pool.points),
"Each `BondedPool.points` must never be lower than the pool's balance"
);

expected_tvl += T::StakeAdapter::total_stake(Pool::from(bonded_pool.bonded_account()));

Ok(())
Expand Down
Loading