Skip to content

Commit

Permalink
Add new try-state check invariant for nomination-pools (points >= sta…
Browse files Browse the repository at this point in the history
…ke) (#5465)

closes #5448

---------

Co-authored-by: Gonçalo Pestana <g6pestana@gmail.com>
Co-authored-by: Ankan <10196091+Ank4n@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 29, 2024
1 parent ddd58c1 commit 61bfcb8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
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

0 comments on commit 61bfcb8

Please sign in to comment.