[pallet-broker] Use saturating math in input validation (#4151)

Changes:
- Saturate in the input validation of he drop history function or
pallet-broker.

---------

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
Oliver Tale-Yazdi
2024-04-16 13:08:26 +03:00
committed by GitHub
parent 4b5c3fd0cb
commit 8891b70fe2
3 changed files with 16 additions and 1 deletions
@@ -419,7 +419,10 @@ impl<T: Config> Pallet<T> {
pub(crate) fn do_drop_history(when: Timeslice) -> DispatchResult {
let config = Configuration::<T>::get().ok_or(Error::<T>::Uninitialized)?;
let status = Status::<T>::get().ok_or(Error::<T>::Uninitialized)?;
ensure!(status.last_timeslice > when + config.contribution_timeout, Error::<T>::StillValid);
ensure!(
status.last_timeslice > when.saturating_add(config.contribution_timeout),
Error::<T>::StillValid
);
let record = InstaPoolHistory::<T>::take(when).ok_or(Error::<T>::NoHistory)?;
if let Some(payout) = record.maybe_payout {
let _ = Self::charge(&Self::account_id(), payout);
+1
View File
@@ -146,6 +146,7 @@ fn drop_history_works() {
advance_to(16);
assert_eq!(InstaPoolHistory::<Test>::iter().count(), 6);
advance_to(17);
assert_noop!(Broker::do_drop_history(u32::MAX), Error::<Test>::StillValid);
assert_noop!(Broker::do_drop_history(region.begin), Error::<Test>::StillValid);
advance_to(18);
assert_eq!(InstaPoolHistory::<Test>::iter().count(), 6);