Skip to content

Commit

Permalink
[pallet-broker] Use saturating math in input validation (#4151)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
ggwpez authored Apr 16, 2024
1 parent 4b5c3fd commit 8891b70
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
11 changes: 11 additions & 0 deletions prdoc/pr_4151.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
title: "[pallet-broker] Use saturating math in input validation"

doc:
- audience: Runtime Dev
description: |
Use saturating in the pallet-broker input validation of the `drop_history` extrinsic. This
fixes a safeguard that only expired historic instantaneous pool records get dropped.

crates:
- name: pallet-broker
bump: patch
5 changes: 4 additions & 1 deletion substrate/frame/broker/src/dispatchable_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/broker/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8891b70

Please sign in to comment.