Commits on Source (2)
......@@ -487,7 +487,7 @@ pub mod pallet {
// If the sender is not the curator, and the curator is inactive,
// slash the curator.
if sender != *curator {
let block_number = Self::local_block_number();
let block_number = Self::treasury_block_number();
if *update_due < block_number {
slash_curator(curator, &mut bounty.curator_deposit);
// Continue to change bounty status below...
......@@ -551,7 +551,8 @@ pub mod pallet {
T::Currency::reserve(curator, deposit)?;
bounty.curator_deposit = deposit;
let update_due = Self::local_block_number() + T::BountyUpdatePeriod::get();
let update_due =
Self::treasury_block_number() + T::BountyUpdatePeriod::get();
bounty.status =
BountyStatus::Active { curator: curator.clone(), update_due };
......@@ -605,7 +606,7 @@ pub mod pallet {
bounty.status = BountyStatus::PendingPayout {
curator: signer,
beneficiary: beneficiary.clone(),
unlock_at: Self::local_block_number() + T::BountyDepositPayoutDelay::get(),
unlock_at: Self::treasury_block_number() + T::BountyDepositPayoutDelay::get(),
};
Ok(())
......@@ -636,7 +637,7 @@ pub mod pallet {
if let BountyStatus::PendingPayout { curator, beneficiary, unlock_at } =
bounty.status
{
ensure!(Self::local_block_number() >= unlock_at, Error::<T, I>::Premature);
ensure!(Self::treasury_block_number() >= unlock_at, Error::<T, I>::Premature);
let bounty_account = Self::bounty_account_id(bounty_id);
let balance = T::Currency::free_balance(&bounty_account);
let fee = bounty.fee.min(balance); // just to be safe
......@@ -789,8 +790,9 @@ pub mod pallet {
match bounty.status {
BountyStatus::Active { ref curator, ref mut update_due } => {
ensure!(*curator == signer, Error::<T, I>::RequireCurator);
*update_due = (Self::local_block_number() + T::BountyUpdatePeriod::get())
.max(*update_due);
*update_due = (Self::treasury_block_number() +
T::BountyUpdatePeriod::get())
.max(*update_due);
},
_ => return Err(Error::<T, I>::UnexpectedStatus.into()),
}
......@@ -805,11 +807,10 @@ pub mod pallet {
}
impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// Get the block number used for this pallet.
/// Get the block number used in the treasury pallet.
///
/// This comes from the Treasury pallet which may be configured to use the relay chain on a
/// parachain.
pub fn local_block_number() -> BlockNumberFor<T> {
/// It may be configured to use the relay chain block number on a parachain.
pub fn treasury_block_number() -> BlockNumberFor<T> {
<T as pallet_treasury::Config<I>>::BlockNumberProvider::current_block_number()
}
......
......@@ -23,6 +23,7 @@ use super::*;
use frame_benchmarking::v1::{account, benchmarks, whitelisted_caller, BenchmarkError};
use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin};
use sp_runtime::traits::BlockNumberProvider;
use crate::Pallet as ChildBounties;
use pallet_bounties::Pallet as Bounties;
......@@ -54,6 +55,10 @@ struct BenchmarkChildBounty<T: Config> {
reason: Vec<u8>,
}
fn set_block_number<T: Config>(n: BlockNumberFor<T>) {
<T as pallet_treasury::Config>::BlockNumberProvider::set_block_number(n);
}
fn setup_bounty<T: Config>(
user: u32,
description: u32,
......@@ -114,7 +119,8 @@ fn activate_bounty<T: Config>(
let approve_origin =
T::SpendOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
Bounties::<T>::approve_bounty(approve_origin, child_bounty_setup.bounty_id)?;
Treasury::<T>::on_initialize(BlockNumberFor::<T>::zero());
set_block_number::<T>(T::SpendPeriod::get());
Treasury::<T>::on_initialize(frame_system::Pallet::<T>::block_number());
Bounties::<T>::propose_curator(
RawOrigin::Root.into(),
child_bounty_setup.bounty_id,
......@@ -229,8 +235,8 @@ benchmarks! {
unassign_curator {
setup_pot_account::<T>();
let bounty_setup = activate_child_bounty::<T>(0, T::MaximumReasonLength::get())?;
Treasury::<T>::on_initialize(BlockNumberFor::<T>::zero());
frame_system::Pallet::<T>::set_block_number(T::BountyUpdatePeriod::get() + 1u32.into());
Treasury::<T>::on_initialize(frame_system::Pallet::<T>::block_number());
set_block_number::<T>(T::SpendPeriod::get() + T::BountyUpdatePeriod::get() + 1u32.into());
let caller = whitelisted_caller();
}: _(RawOrigin::Signed(caller), bounty_setup.bounty_id,
bounty_setup.child_bounty_id)
......@@ -266,7 +272,7 @@ benchmarks! {
let beneficiary_account: T::AccountId = account("beneficiary", 0, SEED);
let beneficiary = T::Lookup::unlookup(beneficiary_account.clone());
frame_system::Pallet::<T>::set_block_number(T::BountyDepositPayoutDelay::get());
set_block_number::<T>(T::SpendPeriod::get() + T::BountyDepositPayoutDelay::get());
ensure!(T::Currency::free_balance(&beneficiary_account).is_zero(),
"Beneficiary already has balance.");
......@@ -303,7 +309,7 @@ benchmarks! {
close_child_bounty_active {
setup_pot_account::<T>();
let bounty_setup = activate_child_bounty::<T>(0, T::MaximumReasonLength::get())?;
Treasury::<T>::on_initialize(BlockNumberFor::<T>::zero());
Treasury::<T>::on_initialize(frame_system::Pallet::<T>::block_number());
}: close_child_bounty(RawOrigin::Root, bounty_setup.bounty_id, bounty_setup.child_bounty_id)
verify {
assert_last_event::<T>(Event::Canceled {
......
......@@ -65,7 +65,10 @@ use frame_support::traits::{
};
use sp_runtime::{
traits::{AccountIdConversion, BadOrigin, CheckedSub, Saturating, StaticLookup, Zero},
traits::{
AccountIdConversion, BadOrigin, BlockNumberProvider, CheckedSub, Saturating, StaticLookup,
Zero,
},
DispatchResult, RuntimeDebug,
};
......@@ -525,7 +528,7 @@ pub mod pallet {
let (parent_curator, update_due) =
Self::ensure_bounty_active(parent_bounty_id)?;
if sender == parent_curator ||
update_due < frame_system::Pallet::<T>::block_number()
update_due < Self::treasury_block_number()
{
// Slash the child-bounty curator if
// + the call is made by the parent bounty curator.
......@@ -604,7 +607,7 @@ pub mod pallet {
child_bounty.status = ChildBountyStatus::PendingPayout {
curator: signer,
beneficiary: beneficiary.clone(),
unlock_at: frame_system::Pallet::<T>::block_number() +
unlock_at: Self::treasury_block_number() +
T::BountyDepositPayoutDelay::get(),
};
Ok(())
......@@ -666,7 +669,7 @@ pub mod pallet {
// Ensure block number is elapsed for processing the
// claim.
ensure!(
frame_system::Pallet::<T>::block_number() >= *unlock_at,
Self::treasury_block_number() >= *unlock_at,
BountiesError::<T>::Premature,
);
......@@ -774,6 +777,13 @@ pub mod pallet {
}
impl<T: Config> Pallet<T> {
/// Get the block number used in the treasury pallet.
///
/// It may be configured to use the relay chain block number on a parachain.
pub fn treasury_block_number() -> BlockNumberFor<T> {
<T as pallet_treasury::Config>::BlockNumberProvider::current_block_number()
}
// This function will calculate the deposit of a curator.
fn calculate_curator_deposit(
parent_curator: &T::AccountId,
......