mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 18:41:03 +00:00
[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:
committed by
GitHub
parent
4b5c3fd0cb
commit
8891b70fe2
@@ -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
|
||||||
@@ -419,7 +419,10 @@ impl<T: Config> Pallet<T> {
|
|||||||
pub(crate) fn do_drop_history(when: Timeslice) -> DispatchResult {
|
pub(crate) fn do_drop_history(when: Timeslice) -> DispatchResult {
|
||||||
let config = Configuration::<T>::get().ok_or(Error::<T>::Uninitialized)?;
|
let config = Configuration::<T>::get().ok_or(Error::<T>::Uninitialized)?;
|
||||||
let status = Status::<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)?;
|
let record = InstaPoolHistory::<T>::take(when).ok_or(Error::<T>::NoHistory)?;
|
||||||
if let Some(payout) = record.maybe_payout {
|
if let Some(payout) = record.maybe_payout {
|
||||||
let _ = Self::charge(&Self::account_id(), payout);
|
let _ = Self::charge(&Self::account_id(), payout);
|
||||||
|
|||||||
@@ -146,6 +146,7 @@ fn drop_history_works() {
|
|||||||
advance_to(16);
|
advance_to(16);
|
||||||
assert_eq!(InstaPoolHistory::<Test>::iter().count(), 6);
|
assert_eq!(InstaPoolHistory::<Test>::iter().count(), 6);
|
||||||
advance_to(17);
|
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);
|
assert_noop!(Broker::do_drop_history(region.begin), Error::<Test>::StillValid);
|
||||||
advance_to(18);
|
advance_to(18);
|
||||||
assert_eq!(InstaPoolHistory::<Test>::iter().count(), 6);
|
assert_eq!(InstaPoolHistory::<Test>::iter().count(), 6);
|
||||||
|
|||||||
Reference in New Issue
Block a user