mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 17:31:05 +00:00
Bound uses of Call (#11649)
* Introduce preimages module in traits * Multisize Preimages * Len not actually necessary * Tweaks to the preimage API * Fixes * Get Scheduler building with new API * Scheduler tests pass * Bounded Scheduler 🎉 * Use Agenda holes and introduce IncompleteSince to avoid need to reschedule * Tests pass with new weight system * New benchmarks * Add missing file * Drop preimage when permenantly overeight * Drop preimage when permenantly overeight * Referenda uses latest preimage API * Testing ok * Adding tests Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * fmt Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Add preimage migration Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Docs * Remove dbg * Refactor Democracy * Refactor Democracy * Add final MEL * Remove silly maps * Fixes * Minor refactor * Formatting * Fixes * Fixes * Fixes * Update frame/preimage/src/lib.rs Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> * Add migrations to Democracy * WIP Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Resolve conflicts Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Revert "Resolve conflicts" This reverts commit 734d66d69e54553471ffa54fa52e3e304dc8f106. * Undo wrong resolves... Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * WIP Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Make compile Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * massage clippy Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * More clippy Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * clippy annoyance Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * clippy annoyance Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix benchmarks Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * add missing file * Test <Preimage as QueryPreimage> Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * More tests Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Clippy harassment Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Add test Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * clippy Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fixup tests Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Remove old stuff Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * fmt Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Test <Scheduler as Anon> trait functions Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update pallet-ui tests Why is this needed? Should not be the case unless master is broken... Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * More scheduler trait test Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * More tests Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Apply review suggestion Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Beauty fixes Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Add Scheduler test migration_v3_to_v4_works Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Merge fixup Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Keep referenda benchmarks instantiatable Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update weights Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Use new scheduler weight functions Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Use new democracy weight functions Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Use weight compare functions Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update pallet-ui tests Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * More renaming… Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * More renaming… Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Add comment Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Implement OnRuntimeUpgrade for scheduler::v3_to_v4 migration Put the migration into a proper `MigrateToV4` struct and implement the OnRuntimeUpgrade hooks for it. Also move the test to use that instead. This should make it easier for adding it to Polkadot. Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Clippy Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Handle undecodable Agendas Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Remove trash Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix test Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Use new OnRuntimeUpgrade functions Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * fix test Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix BoundedSlice::truncate_from Co-authored-by: jakoblell Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix pre_upgrade hook return values Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Add more error logging Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Find too large preimages in the pre_upgrade hook Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Test that too large Calls in agendas are ignored Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Use new OnRuntimeUpgrade hooks Why did the CI not catch this?! Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * works fine - just more logs Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix staking migration Causing issues on Kusama... Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix UI tests No idea why this is needed. This is actually undoing an earlier change. Maybe the CI has different rustc versions!? Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Remove multisig's Calls (#12072) * Remove multisig's Calls * Multisig: Fix tests and re-introduce reserve logic (#12241) * Fix tests and re-introduce reserve logic * fix benches * add todo * remove irrelevant bench * [Feature] Add a migration that drains and refunds stored calls (#12313) * [Feature] Add a migration that drains and refunds stored calls * migration fixes * fixes * address review comments * consume the whole block weight * fix assertions * license header * fix interface Co-authored-by: parity-processbot <> Co-authored-by: parity-processbot <> Co-authored-by: Roman Useinov <roman.useinov@gmail.com> * Fix test Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix multisig benchmarks Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * ".git/.scripts/bench-bot.sh" pallet dev pallet_democracy * ".git/.scripts/bench-bot.sh" pallet dev pallet_scheduler * ".git/.scripts/bench-bot.sh" pallet dev pallet_preimage Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> Co-authored-by: parity-processbot <> Co-authored-by: Roman Useinov <roman.useinov@gmail.com>
This commit is contained in:
@@ -24,10 +24,10 @@ use frame_benchmarking::{account, benchmarks_instance_pallet, whitelist_account}
|
||||
use frame_support::{
|
||||
assert_ok,
|
||||
dispatch::UnfilteredDispatchable,
|
||||
traits::{Currency, EnsureOrigin},
|
||||
traits::{Bounded, Currency, EnsureOrigin},
|
||||
};
|
||||
use frame_system::RawOrigin;
|
||||
use sp_runtime::traits::{Bounded, Hash};
|
||||
use sp_runtime::traits::Bounded as ArithBounded;
|
||||
|
||||
const SEED: u32 = 0;
|
||||
|
||||
@@ -42,6 +42,12 @@ fn funded_account<T: Config<I>, I: 'static>(name: &'static str, index: u32) -> T
|
||||
caller
|
||||
}
|
||||
|
||||
fn dummy_call<T: Config<I>, I: 'static>() -> Bounded<<T as Config<I>>::RuntimeCall> {
|
||||
let inner = frame_system::Call::remark { remark: vec![] };
|
||||
let call = <T as Config<I>>::RuntimeCall::from(inner);
|
||||
T::Preimages::bound(call).unwrap()
|
||||
}
|
||||
|
||||
fn create_referendum<T: Config<I>, I: 'static>() -> (T::RuntimeOrigin, ReferendumIndex) {
|
||||
let origin: T::RuntimeOrigin = T::SubmitOrigin::successful_origin();
|
||||
if let Ok(caller) = frame_system::ensure_signed(origin.clone()) {
|
||||
@@ -50,9 +56,9 @@ fn create_referendum<T: Config<I>, I: 'static>() -> (T::RuntimeOrigin, Referendu
|
||||
}
|
||||
|
||||
let proposal_origin = Box::new(RawOrigin::Root.into());
|
||||
let proposal_hash = T::Hashing::hash_of(&0);
|
||||
let proposal = dummy_call::<T, I>();
|
||||
let enactment_moment = DispatchTime::After(0u32.into());
|
||||
let call = Call::<T, I>::submit { proposal_origin, proposal_hash, enactment_moment };
|
||||
let call = crate::Call::<T, I>::submit { proposal_origin, proposal, enactment_moment };
|
||||
assert_ok!(call.dispatch_bypass_filter(origin.clone()));
|
||||
let index = ReferendumCount::<T, I>::get() - 1;
|
||||
(origin, index)
|
||||
@@ -196,7 +202,7 @@ benchmarks_instance_pallet! {
|
||||
}: _<T::RuntimeOrigin>(
|
||||
origin,
|
||||
Box::new(RawOrigin::Root.into()),
|
||||
T::Hashing::hash_of(&0),
|
||||
dummy_call::<T, I>(),
|
||||
DispatchTime::After(0u32.into())
|
||||
) verify {
|
||||
let index = ReferendumCount::<T, I>::get().checked_sub(1).unwrap();
|
||||
|
||||
@@ -69,11 +69,11 @@ use frame_support::{
|
||||
ensure,
|
||||
traits::{
|
||||
schedule::{
|
||||
v2::{Anon as ScheduleAnon, Named as ScheduleNamed},
|
||||
DispatchTime, MaybeHashed,
|
||||
v3::{Anon as ScheduleAnon, Named as ScheduleNamed},
|
||||
DispatchTime,
|
||||
},
|
||||
Currency, LockIdentifier, OnUnbalanced, OriginTrait, PollStatus, Polling,
|
||||
ReservableCurrency, VoteTally,
|
||||
Currency, LockIdentifier, OnUnbalanced, OriginTrait, PollStatus, Polling, QueryPreimage,
|
||||
ReservableCurrency, StorePreimage, VoteTally,
|
||||
},
|
||||
BoundedVec,
|
||||
};
|
||||
@@ -92,10 +92,10 @@ use self::branch::{BeginDecidingBranch, OneFewerDecidingBranch, ServiceBranch};
|
||||
pub use self::{
|
||||
pallet::*,
|
||||
types::{
|
||||
BalanceOf, CallOf, Curve, DecidingStatus, DecidingStatusOf, Deposit, InsertSorted,
|
||||
NegativeImbalanceOf, PalletsOriginOf, ReferendumIndex, ReferendumInfo, ReferendumInfoOf,
|
||||
ReferendumStatus, ReferendumStatusOf, ScheduleAddressOf, TallyOf, TrackIdOf, TrackInfo,
|
||||
TrackInfoOf, TracksInfo, VotesOf,
|
||||
BalanceOf, BoundedCallOf, CallOf, Curve, DecidingStatus, DecidingStatusOf, Deposit,
|
||||
InsertSorted, NegativeImbalanceOf, PalletsOriginOf, ReferendumIndex, ReferendumInfo,
|
||||
ReferendumInfoOf, ReferendumStatus, ReferendumStatusOf, ScheduleAddressOf, TallyOf,
|
||||
TrackIdOf, TrackInfo, TrackInfoOf, TracksInfo, VotesOf,
|
||||
},
|
||||
weights::WeightInfo,
|
||||
};
|
||||
@@ -149,23 +149,16 @@ pub mod pallet {
|
||||
// System level stuff.
|
||||
type RuntimeCall: Parameter
|
||||
+ Dispatchable<RuntimeOrigin = Self::RuntimeOrigin>
|
||||
+ From<Call<Self, I>>;
|
||||
+ From<Call<Self, I>>
|
||||
+ IsType<<Self as frame_system::Config>::RuntimeCall>
|
||||
+ From<frame_system::Call<Self>>;
|
||||
type RuntimeEvent: From<Event<Self, I>>
|
||||
+ IsType<<Self as frame_system::Config>::RuntimeEvent>;
|
||||
/// Weight information for extrinsics in this pallet.
|
||||
type WeightInfo: WeightInfo;
|
||||
/// The Scheduler.
|
||||
type Scheduler: ScheduleAnon<
|
||||
Self::BlockNumber,
|
||||
CallOf<Self, I>,
|
||||
PalletsOriginOf<Self>,
|
||||
Hash = Self::Hash,
|
||||
> + ScheduleNamed<
|
||||
Self::BlockNumber,
|
||||
CallOf<Self, I>,
|
||||
PalletsOriginOf<Self>,
|
||||
Hash = Self::Hash,
|
||||
>;
|
||||
type Scheduler: ScheduleAnon<Self::BlockNumber, CallOf<Self, I>, PalletsOriginOf<Self>>
|
||||
+ ScheduleNamed<Self::BlockNumber, CallOf<Self, I>, PalletsOriginOf<Self>>;
|
||||
/// Currency type for this pallet.
|
||||
type Currency: ReservableCurrency<Self::AccountId>;
|
||||
// Origins and unbalances.
|
||||
@@ -221,6 +214,9 @@ pub mod pallet {
|
||||
Self::BlockNumber,
|
||||
RuntimeOrigin = <Self::RuntimeOrigin as OriginTrait>::PalletsOrigin,
|
||||
>;
|
||||
|
||||
/// The preimage provider.
|
||||
type Preimages: QueryPreimage + StorePreimage;
|
||||
}
|
||||
|
||||
/// The next free referendum index, aka the number of referenda started so far.
|
||||
@@ -259,8 +255,8 @@ pub mod pallet {
|
||||
index: ReferendumIndex,
|
||||
/// The track (and by extension proposal dispatch origin) of this referendum.
|
||||
track: TrackIdOf<T, I>,
|
||||
/// The hash of the proposal up for referendum.
|
||||
proposal_hash: T::Hash,
|
||||
/// The proposal for the referendum.
|
||||
proposal: BoundedCallOf<T, I>,
|
||||
},
|
||||
/// The decision deposit has been placed.
|
||||
DecisionDepositPlaced {
|
||||
@@ -293,8 +289,8 @@ pub mod pallet {
|
||||
index: ReferendumIndex,
|
||||
/// The track (and by extension proposal dispatch origin) of this referendum.
|
||||
track: TrackIdOf<T, I>,
|
||||
/// The hash of the proposal up for referendum.
|
||||
proposal_hash: T::Hash,
|
||||
/// The proposal for the referendum.
|
||||
proposal: BoundedCallOf<T, I>,
|
||||
/// The current tally of votes in this referendum.
|
||||
tally: T::Tally,
|
||||
},
|
||||
@@ -381,7 +377,7 @@ pub mod pallet {
|
||||
/// - `origin`: must be `SubmitOrigin` and the account must have `SubmissionDeposit` funds
|
||||
/// available.
|
||||
/// - `proposal_origin`: The origin from which the proposal should be executed.
|
||||
/// - `proposal_hash`: The hash of the proposal preimage.
|
||||
/// - `proposal`: The proposal.
|
||||
/// - `enactment_moment`: The moment that the proposal should be enacted.
|
||||
///
|
||||
/// Emits `Submitted`.
|
||||
@@ -389,7 +385,7 @@ pub mod pallet {
|
||||
pub fn submit(
|
||||
origin: OriginFor<T>,
|
||||
proposal_origin: Box<PalletsOriginOf<T>>,
|
||||
proposal_hash: T::Hash,
|
||||
proposal: BoundedCallOf<T, I>,
|
||||
enactment_moment: DispatchTime<T::BlockNumber>,
|
||||
) -> DispatchResult {
|
||||
let who = T::SubmitOrigin::ensure_origin(origin)?;
|
||||
@@ -403,11 +399,12 @@ pub mod pallet {
|
||||
r
|
||||
});
|
||||
let now = frame_system::Pallet::<T>::block_number();
|
||||
let nudge_call = Call::nudge_referendum { index };
|
||||
let nudge_call =
|
||||
T::Preimages::bound(CallOf::<T, I>::from(Call::nudge_referendum { index }))?;
|
||||
let status = ReferendumStatus {
|
||||
track,
|
||||
origin: *proposal_origin,
|
||||
proposal_hash,
|
||||
proposal: proposal.clone(),
|
||||
enactment: enactment_moment,
|
||||
submitted: now,
|
||||
submission_deposit,
|
||||
@@ -419,7 +416,7 @@ pub mod pallet {
|
||||
};
|
||||
ReferendumInfoFor::<T, I>::insert(index, ReferendumInfo::Ongoing(status));
|
||||
|
||||
Self::deposit_event(Event::<T, I>::Submitted { index, track, proposal_hash });
|
||||
Self::deposit_event(Event::<T, I>::Submitted { index, track, proposal });
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -651,7 +648,8 @@ impl<T: Config<I>, I: 'static> Polling<T::Tally> for Pallet<T, I> {
|
||||
let mut status = ReferendumStatusOf::<T, I> {
|
||||
track: class,
|
||||
origin: frame_support::dispatch::RawOrigin::Root.into(),
|
||||
proposal_hash: <T::Hashing as sp_runtime::traits::Hash>::hash_of(&index),
|
||||
proposal: T::Preimages::bound(CallOf::<T, I>::from(Call::nudge_referendum { index }))
|
||||
.map_err(|_| ())?,
|
||||
enactment: DispatchTime::After(Zero::zero()),
|
||||
submitted: now,
|
||||
submission_deposit: Deposit { who: dummy_account_id, amount: Zero::zero() },
|
||||
@@ -709,18 +707,18 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
track: &TrackInfoOf<T, I>,
|
||||
desired: DispatchTime<T::BlockNumber>,
|
||||
origin: PalletsOriginOf<T>,
|
||||
call_hash: T::Hash,
|
||||
call: BoundedCallOf<T, I>,
|
||||
) {
|
||||
let now = frame_system::Pallet::<T>::block_number();
|
||||
let earliest_allowed = now.saturating_add(track.min_enactment_period);
|
||||
let desired = desired.evaluate(now);
|
||||
let ok = T::Scheduler::schedule_named(
|
||||
(ASSEMBLY_ID, "enactment", index).encode(),
|
||||
(ASSEMBLY_ID, "enactment", index).using_encoded(sp_io::hashing::blake2_256),
|
||||
DispatchTime::At(desired.max(earliest_allowed)),
|
||||
None,
|
||||
63,
|
||||
origin,
|
||||
MaybeHashed::Hash(call_hash),
|
||||
call,
|
||||
)
|
||||
.is_ok();
|
||||
debug_assert!(ok, "LOGIC ERROR: bake_referendum/schedule_named failed");
|
||||
@@ -728,7 +726,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
|
||||
/// Set an alarm to dispatch `call` at block number `when`.
|
||||
fn set_alarm(
|
||||
call: impl Into<CallOf<T, I>>,
|
||||
call: BoundedCallOf<T, I>,
|
||||
when: T::BlockNumber,
|
||||
) -> Option<(T::BlockNumber, ScheduleAddressOf<T, I>)> {
|
||||
let alarm_interval = T::AlarmInterval::get().max(One::one());
|
||||
@@ -739,7 +737,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
None,
|
||||
128u8,
|
||||
frame_system::RawOrigin::Root.into(),
|
||||
MaybeHashed::Value(call.into()),
|
||||
call,
|
||||
)
|
||||
.ok()
|
||||
.map(|x| (when, x));
|
||||
@@ -776,7 +774,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
Self::deposit_event(Event::<T, I>::DecisionStarted {
|
||||
index,
|
||||
tally: status.tally.clone(),
|
||||
proposal_hash: status.proposal_hash,
|
||||
proposal: status.proposal.clone(),
|
||||
track: status.track,
|
||||
});
|
||||
let confirming = if is_passing {
|
||||
@@ -843,12 +841,21 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
let alarm_interval = T::AlarmInterval::get().max(One::one());
|
||||
let when = (next_block + alarm_interval - One::one()) / alarm_interval * alarm_interval;
|
||||
|
||||
let call = match T::Preimages::bound(CallOf::<T, I>::from(Call::one_fewer_deciding {
|
||||
track,
|
||||
})) {
|
||||
Ok(c) => c,
|
||||
Err(_) => {
|
||||
debug_assert!(false, "Unable to create a bounded call from `one_fewer_deciding`??",);
|
||||
return
|
||||
},
|
||||
};
|
||||
let maybe_result = T::Scheduler::schedule(
|
||||
DispatchTime::At(when),
|
||||
None,
|
||||
128u8,
|
||||
frame_system::RawOrigin::Root.into(),
|
||||
MaybeHashed::Value(Call::one_fewer_deciding { track }.into()),
|
||||
call,
|
||||
);
|
||||
debug_assert!(
|
||||
maybe_result.is_ok(),
|
||||
@@ -871,7 +878,18 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
if status.alarm.as_ref().map_or(true, |&(when, _)| when != alarm) {
|
||||
// Either no alarm or one that was different
|
||||
Self::ensure_no_alarm(status);
|
||||
status.alarm = Self::set_alarm(Call::nudge_referendum { index }, alarm);
|
||||
let call =
|
||||
match T::Preimages::bound(CallOf::<T, I>::from(Call::nudge_referendum { index })) {
|
||||
Ok(c) => c,
|
||||
Err(_) => {
|
||||
debug_assert!(
|
||||
false,
|
||||
"Unable to create a bounded call from `nudge_referendum`??",
|
||||
);
|
||||
return false
|
||||
},
|
||||
};
|
||||
status.alarm = Self::set_alarm(call, alarm);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
@@ -987,14 +1005,8 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
// Passed!
|
||||
Self::ensure_no_alarm(&mut status);
|
||||
Self::note_one_fewer_deciding(status.track);
|
||||
let (desired, call_hash) = (status.enactment, status.proposal_hash);
|
||||
Self::schedule_enactment(
|
||||
index,
|
||||
track,
|
||||
desired,
|
||||
status.origin,
|
||||
call_hash,
|
||||
);
|
||||
let (desired, call) = (status.enactment, status.proposal);
|
||||
Self::schedule_enactment(index, track, desired, status.origin, call);
|
||||
Self::deposit_event(Event::<T, I>::Confirmed {
|
||||
index,
|
||||
tally: status.tally,
|
||||
|
||||
@@ -24,7 +24,7 @@ use frame_support::{
|
||||
assert_ok, ord_parameter_types, parameter_types,
|
||||
traits::{
|
||||
ConstU32, ConstU64, Contains, EqualPrivilegeOnly, OnInitialize, OriginTrait, Polling,
|
||||
PreimageRecipient, SortedMembers,
|
||||
SortedMembers,
|
||||
},
|
||||
weights::Weight,
|
||||
};
|
||||
@@ -32,7 +32,7 @@ use frame_system::{EnsureRoot, EnsureSignedBy};
|
||||
use sp_core::H256;
|
||||
use sp_runtime::{
|
||||
testing::Header,
|
||||
traits::{BlakeTwo256, Hash, IdentityLookup},
|
||||
traits::{BlakeTwo256, IdentityLookup},
|
||||
DispatchResult, Perbill,
|
||||
};
|
||||
|
||||
@@ -97,7 +97,6 @@ impl pallet_preimage::Config for Test {
|
||||
type WeightInfo = ();
|
||||
type Currency = Balances;
|
||||
type ManagerOrigin = EnsureRoot<u64>;
|
||||
type MaxSize = ConstU32<4096>;
|
||||
type BaseDeposit = ();
|
||||
type ByteDeposit = ();
|
||||
}
|
||||
@@ -111,8 +110,7 @@ impl pallet_scheduler::Config for Test {
|
||||
type MaxScheduledPerBlock = ConstU32<100>;
|
||||
type WeightInfo = ();
|
||||
type OriginPrivilegeCmp = EqualPrivilegeOnly;
|
||||
type PreimageProvider = Preimage;
|
||||
type NoPreimagePostponement = ConstU64<10>;
|
||||
type Preimages = Preimage;
|
||||
}
|
||||
impl pallet_balances::Config for Test {
|
||||
type MaxReserves = ();
|
||||
@@ -229,6 +227,7 @@ impl Config for Test {
|
||||
type UndecidingTimeout = ConstU64<20>;
|
||||
type AlarmInterval = AlarmInterval;
|
||||
type Tracks = TestTracksInfo;
|
||||
type Preimages = Preimage;
|
||||
}
|
||||
|
||||
pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||
@@ -306,14 +305,13 @@ pub fn set_balance_proposal(value: u64) -> Vec<u8> {
|
||||
.encode()
|
||||
}
|
||||
|
||||
pub fn set_balance_proposal_hash(value: u64) -> H256 {
|
||||
pub fn set_balance_proposal_bounded(value: u64) -> BoundedCallOf<Test, ()> {
|
||||
let c = RuntimeCall::Balances(pallet_balances::Call::set_balance {
|
||||
who: 42,
|
||||
new_free: value,
|
||||
new_reserved: 0,
|
||||
});
|
||||
<Preimage as PreimageRecipient<_>>::note_preimage(c.encode().try_into().unwrap());
|
||||
BlakeTwo256::hash_of(&c)
|
||||
<Preimage as StorePreimage>::bound(c).unwrap()
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
@@ -321,7 +319,7 @@ pub fn propose_set_balance(who: u64, value: u64, delay: u64) -> DispatchResult {
|
||||
Referenda::submit(
|
||||
RuntimeOrigin::signed(who),
|
||||
Box::new(frame_system::RawOrigin::Root.into()),
|
||||
set_balance_proposal_hash(value),
|
||||
set_balance_proposal_bounded(value),
|
||||
DispatchTime::After(delay),
|
||||
)
|
||||
}
|
||||
@@ -449,7 +447,7 @@ impl RefState {
|
||||
assert_ok!(Referenda::submit(
|
||||
RuntimeOrigin::signed(1),
|
||||
Box::new(frame_support::dispatch::RawOrigin::Root.into()),
|
||||
set_balance_proposal_hash(1),
|
||||
set_balance_proposal_bounded(1),
|
||||
DispatchTime::At(10),
|
||||
));
|
||||
assert_ok!(Referenda::place_decision_deposit(RuntimeOrigin::signed(2), 0));
|
||||
|
||||
@@ -44,7 +44,7 @@ fn basic_happy_path_works() {
|
||||
assert_ok!(Referenda::submit(
|
||||
RuntimeOrigin::signed(1),
|
||||
Box::new(RawOrigin::Root.into()),
|
||||
set_balance_proposal_hash(1),
|
||||
set_balance_proposal_bounded(1),
|
||||
DispatchTime::At(10),
|
||||
));
|
||||
assert_eq!(Balances::reserved_balance(&1), 2);
|
||||
@@ -175,7 +175,7 @@ fn queueing_works() {
|
||||
assert_ok!(Referenda::submit(
|
||||
RuntimeOrigin::signed(5),
|
||||
Box::new(RawOrigin::Root.into()),
|
||||
set_balance_proposal_hash(0),
|
||||
set_balance_proposal_bounded(0),
|
||||
DispatchTime::After(0),
|
||||
));
|
||||
assert_ok!(Referenda::place_decision_deposit(RuntimeOrigin::signed(5), 0));
|
||||
@@ -187,7 +187,7 @@ fn queueing_works() {
|
||||
assert_ok!(Referenda::submit(
|
||||
RuntimeOrigin::signed(i),
|
||||
Box::new(RawOrigin::Root.into()),
|
||||
set_balance_proposal_hash(i),
|
||||
set_balance_proposal_bounded(i),
|
||||
DispatchTime::After(0),
|
||||
));
|
||||
assert_ok!(Referenda::place_decision_deposit(RuntimeOrigin::signed(i), i as u32));
|
||||
@@ -272,7 +272,7 @@ fn auto_timeout_should_happen_with_nothing_but_submit() {
|
||||
assert_ok!(Referenda::submit(
|
||||
RuntimeOrigin::signed(1),
|
||||
Box::new(RawOrigin::Root.into()),
|
||||
set_balance_proposal_hash(1),
|
||||
set_balance_proposal_bounded(1),
|
||||
DispatchTime::At(20),
|
||||
));
|
||||
run_to(20);
|
||||
@@ -292,13 +292,13 @@ fn tracks_are_distinguished() {
|
||||
assert_ok!(Referenda::submit(
|
||||
RuntimeOrigin::signed(1),
|
||||
Box::new(RawOrigin::Root.into()),
|
||||
set_balance_proposal_hash(1),
|
||||
set_balance_proposal_bounded(1),
|
||||
DispatchTime::At(10),
|
||||
));
|
||||
assert_ok!(Referenda::submit(
|
||||
RuntimeOrigin::signed(2),
|
||||
Box::new(RawOrigin::None.into()),
|
||||
set_balance_proposal_hash(2),
|
||||
set_balance_proposal_bounded(2),
|
||||
DispatchTime::At(20),
|
||||
));
|
||||
|
||||
@@ -315,7 +315,7 @@ fn tracks_are_distinguished() {
|
||||
ReferendumInfo::Ongoing(ReferendumStatus {
|
||||
track: 0,
|
||||
origin: OriginCaller::system(RawOrigin::Root),
|
||||
proposal_hash: set_balance_proposal_hash(1),
|
||||
proposal: set_balance_proposal_bounded(1),
|
||||
enactment: DispatchTime::At(10),
|
||||
submitted: 1,
|
||||
submission_deposit: Deposit { who: 1, amount: 2 },
|
||||
@@ -331,7 +331,7 @@ fn tracks_are_distinguished() {
|
||||
ReferendumInfo::Ongoing(ReferendumStatus {
|
||||
track: 1,
|
||||
origin: OriginCaller::system(RawOrigin::None),
|
||||
proposal_hash: set_balance_proposal_hash(2),
|
||||
proposal: set_balance_proposal_bounded(2),
|
||||
enactment: DispatchTime::At(20),
|
||||
submitted: 1,
|
||||
submission_deposit: Deposit { who: 2, amount: 2 },
|
||||
@@ -350,13 +350,13 @@ fn tracks_are_distinguished() {
|
||||
#[test]
|
||||
fn submit_errors_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let h = set_balance_proposal_hash(1);
|
||||
let h = set_balance_proposal_bounded(1);
|
||||
// No track for Signed origins.
|
||||
assert_noop!(
|
||||
Referenda::submit(
|
||||
RuntimeOrigin::signed(1),
|
||||
Box::new(RawOrigin::Signed(2).into()),
|
||||
h,
|
||||
h.clone(),
|
||||
DispatchTime::At(10),
|
||||
),
|
||||
Error::<Test>::NoTrack
|
||||
@@ -381,7 +381,7 @@ fn decision_deposit_errors_work() {
|
||||
let e = Error::<Test>::NotOngoing;
|
||||
assert_noop!(Referenda::place_decision_deposit(RuntimeOrigin::signed(2), 0), e);
|
||||
|
||||
let h = set_balance_proposal_hash(1);
|
||||
let h = set_balance_proposal_bounded(1);
|
||||
assert_ok!(Referenda::submit(
|
||||
RuntimeOrigin::signed(1),
|
||||
Box::new(RawOrigin::Root.into()),
|
||||
@@ -403,7 +403,7 @@ fn refund_deposit_works() {
|
||||
let e = Error::<Test>::BadReferendum;
|
||||
assert_noop!(Referenda::refund_decision_deposit(RuntimeOrigin::signed(1), 0), e);
|
||||
|
||||
let h = set_balance_proposal_hash(1);
|
||||
let h = set_balance_proposal_bounded(1);
|
||||
assert_ok!(Referenda::submit(
|
||||
RuntimeOrigin::signed(1),
|
||||
Box::new(RawOrigin::Root.into()),
|
||||
@@ -425,7 +425,7 @@ fn refund_deposit_works() {
|
||||
#[test]
|
||||
fn cancel_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let h = set_balance_proposal_hash(1);
|
||||
let h = set_balance_proposal_bounded(1);
|
||||
assert_ok!(Referenda::submit(
|
||||
RuntimeOrigin::signed(1),
|
||||
Box::new(RawOrigin::Root.into()),
|
||||
@@ -444,7 +444,7 @@ fn cancel_works() {
|
||||
#[test]
|
||||
fn cancel_errors_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let h = set_balance_proposal_hash(1);
|
||||
let h = set_balance_proposal_bounded(1);
|
||||
assert_ok!(Referenda::submit(
|
||||
RuntimeOrigin::signed(1),
|
||||
Box::new(RawOrigin::Root.into()),
|
||||
@@ -462,7 +462,7 @@ fn cancel_errors_works() {
|
||||
#[test]
|
||||
fn kill_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let h = set_balance_proposal_hash(1);
|
||||
let h = set_balance_proposal_bounded(1);
|
||||
assert_ok!(Referenda::submit(
|
||||
RuntimeOrigin::signed(1),
|
||||
Box::new(RawOrigin::Root.into()),
|
||||
@@ -482,7 +482,7 @@ fn kill_works() {
|
||||
#[test]
|
||||
fn kill_errors_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let h = set_balance_proposal_hash(1);
|
||||
let h = set_balance_proposal_bounded(1);
|
||||
assert_ok!(Referenda::submit(
|
||||
RuntimeOrigin::signed(1),
|
||||
Box::new(RawOrigin::Root.into()),
|
||||
|
||||
@@ -19,7 +19,10 @@
|
||||
|
||||
use super::*;
|
||||
use codec::{Decode, Encode, EncodeLike, MaxEncodedLen};
|
||||
use frame_support::{traits::schedule::Anon, Parameter};
|
||||
use frame_support::{
|
||||
traits::{schedule::v3::Anon, Bounded},
|
||||
Parameter,
|
||||
};
|
||||
use scale_info::TypeInfo;
|
||||
use sp_arithmetic::{Rounding::*, SignedRounding::*};
|
||||
use sp_runtime::{FixedI64, PerThing, RuntimeDebug};
|
||||
@@ -31,6 +34,7 @@ pub type NegativeImbalanceOf<T, I> = <<T as Config<I>>::Currency as Currency<
|
||||
<T as frame_system::Config>::AccountId,
|
||||
>>::NegativeImbalance;
|
||||
pub type CallOf<T, I> = <T as Config<I>>::RuntimeCall;
|
||||
pub type BoundedCallOf<T, I> = Bounded<<T as Config<I>>::RuntimeCall>;
|
||||
pub type VotesOf<T, I> = <T as Config<I>>::Votes;
|
||||
pub type TallyOf<T, I> = <T as Config<I>>::Tally;
|
||||
pub type PalletsOriginOf<T> =
|
||||
@@ -39,7 +43,7 @@ pub type ReferendumInfoOf<T, I> = ReferendumInfo<
|
||||
TrackIdOf<T, I>,
|
||||
PalletsOriginOf<T>,
|
||||
<T as frame_system::Config>::BlockNumber,
|
||||
<T as frame_system::Config>::Hash,
|
||||
BoundedCallOf<T, I>,
|
||||
BalanceOf<T, I>,
|
||||
TallyOf<T, I>,
|
||||
<T as frame_system::Config>::AccountId,
|
||||
@@ -49,7 +53,7 @@ pub type ReferendumStatusOf<T, I> = ReferendumStatus<
|
||||
TrackIdOf<T, I>,
|
||||
PalletsOriginOf<T>,
|
||||
<T as frame_system::Config>::BlockNumber,
|
||||
<T as frame_system::Config>::Hash,
|
||||
BoundedCallOf<T, I>,
|
||||
BalanceOf<T, I>,
|
||||
TallyOf<T, I>,
|
||||
<T as frame_system::Config>::AccountId,
|
||||
@@ -160,7 +164,7 @@ pub struct ReferendumStatus<
|
||||
TrackId: Eq + PartialEq + Debug + Encode + Decode + TypeInfo + Clone,
|
||||
RuntimeOrigin: Eq + PartialEq + Debug + Encode + Decode + TypeInfo + Clone,
|
||||
Moment: Parameter + Eq + PartialEq + Debug + Encode + Decode + TypeInfo + Clone + EncodeLike,
|
||||
Hash: Eq + PartialEq + Debug + Encode + Decode + TypeInfo + Clone,
|
||||
Call: Eq + PartialEq + Debug + Encode + Decode + TypeInfo + Clone,
|
||||
Balance: Eq + PartialEq + Debug + Encode + Decode + TypeInfo + Clone,
|
||||
Tally: Eq + PartialEq + Debug + Encode + Decode + TypeInfo + Clone,
|
||||
AccountId: Eq + PartialEq + Debug + Encode + Decode + TypeInfo + Clone,
|
||||
@@ -171,7 +175,7 @@ pub struct ReferendumStatus<
|
||||
/// The origin for this referendum.
|
||||
pub(crate) origin: RuntimeOrigin,
|
||||
/// The hash of the proposal up for referendum.
|
||||
pub(crate) proposal_hash: Hash,
|
||||
pub(crate) proposal: Call,
|
||||
/// The time the proposal should be scheduled for enactment.
|
||||
pub(crate) enactment: DispatchTime<Moment>,
|
||||
/// The time of submission. Once `UndecidingTimeout` passes, it may be closed by anyone if it
|
||||
@@ -197,7 +201,7 @@ pub enum ReferendumInfo<
|
||||
TrackId: Eq + PartialEq + Debug + Encode + Decode + TypeInfo + Clone,
|
||||
RuntimeOrigin: Eq + PartialEq + Debug + Encode + Decode + TypeInfo + Clone,
|
||||
Moment: Eq + PartialEq + Debug + Encode + Decode + TypeInfo + Clone + EncodeLike,
|
||||
Hash: Eq + PartialEq + Debug + Encode + Decode + TypeInfo + Clone,
|
||||
Call: Eq + PartialEq + Debug + Encode + Decode + TypeInfo + Clone,
|
||||
Balance: Eq + PartialEq + Debug + Encode + Decode + TypeInfo + Clone,
|
||||
Tally: Eq + PartialEq + Debug + Encode + Decode + TypeInfo + Clone,
|
||||
AccountId: Eq + PartialEq + Debug + Encode + Decode + TypeInfo + Clone,
|
||||
@@ -209,7 +213,7 @@ pub enum ReferendumInfo<
|
||||
TrackId,
|
||||
RuntimeOrigin,
|
||||
Moment,
|
||||
Hash,
|
||||
Call,
|
||||
Balance,
|
||||
Tally,
|
||||
AccountId,
|
||||
@@ -232,12 +236,12 @@ impl<
|
||||
TrackId: Eq + PartialEq + Debug + Encode + Decode + TypeInfo + Clone,
|
||||
RuntimeOrigin: Eq + PartialEq + Debug + Encode + Decode + TypeInfo + Clone,
|
||||
Moment: Parameter + Eq + PartialEq + Debug + Encode + Decode + TypeInfo + Clone + EncodeLike,
|
||||
Hash: Eq + PartialEq + Debug + Encode + Decode + TypeInfo + Clone,
|
||||
Call: Eq + PartialEq + Debug + Encode + Decode + TypeInfo + Clone,
|
||||
Balance: Eq + PartialEq + Debug + Encode + Decode + TypeInfo + Clone,
|
||||
Tally: Eq + PartialEq + Debug + Encode + Decode + TypeInfo + Clone,
|
||||
AccountId: Eq + PartialEq + Debug + Encode + Decode + TypeInfo + Clone,
|
||||
ScheduleAddress: Eq + PartialEq + Debug + Encode + Decode + TypeInfo + Clone,
|
||||
> ReferendumInfo<TrackId, RuntimeOrigin, Moment, Hash, Balance, Tally, AccountId, ScheduleAddress>
|
||||
> ReferendumInfo<TrackId, RuntimeOrigin, Moment, Call, Balance, Tally, AccountId, ScheduleAddress>
|
||||
{
|
||||
/// Take the Decision Deposit from `self`, if there is one. Returns an `Err` if `self` is not
|
||||
/// in a valid state for the Decision Deposit to be refunded.
|
||||
|
||||
Reference in New Issue
Block a user