Skip to content

Commit

Permalink
docs: improves migration path and adds function to reuse update_due c…
Browse files Browse the repository at this point in the history
…alculation
  • Loading branch information
BigTava committed Feb 28, 2025
1 parent 2ef5617 commit 1ee5b56
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
5 changes: 3 additions & 2 deletions prdoc/pr_7723.prdoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ migrations:
runtime:
- reference: pallet-bounties
description: |
Migrating `BountyUpdatePeriod` from `BlockNumber` to `Option<BlockNumber>` where
if set to (), bounties will no longer expire.
Migrating `BountyUpdatePeriod` from `BlockNumber` to `Option<BlockNumber>`.
To preserve the existing behavior, wrap the current value in `Some(BountyUpdatePeriod)`.
if set to None, bounties will no longer expire.

crates:
- name: pallet-bounties
Expand Down
15 changes: 6 additions & 9 deletions substrate/frame/bounties/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,10 +586,7 @@ pub mod pallet {
T::Currency::reserve(curator, deposit)?;
bounty.curator_deposit = deposit;

let update_due = Self::treasury_block_number().saturating_add(
T::BountyUpdatePeriod::get()
.unwrap_or(BlockNumberFor::<T, I>::max_value()),
);
let update_due = Self::calculate_update_due();
bounty.status =
BountyStatus::Active { curator: curator.clone(), update_due };

Expand Down Expand Up @@ -830,11 +827,7 @@ pub mod pallet {
match bounty.status {
BountyStatus::Active { ref curator, ref mut update_due } => {
ensure!(*curator == signer, Error::<T, I>::RequireCurator);
*update_due = (Self::treasury_block_number().saturating_add(
T::BountyUpdatePeriod::get()
.unwrap_or(BlockNumberFor::<T, I>::max_value()),
))
.max(*update_due);
*update_due = Self::calculate_update_due().max(*update_due);
},
_ => return Err(Error::<T, I>::UnexpectedStatus.into()),
}
Expand Down Expand Up @@ -965,6 +958,10 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
deposit
}

pub fn calculate_update_due() -> BlockNumberFor<T, I> {
Self::treasury_block_number().saturating_add(T::BountyUpdatePeriod::get().unwrap_or(BlockNumberFor::<T, I>::max_value()))
}

/// The account ID of the treasury pot.
///
/// This actually does computation. If you need to keep using it, then make sure you cache the
Expand Down

0 comments on commit 1ee5b56

Please sign in to comment.