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:
Gavin Wood
2022-10-05 19:21:37 +01:00
committed by GitHub
parent 24f0c3601c
commit 93e8ffed55
67 changed files with 5089 additions and 3488 deletions
+58 -46
View File
@@ -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,