Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/beacon-fast-runtime' into beacon…
Browse files Browse the repository at this point in the history
…-fast-runtime
  • Loading branch information
claravanstaden authored and claravanstaden committed Dec 22, 2023
2 parents 6fa63c1 + ed3f4a2 commit 082f544
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion substrate/frame/assets/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
}
} else if d.is_sufficient {
frame_system::Pallet::<T>::inc_sufficients(who);
d.sufficients += 1;
d.sufficients.saturating_inc();
ExistenceReason::Sufficient
} else {
frame_system::Pallet::<T>::inc_consumers(who)
Expand Down
9 changes: 6 additions & 3 deletions substrate/frame/nomination-pools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2955,9 +2955,12 @@ impl<T: Config> Pallet<T> {
},
(false, false) => {
// Equivalent to (current_points / current_balance) * new_funds
balance(u256(current_points).saturating_mul(u256(new_funds)))
// We check for zero above
.div(current_balance)
balance(
u256(current_points)
.saturating_mul(u256(new_funds))
// We check for zero above
.div(u256(current_balance)),
)
},
}
}
Expand Down
22 changes: 22 additions & 0 deletions substrate/frame/nomination-pools/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,28 @@ mod bonded_pool {
assert_ok!(pool.ok_to_join());
});
}

#[test]
fn points_and_balance_conversions_are_safe() {
ExtBuilder::default().build_and_execute(|| {
let bonded_pool = BondedPool::<Runtime> {
id: 123123,
inner: BondedPoolInner {
commission: Commission::default(),
member_counter: 1,
points: u128::MAX,
roles: DEFAULT_ROLES,
state: PoolState::Open,
},
};
StakingMock::set_bonded_balance(bonded_pool.bonded_account(), u128::MAX);

// Max out the points and balance of the pool and make sure the conversion works as
// expected and does not overflow.
assert_eq!(bonded_pool.balance_to_point(u128::MAX), u128::MAX);
assert_eq!(bonded_pool.points_to_balance(u128::MAX), u128::MAX);
})
}
}

mod reward_pool {
Expand Down

0 comments on commit 082f544

Please sign in to comment.