diff --git a/prdoc/pr_5465.prdoc b/prdoc/pr_5465.prdoc new file mode 100644 index 000000000000..ae185dc250f6 --- /dev/null +++ b/prdoc/pr_5465.prdoc @@ -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 diff --git a/substrate/frame/nomination-pools/src/lib.rs b/substrate/frame/nomination-pools/src/lib.rs index 44e3463dc9f2..177c5da74d4f 100644 --- a/substrate/frame/nomination-pools/src/lib.rs +++ b/substrate/frame/nomination-pools/src/lib.rs @@ -3658,6 +3658,7 @@ impl Pallet { /// * 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: /// @@ -3786,6 +3787,11 @@ impl Pallet { 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(())