Skip to content

Commit

Permalink
Preimage: Check that at least one is upgraded (paritytech#1648)
Browse files Browse the repository at this point in the history
Sanity check.
  • Loading branch information
gavofyork authored Sep 20, 2023
1 parent d92af13 commit b32da58
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion substrate/frame/preimage/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ benchmarks! {
}

ensure_updated {
let n in 0..MAX_HASH_UPGRADE_BULK_COUNT;
let n in 1..MAX_HASH_UPGRADE_BULK_COUNT;

let caller = funded_account::<T>();
let hashes = (0..n).map(|i| insert_old_unrequested::<T>(i)).collect::<Vec<_>>();
Expand Down
3 changes: 3 additions & 0 deletions substrate/frame/preimage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ pub mod pallet {
NotRequested,
/// More than `MAX_HASH_UPGRADE_BULK_COUNT` hashes were requested to be upgraded at once.
TooMany,
/// Too few hashes were requested to be upgraded (i.e. zero).
TooFew,
}

/// A reason for this pallet placing a hold on funds.
Expand Down Expand Up @@ -242,6 +244,7 @@ pub mod pallet {
hashes: Vec<T::Hash>,
) -> DispatchResultWithPostInfo {
ensure_signed(origin)?;
ensure!(hashes.len() > 0, Error::<T>::TooFew);
ensure!(hashes.len() <= MAX_HASH_UPGRADE_BULK_COUNT as usize, Error::<T>::TooMany);

let updated = hashes.iter().map(Self::do_ensure_updated).filter(|b| *b).count() as u32;
Expand Down

0 comments on commit b32da58

Please sign in to comment.