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
@@ -94,6 +94,12 @@ pub trait TryDrop: Sized {
fn try_drop(self) -> Result<(), Self>;
}
impl TryDrop for () {
fn try_drop(self) -> Result<(), Self> {
Ok(())
}
}
/// Return type used when we need to return one of two items, each of the opposite direction or
/// sign, with one (`Same`) being of the same type as the `self` or primary argument of the function
/// that returned it.
@@ -577,6 +583,65 @@ impl<T: TypeInfo + 'static> TypeInfo for WrapperKeepOpaque<T> {
}
}
/// A interface for looking up preimages from their hash on chain.
pub trait PreimageProvider<Hash> {
/// Returns whether a preimage exists for a given hash.
///
/// A value of `true` implies that `get_preimage` is `Some`.
fn have_preimage(hash: &Hash) -> bool;
/// Returns the preimage for a given hash.
fn get_preimage(hash: &Hash) -> Option<Vec<u8>>;
/// Returns whether a preimage request exists for a given hash.
fn preimage_requested(hash: &Hash) -> bool;
/// Request that someone report a preimage. Providers use this to optimise the economics for
/// preimage reporting.
fn request_preimage(hash: &Hash);
/// Cancel a previous preimage request.
fn unrequest_preimage(hash: &Hash);
}
impl<Hash> PreimageProvider<Hash> for () {
fn have_preimage(_: &Hash) -> bool {
false
}
fn get_preimage(_: &Hash) -> Option<Vec<u8>> {
None
}
fn preimage_requested(_: &Hash) -> bool {
false
}
fn request_preimage(_: &Hash) {}
fn unrequest_preimage(_: &Hash) {}
}
/// A interface for managing preimages to hashes on chain.
///
/// Note that this API does not assume any underlying user is calling, and thus
/// does not handle any preimage ownership or fees. Other system level logic that
/// uses this API should implement that on their own side.
pub trait PreimageRecipient<Hash>: PreimageProvider<Hash> {
/// Maximum size of a preimage.
type MaxSize: Get<u32>;
/// Store the bytes of a preimage on chain.
fn note_preimage(bytes: crate::BoundedVec<u8, Self::MaxSize>);
/// Clear a previously noted preimage. This is infallible and should be treated more like a
/// hint - if it was not previously noted or if it is now requested, then this will not do
/// anything.
fn unnote_preimage(hash: &Hash);
}
impl<Hash> PreimageRecipient<Hash> for () {
type MaxSize = ();
fn note_preimage(_: crate::BoundedVec<u8, Self::MaxSize>) {}
fn unnote_preimage(_: &Hash) {}
}
#[cfg(test)]
mod test {
use super::*;