Preimage registrar and Scheduler integration (#10356)

* initial idea

* more

* fix compile

* add clear and request logic

* improve some docs

* Add and implement trait

* continuing to improve

* refcount type

* infallible system preimage upload

* fmt

* fix requests

* Make it simple

* Make it simple

* Formatting

* Initial draft

* request when scheduled

* Docs

* Scheduler good

* Scheduler good

* Scheduler tests working

* Add new files

* Missing stuff

* Repotting, add weights.

* Add some tests to preimage pallet

* More tests

* Fix benchmarks

* preimage benchmarks

* All preimage benchmarks

* Tidy cargo

* Update weights.rs

* Allow hash provision in benchmarks

* Initial work on new benchmarks for Scheduler

* Tests working, refactor looks good

* Tests for new Scheduler functionality

* Use real weight, make tests work with runtimes without Preimage

* Rename

* Update benchmarks

* Formatting

* Formatting

* Fix weird formatting

* Update frame/preimage/src/lib.rs

* Fix try-runtime build

* Fixes

* Fixes

* Update frame/support/src/traits/tokens/currency.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Update frame/support/src/traits/tokens/currency/reservable.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Update frame/support/src/traits/tokens/imbalance.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Update frame/preimage/src/mock.rs

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Update frame/scheduler/src/lib.rs

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Update frame/preimage/src/lib.rs

* Fixes

* Fixes

* Formatting

* Fixes

* Fixes

* cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_scheduler --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/scheduler/src/weights.rs --template=./.maintain/frame-weight-template.hbs

* cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_preimage --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/preimage/src/weights.rs --template=./.maintain/frame-weight-template.hbs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
Co-authored-by: Parity Bot <admin@parity.io>
This commit is contained in:
Gavin Wood
2021-12-11 15:55:23 +01:00
committed by GitHub
parent f6f58f95e1
commit 5e50e0bc2c
24 changed files with 3592 additions and 1287 deletions
@@ -199,3 +199,91 @@ pub trait Currency<AccountId> {
balance: Self::Balance,
) -> SignedImbalance<Self::Balance, Self::PositiveImbalance>;
}
#[cfg(feature = "std")]
impl<AccountId> Currency<AccountId> for () {
type Balance = u32;
type PositiveImbalance = ();
type NegativeImbalance = ();
fn total_balance(_: &AccountId) -> Self::Balance {
0
}
fn can_slash(_: &AccountId, _: Self::Balance) -> bool {
true
}
fn total_issuance() -> Self::Balance {
0
}
fn minimum_balance() -> Self::Balance {
0
}
fn burn(_: Self::Balance) -> Self::PositiveImbalance {
()
}
fn issue(_: Self::Balance) -> Self::NegativeImbalance {
()
}
fn pair(_: Self::Balance) -> (Self::PositiveImbalance, Self::NegativeImbalance) {
((), ())
}
fn free_balance(_: &AccountId) -> Self::Balance {
0
}
fn ensure_can_withdraw(
_: &AccountId,
_: Self::Balance,
_: WithdrawReasons,
_: Self::Balance,
) -> DispatchResult {
Ok(())
}
fn transfer(
_: &AccountId,
_: &AccountId,
_: Self::Balance,
_: ExistenceRequirement,
) -> DispatchResult {
Ok(())
}
fn slash(_: &AccountId, _: Self::Balance) -> (Self::NegativeImbalance, Self::Balance) {
((), 0)
}
fn deposit_into_existing(
_: &AccountId,
_: Self::Balance,
) -> Result<Self::PositiveImbalance, DispatchError> {
Ok(())
}
fn resolve_into_existing(
_: &AccountId,
_: Self::NegativeImbalance,
) -> Result<(), Self::NegativeImbalance> {
Ok(())
}
fn deposit_creating(_: &AccountId, _: Self::Balance) -> Self::PositiveImbalance {
()
}
fn resolve_creating(_: &AccountId, _: Self::NegativeImbalance) {}
fn withdraw(
_: &AccountId,
_: Self::Balance,
_: WithdrawReasons,
_: ExistenceRequirement,
) -> Result<Self::NegativeImbalance, DispatchError> {
Ok(())
}
fn settle(
_: &AccountId,
_: Self::PositiveImbalance,
_: WithdrawReasons,
_: ExistenceRequirement,
) -> Result<(), Self::PositiveImbalance> {
Ok(())
}
fn make_free_balance_be(
_: &AccountId,
_: Self::Balance,
) -> SignedImbalance<Self::Balance, Self::PositiveImbalance> {
SignedImbalance::Positive(())
}
}
@@ -81,6 +81,33 @@ pub trait ReservableCurrency<AccountId>: Currency<AccountId> {
) -> Result<Self::Balance, DispatchError>;
}
#[cfg(feature = "std")]
impl<AccountId> ReservableCurrency<AccountId> for () {
fn can_reserve(_: &AccountId, _: Self::Balance) -> bool {
true
}
fn slash_reserved(_: &AccountId, _: Self::Balance) -> (Self::NegativeImbalance, Self::Balance) {
((), 0)
}
fn reserved_balance(_: &AccountId) -> Self::Balance {
0
}
fn reserve(_: &AccountId, _: Self::Balance) -> DispatchResult {
Ok(())
}
fn unreserve(_: &AccountId, _: Self::Balance) -> Self::Balance {
0
}
fn repatriate_reserved(
_: &AccountId,
_: &AccountId,
_: Self::Balance,
_: BalanceStatus,
) -> Result<Self::Balance, DispatchError> {
Ok(0)
}
}
pub trait NamedReservableCurrency<AccountId>: ReservableCurrency<AccountId> {
/// An identifier for a reserve. Used for disambiguating different reserves so that
/// they can be individually replaced or removed.
@@ -177,3 +177,55 @@ pub trait Imbalance<Balance>: Sized + TryDrop + Default {
/// The raw value of self.
fn peek(&self) -> Balance;
}
#[cfg(feature = "std")]
impl<Balance: Default> Imbalance<Balance> for () {
type Opposite = ();
fn zero() -> Self {
()
}
fn drop_zero(self) -> Result<(), Self> {
Ok(())
}
fn split(self, _: Balance) -> (Self, Self) {
((), ())
}
fn ration(self, _: u32, _: u32) -> (Self, Self)
where
Balance: From<u32> + Saturating + Div<Output = Balance>,
{
((), ())
}
fn split_merge(self, _: Balance, _: (Self, Self)) -> (Self, Self) {
((), ())
}
fn ration_merge(self, _: u32, _: u32, _: (Self, Self)) -> (Self, Self)
where
Balance: From<u32> + Saturating + Div<Output = Balance>,
{
((), ())
}
fn split_merge_into(self, _: Balance, _: &mut (Self, Self)) {}
fn ration_merge_into(self, _: u32, _: u32, _: &mut (Self, Self))
where
Balance: From<u32> + Saturating + Div<Output = Balance>,
{
}
fn merge(self, _: Self) -> Self {
()
}
fn merge_into(self, _: &mut Self) {}
fn maybe_merge(self, _: Option<Self>) -> Self {
()
}
fn subsume(&mut self, _: Self) {}
fn maybe_subsume(&mut self, _: Option<Self>) {
()
}
fn offset(self, _: Self::Opposite) -> SameOrOther<Self, Self::Opposite> {
SameOrOther::None
}
fn peek(&self) -> Balance {
Default::default()
}
}