From 1ee5b56de7cb4d4a84bc15ab495195af10e76adf Mon Sep 17 00:00:00 2001 From: Tiago Tavares Date: Fri, 28 Feb 2025 11:47:08 +0000 Subject: [PATCH] docs: improves migration path and adds function to reuse update_due calculation --- prdoc/pr_7723.prdoc | 5 +++-- substrate/frame/bounties/src/lib.rs | 15 ++++++--------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/prdoc/pr_7723.prdoc b/prdoc/pr_7723.prdoc index d03274ab2185..9f225a502556 100644 --- a/prdoc/pr_7723.prdoc +++ b/prdoc/pr_7723.prdoc @@ -11,8 +11,9 @@ migrations: runtime: - reference: pallet-bounties description: | - Migrating `BountyUpdatePeriod` from `BlockNumber` to `Option` where - if set to (), bounties will no longer expire. + Migrating `BountyUpdatePeriod` from `BlockNumber` to `Option`. + 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 diff --git a/substrate/frame/bounties/src/lib.rs b/substrate/frame/bounties/src/lib.rs index 3763db958756..51ae76c04e85 100644 --- a/substrate/frame/bounties/src/lib.rs +++ b/substrate/frame/bounties/src/lib.rs @@ -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::::max_value()), - ); + let update_due = Self::calculate_update_due(); bounty.status = BountyStatus::Active { curator: curator.clone(), update_due }; @@ -830,11 +827,7 @@ pub mod pallet { match bounty.status { BountyStatus::Active { ref curator, ref mut update_due } => { ensure!(*curator == signer, Error::::RequireCurator); - *update_due = (Self::treasury_block_number().saturating_add( - T::BountyUpdatePeriod::get() - .unwrap_or(BlockNumberFor::::max_value()), - )) - .max(*update_due); + *update_due = Self::calculate_update_due().max(*update_due); }, _ => return Err(Error::::UnexpectedStatus.into()), } @@ -965,6 +958,10 @@ impl, I: 'static> Pallet { deposit } + pub fn calculate_update_due() -> BlockNumberFor { + Self::treasury_block_number().saturating_add(T::BountyUpdatePeriod::get().unwrap_or(BlockNumberFor::::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