Frame: Give Referendum SubmitOrigin argument (#14326)

* Referedum's SubmitOrigin should have an arg

* Fixes

* Nits and two extra utils

* Fixes

* Fixes
This commit is contained in:
Gavin Wood
2023-06-12 09:10:19 +01:00
committed by GitHub
parent 62f37e105c
commit 9716c8a1cb
14 changed files with 462 additions and 88 deletions
+31 -31
View File
@@ -26,7 +26,7 @@ use frame_benchmarking::v1::{
use frame_support::{
assert_ok,
dispatch::UnfilteredDispatchable,
traits::{Bounded, Currency, EnsureOrigin},
traits::{Bounded, Currency, EnsureOrigin, EnsureOriginWithArg},
};
use frame_system::RawOrigin;
use sp_runtime::traits::Bounded as ArithBounded;
@@ -196,7 +196,7 @@ fn is_not_confirming<T: Config<I>, I: 'static>(index: ReferendumIndex) -> bool {
benchmarks_instance_pallet! {
submit {
let origin =
T::SubmitOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
T::SubmitOrigin::try_successful_origin(&RawOrigin::Root.into()).map_err(|_| BenchmarkError::Weightless)?;
if let Ok(caller) = frame_system::ensure_signed(origin.clone()) {
T::Currency::make_free_balance_be(&caller, BalanceOf::<T, I>::max_value());
whitelist_account!(caller);
@@ -213,7 +213,7 @@ benchmarks_instance_pallet! {
place_decision_deposit_preparing {
let origin =
T::SubmitOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
T::SubmitOrigin::try_successful_origin(&RawOrigin::Root.into()).map_err(|_| BenchmarkError::Weightless)?;
let index = create_referendum::<T, I>(origin.clone());
}: place_decision_deposit<T::RuntimeOrigin>(origin, index)
verify {
@@ -222,7 +222,7 @@ benchmarks_instance_pallet! {
place_decision_deposit_queued {
let origin =
T::SubmitOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
T::SubmitOrigin::try_successful_origin(&RawOrigin::Root.into()).map_err(|_| BenchmarkError::Weightless)?;
let index = create_referendum::<T, I>(origin.clone());
fill_queue::<T, I>(origin.clone(), index, 1, 90);
}: place_decision_deposit<T::RuntimeOrigin>(origin, index)
@@ -234,7 +234,7 @@ benchmarks_instance_pallet! {
place_decision_deposit_not_queued {
let origin =
T::SubmitOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
T::SubmitOrigin::try_successful_origin(&RawOrigin::Root.into()).map_err(|_| BenchmarkError::Weightless)?;
let index = create_referendum::<T, I>(origin.clone());
fill_queue::<T, I>(origin.clone(), index, 0, 90);
let track = Referenda::<T, I>::ensure_ongoing(index).unwrap().track;
@@ -248,7 +248,7 @@ benchmarks_instance_pallet! {
place_decision_deposit_passing {
let origin =
T::SubmitOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
T::SubmitOrigin::try_successful_origin(&RawOrigin::Root.into()).map_err(|_| BenchmarkError::Weightless)?;
let index = create_referendum::<T, I>(origin.clone());
skip_prepare_period::<T, I>(index);
make_passing::<T, I>(index);
@@ -259,7 +259,7 @@ benchmarks_instance_pallet! {
place_decision_deposit_failing {
let origin =
T::SubmitOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
T::SubmitOrigin::try_successful_origin(&RawOrigin::Root.into()).map_err(|_| BenchmarkError::Weightless)?;
let index = create_referendum::<T, I>(origin.clone());
skip_prepare_period::<T, I>(index);
}: place_decision_deposit<T::RuntimeOrigin>(origin, index)
@@ -269,7 +269,7 @@ benchmarks_instance_pallet! {
refund_decision_deposit {
let origin =
T::SubmitOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
T::SubmitOrigin::try_successful_origin(&RawOrigin::Root.into()).map_err(|_| BenchmarkError::Weightless)?;
let index = create_referendum::<T, I>(origin.clone());
place_deposit::<T, I>(index);
assert_ok!(Referenda::<T, I>::cancel(
@@ -284,7 +284,7 @@ benchmarks_instance_pallet! {
refund_submission_deposit {
let origin =
T::SubmitOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
T::SubmitOrigin::try_successful_origin(&RawOrigin::Root.into()).map_err(|_| BenchmarkError::Weightless)?;
let index = create_referendum::<T, I>(origin.clone());
let caller = frame_system::ensure_signed(origin.clone()).unwrap();
let balance = T::Currency::free_balance(&caller);
@@ -303,7 +303,7 @@ benchmarks_instance_pallet! {
}
cancel {
let origin = T::SubmitOrigin::try_successful_origin()
let origin = T::SubmitOrigin::try_successful_origin(&RawOrigin::Root.into())
.expect("SubmitOrigin has no successful origin required for the benchmark");
let index = create_referendum::<T, I>(origin);
place_deposit::<T, I>(index);
@@ -315,7 +315,7 @@ benchmarks_instance_pallet! {
}
kill {
let origin = T::SubmitOrigin::try_successful_origin()
let origin = T::SubmitOrigin::try_successful_origin(&RawOrigin::Root.into())
.expect("SubmitOrigin has no successful origin required for the benchmark");
let index = create_referendum::<T, I>(origin);
place_deposit::<T, I>(index);
@@ -327,7 +327,7 @@ benchmarks_instance_pallet! {
}
one_fewer_deciding_queue_empty {
let origin = T::SubmitOrigin::try_successful_origin()
let origin = T::SubmitOrigin::try_successful_origin(&RawOrigin::Root.into())
.expect("SubmitOrigin has no successful origin required for the benchmark");
let index = create_referendum::<T, I>(origin);
place_deposit::<T, I>(index);
@@ -346,7 +346,7 @@ benchmarks_instance_pallet! {
}
one_fewer_deciding_failing {
let origin = T::SubmitOrigin::try_successful_origin()
let origin = T::SubmitOrigin::try_successful_origin(&RawOrigin::Root.into())
.expect("SubmitOrigin has no successful origin required for the benchmark");
let index = create_referendum::<T, I>(origin.clone());
// No spaces free in the queue.
@@ -371,7 +371,7 @@ benchmarks_instance_pallet! {
}
one_fewer_deciding_passing {
let origin = T::SubmitOrigin::try_successful_origin()
let origin = T::SubmitOrigin::try_successful_origin(&RawOrigin::Root.into())
.expect("SubmitOrigin has no successful origin required for the benchmark");
let index = create_referendum::<T, I>(origin.clone());
// No spaces free in the queue.
@@ -396,7 +396,7 @@ benchmarks_instance_pallet! {
}
nudge_referendum_requeued_insertion {
let origin = T::SubmitOrigin::try_successful_origin()
let origin = T::SubmitOrigin::try_successful_origin(&RawOrigin::Root.into())
.expect("SubmitOrigin has no successful origin required for the benchmark");
// First create our referendum and place the deposit. It will be failing.
let index = create_referendum::<T, I>(origin.clone());
@@ -419,7 +419,7 @@ benchmarks_instance_pallet! {
}
nudge_referendum_requeued_slide {
let origin = T::SubmitOrigin::try_successful_origin()
let origin = T::SubmitOrigin::try_successful_origin(&RawOrigin::Root.into())
.expect("SubmitOrigin has no successful origin required for the benchmark");
// First create our referendum and place the deposit. It will be failing.
let index = create_referendum::<T, I>(origin.clone());
@@ -447,7 +447,7 @@ benchmarks_instance_pallet! {
// free and this failing. It would result in `QUEUE_SIZE - 1` items being shifted for the
// insertion at the beginning.
let origin = T::SubmitOrigin::try_successful_origin()
let origin = T::SubmitOrigin::try_successful_origin(&RawOrigin::Root.into())
.expect("SubmitOrigin has no successful origin required for the benchmark");
// First create our referendum and place the deposit. It will be failing.
let index = create_referendum::<T, I>(origin.clone());
@@ -466,7 +466,7 @@ benchmarks_instance_pallet! {
}
nudge_referendum_not_queued {
let origin = T::SubmitOrigin::try_successful_origin()
let origin = T::SubmitOrigin::try_successful_origin(&RawOrigin::Root.into())
.expect("SubmitOrigin has no successful origin required for the benchmark");
// First create our referendum and place the deposit. It will be failing.
let index = create_referendum::<T, I>(origin.clone());
@@ -485,7 +485,7 @@ benchmarks_instance_pallet! {
}
nudge_referendum_no_deposit {
let origin = T::SubmitOrigin::try_successful_origin()
let origin = T::SubmitOrigin::try_successful_origin(&RawOrigin::Root.into())
.expect("SubmitOrigin has no successful origin required for the benchmark");
let index = create_referendum::<T, I>(origin);
skip_prepare_period::<T, I>(index);
@@ -496,7 +496,7 @@ benchmarks_instance_pallet! {
}
nudge_referendum_preparing {
let origin = T::SubmitOrigin::try_successful_origin()
let origin = T::SubmitOrigin::try_successful_origin(&RawOrigin::Root.into())
.expect("SubmitOrigin has no successful origin required for the benchmark");
let index = create_referendum::<T, I>(origin);
place_deposit::<T, I>(index);
@@ -507,7 +507,7 @@ benchmarks_instance_pallet! {
}
nudge_referendum_timed_out {
let origin = T::SubmitOrigin::try_successful_origin()
let origin = T::SubmitOrigin::try_successful_origin(&RawOrigin::Root.into())
.expect("SubmitOrigin has no successful origin required for the benchmark");
let index = create_referendum::<T, I>(origin);
skip_timeout_period::<T, I>(index);
@@ -518,7 +518,7 @@ benchmarks_instance_pallet! {
}
nudge_referendum_begin_deciding_failing {
let origin = T::SubmitOrigin::try_successful_origin()
let origin = T::SubmitOrigin::try_successful_origin(&RawOrigin::Root.into())
.expect("SubmitOrigin has no successful origin required for the benchmark");
let index = create_referendum::<T, I>(origin);
place_deposit::<T, I>(index);
@@ -529,7 +529,7 @@ benchmarks_instance_pallet! {
}
nudge_referendum_begin_deciding_passing {
let origin = T::SubmitOrigin::try_successful_origin()
let origin = T::SubmitOrigin::try_successful_origin(&RawOrigin::Root.into())
.expect("SubmitOrigin has no successful origin required for the benchmark");
let index = create_referendum::<T, I>(origin);
place_deposit::<T, I>(index);
@@ -541,7 +541,7 @@ benchmarks_instance_pallet! {
}
nudge_referendum_begin_confirming {
let origin = T::SubmitOrigin::try_successful_origin()
let origin = T::SubmitOrigin::try_successful_origin(&RawOrigin::Root.into())
.expect("SubmitOrigin has no successful origin required for the benchmark");
let index = create_referendum::<T, I>(origin);
place_deposit::<T, I>(index);
@@ -555,7 +555,7 @@ benchmarks_instance_pallet! {
}
nudge_referendum_end_confirming {
let origin = T::SubmitOrigin::try_successful_origin()
let origin = T::SubmitOrigin::try_successful_origin(&RawOrigin::Root.into())
.expect("SubmitOrigin has no successful origin required for the benchmark");
let index = create_referendum::<T, I>(origin);
place_deposit::<T, I>(index);
@@ -570,7 +570,7 @@ benchmarks_instance_pallet! {
}
nudge_referendum_continue_not_confirming {
let origin = T::SubmitOrigin::try_successful_origin()
let origin = T::SubmitOrigin::try_successful_origin(&RawOrigin::Root.into())
.expect("SubmitOrigin has no successful origin required for the benchmark");
let index = create_referendum::<T, I>(origin);
place_deposit::<T, I>(index);
@@ -586,7 +586,7 @@ benchmarks_instance_pallet! {
}
nudge_referendum_continue_confirming {
let origin = T::SubmitOrigin::try_successful_origin()
let origin = T::SubmitOrigin::try_successful_origin(&RawOrigin::Root.into())
.expect("SubmitOrigin has no successful origin required for the benchmark");
let index = create_referendum::<T, I>(origin);
place_deposit::<T, I>(index);
@@ -601,7 +601,7 @@ benchmarks_instance_pallet! {
}
nudge_referendum_approved {
let origin = T::SubmitOrigin::try_successful_origin()
let origin = T::SubmitOrigin::try_successful_origin(&RawOrigin::Root.into())
.expect("SubmitOrigin has no successful origin required for the benchmark");
let index = create_referendum::<T, I>(origin);
place_deposit::<T, I>(index);
@@ -616,7 +616,7 @@ benchmarks_instance_pallet! {
}
nudge_referendum_rejected {
let origin = T::SubmitOrigin::try_successful_origin()
let origin = T::SubmitOrigin::try_successful_origin(&RawOrigin::Root.into())
.expect("SubmitOrigin has no successful origin required for the benchmark");
let index = create_referendum::<T, I>(origin);
place_deposit::<T, I>(index);
@@ -632,7 +632,7 @@ benchmarks_instance_pallet! {
set_some_metadata {
use sp_std::borrow::Cow;
let origin = T::SubmitOrigin::try_successful_origin()
let origin = T::SubmitOrigin::try_successful_origin(&RawOrigin::Root.into())
.expect("SubmitOrigin has no successful origin required for the benchmark");
let index = create_referendum::<T, I>(origin.clone());
let hash = T::Preimages::note(Cow::from(vec![5, 6])).unwrap();
@@ -643,7 +643,7 @@ benchmarks_instance_pallet! {
clear_metadata {
use sp_std::borrow::Cow;
let origin = T::SubmitOrigin::try_successful_origin()
let origin = T::SubmitOrigin::try_successful_origin(&RawOrigin::Root.into())
.expect("SubmitOrigin has no successful origin required for the benchmark");
let index = create_referendum::<T, I>(origin.clone());
let hash = T::Preimages::note(Cow::from(vec![6, 7, 8])).unwrap();
+9 -4
View File
@@ -138,7 +138,7 @@ const ASSEMBLY_ID: LockIdentifier = *b"assembly";
#[frame_support::pallet]
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
use frame_support::{pallet_prelude::*, traits::EnsureOriginWithArg};
use frame_system::pallet_prelude::*;
/// The current storage version.
@@ -167,7 +167,11 @@ pub mod pallet {
type Currency: ReservableCurrency<Self::AccountId>;
// Origins and unbalances.
/// Origin from which proposals may be submitted.
type SubmitOrigin: EnsureOrigin<Self::RuntimeOrigin, Success = Self::AccountId>;
type SubmitOrigin: EnsureOriginWithArg<
Self::RuntimeOrigin,
PalletsOriginOf<Self>,
Success = Self::AccountId,
>;
/// Origin from which any vote may be cancelled.
type CancelOrigin: EnsureOrigin<Self::RuntimeOrigin>;
/// Origin from which any vote may be killed.
@@ -430,7 +434,8 @@ pub mod pallet {
proposal: BoundedCallOf<T, I>,
enactment_moment: DispatchTime<T::BlockNumber>,
) -> DispatchResult {
let who = T::SubmitOrigin::ensure_origin(origin)?;
let proposal_origin = *proposal_origin;
let who = T::SubmitOrigin::ensure_origin(origin, &proposal_origin)?;
let track =
T::Tracks::track_for(&proposal_origin).map_err(|_| Error::<T, I>::NoTrack)?;
@@ -445,7 +450,7 @@ pub mod pallet {
T::Preimages::bound(CallOf::<T, I>::from(Call::nudge_referendum { index }))?;
let status = ReferendumStatus {
track,
origin: *proposal_origin,
origin: proposal_origin,
proposal: proposal.clone(),
enactment: enactment_moment,
submitted: now,