While `sp-api-proc-macro` isn't used directly and thus, it should have
the same features enabled as `sp-api`. However, I have seen issues
around `frame-metadata` not being enabled for `sp-api`, but for
`sp-api-proc-macro`. This can be prevented by using the
`frame_metadata_enabled` macro from `sp-api` that ensures we have the
same feature set between both crates.
This MR is the merge of
https://github.com/paritytech/substrate/pull/14414 and
https://github.com/paritytech/substrate/pull/14275. It implements
[RFC#13](https://github.com/polkadot-fellows/RFCs/pull/13), closes
https://github.com/paritytech/polkadot-sdk/issues/198.
-----
This Merge request introduces three major topicals:
1. Multi-Block-Migrations
1. New pallet `poll` hook for periodic service work
1. Replacement hooks for `on_initialize` and `on_finalize` in cases
where `poll` cannot be used
and some more general changes to FRAME.
The changes for each topical span over multiple crates. They are listed
in topical order below.
# 1.) Multi-Block-Migrations
Multi-Block-Migrations are facilitated by creating `pallet_migrations`
and configuring `System::Config::MultiBlockMigrator` to point to it.
Executive picks this up and triggers one step of the migrations pallet
per block.
The chain is in lockdown mode for as long as an MBM is ongoing.
Executive does this by polling `MultiBlockMigrator::ongoing` and not
allowing any transaction in a block, if true.
A MBM is defined through trait `SteppedMigration`. A condensed version
looks like this:
```rust
/// A migration that can proceed in multiple steps.
pub trait SteppedMigration {
type Cursor: FullCodec + MaxEncodedLen;
type Identifier: FullCodec + MaxEncodedLen;
fn id() -> Self::Identifier;
fn max_steps() -> Option<u32>;
fn step(
cursor: Option<Self::Cursor>,
meter: &mut WeightMeter,
) -> Result<Option<Self::Cursor>, SteppedMigrationError>;
}
```
`pallet_migrations` can be configured with an aggregated tuple of these
migrations. It then starts to migrate them one-by-one on the next
runtime upgrade.
Two things are important here:
- 1. Doing another runtime upgrade while MBMs are ongoing is not a good
idea and can lead to messed up state.
- 2. **Pallet Migrations MUST BE CONFIGURED IN `System::Config`,
otherwise it is not used.**
The pallet supports an `UpgradeStatusHandler` that can be used to notify
external logic of upgrade start/finish (for example to pause XCM
dispatch).
Error recovery is very limited in the case that a migration errors or
times out (exceeds its `max_steps`). Currently the runtime dev can
decide in `FailedMigrationHandler::failed` how to handle this. One
follow-up would be to pair this with the `SafeMode` pallet and enact
safe mode when an upgrade fails, to allow governance to rescue the
chain. This is currently not possible, since governance is not
`Mandatory`.
## Runtime API
- `Core`: `initialize_block` now returns `ExtrinsicInclusionMode` to
inform the Block Author whether they can push transactions.
### Integration
Add it to your runtime implementation of `Core` and `BlockBuilder`:
```patch
diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs
@@ impl_runtime_apis! {
impl sp_block_builder::Core<Block> for Runtime {
- fn initialize_block(header: &<Block as BlockT>::Header) {
+ fn initialize_block(header: &<Block as BlockT>::Header) -> RuntimeExecutiveMode {
Executive::initialize_block(header)
}
...
}
```
# 2.) `poll` hook
A new pallet hook is introduced: `poll`. `Poll` is intended to replace
mostly all usage of `on_initialize`.
The reason for this is that any code that can be called from
`on_initialize` cannot be migrated through an MBM. Currently there is no
way to statically check this; the implication is to use `on_initialize`
as rarely as possible.
Failing to do so can result in broken storage invariants.
The implementation of the poll hook depends on the `Runtime API` changes
that are explained above.
# 3.) Hard-Deadline callbacks
Three new callbacks are introduced and configured on `System::Config`:
`PreInherents`, `PostInherents` and `PostTransactions`.
These hooks are meant as replacement for `on_initialize` and
`on_finalize` in cases where the code that runs cannot be moved to
`poll`.
The reason for this is to make the usage of HD-code (hard deadline) more
explicit - again to prevent broken invariants by MBMs.
# 4.) FRAME (general changes)
## `frame_system` pallet
A new memorize storage item `InherentsApplied` is added. It is used by
executive to track whether inherents have already been applied.
Executive and can then execute the MBMs directly between inherents and
transactions.
The `Config` gets five new items:
- `SingleBlockMigrations` this is the new way of configuring migrations
that run in a single block. Previously they were defined as last generic
argument of `Executive`. This shift is brings all central configuration
about migrations closer into view of the developer (migrations that are
configured in `Executive` will still work for now but is deprecated).
- `MultiBlockMigrator` this can be configured to an engine that drives
MBMs. One example would be the `pallet_migrations`. Note that this is
only the engine; the exact MBMs are injected into the engine.
- `PreInherents` a callback that executes after `on_initialize` but
before inherents.
- `PostInherents` a callback that executes after all inherents ran
(including MBMs and `poll`).
- `PostTransactions` in symmetry to `PreInherents`, this one is called
before `on_finalize` but after all transactions.
A sane default is to set all of these to `()`. Example diff suitable for
any chain:
```patch
@@ impl frame_system::Config for Test {
type MaxConsumers = ConstU32<16>;
+ type SingleBlockMigrations = ();
+ type MultiBlockMigrator = ();
+ type PreInherents = ();
+ type PostInherents = ();
+ type PostTransactions = ();
}
```
An overview of how the block execution now looks like is here. The same
graph is also in the rust doc.
<details><summary>Block Execution Flow</summary>
<p>

</p>
</details>
## Inherent Order
Moved to https://github.com/paritytech/polkadot-sdk/pull/2154
---------------
## TODO
- [ ] Check that `try-runtime` still works
- [ ] Ensure backwards compatibility with old Runtime APIs
- [x] Consume weight correctly
- [x] Cleanup
---------
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
Co-authored-by: Juan Girini <juangirini@gmail.com>
Co-authored-by: command-bot <>
Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com>
Co-authored-by: Gavin Wood <gavin@parity.io>
Co-authored-by: Bastian Köcher <git@kchr.de>
This PR adds initial support for building RISC-V runtimes targeting
PolkaVM.
- Setting the `SUBSTRATE_RUNTIME_TARGET=riscv` environment variable will
now build a RISC-V runtime instead of a WASM runtime.
- This only adds support for *building* runtimes; running them will need
a PolkaVM-based executor, which I will add in a future PR.
- Only building the minimal runtime is supported (building the Polkadot
runtime doesn't work *yet* due to one of the dependencies).
- The builder now sets a `substrate_runtime` cfg flag when building the
runtimes, with the idea being that instead of doing `#[cfg(not(feature =
"std"))]` or `#[cfg(target_arch = "wasm32")]` to detect that we're
building a runtime you'll do `#[cfg(substrate_runtime)]`. (Switching the
whole codebase to use this will be done in a future PR; I deliberately
didn't do this here to keep this PR minimal and reviewable.)
- Further renaming of things (e.g. types, environment variables and proc
macro attributes having "wasm" in their name) to be target-agnostic will
also be done in a future refactoring PR (while keeping backwards
compatibility where it makes sense; I don't intend to break anyone's
workflow or create unnecessary churn).
- This PR also fixes two bugs in the `wasm-builder` crate:
* The `RUSTC` environment variable is now removed when invoking the
compiler. This prevents the toolchain version from being overridden when
called from a `build.rs` script.
* When parsing the `rustup toolchain list` output the `(default)` is now
properly stripped and not treated as part of the version.
- I've also added a minimal CI job that makes sure this doesn't break in
the future. (cc @paritytech/ci)
cc @athei
------
Also, just a fun little tidbit: quickly comparing the size of the built
runtimes it seems that the PolkaVM runtime is slightly smaller than the
WASM one. (`production` build, with the `names` section substracted from
the WASM's size to keep things fair, since for the PolkaVM runtime we're
currently stripping out everything)
- `.wasm`: 625505 bytes
- `.wasm` (after wasm-opt -O3): 563205 bytes
- `.wasm` (after wasm-opt -Os): 562987 bytes
- `.wasm` (after wasm-opt -Oz): 536852 bytes
- `.polkavm`: ~~580338 bytes~~ 550476 bytes (after enabling extra target
features; I'll add those in another PR once we have an executor working)
---------
Co-authored-by: Bastian Köcher <git@kchr.de>
This moves the macro related re-exports to `__private` to make it more
obvious for downstream users that they are using an internal api.
---------
Co-authored-by: command-bot <>
The `BlockBuilderProvider` was a trait that was defined in
`sc-block-builder`. The trait was implemented for `Client`. This
basically meant that you needed to import `sc-block-builder` any way to
have access to the block builder. So, this trait was not providing any
real value. This pull request is removing the said trait. Instead of the
trait it introduces a builder for creating a `BlockBuilder`. The builder
currently has the quite fabulous name `BlockBuilderBuilder` (I'm open to
any better name 😅). The rest of the pull request is about
replacing the old trait with the new builder.
# Downstream code changes
If you used `new_block` or `new_block_at` before you now need to switch
it over to the new `BlockBuilderBuilder` pattern:
```rust
// `new` requires a type that implements `CallApiAt`.
let mut block_builder = BlockBuilderBuilder::new(client)
// Then you need to specify the hash of the parent block the block will be build on top of
.on_parent_block(at)
// The block builder also needs the block number of the parent block.
// Here it is fetched from the given `client` using the `HeaderBackend`
// However, there also exists `with_parent_block_number` for directly passing the number
.fetch_parent_block_number(client)
.unwrap()
// Enable proof recording if required. This call is optional.
.enable_proof_recording()
// Pass the digests. This call is optional.
.with_inherent_digests(digests)
.build()
.expect("Creates new block builder");
```
---------
Co-authored-by: Sebastian Kunert <skunert49@gmail.com>
Co-authored-by: command-bot <>
* Start
* More work!
* Moar
* More changes
* More fixes
* More worrk
* More fixes
* More fixes to make it compile
* Adds `NoOffchainStorage`
* Pass the extensions
* Small basti making small progress
* Fix merge errors and remove `ExecutionContext`
* Move registration of `ReadRuntimeVersionExt` to `ExecutionExtension`
Instead of registering `ReadRuntimeVersionExt` in `sp-state-machine` it is moved to
`ExecutionExtension` which provides the default extensions.
* Fix compilation
* Register the global extensions inside runtime api instance
* Fixes
* Fix `generate_initial_session_keys` by passing the keystore extension
* Fix the grandpa tests
* Fix more tests
* Fix more tests
* Don't set any heap pages if there isn't an override
* Fix small fallout
* FMT
* Fix tests
* More tests
* Offchain worker custom extensions
* More fixes
* Make offchain tx pool creation reusable
Introduces an `OffchainTransactionPoolFactory` for creating offchain transactions pools that can be
registered in the runtime externalities context. This factory will be required for a later pr to
make the creation of offchain transaction pools easier.
* Fixes
* Fixes
* Set offchain transaction pool in BABE before using it in the runtime
* Add the `offchain_tx_pool` to Grandpa as well
* Fix the nodes
* Print some error when using the old warnings
* Fix merge issues
* Fix compilation
* Rename `babe_link`
* Rename to `offchain_tx_pool_factory`
* Cleanup
* FMT
* Fix benchmark name
* Fix `try-runtime`
* Remove `--execution` CLI args
* Make clippy happy
* Forward bls functions
* Fix docs
* Update UI tests
* Update client/api/src/execution_extensions.rs
Co-authored-by: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com>
* Apply suggestions from code review
Co-authored-by: Koute <koute@users.noreply.github.com>
* Update client/cli/src/params/import_params.rs
Co-authored-by: Koute <koute@users.noreply.github.com>
* Update client/api/src/execution_extensions.rs
Co-authored-by: Koute <koute@users.noreply.github.com>
* Pass the offchain storage to the MMR RPC
* Update client/api/src/execution_extensions.rs
Co-authored-by: Sebastian Kunert <skunert49@gmail.com>
* Review comments
* Fixes
---------
Co-authored-by: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com>
Co-authored-by: Koute <koute@users.noreply.github.com>
Co-authored-by: Sebastian Kunert <skunert49@gmail.com>
* sp-api: Make the generated code act based on `std` in `sp-api`
Instead of letting the macro generate code that checks if the `std` feature is enabled, it will now
generate code that checks if the `std` feature is enabled for the `sp-api` crate. The old
implementation basically required that the crate in which the macro was used, had a `std` feature.
Now we don't have this requirement anymore and act accordingly the feature in `sp-api` directly.
* Missing feature!
---------
Co-authored-by: parity-processbot <>
* impl_runtime_apis: Generate getters for `metadata_at` functions
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* runtime: Implement new `Metadata` runtime trait
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* runtime: Move `metadata_at` functions to construct_runtime macro
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* contruct_runtime: Use `OpaqueMetadata` from hidden imports
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* Adjust testing
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/tests: Add tests for the new API
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* primitives/proc-macro: Helper to extract documentation literals
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* primitives/proc-macro: Helper to filter all `cfg` attributes
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* primitives/proc-macro: Generate documentation getters for metadata
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* primitives/proc-macro: Avoid trait collision with snake case methods
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* proc-macro/tests: Check doc getters
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* primitives/proc-macro: Generate metadata for runtime methods
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* primitives/api: Export scale-info and frame-metadata
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* primitives/proc-macro: Generate metadata for runtime traits
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/runtime: Expose metadata v15 internally
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* test: Use metadata v15 from `lexnv/md_v15_test` branch
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* primitives/proc-macro: Generate crate access one module up
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame: Implement `runtime_metadata` for mocks and tests
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* primitives/proc-macro: Fix warnings
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* primitives/proc-macro: Add no-docs flag
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame: Adjust more tests
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/tests: Check runtime metadata correctness
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/benchmarking: Adjust benchmarks
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/benchmarks: Adjust more benchmarks
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* primitives/api: Fix clippy
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* primitives/proc-macro: Generate runtime metadata on the `decl_runtime_apis`
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame: Abuse Deref to resolve `runtime_metadata`
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* Revert "frame: Implement `runtime_metadata` for mocks and tests"
This reverts commit b7f41aa189218589392a6e713ea9488e93c4db45.
Revert "frame: Adjust more tests"
This reverts commit 3cba5982c7f45552e76335e96c430aecbc42d8c6.
Revert "frame/benchmarking: Adjust benchmarks"
This reverts commit 60b382ada486c791ffceeb65da587e949b90ec5d.
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Revert "frame/benchmarks: Adjust more benchmarks"
This reverts commit eb75c477179b1a27347a5554c5732ef26a00d7e8.
* primitives/proc-macro: Remove unused imports and function
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/support: Adjust runtime metadata test
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* primitives/tests: Remove doc getter test
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/support: Enable `no-metadata-docs` feature from `sp-api`
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* primitives/tests: Add `TypeInfo` for test::extrinsic
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* primitives/api: Expose scale-info and frame-metadata
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* Update frame-metadata to include v15
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* Fix merge conflicts
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/metadata_ir: Add IR for runtime API metadata
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/metadata_ir: Convert IR to V15
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* primitives/api: Collect IR metadata for runtime API
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* primitives/api: Move `metadata_ir` from frame/support
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/tests: Adjust testing
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/tests: Adjust `metadata_versions` test
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* primitives/runtime_metadata: Exclude default type parameters from methods
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* Update primitives/api/proc-macro/src/runtime_metadata.rs
Co-authored-by: Bastian Köcher <git@kchr.de>
* Update primitives/api/src/metadata_ir/types.rs
Co-authored-by: Bastian Köcher <git@kchr.de>
* Update primitives/api/src/metadata_ir/mod.rs
Co-authored-by: Bastian Köcher <git@kchr.de>
* Update primitives/api/proc-macro/src/utils.rs
Co-authored-by: Bastian Köcher <git@kchr.de>
* Update primitives/api/proc-macro/src/runtime_metadata.rs
Co-authored-by: Bastian Köcher <git@kchr.de>
* Update primitives/api/proc-macro/src/runtime_metadata.rs
Co-authored-by: Bastian Köcher <git@kchr.de>
* Update primitives/api/proc-macro/src/runtime_metadata.rs
Co-authored-by: Bastian Köcher <git@kchr.de>
* Update primitives/api/proc-macro/src/runtime_metadata.rs
Co-authored-by: Bastian Köcher <git@kchr.de>
* Update primitives/api/proc-macro/src/runtime_metadata.rs
Co-authored-by: Bastian Köcher <git@kchr.de>
* Update primitives/api/proc-macro/src/runtime_metadata.rs
Co-authored-by: Bastian Köcher <git@kchr.de>
* primitives: Fix build
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* primitives/metadata-ir: Move IR to dedicated crate
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* primitives: Reexport metadata-ir and frame-metadata
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame: Use apis field instead of runtime
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* Better documentation for the `Deref` abstraction
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* ui-tests: Check empty `impl_runtime_apis`
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* primitives: Remove unneeded bounds on generic params
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* primitives: Rename `collect_where_bounds` to `get_argument_type_param`
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* primitives: Generate crate access per fn call
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* Revert "primitives: Remove unneeded bounds on generic params"
This reverts commit 5178e38cf21cfb481156eefd628d62989201d59a.
* metadata-ir: Add no-std
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* primitives: Adjust where bounds
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* Change `frame-metadata` branch to "origin/main"
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* Update to `main` from origin
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* Update frame-metadata to crates.io v15.1
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* Revert "ui-tests: Check empty `impl_runtime_apis`"
This reverts commit cf78a7190ad9cba3c3bb2e78dc3d0dc382b2fea9.
* Move ui test to primitives/ui
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* Update frame/support/test/tests/runtime_metadata.rs
Co-authored-by: Bastian Köcher <git@kchr.de>
* Update primitives/api/proc-macro/src/runtime_metadata.rs
Co-authored-by: Bastian Köcher <git@kchr.de>
* Test already covered by `empty_impl_runtime_apis_call.stderr`
This reverts commit 3bafb294cbe9745569bf5e5a1a2e6b4a4c1aadc5.
* Retriger CI
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* Import `TokenStream` as `TokenStream2`
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
---------
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: parity-processbot <>
Co-authored-by: Bastian Köcher <git@kchr.de>
* impl_runtime_apis: Generate getters for `metadata_at` functions
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* runtime: Implement new `Metadata` runtime trait
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* runtime: Move `metadata_at` functions to construct_runtime macro
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* contruct_runtime: Use `OpaqueMetadata` from hidden imports
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* Adjust testing
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/tests: Add tests for the new API
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/tests: Adjust metdata naming
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/support: Expose `metadata-v14` feature flag
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/support: Expose metadata only under feature flags
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/support: Expose v14 metadata by default
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/support: Expose metadata feature for testing
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/support: Test metadata under different feature flags
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* Update primitives/api/src/lib.rs
Co-authored-by: Bastian Köcher <git@kchr.de>
* Update primitives/api/src/lib.rs
Co-authored-by: Bastian Köcher <git@kchr.de>
* client/tests: Adjust testing to reflect trait Metadata change
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/metadata-ir: Add intermediate representation types for metadata
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/metadata-ir: Convert metadata to V14
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/metadata-ir: Add API to convert metadata to multiple versions
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/metadata-ir: Expose V14 under feature flag
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/support: Adjust to metadata IR
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/support: More adjustments
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/support: Guard v14 details under feature flag
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/support: Adjust testing
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* CI: Ensure `quick-benchmarks` uses `metadata-v14`
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/support: Use `metadata-v14` for benchmarks
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* Adjust cargo fmt
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* kitchensink-runtime: Add feature flag for `metadata-v14`
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/support/test: Adjust testing
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/support/test: Check crates locally
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* Activate metadata-v14 for pallets
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* Remove metadata-v14 feature flag
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/metadata_ir: Move `api.rs` to `mod.rs`
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/support: Handle latest metadata conversion via IR
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/tests: Add constant for metadata version 14
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/support/test: Fix merge conflict
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* Update frame/support/Cargo.toml
Co-authored-by: Bastian Köcher <git@kchr.de>
* Update frame/support/src/metadata_ir/mod.rs
Co-authored-by: Bastian Köcher <git@kchr.de>
* Update frame/support/test/Cargo.toml
Co-authored-by: Bastian Köcher <git@kchr.de>
* Update primitives/api/src/lib.rs
Co-authored-by: Bastian Köcher <git@kchr.de>
* frame/metadata: Collect pallet documentation for MetadataIR
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/tests: Check pallet documentation is propagated to MetadataIR
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* frame/support: Improve documentation
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
---------
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: parity-processbot <>
Co-authored-by: Bastian Köcher <git@kchr.de>
* Change copyright year to 2023 from 2022
* Fix incorrect update of copyright year
* Remove years from copy right header
* Fix remaining files
* Fix typo in a header and remove update-copyright.sh
* BlockId removal: refactor of runtime API
It changes the arguments of:
- `ApiExt` methods: `has_api`, `has_api_with`, `api_version`
- `CallApiAt` method: `runtime_version_at`
from: `BlockId<Block>` to: `Block::Hash`
It also changes the first argument of all generated runtime API calls from: `BlockId<Block>` to: `Block::Hash`
This PR is part of BlockId::Number refactoring analysis (paritytech/substrate#11292)
* BlockId removal: refactor of runtime API - tests
- tests adjusted to new runtime API,
- some tests migrated from block number to block hash
* benchmarking-cli: BlockId(0) migrated to info().genesis_hash
`runtime_api.call()` now requires the block hash instead of BlockId::Number.
To access the genesis hash widely used in benchmarking engine the Client
was constrained to satisfy `sp_blockchain::HeaderBackend<Block>` trait
which provides `info().genesis_hash`.
* trivial: api.call(BlockId) -> api.call(Hash)
- Migrated all `runtime_api.calls` to use Hash
- Noteworthy (?):
-- `validate_transaction_blocking` in transaction pool,
* CallApiAtParams::at changed to Block::Hash
* missed doc updated
* Apply suggestions from code review
Co-authored-by: Bastian Köcher <git@kchr.de>
* ".git/.scripts/commands/fmt/fmt.sh"
* BlockId removal: Benchmark::consumed_weight
Little refactor around `Benchmark::consumed_weight`: `BlockId` removed.
* at_hash renamed
* wrong merge fixed
* beefy worker: merged with master
* beefy: tests: missing block problem fixed
* Apply review suggestion
* fix
---------
Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: command-bot <>
* Expose `UnknownBlock` error via `ApiError`
In [certain cases](https://github.com/paritytech/polkadot/issues/5885) a
runtime api is called for an unknown block. For example a block which is
already pruned or on an abandon fork.
In such cases the correct error is returned but it is wrapped in
`ApiError::Application` and the only way to figure out what is the
problem is to inspect the actual message in the error. In polkadot for
example this usually happens when the runtime api version is being
queried. It's beneficial to be able to clearly separate such errors so i
that when they occur the client side can handle them more gracefully.
E.g. log less stressful error message than `State already discarded for
BlockId` or cancel any pending work related on this block.
* Update primitives/api/src/lib.rs
Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: Bastian Köcher <git@kchr.de>
* Remove native call
With the recent introduction of staging runtime apis the native call wasn't supported anymore. This
removes the entire support for this as it is not used anymore.
* FMT
* Fix benchmarks
* FIX ui tests
* trie state cache
* Also cache missing access on read.
* fix comp
* bis
* fix
* use has_lru
* remove local storage cache on size 0.
* No cache.
* local cache only
* trie cache and local cache
* storage cache (with local)
* trie cache no local cache
* Add state access benchmark
* Remove warnings etc
* Add trie cache benchmark
* No extra "clone" required
* Change benchmark to use multiple blocks
* Use patches
* Integrate shitty implementation
* More stuff
* Revert "Merge branch 'master' into trie_state_cache"
This reverts commit 947cd8e6d43fced10e21b76d5b92ffa57b57c318, reversing
changes made to 29ff036463.
* Improve benchmark
* Adapt to latest changes
* Adapt to changes in trie
* Add a test that uses iterator
* Start fixing it
* Remove obsolete file
* Make it compile
* Start rewriting the trie node cache
* More work on the cache
* More docs and code etc
* Make data cache an optional
* Tests
* Remove debug stuff
* Recorder
* Some docs and a simple test for the recorder
* Compile fixes
* Make it compile
* More fixes
* More fixes
* Fix fix fix
* Make sure cache and recorder work together for basic stuff
* Test that data caching and recording works
* Test `TrieDBMut` with caching
* Try something
* Fixes, fixes, fixes
* Forward the recorder
* Make it compile
* Use recorder in more places
* Switch to new `with_optional_recorder` fn
* Refactor and cleanups
* Move `ProvingBackend` tests
* Simplify
* Move over all functionality to the essence
* Fix compilation
* Implement estimate encoded size for StorageProof
* Start using the `cache` everywhere
* Use the cache everywhere
* Fix compilation
* Fix tests
* Adds `TrieBackendBuilder` and enhances the tests
* Ensure that recorder drain checks that values are found as expected
* Switch over to `TrieBackendBuilder`
* Start fixing the problem with child tries and recording
* Fix recording of child tries
* Make it compile
* Overwrite `storage_hash` in `TrieBackend`
* Add `storage_cache` to the benchmarks
* Fix `no_std` build
* Speed up cache lookup
* Extend the state access benchmark to also hash a runtime
* Fix build
* Fix compilation
* Rewrite value cache
* Add lru cache
* Ensure that the cache lru works
* Value cache should not be optional
* Add support for keeping the shared node cache in its bounds
* Make the cache configurable
* Check that the cache respects the bounds
* Adds a new test
* Fixes
* Docs and some renamings
* More docs
* Start using the new recorder
* Fix more code
* Take `self` argument
* Remove warnings
* Fix benchmark
* Fix accounting
* Rip off the state cache
* Start fixing fallout after removing the state cache
* Make it compile after trie changes
* Fix test
* Add some logging
* Some docs
* Some fixups and clean ups
* Fix benchmark
* Remove unneeded file
* Use git for patching
* Make CI happy
* Update primitives/trie/Cargo.toml
Co-authored-by: Koute <koute@users.noreply.github.com>
* Update primitives/state-machine/src/trie_backend.rs
Co-authored-by: cheme <emericchevalier.pro@gmail.com>
* Introduce new `AsTrieBackend` trait
* Make the LocalTrieCache not clonable
* Make it work in no_std and add docs
* Remove duplicate dependency
* Switch to ahash for better performance
* Speedup value cache merge
* Output errors on underflow
* Ensure the internal LRU map doesn't grow too much
* Use const fn to calculate the value cache element size
* Remove cache configuration
* Fix
* Clear the cache in between for more testing
* Try to come up with a failing test case
* Make the test fail
* Fix the child trie recording
* Make everything compile after the changes to trie
* Adapt to latest trie-db changes
* Fix on stable
* Update primitives/trie/src/cache.rs
Co-authored-by: cheme <emericchevalier.pro@gmail.com>
* Fix wrong merge
* Docs
* Fix warnings
* Cargo.lock
* Bump pin-project
* Fix warnings
* Switch to released crate version
* More fixes
* Make clippy and rustdocs happy
* More clippy
* Print error when using deprecated `--state-cache-size`
* 🤦
* Fixes
* Fix storage_hash linkings
* Update client/rpc/src/dev/mod.rs
Co-authored-by: Arkadiy Paronyan <arkady.paronyan@gmail.com>
* Review feedback
* encode bound
* Rework the shared value cache
Instead of using a `u64` to represent the key we now use an `Arc<[u8]>`. This arc is also stored in
some extra `HashSet`. We store the key are in an extra `HashSet` to de-duplicate the keys accross
different storage roots. When the latest key usage is dropped in the lru, we also remove the key
from the `HashSet`.
* Improve of the cache by merging the old and new solution
* FMT
* Please stop coming back all the time :crying:
* Update primitives/trie/src/cache/shared_cache.rs
Co-authored-by: Arkadiy Paronyan <arkady.paronyan@gmail.com>
* Fixes
* Make clippy happy
* Ensure we don't deadlock
* Only use one lock to simplify the code
* Do not depend on `Hasher`
* Fix tests
* FMT
* Clippy 🤦
Co-authored-by: cheme <emericchevalier.pro@gmail.com>
Co-authored-by: Koute <koute@users.noreply.github.com>
Co-authored-by: Arkadiy Paronyan <arkady.paronyan@gmail.com>
* Runtime API versioning
Related to issue #11577
Add support for multiple versions of a Runtime API. The purpose is to
have one main version of the API, which is considered stable and
multiple unstable (aka staging) ones.
How it works
===========
Some methods of the API trait can be tagged with `#[api_version(N)]`
attribute where N is version number bigger than the main one. Let's call
them **staging methods** for brevity.
The implementor of the API decides which version to implement.
Example (from https://github.com/paritytech/substrate/issues/11577#issuecomment-1145347025):
```
decl_runtime_apis! {
#{api_version(10)]
trait Test {
fn something() -> Vec<u8>;
#[api_version(11)]
fn new_cool_function() -> u32;
}
}
```
```
impl_runtime_apis! {
#[api_version(11)]
impl Test for Runtime {
fn something() -> Vec<u8> { vec![1, 2, 3] }
fn new_cool_function() -> u32 {
10
}
}
}
```
Version safety checks (currently not implemented)
=================================================
By default in the API trait all staging methods has got default
implementation calling `unimplemented!()`. This is a problem because if
the developer wants to implement version 11 in the example above and
forgets to add `fn new_cool_function()` in `impl_runtime_apis!` the
runtime will crash when the function is executed.
Ideally a compilation error should be generated in such cases.
TODOs
=====
Things not working well at the moment:
[ ] Version safety check
[ ] Integration tests of `primitives/api` are messed up a bit. More
specifically `primitives/api/test/tests/decl_and_impl.rs`
[ ] Integration test covering the new functionality.
[ ] Some duplicated code
* Update primitives/api/proc-macro/src/impl_runtime_apis.rs
Code review feedback and formatting
Co-authored-by: asynchronous rob <rphmeier@gmail.com>
* Code review feedback
Applying suggestions from @bkchr
* fmt
* Apply suggestions from code review
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* Code review feedback
* dummy trait -> versioned trait
* Implement only versioned traits (not compiling)
* Remove native API calls (still not compiling)
* fmt
* Fix compilation
* Comments
* Remove unused code
* Remove native runtime tests
* Remove unused code
* Fix UI tests
* Code review feedback
* Code review feedback
* attribute_names -> common
* Rework `append_api_version`
* Code review feedback
* Apply suggestions from code review
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* Code review feedback
* Code review feedback
* Code review feedback
* Use type alias for the default trait - doesn't compile
* Fixes
* Better error for `method_api_ver < trait_api_version`
* fmt
* Rework how we call runtime functions
* Update UI tests
* Fix warnings
* Fix doctests
* Apply suggestions from code review
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* Apply suggestions from code review
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* Fix formatting and small compilation errors
* Update primitives/api/proc-macro/src/impl_runtime_apis.rs
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Co-authored-by: asynchronous rob <rphmeier@gmail.com>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Co-authored-by: Bastian Köcher <info@kchr.de>
* starting
* Updated from other branch.
* setting flag
* flag in storage struct
* fix flagging to access and insert.
* added todo to fix
* also missing serialize meta to storage proof
* extract meta.
* Isolate old trie layout.
* failing test that requires storing in meta when old hash scheme is used.
* old hash compatibility
* Db migrate.
* runing tests with both states when interesting.
* fix chain spec test with serde default.
* export state (missing trie function).
* Pending using new branch, lacking genericity on layout resolution.
* extract and set global meta
* Update to branch 4
* fix iterator with root flag (no longer insert node).
* fix trie root hashing of root
* complete basic backend.
* Remove old_hash meta from proof that do not use inner_hashing.
* fix trie test for empty (force layout on empty deltas).
* Root update fix.
* debug on meta
* Use trie key iteration that do not include value in proofs.
* switch default test ext to use inner hash.
* small integration test, and fix tx cache mgmt in ext.
test failing
* Proof scenario at state-machine level.
* trace for db upgrade
* try different param
* act more like iter_from.
* Bigger batches.
* Update trie dependency.
* drafting codec changes and refact
* before removing unused branch no value alt hashing.
more work todo rename all flag var to alt_hash, and remove extrinsic
replace by storage query at every storage_root call.
* alt hashing only for branch with value.
* fix trie tests
* Hash of value include the encoded size.
* removing fields(broken)
* fix trie_stream to also include value length in inner hash.
* triedbmut only using alt type if inner hashing.
* trie_stream to also only use alt hashing type when actually alt hashing.
* Refactor meta state, logic should work with change of trie treshold.
* Remove NoMeta variant.
* Remove state_hashed trigger specific functions.
* pending switching to using threshold, new storage root api does not
make much sense.
* refactoring to use state from backend (not possible payload changes).
* Applying from previous state
* Remove default from storage, genesis need a special build.
* rem empty space
* Catch problem: when using triedb with default: we should not revert
nodes: otherwhise thing as trie codec cannot decode-encode without
changing state.
* fix compilation
* Right logic to avoid switch on reencode when default layout.
* Clean up some todos
* remove trie meta from root upstream
* update upstream and fix benches.
* split some long lines.
* UPdate trie crate to work with new design.
* Finish update to refactored upstream.
* update to latest triedb changes.
* Clean up.
* fix executor test.
* rust fmt from master.
* rust format.
* rustfmt
* fix
* start host function driven versioning
* update state-machine part
* still need access to state version from runtime
* state hash in mem: wrong
* direction likely correct, but passing call to code exec for genesis
init seem awkward.
* state version serialize in runtime, wrong approach, just initialize it
with no threshold for core api < 4 seems more proper.
* stateversion from runtime version (core api >= 4).
* update trie, fix tests
* unused import
* clean some TODOs
* Require RuntimeVersionOf for executor
* use RuntimeVersionOf to resolve genesis state version.
* update runtime version test
* fix state-machine tests
* TODO
* Use runtime version from storage wasm with fast sync.
* rustfmt
* fmt
* fix test
* revert useless changes.
* clean some unused changes
* fmt
* removing useless trait function.
* remove remaining reference to state_hash
* fix some imports
* Follow chain state version management.
* trie update, fix and constant threshold for trie layouts.
* update deps
* Update to latest trie pr changes.
* fix benches
* Verify proof requires right layout.
* update trie_root
* Update trie deps to latest
* Update to latest trie versioning
* Removing patch
* update lock
* extrinsic for sc-service-test using layout v0.
* Adding RuntimeVersionOf to CallExecutor works.
* fmt
* error when resolving version and no wasm in storage.
* use existing utils to instantiate runtime code.
* Patch to delay runtime switch.
* Revert "Patch to delay runtime switch."
This reverts commit 67e55fee468f1a0cda853f5362b22e0d775786da.
* useless closure
* remove remaining state_hash variables.
* Remove outdated comment
* useless inner hash
* fmt
* fmt and opt-in feature to apply state change.
* feature gate core version, use new test feature for node and test node
* Use a 'State' api version instead of Core one.
* fix merge of test function
* use blake macro.
* Fix state api (require declaring the api in runtime).
* Opt out feature, fix macro for io to select a given version
instead of latest.
* run test nodes on new state.
* fix
* Apply review change (docs and error).
* fmt
* use explicit runtime_interface in doc test
* fix ui test
* fix doc test
* fmt
* use default for path and specname when resolving version.
* small review related changes.
* doc value size requirement.
* rename old_state feature
* Remove macro changes
* feature rename
* state version as host function parameter
* remove flag for client api
* fix tests
* switch storage chain proof to V1
* host functions, pass by state version enum
* use WrappedRuntimeCode
* start
* state_version in runtime version
* rust fmt
* Update storage proof of max size.
* fix runtime version rpc test
* right intent of convert from compat
* fix doc test
* fix doc test
* split proof
* decode without replay, and remove some reexports.
* Decode with compatibility by default.
* switch state_version to u8. And remove RuntimeVersionBasis.
* test
* use api when reading embedded version
* fix decode with apis
* extract core version instead
* test fix
* unused import
* review changes.
Co-authored-by: kianenigma <kian@parity.io>
* Run cargo fmt on the whole code base
* Second run
* Add CI check
* Fix compilation
* More unnecessary braces
* Handle weights
* Use --all
* Use correct attributes...
* Fix UI tests
* AHHHHHHHHH
* 🤦
* Docs
* Fix compilation
* 🤷
* Please stop
* 🤦 x 2
* More
* make rustfmt.toml consistent with polkadot
Co-authored-by: André Silva <andrerfosilva@gmail.com>
* Do not call `initialize_block` before any runtime api
Before this change we always called `initialize_block` before calling
into the runtime. There was already support with `skip_initialize` to skip
the initialization. Almost no runtime_api requires that
`initialize_block` is called before. Actually this only leads to higher
execution times most of the time, because all runtime modules are
initialized and this is especially expensive when the block contained a
runtime upgrade.
TLDR: Do not call `initialize_block` before calling a runtime api.
* Change `validate_transaction` interface
* Fix rpc test
* Fixes and comments
* Some docs
* emit a custom section from impl_runtime_apis!
This change emits a custom section from the impl_runtime_apis! proc macro.
Each implemented API will result to emitting a link section `runtime_apis`.
During linking all sections with this name will be concatenated and
placed into the final wasm binary under the same name.
* Introduce `runtime_version` proc macro
This macro takes an existing `RuntimeVersion` const declaration, parses
it and emits the version information in form of a linking section.
Ultimately such a linking section will result into a custom wasm
section.
* Parse custom wasm section for runtime version
* Apply suggestions from code review
Co-authored-by: David <dvdplm@gmail.com>
* Fix sc-executor integration tests
* Nits
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* Refactor apis section deserialization
* Fix version decoding
* Reuse uncompressed value for CallInWasm
* Log on decompression error
* Simplify if
* Reexport proc-macro from sp_version
* Merge ReadRuntimeVersionExt
* Export `read_embedded_version`
* Fix test
* Simplify searching for custom section
Co-authored-by: David <dvdplm@gmail.com>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* Introduce a "dynamic" block size limit for proposing
This adds support for using a dynamic block size limit per call to
`propose`. This is required for Cumulus/Parachains to always use stay in
the limits of the maximum allowed PoV size.
As described in the docs, the block limit is only checked in the process
of pushing transactions. As we normally do some other operations in
`on_finalize`, it can happen that the block size still grows when there
is some proof being collected (as we do for parachains). This means,
that the given block limit needs to be rather conservative on the actual
value and should not be the upper limit.
* Update client/basic-authorship/src/basic_authorship.rs
Co-authored-by: Andronik Ordian <write@reusable.software>
* More future proof encoded size updating
* Use `ProofRecorderInner`
* Update client/basic-authorship/src/basic_authorship.rs
Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
* Update client/basic-authorship/src/basic_authorship.rs
Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
* Update client/basic-authorship/src/basic_authorship.rs
Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
* Update client/consensus/slots/src/lib.rs
Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
* Update client/consensus/slots/src/slots.rs
Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
* Update client/basic-authorship/src/basic_authorship.rs
Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
* Update client/basic-authorship/src/basic_authorship.rs
Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
* Update client/basic-authorship/src/basic_authorship.rs
Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
Co-authored-by: Andronik Ordian <write@reusable.software>
Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
* Init `RuntimeLogger` automatically for each runtime api call
This pr change the runtime api in such a way to always and automatically
enable the `RuntimeLogger`. This enables the user to use `log` or
`tracing` from inside the runtime to create log messages. As logging
introduces some extra code and especially increases the size of the wasm
blob. It is advised to disable all logging completely with
`sp-api/disable-logging` when doing the wasm builds for the on-chain
wasm runtime.
Besides these changes, the pr also brings most of the logging found in
frame to the same format "runtime::*".
* Update frame/im-online/src/lib.rs
Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
* Update test-utils/runtime/Cargo.toml
* Fix test
* Don't use tracing in the runtime, as we don't support it :D
* Fixes
Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
* Make offchain indexing work
This fixes some bugs with offchain indexing to make it actually working ;)
* Fix tests
* Fix browser build
* Update client/db/src/offchain.rs
Co-authored-by: cheme <emericchevalier.pro@gmail.com>
* Remove seperation between prefix and key
Co-authored-by: cheme <emericchevalier.pro@gmail.com>
* chore/error: remove from str conversion and add deprecation notifications
* fixup changes
* fix test looking for gone ::Msg variant
* another test fix
* one is duplicate, the other is not, so duplicates reported are n-1
* darn spaces
Co-authored-by: Andronik Ordian <write@reusable.software>
* remove pointless doc comments of error variants without any value
* low hanging fruits (for a tall person)
* moar error type variants
* avoid the storage modules for now
They are in need of a refactor, and the pain is rather large
removing all String error and DefaultError occurences.
* chore remove pointless error generic
* fix test for mocks, add a bunch of non_exhaustive
* max line width
* test fixes due to error changes
* fin
* error outputs... again
* undo stderr adjustments
* Update client/consensus/slots/src/lib.rs
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* remove closure clutter
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* more error types
* introduce ApiError
* extract Mock error
* ApiError refactor
* even more error types
* the last for now
* chore unused deps
* another extraction
* reduce should panic, due to extended error messages
* error test happiness
* shift error lines by one
* doc tests
* white space
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* Into -> From
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* remove pointless codec
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* avoid pointless self import
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Co-authored-by: Bernhard Schuster <bernhard@parity.io>
Co-authored-by: Andronik Ordian <write@reusable.software>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* Improve `mock_impl_runtime_apis!`
This adds a new attribute for functions being implemented in the
`mock_impl_runtime_apis!` macro, the `advanced` attribute. When this
attribute is given the user gets access to the `at` parameter and is
able to return a `Result`, instead of letting the macro generate this
stuff.
* Use the `at_param_name` directly
* Prevent clashing of `params`
* Move `create_inherents` into the block-builder
This moves the `create_inherents` call into the block-builder. This has
the advantage that `create_inherents` will be able to reuse the same
context that will be used when applying the extrinsics and we also save
one call to `on_initialize`. To make sure that `create_inherents` does
not modify any state, we execute it in a transaction that is
rolled-back after doing the runtime call.
* Feedback and build fix
* Update primitives/runtime/src/lib.rs
Co-authored-by: Sergei Shulepov <sergei@parity.io>
* Update client/block-builder/src/lib.rs
Co-authored-by: Sergei Shulepov <sergei@parity.io>
* `decl_runtime_apis!` - check that a method without `changed_in` exists
This adds another check to the macro that ensures that not only methods
with `changed_in` exists, but there are also the default methods exist.
* Update primitives/api/proc-macro/src/decl_runtime_apis.rs
Co-Authored-By: Nikolay Volf <nikvolf@gmail.com>
* Fix test
Co-authored-by: Nikolay Volf <nikvolf@gmail.com>
* Implements mocking of runtime apis
This pr adds support for easily mock runtime api implementations for
tests by using the `mock_impl_runtime_apis!` macro. The syntax is
similar to `impl_runtime_apis!`. The mocked implementation automatically
implements `ApiExt`, `ApiErrorExt` and `Core` as these are required by
the runtime api traits, but not required in tests or only a subset of them.
* Fix warnings
* Update primitives/api/proc-macro/src/utils.rs
Co-Authored-By: Nikolay Volf <nikvolf@gmail.com>
* Review feedback
Co-authored-by: Nikolay Volf <nikvolf@gmail.com>
This reduces the usage of `Blake2Hasher` in the code base and replaces
it with `BlakeTwo256`. The most important change is the removal of the
custom extern function for `Blake2Hasher`. The runtime `Hash` trait is
now also simplified and directly requires that the implementing type
implements `Hashable`.
* Extend `Proposer` to optionally generate a proof of the proposal
* Something
* Refactor sr-api to not depend on client anymore
* Fix benches
* Apply suggestions from code review
Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
* Apply suggestions from code review
* Introduce new `into_storage_changes` function
* Switch to runtime api for `execute_block` and don't require `H256`
anywhere in the code
* Put the `StorageChanges` into the `Proposal`
* Move the runtime api error to its own trait
* Adds `StorageTransactionCache` to the runtime api
This requires that we add `type NodeBlock = ` to the
`impl_runtime_apis!` macro to work around some bugs in rustc :(
* Remove `type NodeBlock` and switch to a "better" hack
* Start using the transaction cache from the runtime api
* Make it compile
* Move `InMemory` to its own file
* Make all tests work again
* Return block, storage_changes and proof from Blockbuilder::bake()
* Make sure that we use/set `storage_changes` when possible
* Add test
* Fix deadlock
* Remove accidentally added folders
* Introduce `RecordProof` as argument type to be more explicit
* Update client/src/client.rs
Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
* Update primitives/state-machine/src/ext.rs
Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
* Integrates review feedback
* Remove `unsafe` usage
* Update client/block-builder/src/lib.rs
Co-Authored-By: Benjamin Kampmann <ben@gnunicorn.org>
* Update client/src/call_executor.rs
* Bump versions
Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
Co-authored-by: Benjamin Kampmann <ben.kampmann@googlemail.com>