diff --git a/Cargo.lock b/Cargo.lock index 9ef971b4be93..a01420bc3ef6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6055,6 +6055,7 @@ dependencies = [ name = "frame-system-rpc-runtime-api" version = "26.0.0" dependencies = [ + "docify", "parity-scale-codec", "sp-api", ] @@ -8372,6 +8373,7 @@ name = "minimal-template-node" version = "0.0.0" dependencies = [ "clap 4.5.3", + "docify", "futures", "futures-timer", "jsonrpsee", @@ -20961,6 +20963,7 @@ name = "substrate-frame-rpc-system" version = "28.0.0" dependencies = [ "assert_matches", + "docify", "frame-system-rpc-runtime-api", "futures", "jsonrpsee", diff --git a/bridges/modules/beefy/src/mock.rs b/bridges/modules/beefy/src/mock.rs index c99566b6b06d..53efd57c29a0 100644 --- a/bridges/modules/beefy/src/mock.rs +++ b/bridges/modules/beefy/src/mock.rs @@ -66,7 +66,7 @@ construct_runtime! { } } -#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] +#[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for TestRuntime { type Block = Block; } diff --git a/bridges/snowbridge/pallets/inbound-queue/src/mock.rs b/bridges/snowbridge/pallets/inbound-queue/src/mock.rs index 05481ca2f6b4..a842f9aa60cb 100644 --- a/bridges/snowbridge/pallets/inbound-queue/src/mock.rs +++ b/bridges/snowbridge/pallets/inbound-queue/src/mock.rs @@ -2,11 +2,7 @@ // SPDX-FileCopyrightText: 2023 Snowfork use super::*; -use frame_support::{ - derive_impl, parameter_types, - traits::{ConstU32, Everything}, - weights::IdentityFee, -}; +use frame_support::{derive_impl, parameter_types, traits::ConstU32, weights::IdentityFee}; use hex_literal::hex; use snowbridge_beacon_primitives::{ types::deneb, BeaconHeader, ExecutionProof, Fork, ForkVersions, VersionedExecutionPayloadHeader, @@ -19,7 +15,7 @@ use snowbridge_core::{ use snowbridge_router_primitives::inbound::MessageToXcm; use sp_core::{H160, H256}; use sp_runtime::{ - traits::{BlakeTwo256, IdentifyAccount, IdentityLookup, Verify}, + traits::{IdentifyAccount, IdentityLookup, Verify}, BuildStorage, FixedU128, MultiSignature, }; use sp_std::{convert::From, default::Default}; @@ -47,18 +43,9 @@ type Balance = u128; #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Test { - type BaseCallFilter = Everything; - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; - type Hash = H256; - type Hashing = BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; - type RuntimeEvent = RuntimeEvent; - type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; - type Nonce = u64; type Block = Block; } diff --git a/cumulus/pallets/collator-selection/src/mock.rs b/cumulus/pallets/collator-selection/src/mock.rs index 196184d62781..6521c954eac2 100644 --- a/cumulus/pallets/collator-selection/src/mock.rs +++ b/cumulus/pallets/collator-selection/src/mock.rs @@ -22,12 +22,7 @@ use frame_support::{ }; use frame_system as system; use frame_system::EnsureSignedBy; -use sp_core::H256; -use sp_runtime::{ - testing::UintAuthorityId, - traits::{BlakeTwo256, IdentityLookup, OpaqueKeys}, - BuildStorage, RuntimeAppPublic, -}; +use sp_runtime::{testing::UintAuthorityId, traits::OpaqueKeys, BuildStorage, RuntimeAppPublic}; type Block = frame_system::mocking::MockBlock; @@ -51,28 +46,9 @@ parameter_types! { #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl system::Config for Test { - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = (); - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Nonce = u64; - type Hash = H256; - type Hashing = BlakeTwo256; - type AccountId = u64; - type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type Version = (); - type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); type SS58Prefix = SS58Prefix; - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; } parameter_types! { diff --git a/docs/sdk/src/reference_docs/custom_runtime_api_rpc.rs b/docs/sdk/src/reference_docs/custom_runtime_api_rpc.rs new file mode 100644 index 000000000000..83a70606cb8d --- /dev/null +++ b/docs/sdk/src/reference_docs/custom_runtime_api_rpc.rs @@ -0,0 +1,77 @@ +//! # Custom RPC do's and don'ts +//! +//! **TLDR:** don't create new custom RPCs. Instead, rely on custom Runtime APIs, combined with +//! `state_call` +//! +//! ## Background +//! +//! Polkadot-SDK offers the ability to query and subscribe storages directly. However what it does +//! not have is [view functions](https://github.com/paritytech/polkadot-sdk/issues/216). This is an +//! essential feature to avoid duplicated logic between runtime and the client SDK. Custom RPC was +//! used as a solution. It allow the RPC node to expose new RPCs that clients can be used to query +//! computed properties. +//! +//! ## Problems with Custom RPC +//! +//! Unfortunately, custom RPC comes with many problems. To list a few: +//! +//! - It is offchain logic executed by the RPC node and therefore the client has to trust the RPC +//! node. +//! - To upgrade or add a new RPC logic, the RPC node has to be upgraded. This can cause significant +//! trouble when the RPC infrastructure is decentralized as we will need to coordinate multiple +//! parties to upgrade the RPC nodes. +//! - A lot of boilerplate code are required to add custom RPC. +//! - It prevents the dApp to use a light client or alternative client. +//! - It makes ecosystem tooling integration much more complicated. For example, the dApp will not +//! be able to use [Chopsticks](https://github.com/AcalaNetwork/chopsticks) for testing as +//! Chopsticks will not have the custom RPC implementation. +//! - Poorly implemented custom RPC can be a DoS vector. +//! +//! Hence, we should avoid custom RPC. +//! +//! ## Alternatives +//! +//! Generally, [`sc_rpc::state::StateBackend::call`] aka. `state_call` should be used instead of +//! custom RPC. +//! +//! Usually, each custom RPC comes with a corresponding runtime API which implements the business +//! logic. So instead of invoke the custom RPC, we can use `state_call` to invoke the runtime API +//! directly. This is a trivial change on the dApp and no change on the runtime side. We may remove +//! the custom RPC from the node side if wanted. +//! +//! There are some other cases that a simple runtime API is not enough. For example, implementation +//! of Ethereum RPC requires an additional offchain database to index transactions. In this +//! particular case, we can have the RPC implemented on another client. +//! +//! For example, the Acala EVM+ RPC are implemented by +//! [eth-rpc-adapter](https://github.com/AcalaNetwork/bodhi.js/tree/master/packages/eth-rpc-adapter). +//! Alternatively, the [Frontier](https://github.com/polkadot-evm/frontier) project also provided +//! Ethereum RPC compatibility directly in the node-side software. +//! +//! ## Create a new Runtime API +//! +//! For example, let's take a look a the process through which the account nonce can be queried +//! through an RPC. First, a new runtime-api needs to be declared: +#![doc = docify::embed!("../../substrate/frame/system/rpc/runtime-api/src/lib.rs", AccountNonceApi)] +//! +//! This API is implemented at the runtime level, always inside [`sp_api::impl_runtime_apis!`]. +//! +//! As noted, this is already enough to make this API usable via `state_call`. +//! +//! ## Create a new custom RPC (Legacy) +//! +//! Should you wish to implement the legacy approach of exposing this runtime-api as a custom +//! RPC-api, then a custom RPC server has to be defined. +#![doc = docify::embed!("../../substrate/utils/frame/rpc/system/src/lib.rs", SystemApi)] +//! +//! ## Add a new RPC to the node (Legacy) +//! +//! Finally, this custom RPC needs to be integrated into the node side. This is usually done in a +//! `rpc.rs` in a typical template, as follows: +#![doc = docify::embed!("../../templates/minimal/node/src/rpc.rs", create_full)] +//! +//! ## Future +//! +//! - [XCQ](https://forum.polkadot.network/t/cross-consensus-query-language-xcq/7583) will be a good +//! solution for most of the query needs. +//! - [New JSON-RPC Specification](https://github.com/paritytech/json-rpc-interface-spec) diff --git a/docs/sdk/src/reference_docs/mod.rs b/docs/sdk/src/reference_docs/mod.rs index e50690b50212..8e0431c48b6f 100644 --- a/docs/sdk/src/reference_docs/mod.rs +++ b/docs/sdk/src/reference_docs/mod.rs @@ -108,3 +108,6 @@ pub mod frame_pallet_coupling; /// Learn about the Polkadot Umbrella crate that re-exports all other crates. pub mod umbrella_crate; + +/// Learn about how to create custom RPC endpoints and runtime APIs. +pub mod custom_runtime_api_rpc; diff --git a/polkadot/README.md b/polkadot/README.md index d7435f27b946..47af79a3aa92 100644 --- a/polkadot/README.md +++ b/polkadot/README.md @@ -11,7 +11,7 @@ guides, like how to run a validator node, see the [Polkadot Wiki](https://wiki.p If you just wish to run a Polkadot node without compiling it yourself, you may either: -- run the latest binary from our [releases](https://github.com/paritytech/polkadot-sdk/releases) page (make sure to also +- run the [latest released binary](https://github.com/paritytech/polkadot-sdk/releases/latest) (make sure to also download all the `worker` binaries and put them in the same directory as `polkadot`), or - install Polkadot from one of our package repositories. diff --git a/polkadot/node/core/pvf/common/src/prepare.rs b/polkadot/node/core/pvf/common/src/prepare.rs index 64e7f3d6bcf4..81e165a7b8a4 100644 --- a/polkadot/node/core/pvf/common/src/prepare.rs +++ b/polkadot/node/core/pvf/common/src/prepare.rs @@ -31,6 +31,8 @@ pub struct PrepareWorkerSuccess { pub struct PrepareSuccess { /// Canonical path to the compiled artifact. pub path: PathBuf, + /// Size in bytes + pub size: u64, /// Stats of the current preparation run. pub stats: PrepareStats, } diff --git a/polkadot/node/core/pvf/src/artifacts.rs b/polkadot/node/core/pvf/src/artifacts.rs index a3a48b61acb1..119af34082a9 100644 --- a/polkadot/node/core/pvf/src/artifacts.rs +++ b/polkadot/node/core/pvf/src/artifacts.rs @@ -142,6 +142,8 @@ pub enum ArtifactState { /// This is updated when we get the heads up for this artifact or when we just discover /// this file. last_time_needed: SystemTime, + /// Size in bytes + size: u64, /// Stats produced by successful preparation. prepare_stats: PrepareStats, }, @@ -169,6 +171,33 @@ pub struct Artifacts { inner: HashMap, } +/// Parameters we use to cleanup artifacts +/// After we hit the cache limit we remove the least used artifacts +/// but only if they are stale more than minimum stale time +#[derive(Debug)] +pub struct ArtifactsCleanupConfig { + // Max size in bytes. Reaching it the least used artefacts are deleted + cache_limit: u64, + // Inactive time after which artefact is allowed to be deleted + min_stale_time: Duration, +} + +impl Default for ArtifactsCleanupConfig { + fn default() -> Self { + Self { + cache_limit: 10 * 1024 * 1024 * 1024, // 10 GiB + min_stale_time: Duration::from_secs(24 * 60 * 60), // 24 hours + } + } +} + +#[cfg(test)] +impl ArtifactsCleanupConfig { + pub fn new(cache_limit: u64, min_stale_time: Duration) -> Self { + Self { cache_limit, min_stale_time } + } +} + impl Artifacts { #[cfg(test)] pub(crate) fn empty() -> Self { @@ -180,6 +209,11 @@ impl Artifacts { self.inner.len() } + #[cfg(test)] + fn artifact_ids(&self) -> Vec { + self.inner.keys().cloned().collect() + } + /// Create an empty table and the cache directory on-disk if it doesn't exist. pub async fn new(cache_path: &Path) -> Self { // Make sure that the cache path directory and all its parents are created. @@ -234,12 +268,16 @@ impl Artifacts { artifact_id: ArtifactId, path: PathBuf, last_time_needed: SystemTime, + size: u64, prepare_stats: PrepareStats, ) { // See the precondition. always!(self .inner - .insert(artifact_id, ArtifactState::Prepared { path, last_time_needed, prepare_stats }) + .insert( + artifact_id, + ArtifactState::Prepared { path, last_time_needed, size, prepare_stats } + ) .is_none()); } @@ -251,25 +289,40 @@ impl Artifacts { }) } - /// Remove artifacts older than the given TTL and return id and path of the removed ones. - pub fn prune(&mut self, artifact_ttl: Duration) -> Vec<(ArtifactId, PathBuf)> { + /// Remove artifacts older than the given TTL when the total artifact size reaches the limit + /// and return id and path of the removed ones + pub fn prune(&mut self, cleanup_config: &ArtifactsCleanupConfig) -> Vec<(ArtifactId, PathBuf)> { + let mut to_remove = vec![]; let now = SystemTime::now(); - let mut to_remove = vec![]; + let mut total_size = 0; + let mut artifact_sizes = vec![]; + for (k, v) in self.inner.iter() { - if let ArtifactState::Prepared { last_time_needed, ref path, .. } = *v { - if now - .duration_since(last_time_needed) - .map(|age| age > artifact_ttl) - .unwrap_or(false) - { - to_remove.push((k.clone(), path.clone())); - } + if let ArtifactState::Prepared { ref path, last_time_needed, size, .. } = *v { + total_size += size; + artifact_sizes.push((k.clone(), path.clone(), size, last_time_needed)); } } + artifact_sizes + .sort_by_key(|&(_, _, _, last_time_needed)| std::cmp::Reverse(last_time_needed)); + + while total_size > cleanup_config.cache_limit { + let Some((artifact_id, path, size, last_time_needed)) = artifact_sizes.pop() else { + break + }; + + let used_recently = now + .duration_since(last_time_needed) + .map(|stale_time| stale_time < cleanup_config.min_stale_time) + .unwrap_or(true); + if used_recently { + break; + } - for artifact in &to_remove { - self.inner.remove(&artifact.0); + self.inner.remove(&artifact_id); + to_remove.push((artifact_id, path)); + total_size -= size; } to_remove @@ -278,6 +331,8 @@ impl Artifacts { #[cfg(test)] mod tests { + use crate::testing::artifact_id; + use super::*; #[tokio::test] @@ -307,4 +362,100 @@ mod tests { assert!(entries.contains(&String::from("worker-prepare-test"))); assert_eq!(artifacts.len(), 0); } + + #[tokio::test] + async fn test_pruned_by_cache_size() { + let mock_now = SystemTime::now(); + let tempdir = tempfile::tempdir().unwrap(); + let cache_path = tempdir.path(); + + let path1 = generate_artifact_path(cache_path); + let path2 = generate_artifact_path(cache_path); + let path3 = generate_artifact_path(cache_path); + let artifact_id1 = artifact_id(1); + let artifact_id2 = artifact_id(2); + let artifact_id3 = artifact_id(3); + + let mut artifacts = Artifacts::new(cache_path).await; + let cleanup_config = ArtifactsCleanupConfig::new(1500, Duration::from_secs(0)); + + artifacts.insert_prepared( + artifact_id1.clone(), + path1.clone(), + mock_now - Duration::from_secs(5), + 1024, + PrepareStats::default(), + ); + artifacts.insert_prepared( + artifact_id2.clone(), + path2.clone(), + mock_now - Duration::from_secs(10), + 1024, + PrepareStats::default(), + ); + artifacts.insert_prepared( + artifact_id3.clone(), + path3.clone(), + mock_now - Duration::from_secs(15), + 1024, + PrepareStats::default(), + ); + + let pruned = artifacts.prune(&cleanup_config); + + assert!(artifacts.artifact_ids().contains(&artifact_id1)); + assert!(!pruned.contains(&(artifact_id1, path1))); + assert!(!artifacts.artifact_ids().contains(&artifact_id2)); + assert!(pruned.contains(&(artifact_id2, path2))); + assert!(!artifacts.artifact_ids().contains(&artifact_id3)); + assert!(pruned.contains(&(artifact_id3, path3))); + } + + #[tokio::test] + async fn test_did_not_prune_by_cache_size_because_of_stale_time() { + let mock_now = SystemTime::now(); + let tempdir = tempfile::tempdir().unwrap(); + let cache_path = tempdir.path(); + + let path1 = generate_artifact_path(cache_path); + let path2 = generate_artifact_path(cache_path); + let path3 = generate_artifact_path(cache_path); + let artifact_id1 = artifact_id(1); + let artifact_id2 = artifact_id(2); + let artifact_id3 = artifact_id(3); + + let mut artifacts = Artifacts::new(cache_path).await; + let cleanup_config = ArtifactsCleanupConfig::new(1500, Duration::from_secs(12)); + + artifacts.insert_prepared( + artifact_id1.clone(), + path1.clone(), + mock_now - Duration::from_secs(5), + 1024, + PrepareStats::default(), + ); + artifacts.insert_prepared( + artifact_id2.clone(), + path2.clone(), + mock_now - Duration::from_secs(10), + 1024, + PrepareStats::default(), + ); + artifacts.insert_prepared( + artifact_id3.clone(), + path3.clone(), + mock_now - Duration::from_secs(15), + 1024, + PrepareStats::default(), + ); + + let pruned = artifacts.prune(&cleanup_config); + + assert!(artifacts.artifact_ids().contains(&artifact_id1)); + assert!(!pruned.contains(&(artifact_id1, path1))); + assert!(artifacts.artifact_ids().contains(&artifact_id2)); + assert!(!pruned.contains(&(artifact_id2, path2))); + assert!(!artifacts.artifact_ids().contains(&artifact_id3)); + assert!(pruned.contains(&(artifact_id3, path3))); + } } diff --git a/polkadot/node/core/pvf/src/host.rs b/polkadot/node/core/pvf/src/host.rs index 4065598a3ac4..462631d33b52 100644 --- a/polkadot/node/core/pvf/src/host.rs +++ b/polkadot/node/core/pvf/src/host.rs @@ -21,7 +21,7 @@ //! [`ValidationHost`], that allows communication with that event-loop. use crate::{ - artifacts::{ArtifactId, ArtifactPathId, ArtifactState, Artifacts}, + artifacts::{ArtifactId, ArtifactPathId, ArtifactState, Artifacts, ArtifactsCleanupConfig}, execute::{self, PendingExecutionRequest}, metrics::Metrics, prepare, Priority, SecurityStatus, ValidationError, LOG_TARGET, @@ -293,7 +293,7 @@ pub async fn start( let run_host = async move { run(Inner { cleanup_pulse_interval: Duration::from_secs(3600), - artifact_ttl: Duration::from_secs(3600 * 24), + cleanup_config: ArtifactsCleanupConfig::default(), artifacts, to_host_rx, to_prepare_queue_tx, @@ -337,7 +337,7 @@ impl AwaitingPrepare { struct Inner { cleanup_pulse_interval: Duration, - artifact_ttl: Duration, + cleanup_config: ArtifactsCleanupConfig, artifacts: Artifacts, to_host_rx: mpsc::Receiver, @@ -359,7 +359,7 @@ struct Fatal; async fn run( Inner { cleanup_pulse_interval, - artifact_ttl, + cleanup_config, mut artifacts, to_host_rx, from_prepare_queue_rx, @@ -415,7 +415,7 @@ async fn run( break_if_fatal!(handle_cleanup_pulse( &mut to_sweeper_tx, &mut artifacts, - artifact_ttl, + &cleanup_config, ).await); }, to_host = to_host_rx.next() => { @@ -803,8 +803,12 @@ async fn handle_prepare_done( } *state = match result { - Ok(PrepareSuccess { path, stats: prepare_stats }) => - ArtifactState::Prepared { path, last_time_needed: SystemTime::now(), prepare_stats }, + Ok(PrepareSuccess { path, stats: prepare_stats, size }) => ArtifactState::Prepared { + path, + last_time_needed: SystemTime::now(), + size, + prepare_stats, + }, Err(error) => { let last_time_failed = SystemTime::now(); let num_failures = *num_failures + 1; @@ -859,9 +863,9 @@ async fn enqueue_prepare_for_execute( async fn handle_cleanup_pulse( sweeper_tx: &mut mpsc::Sender, artifacts: &mut Artifacts, - artifact_ttl: Duration, + cleanup_config: &ArtifactsCleanupConfig, ) -> Result<(), Fatal> { - let to_remove = artifacts.prune(artifact_ttl); + let to_remove = artifacts.prune(cleanup_config); gum::debug!( target: LOG_TARGET, "PVF pruning: {} artifacts reached their end of life", @@ -959,7 +963,7 @@ fn pulse_every(interval: std::time::Duration) -> impl futures::Stream #[cfg(test)] pub(crate) mod tests { use super::*; - use crate::{artifacts::generate_artifact_path, PossiblyInvalidError}; + use crate::{artifacts::generate_artifact_path, testing::artifact_id, PossiblyInvalidError}; use assert_matches::assert_matches; use futures::future::BoxFuture; use polkadot_node_core_pvf_common::prepare::PrepareStats; @@ -981,14 +985,9 @@ pub(crate) mod tests { } } - /// Creates a new PVF which artifact id can be uniquely identified by the given number. - fn artifact_id(discriminator: u32) -> ArtifactId { - ArtifactId::from_pvf_prep_data(&PvfPrepData::from_discriminator(discriminator)) - } - struct Builder { cleanup_pulse_interval: Duration, - artifact_ttl: Duration, + cleanup_config: ArtifactsCleanupConfig, artifacts: Artifacts, } @@ -997,8 +996,7 @@ pub(crate) mod tests { Self { // these are selected high to not interfere in tests in which pruning is irrelevant. cleanup_pulse_interval: Duration::from_secs(3600), - artifact_ttl: Duration::from_secs(3600), - + cleanup_config: ArtifactsCleanupConfig::default(), artifacts: Artifacts::empty(), } } @@ -1022,7 +1020,7 @@ pub(crate) mod tests { } impl Test { - fn new(Builder { cleanup_pulse_interval, artifact_ttl, artifacts }: Builder) -> Self { + fn new(Builder { cleanup_pulse_interval, artifacts, cleanup_config }: Builder) -> Self { let (to_host_tx, to_host_rx) = mpsc::channel(10); let (to_prepare_queue_tx, to_prepare_queue_rx) = mpsc::channel(10); let (from_prepare_queue_tx, from_prepare_queue_rx) = mpsc::unbounded(); @@ -1032,7 +1030,7 @@ pub(crate) mod tests { let run = run(Inner { cleanup_pulse_interval, - artifact_ttl, + cleanup_config, artifacts, to_host_rx, to_prepare_queue_tx, @@ -1183,19 +1181,21 @@ pub(crate) mod tests { let mut builder = Builder::default(); builder.cleanup_pulse_interval = Duration::from_millis(100); - builder.artifact_ttl = Duration::from_millis(500); + builder.cleanup_config = ArtifactsCleanupConfig::new(1024, Duration::from_secs(0)); let path1 = generate_artifact_path(cache_path); let path2 = generate_artifact_path(cache_path); builder.artifacts.insert_prepared( artifact_id(1), path1.clone(), mock_now, + 1024, PrepareStats::default(), ); builder.artifacts.insert_prepared( artifact_id(2), path2.clone(), mock_now, + 1024, PrepareStats::default(), ); let mut test = builder.build(); diff --git a/polkadot/node/core/pvf/src/prepare/worker_interface.rs b/polkadot/node/core/pvf/src/prepare/worker_interface.rs index 5c4245d76315..22ee93319d84 100644 --- a/polkadot/node/core/pvf/src/prepare/worker_interface.rs +++ b/polkadot/node/core/pvf/src/prepare/worker_interface.rs @@ -234,6 +234,19 @@ async fn handle_response( return Outcome::TimedOut } + let size = match tokio::fs::metadata(cache_path).await { + Ok(metadata) => metadata.len(), + Err(err) => { + gum::warn!( + target: LOG_TARGET, + ?cache_path, + "failed to read size of the artifact: {}", + err, + ); + return Outcome::IoErr(err.to_string()) + }, + }; + // The file name should uniquely identify the artifact even across restarts. In case the cache // for some reason is not cleared correctly, we cannot // accidentally execute an artifact compiled under a different wasmtime version, host @@ -253,6 +266,7 @@ async fn handle_response( worker, result: Ok(PrepareSuccess { path: artifact_path, + size, stats: PrepareStats { cpu_time_elapsed, memory_stats: memory_stats.clone() }, }), }, diff --git a/polkadot/node/core/pvf/src/testing.rs b/polkadot/node/core/pvf/src/testing.rs index 60b0b4b8d3d0..8c75dafa69c2 100644 --- a/polkadot/node/core/pvf/src/testing.rs +++ b/polkadot/node/core/pvf/src/testing.rs @@ -21,8 +21,9 @@ pub use crate::{ worker_interface::{spawn_with_program_path, SpawnErr}, }; -use crate::get_worker_version; +use crate::{artifacts::ArtifactId, get_worker_version}; use is_executable::IsExecutable; +use polkadot_node_core_pvf_common::pvf::PvfPrepData; use polkadot_node_primitives::NODE_VERSION; use polkadot_primitives::ExecutorParams; use std::{ @@ -126,3 +127,8 @@ pub fn build_workers_and_get_paths() -> (PathBuf, PathBuf) { let guard = mutex.lock().unwrap(); (guard.0.clone(), guard.1.clone()) } + +/// Creates a new PVF which artifact id can be uniquely identified by the given number. +pub fn artifact_id(discriminator: u32) -> ArtifactId { + ArtifactId::from_pvf_prep_data(&PvfPrepData::from_discriminator(discriminator)) +} diff --git a/polkadot/node/network/statement-distribution/src/v2/cluster.rs b/polkadot/node/network/statement-distribution/src/v2/cluster.rs index 87b25c785d83..26d7a68eb2a7 100644 --- a/polkadot/node/network/statement-distribution/src/v2/cluster.rs +++ b/polkadot/node/network/statement-distribution/src/v2/cluster.rs @@ -429,7 +429,9 @@ impl ClusterTracker { pub fn warn_if_too_many_pending_statements(&self, parent_hash: Hash) { if self.pending.iter().filter(|pending| !pending.1.is_empty()).count() >= - self.validators.len() + self.validators.len() && + // No reason to warn if we are the only node in the cluster. + self.validators.len() > 1 { gum::warn!( target: LOG_TARGET, diff --git a/polkadot/runtime/parachains/src/assigner_coretime/tests.rs b/polkadot/runtime/parachains/src/assigner_coretime/tests.rs index 41cf21e267e4..81a0988ea67c 100644 --- a/polkadot/runtime/parachains/src/assigner_coretime/tests.rs +++ b/polkadot/runtime/parachains/src/assigner_coretime/tests.rs @@ -75,7 +75,7 @@ fn run_to_block( Scheduler::initializer_initialize(b + 1); // In the real runtime this is expected to be called by the `InclusionInherent` pallet. - Scheduler::free_cores_and_fill_claimqueue(BTreeMap::new(), b + 1); + Scheduler::free_cores_and_fill_claim_queue(BTreeMap::new(), b + 1); } } diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs b/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs index 8ac6ab77beee..5747413e7147 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs @@ -77,7 +77,7 @@ fn run_to_block( OnDemandAssigner::on_initialize(b + 1); // In the real runtime this is expected to be called by the `InclusionInherent` pallet. - Scheduler::free_cores_and_fill_claimqueue(BTreeMap::new(), b + 1); + Scheduler::free_cores_and_fill_claim_queue(BTreeMap::new(), b + 1); } } diff --git a/polkadot/runtime/parachains/src/assigner_parachains/tests.rs b/polkadot/runtime/parachains/src/assigner_parachains/tests.rs index ebd24e89162a..14cb1a897860 100644 --- a/polkadot/runtime/parachains/src/assigner_parachains/tests.rs +++ b/polkadot/runtime/parachains/src/assigner_parachains/tests.rs @@ -71,7 +71,7 @@ fn run_to_block( Scheduler::initializer_initialize(b + 1); // In the real runtime this is expected to be called by the `InclusionInherent` pallet. - Scheduler::free_cores_and_fill_claimqueue(BTreeMap::new(), b + 1); + Scheduler::free_cores_and_fill_claim_queue(BTreeMap::new(), b + 1); } } diff --git a/polkadot/runtime/parachains/src/builder.rs b/polkadot/runtime/parachains/src/builder.rs index 5ed5a2b527c0..c046526ba372 100644 --- a/polkadot/runtime/parachains/src/builder.rs +++ b/polkadot/runtime/parachains/src/builder.rs @@ -92,11 +92,17 @@ pub(crate) struct BenchBuilder { /// will correspond to core index 3. There must be one entry for each core with a dispute /// statement set. dispute_sessions: Vec, + /// Paras here will both be backed in the inherent data and already occupying a core (which is + /// freed via bitfields). + /// /// Map from para id to number of validity votes. Core indices are generated based on /// `elastic_paras` configuration. Each para id in `elastic_paras` gets the /// specified amount of consecutive cores assigned to it. If a para id is not present /// in `elastic_paras` it get assigned to a single core. backed_and_concluding_paras: BTreeMap, + + /// Paras which don't yet occupy a core, but will after the inherent has been processed. + backed_in_inherent_paras: BTreeMap, /// Map from para id (seed) to number of chained candidates. elastic_paras: BTreeMap, /// Make every candidate include a code upgrade by setting this to `Some` where the interior @@ -132,6 +138,7 @@ impl BenchBuilder { dispute_statements: BTreeMap::new(), dispute_sessions: Default::default(), backed_and_concluding_paras: Default::default(), + backed_in_inherent_paras: Default::default(), elastic_paras: Default::default(), code_upgrade: None, fill_claimqueue: true, @@ -167,6 +174,12 @@ impl BenchBuilder { self } + /// Set a map from para id seed to number of validity votes for votes in inherent data. + pub(crate) fn set_backed_in_inherent_paras(mut self, backed: BTreeMap) -> Self { + self.backed_in_inherent_paras = backed; + self + } + /// Set a map from para id seed to number of cores assigned to it. pub(crate) fn set_elastic_paras(mut self, elastic_paras: BTreeMap) -> Self { self.elastic_paras = elastic_paras; @@ -753,8 +766,8 @@ impl BenchBuilder { /// /// Note that this API only allows building scenarios where the `backed_and_concluding_paras` /// are mutually exclusive with the cores for disputes. So - /// `backed_and_concluding_paras.len() + dispute_sessions.len()` must be less than the max - /// number of cores. + /// `backed_and_concluding_paras.len() + dispute_sessions.len() + backed_in_inherent_paras` must + /// be less than the max number of cores. pub(crate) fn build(self) -> Bench { // Make sure relevant storage is cleared. This is just to get the asserts to work when // running tests because it seems the storage is not cleared in between. @@ -771,8 +784,10 @@ impl BenchBuilder { .sum::() .saturating_sub(self.elastic_paras.len() as usize); - let used_cores = - self.dispute_sessions.len() + self.backed_and_concluding_paras.len() + extra_cores; + let used_cores = self.dispute_sessions.len() + + self.backed_and_concluding_paras.len() + + self.backed_in_inherent_paras.len() + + extra_cores; assert!(used_cores <= max_cores); let fill_claimqueue = self.fill_claimqueue; @@ -793,8 +808,12 @@ impl BenchBuilder { &builder.elastic_paras, used_cores, ); + + let mut backed_in_inherent = BTreeMap::new(); + backed_in_inherent.append(&mut builder.backed_and_concluding_paras.clone()); + backed_in_inherent.append(&mut builder.backed_in_inherent_paras.clone()); let backed_candidates = builder.create_backed_candidates( - &builder.backed_and_concluding_paras, + &backed_in_inherent, &builder.elastic_paras, builder.code_upgrade, ); @@ -845,12 +864,16 @@ impl BenchBuilder { scheduler::AvailabilityCores::::set(cores); core_idx = 0u32; + + // We need entries in the claim queue for those: + all_cores.append(&mut builder.backed_in_inherent_paras.clone()); + if fill_claimqueue { let cores = all_cores .keys() .flat_map(|para_id| { (0..elastic_paras.get(¶_id).cloned().unwrap_or(1)) - .filter_map(|_para_local_core_idx| { + .map(|_para_local_core_idx| { let ttl = configuration::ActiveConfig::::get().scheduler_params.ttl; // Load an assignment into provider so that one is present to pop let assignment = @@ -859,17 +882,11 @@ impl BenchBuilder { ParaId::from(*para_id), ); - let entry = ( - CoreIndex(core_idx), - [ParasEntry::new(assignment, now + ttl)].into(), - ); - let res = if builder.unavailable_cores.contains(&core_idx) { - None - } else { - Some(entry) - }; core_idx += 1; - res + ( + CoreIndex(core_idx - 1), + [ParasEntry::new(assignment, now + ttl)].into(), + ) }) .collect::>)>>() }) diff --git a/polkadot/runtime/parachains/src/configuration.rs b/polkadot/runtime/parachains/src/configuration.rs index 10ecaa16a846..bffeab4a0d21 100644 --- a/polkadot/runtime/parachains/src/configuration.rs +++ b/polkadot/runtime/parachains/src/configuration.rs @@ -335,6 +335,8 @@ pub enum InconsistentError { InconsistentExecutorParams { inner: ExecutorParamError }, /// TTL should be bigger than lookahead LookaheadExceedsTTL, + /// Lookahead is zero, while it must be at least 1 for parachains to work. + LookaheadZero, /// Passed in queue size for on-demand was too large. OnDemandQueueSizeTooLarge, /// Number of delay tranches cannot be 0. @@ -432,6 +434,10 @@ where return Err(LookaheadExceedsTTL) } + if self.scheduler_params.lookahead == 0 { + return Err(LookaheadZero) + } + if self.scheduler_params.on_demand_queue_max_size > ON_DEMAND_MAX_QUEUE_MAX_SIZE { return Err(OnDemandQueueSizeTooLarge) } diff --git a/polkadot/runtime/parachains/src/paras_inherent/benchmarking.rs b/polkadot/runtime/parachains/src/paras_inherent/benchmarking.rs index 267a9781a106..4c8b093451ed 100644 --- a/polkadot/runtime/parachains/src/paras_inherent/benchmarking.rs +++ b/polkadot/runtime/parachains/src/paras_inherent/benchmarking.rs @@ -110,7 +110,7 @@ benchmarks! { .collect(); let scenario = BenchBuilder::::new() - .set_backed_and_concluding_paras(cores_with_backed.clone()) + .set_backed_in_inherent_paras(cores_with_backed.clone()) .build(); let mut benchmark = scenario.data.clone(); @@ -161,7 +161,7 @@ benchmarks! { .collect(); let scenario = BenchBuilder::::new() - .set_backed_and_concluding_paras(cores_with_backed.clone()) + .set_backed_in_inherent_paras(cores_with_backed.clone()) .set_code_upgrade(v) .build(); diff --git a/polkadot/runtime/parachains/src/paras_inherent/mod.rs b/polkadot/runtime/parachains/src/paras_inherent/mod.rs index 386873aad457..8b527c09490d 100644 --- a/polkadot/runtime/parachains/src/paras_inherent/mod.rs +++ b/polkadot/runtime/parachains/src/paras_inherent/mod.rs @@ -560,7 +560,7 @@ impl Pallet { .chain(freed_disputed.into_iter().map(|core| (core, FreedReason::Concluded))) .chain(freed_timeout.into_iter().map(|c| (c, FreedReason::TimedOut))) .collect::>(); - scheduler::Pallet::::free_cores_and_fill_claimqueue(freed, now); + scheduler::Pallet::::free_cores_and_fill_claim_queue(freed, now); METRICS.on_candidates_processed_total(backed_candidates.len() as u64); @@ -570,12 +570,13 @@ impl Pallet { .map(|b| *b) .unwrap_or(false); - let mut scheduled: BTreeMap> = BTreeMap::new(); - let mut total_scheduled_cores = 0; + let mut eligible: BTreeMap> = BTreeMap::new(); + let mut total_eligible_cores = 0; - for (core_idx, para_id) in scheduler::Pallet::::scheduled_paras() { - total_scheduled_cores += 1; - scheduled.entry(para_id).or_default().insert(core_idx); + for (core_idx, para_id) in scheduler::Pallet::::eligible_paras() { + total_eligible_cores += 1; + log::trace!(target: LOG_TARGET, "Found eligible para {:?} on core {:?}", para_id, core_idx); + eligible.entry(para_id).or_default().insert(core_idx); } let initial_candidate_count = backed_candidates.len(); @@ -583,12 +584,12 @@ impl Pallet { backed_candidates, &allowed_relay_parents, concluded_invalid_hashes, - scheduled, + eligible, core_index_enabled, ); let count = count_backed_candidates(&backed_candidates_with_core); - ensure!(count <= total_scheduled_cores, Error::::UnscheduledCandidate); + ensure!(count <= total_eligible_cores, Error::::UnscheduledCandidate); METRICS.on_candidates_sanitized(count as u64); @@ -1422,7 +1423,7 @@ fn map_candidates_to_cores::claimqueue_is_empty()); + assert!(scheduler::Pallet::::claim_queue_is_empty()); // Nothing is filtered out (including the backed candidates.) assert_eq!( @@ -257,7 +257,7 @@ mod enter { .unwrap(); // The current schedule is empty prior to calling `create_inherent_enter`. - assert!(scheduler::Pallet::::claimqueue_is_empty()); + assert!(scheduler::Pallet::::claim_queue_is_empty()); assert!(pallet::OnChainVotes::::get().is_none()); @@ -372,7 +372,7 @@ mod enter { let mut inherent_data = InherentData::new(); inherent_data.put_data(PARACHAINS_INHERENT_IDENTIFIER, &scenario.data).unwrap(); - assert!(!scheduler::Pallet::::claimqueue_is_empty()); + assert!(!scheduler::Pallet::::claim_queue_is_empty()); // The right candidates have been filtered out (the ones for cores 0,4,5) assert_eq!( @@ -618,7 +618,7 @@ mod enter { .unwrap(); // The current schedule is empty prior to calling `create_inherent_enter`. - assert!(scheduler::Pallet::::claimqueue_is_empty()); + assert!(scheduler::Pallet::::claim_queue_is_empty()); let multi_dispute_inherent_data = Pallet::::create_inherent_inner(&inherent_data.clone()).unwrap(); @@ -690,7 +690,7 @@ mod enter { .unwrap(); // The current schedule is empty prior to calling `create_inherent_enter`. - assert!(scheduler::Pallet::::claimqueue_is_empty()); + assert!(scheduler::Pallet::::claim_queue_is_empty()); let limit_inherent_data = Pallet::::create_inherent_inner(&inherent_data.clone()).unwrap(); @@ -762,7 +762,7 @@ mod enter { .unwrap(); // The current schedule is empty prior to calling `create_inherent_enter`. - assert!(scheduler::Pallet::::claimqueue_is_empty()); + assert!(scheduler::Pallet::::claim_queue_is_empty()); // Nothing is filtered out (including the backed candidates.) let limit_inherent_data = @@ -849,7 +849,7 @@ mod enter { .unwrap(); // The current schedule is empty prior to calling `create_inherent_enter`. - assert!(scheduler::Pallet::::claimqueue_is_empty()); + assert!(scheduler::Pallet::::claim_queue_is_empty()); // Nothing is filtered out (including the backed candidates.) let limit_inherent_data = @@ -1818,7 +1818,7 @@ mod sanitizers { ]); // Update scheduler's claimqueue with the parachains - scheduler::Pallet::::set_claimqueue(BTreeMap::from([ + scheduler::Pallet::::set_claim_queue(BTreeMap::from([ ( CoreIndex::from(0), VecDeque::from([ParasEntry::new( @@ -2001,7 +2001,7 @@ mod sanitizers { ]); // Update scheduler's claimqueue with the parachains - scheduler::Pallet::::set_claimqueue(BTreeMap::from([ + scheduler::Pallet::::set_claim_queue(BTreeMap::from([ ( CoreIndex::from(0), VecDeque::from([ParasEntry::new( @@ -2542,7 +2542,7 @@ mod sanitizers { ]); // Update scheduler's claimqueue with the parachains - scheduler::Pallet::::set_claimqueue(BTreeMap::from([ + scheduler::Pallet::::set_claim_queue(BTreeMap::from([ ( CoreIndex::from(0), VecDeque::from([ParasEntry::new( diff --git a/polkadot/runtime/parachains/src/runtime_api_impl/v10.rs b/polkadot/runtime/parachains/src/runtime_api_impl/v10.rs index dbb79b86c56c..4417ec75abd6 100644 --- a/polkadot/runtime/parachains/src/runtime_api_impl/v10.rs +++ b/polkadot/runtime/parachains/src/runtime_api_impl/v10.rs @@ -66,7 +66,7 @@ pub fn availability_cores() -> Vec::free_cores_and_fill_claimqueue(Vec::new(), now); + scheduler::Pallet::::free_cores_and_fill_claim_queue(Vec::new(), now); let time_out_for = scheduler::Pallet::::availability_timeout_predicate(); @@ -305,7 +305,7 @@ pub fn validation_code( /// Implementation for the `candidate_pending_availability` function of the runtime API. #[deprecated( - note = "`candidate_pending_availability` will be removed. Use `candidates_pending_availability` to query + note = "`candidate_pending_availability` will be removed. Use `candidates_pending_availability` to query all candidates pending availability" )] pub fn candidate_pending_availability( diff --git a/polkadot/runtime/parachains/src/runtime_api_impl/vstaging.rs b/polkadot/runtime/parachains/src/runtime_api_impl/vstaging.rs index 8c239dc207f6..62e96e9fbb05 100644 --- a/polkadot/runtime/parachains/src/runtime_api_impl/vstaging.rs +++ b/polkadot/runtime/parachains/src/runtime_api_impl/vstaging.rs @@ -16,7 +16,7 @@ //! Put implementations of functions from staging APIs here. -use crate::{inclusion, initializer, scheduler}; +use crate::{configuration, inclusion, initializer, scheduler}; use polkadot_primitives::{CommittedCandidateReceipt, CoreIndex, Id as ParaId}; use sp_runtime::traits::One; use sp_std::{ @@ -32,12 +32,21 @@ pub fn claim_queue() -> BTreeMap>::free_cores_and_fill_claimqueue(Vec::new(), now); + >::free_cores_and_fill_claim_queue(Vec::new(), now); + let config = configuration::ActiveConfig::::get(); + // Extra sanity, config should already never be smaller than 1: + let n_lookahead = config.scheduler_params.lookahead.max(1); scheduler::ClaimQueue::::get() .into_iter() .map(|(core_index, entries)| { - (core_index, entries.into_iter().map(|e| e.para_id()).collect()) + // on cores timing out internal claim queue size may be temporarily longer than it + // should be as the timed out assignment might got pushed back to an already full claim + // queue: + ( + core_index, + entries.into_iter().map(|e| e.para_id()).take(n_lookahead as usize).collect(), + ) }) .collect() } diff --git a/polkadot/runtime/parachains/src/scheduler.rs b/polkadot/runtime/parachains/src/scheduler.rs index 0442301a32ff..33b4d849c490 100644 --- a/polkadot/runtime/parachains/src/scheduler.rs +++ b/polkadot/runtime/parachains/src/scheduler.rs @@ -36,6 +36,8 @@ //! number of groups as availability cores. Validator groups will be assigned to different //! availability cores over time. +use core::iter::Peekable; + use crate::{configuration, initializer::SessionChangeNotification, paras}; use frame_support::{pallet_prelude::*, traits::Defensive}; use frame_system::pallet_prelude::BlockNumberFor; @@ -45,7 +47,10 @@ use polkadot_primitives::{ }; use sp_runtime::traits::One; use sp_std::{ - collections::{btree_map::BTreeMap, vec_deque::VecDeque}, + collections::{ + btree_map::{self, BTreeMap}, + vec_deque::VecDeque, + }, prelude::*, }; @@ -190,7 +195,29 @@ pub mod pallet { } } -type PositionInClaimqueue = u32; +type PositionInClaimQueue = u32; + +struct ClaimQueueIterator { + next_idx: u32, + queue: Peekable>>, +} + +impl Iterator for ClaimQueueIterator { + type Item = (CoreIndex, VecDeque); + + fn next(&mut self) -> Option { + let (idx, _) = self.queue.peek()?; + let val = if idx != &CoreIndex(self.next_idx) { + log::trace!(target: LOG_TARGET, "idx did not match claim queue idx: {:?} vs {:?}", idx, self.next_idx); + (CoreIndex(self.next_idx), VecDeque::new()) + } else { + let (idx, q) = self.queue.next()?; + (idx, q) + }; + self.next_idx += 1; + Some(val) + } +} impl Pallet { /// Called by the initializer to initialize the scheduler pallet. @@ -203,7 +230,7 @@ impl Pallet { /// Called before the initializer notifies of a new session. pub(crate) fn pre_new_session() { - Self::push_claimqueue_items_to_assignment_provider(); + Self::push_claim_queue_items_to_assignment_provider(); Self::push_occupied_cores_to_assignment_provider(); } @@ -309,37 +336,51 @@ impl Pallet { (concluded_paras, timedout_paras) } - /// Note that the given cores have become occupied. Update the claimqueue accordingly. + /// Get an iterator into the claim queues. + /// + /// This iterator will have an item for each and every core index up to the maximum core index + /// found in the claim queue. In other words there will be no holes/missing core indices, + /// between core 0 and the maximum, even if the claim queue was missing entries for particular + /// indices in between. (The iterator will return an empty `VecDeque` for those indices. + fn claim_queue_iterator() -> impl Iterator>)> { + let queues = ClaimQueue::::get(); + return ClaimQueueIterator::> { + next_idx: 0, + queue: queues.into_iter().peekable(), + } + } + + /// Note that the given cores have become occupied. Update the claim queue accordingly. pub(crate) fn occupied( now_occupied: BTreeMap, - ) -> BTreeMap { + ) -> BTreeMap { let mut availability_cores = AvailabilityCores::::get(); log::debug!(target: LOG_TARGET, "[occupied] now_occupied {:?}", now_occupied); - let pos_mapping: BTreeMap = now_occupied + let pos_mapping: BTreeMap = now_occupied .iter() .flat_map(|(core_idx, para_id)| { - match Self::remove_from_claimqueue(*core_idx, *para_id) { + match Self::remove_from_claim_queue(*core_idx, *para_id) { Err(e) => { log::debug!( target: LOG_TARGET, - "[occupied] error on remove_from_claimqueue {}", + "[occupied] error on remove_from_claim queue {}", e ); None }, - Ok((pos_in_claimqueue, pe)) => { + Ok((pos_in_claim_queue, pe)) => { availability_cores[core_idx.0 as usize] = CoreOccupied::Paras(pe); - Some((*core_idx, pos_in_claimqueue)) + Some((*core_idx, pos_in_claim_queue)) }, } }) .collect(); // Drop expired claims after processing now_occupied. - Self::drop_expired_claims_from_claimqueue(); + Self::drop_expired_claims_from_claim_queue(); AvailabilityCores::::set(availability_cores); @@ -349,7 +390,7 @@ impl Pallet { /// Iterates through every element in all claim queues and tries to add new assignments from the /// `AssignmentProvider`. A claim is considered expired if it's `ttl` field is lower than the /// current block height. - fn drop_expired_claims_from_claimqueue() { + fn drop_expired_claims_from_claim_queue() { let now = frame_system::Pallet::::block_number(); let availability_cores = AvailabilityCores::::get(); let ttl = configuration::ActiveConfig::::get().scheduler_params.ttl; @@ -357,13 +398,13 @@ impl Pallet { ClaimQueue::::mutate(|cq| { for (idx, _) in (0u32..).zip(availability_cores) { let core_idx = CoreIndex(idx); - if let Some(core_claimqueue) = cq.get_mut(&core_idx) { + if let Some(core_claim_queue) = cq.get_mut(&core_idx) { let mut i = 0; let mut num_dropped = 0; - while i < core_claimqueue.len() { - let maybe_dropped = if let Some(entry) = core_claimqueue.get(i) { + while i < core_claim_queue.len() { + let maybe_dropped = if let Some(entry) = core_claim_queue.get(i) { if entry.ttl < now { - core_claimqueue.remove(i) + core_claim_queue.remove(i) } else { None } @@ -381,11 +422,11 @@ impl Pallet { for _ in 0..num_dropped { // For all claims dropped due to TTL, attempt to pop a new entry to - // the back of the claimqueue. + // the back of the claim queue. if let Some(assignment) = T::AssignmentProvider::pop_assignment_for_core(core_idx) { - core_claimqueue.push_back(ParasEntry::new(assignment, now + ttl)); + core_claim_queue.push_back(ParasEntry::new(assignment, now + ttl)); } } } @@ -536,10 +577,10 @@ impl Pallet { } // on new session - fn push_claimqueue_items_to_assignment_provider() { + fn push_claim_queue_items_to_assignment_provider() { for (_, claim_queue) in ClaimQueue::::take() { // Push back in reverse order so that when we pop from the provider again, - // the entries in the claimqueue are in the same order as they are right now. + // the entries in the claim queue are in the same order as they are right now. for para_entry in claim_queue.into_iter().rev() { Self::maybe_push_assignment(para_entry); } @@ -554,15 +595,8 @@ impl Pallet { } } - // - // ClaimQueue related functions - // - fn claimqueue_lookahead() -> u32 { - configuration::ActiveConfig::::get().scheduler_params.lookahead - } - - /// Frees cores and fills the free claimqueue spots by popping from the `AssignmentProvider`. - pub fn free_cores_and_fill_claimqueue( + /// Frees cores and fills the free claim queue spots by popping from the `AssignmentProvider`. + pub fn free_cores_and_fill_claim_queue( just_freed_cores: impl IntoIterator, now: BlockNumberFor, ) { @@ -573,26 +607,33 @@ impl Pallet { if ValidatorGroups::::decode_len().map_or(true, |l| l == 0) { return } - // If there exists a core, ensure we schedule at least one job onto it. - let n_lookahead = Self::claimqueue_lookahead().max(1); let n_session_cores = T::AssignmentProvider::session_core_count(); let cq = ClaimQueue::::get(); let config = configuration::ActiveConfig::::get(); + // Extra sanity, config should already never be smaller than 1: + let n_lookahead = config.scheduler_params.lookahead.max(1); let max_availability_timeouts = config.scheduler_params.max_availability_timeouts; let ttl = config.scheduler_params.ttl; for core_idx in 0..n_session_cores { let core_idx = CoreIndex::from(core_idx); + let n_lookahead_used = cq.get(&core_idx).map_or(0, |v| v.len() as u32); + // add previously timedout paras back into the queue if let Some(mut entry) = timedout_paras.remove(&core_idx) { if entry.availability_timeouts < max_availability_timeouts { // Increment the timeout counter. entry.availability_timeouts += 1; - // Reset the ttl so that a timed out assignment. - entry.ttl = now + ttl; - Self::add_to_claimqueue(core_idx, entry); - // The claim has been added back into the claimqueue. + if n_lookahead_used < n_lookahead { + entry.ttl = now + ttl; + } else { + // Over max capacity, we need to bump ttl (we exceeded the claim queue + // size, so otherwise the entry might get dropped before reaching the top): + entry.ttl = now + ttl + One::one(); + } + Self::add_to_claim_queue(core_idx, entry); + // The claim has been added back into the claim queue. // Do not pop another assignment for the core. continue } else { @@ -606,12 +647,9 @@ impl Pallet { if let Some(concluded_para) = concluded_paras.remove(&core_idx) { T::AssignmentProvider::report_processed(concluded_para); } - // We consider occupied cores to be part of the claimqueue - let n_lookahead_used = cq.get(&core_idx).map_or(0, |v| v.len() as u32) + - if Self::is_core_occupied(core_idx) { 1 } else { 0 }; for _ in n_lookahead_used..n_lookahead { if let Some(assignment) = T::AssignmentProvider::pop_assignment_for_core(core_idx) { - Self::add_to_claimqueue(core_idx, ParasEntry::new(assignment, now + ttl)); + Self::add_to_claim_queue(core_idx, ParasEntry::new(assignment, now + ttl)); } } } @@ -620,24 +658,17 @@ impl Pallet { debug_assert!(concluded_paras.is_empty()); } - fn is_core_occupied(core_idx: CoreIndex) -> bool { - match AvailabilityCores::::get().get(core_idx.0 as usize) { - None | Some(CoreOccupied::Free) => false, - Some(CoreOccupied::Paras(_)) => true, - } - } - - fn add_to_claimqueue(core_idx: CoreIndex, pe: ParasEntryType) { + fn add_to_claim_queue(core_idx: CoreIndex, pe: ParasEntryType) { ClaimQueue::::mutate(|la| { la.entry(core_idx).or_default().push_back(pe); }); } /// Returns `ParasEntry` with `para_id` at `core_idx` if found. - fn remove_from_claimqueue( + fn remove_from_claim_queue( core_idx: CoreIndex, para_id: ParaId, - ) -> Result<(PositionInClaimqueue, ParasEntryType), &'static str> { + ) -> Result<(PositionInClaimQueue, ParasEntryType), &'static str> { ClaimQueue::::mutate(|cq| { let core_claims = cq.get_mut(&core_idx).ok_or("core_idx not found in lookahead")?; @@ -654,20 +685,38 @@ impl Pallet { /// Paras scheduled next in the claim queue. pub(crate) fn scheduled_paras() -> impl Iterator { - let claimqueue = ClaimQueue::::get(); - claimqueue + let claim_queue = ClaimQueue::::get(); + claim_queue .into_iter() .filter_map(|(core_idx, v)| v.front().map(|e| (core_idx, e.assignment.para_id()))) } + /// Paras that may get backed on cores. + /// + /// 1. The para must be scheduled on core. + /// 2. Core needs to be free, otherwise backing is not possible. + pub(crate) fn eligible_paras() -> impl Iterator { + let availability_cores = AvailabilityCores::::get(); + + Self::claim_queue_iterator().zip(availability_cores.into_iter()).filter_map( + |((core_idx, queue), core)| { + if core != CoreOccupied::Free { + return None + } + let next_scheduled = queue.front()?; + Some((core_idx, next_scheduled.assignment.para_id())) + }, + ) + } + #[cfg(any(feature = "try-runtime", test))] - fn claimqueue_len() -> usize { + fn claim_queue_len() -> usize { ClaimQueue::::get().iter().map(|la_vec| la_vec.1.len()).sum() } #[cfg(all(not(feature = "runtime-benchmarks"), test))] - pub(crate) fn claimqueue_is_empty() -> bool { - Self::claimqueue_len() == 0 + pub(crate) fn claim_queue_is_empty() -> bool { + Self::claim_queue_len() == 0 } #[cfg(test)] @@ -676,7 +725,7 @@ impl Pallet { } #[cfg(test)] - pub(crate) fn set_claimqueue(claimqueue: BTreeMap>>) { - ClaimQueue::::set(claimqueue); + pub(crate) fn set_claim_queue(claim_queue: BTreeMap>>) { + ClaimQueue::::set(claim_queue); } } diff --git a/polkadot/runtime/parachains/src/scheduler/migration.rs b/polkadot/runtime/parachains/src/scheduler/migration.rs index 57f4fd670fbe..84d7d4b56710 100644 --- a/polkadot/runtime/parachains/src/scheduler/migration.rs +++ b/polkadot/runtime/parachains/src/scheduler/migration.rs @@ -248,7 +248,7 @@ mod v1 { .count(); ensure!( - Pallet::::claimqueue_len() as u32 + availability_cores_waiting as u32 == + Pallet::::claim_queue_len() as u32 + availability_cores_waiting as u32 == expected_len, "ClaimQueue and AvailabilityCores should have the correct length", ); diff --git a/polkadot/runtime/parachains/src/scheduler/tests.rs b/polkadot/runtime/parachains/src/scheduler/tests.rs index 74ad8adf00c4..32811241e171 100644 --- a/polkadot/runtime/parachains/src/scheduler/tests.rs +++ b/polkadot/runtime/parachains/src/scheduler/tests.rs @@ -80,7 +80,7 @@ fn run_to_block( Scheduler::initializer_initialize(b + 1); // In the real runtime this is expected to be called by the `InclusionInherent` pallet. - Scheduler::free_cores_and_fill_claimqueue(BTreeMap::new(), b + 1); + Scheduler::free_cores_and_fill_claim_queue(BTreeMap::new(), b + 1); } } @@ -158,6 +158,37 @@ fn scheduled_entries() -> impl Iterator(vec![para_id])); // Claim is dropped post call. - Scheduler::drop_expired_claims_from_claimqueue(); + Scheduler::drop_expired_claims_from_claim_queue(); assert!(!claimqueue_contains_para_ids::(vec![para_id])); // Add a claim on core 0 with a ttl in the future (15). let paras_entry = ParasEntry::new(Assignment::Bulk(para_id), now + 5); - Scheduler::add_to_claimqueue(core_idx, paras_entry.clone()); + Scheduler::add_to_claim_queue(core_idx, paras_entry.clone()); // Claim is in queue post call. - Scheduler::drop_expired_claims_from_claimqueue(); + Scheduler::drop_expired_claims_from_claim_queue(); assert!(claimqueue_contains_para_ids::(vec![para_id])); now = now + 6; run_to_block(now, |_| None); // Claim is dropped - Scheduler::drop_expired_claims_from_claimqueue(); + Scheduler::drop_expired_claims_from_claim_queue(); assert!(!claimqueue_contains_para_ids::(vec![para_id])); // Add a claim on core 0 with a ttl == now (16) let paras_entry = ParasEntry::new(Assignment::Bulk(para_id), now); - Scheduler::add_to_claimqueue(core_idx, paras_entry.clone()); + Scheduler::add_to_claim_queue(core_idx, paras_entry.clone()); // Claim is in queue post call. - Scheduler::drop_expired_claims_from_claimqueue(); + Scheduler::drop_expired_claims_from_claim_queue(); assert!(claimqueue_contains_para_ids::(vec![para_id])); now = now + 1; run_to_block(now, |_| None); // Drop expired claim. - Scheduler::drop_expired_claims_from_claimqueue(); + Scheduler::drop_expired_claims_from_claim_queue(); assert!(!claimqueue_contains_para_ids::(vec![para_id])); // Add a claim on core 0 with a ttl == now (17) let paras_entry_non_expired = ParasEntry::new(Assignment::Bulk(para_id), now); let paras_entry_expired = ParasEntry::new(Assignment::Bulk(para_id), now - 2); // ttls = [17, 15, 17] - Scheduler::add_to_claimqueue(core_idx, paras_entry_non_expired.clone()); - Scheduler::add_to_claimqueue(core_idx, paras_entry_expired.clone()); - Scheduler::add_to_claimqueue(core_idx, paras_entry_non_expired.clone()); + Scheduler::add_to_claim_queue(core_idx, paras_entry_non_expired.clone()); + Scheduler::add_to_claim_queue(core_idx, paras_entry_expired.clone()); + Scheduler::add_to_claim_queue(core_idx, paras_entry_non_expired.clone()); let cq = scheduler::ClaimQueue::::get(); assert_eq!(cq.get(&core_idx).unwrap().len(), 3); @@ -231,7 +262,7 @@ fn claimqueue_ttl_drop_fn_works() { MockAssigner::add_test_assignment(assignment.clone()); // Drop expired claim. - Scheduler::drop_expired_claims_from_claimqueue(); + Scheduler::drop_expired_claims_from_claim_queue(); let cq = scheduler::ClaimQueue::::get(); let cqc = cq.get(&core_idx).unwrap(); @@ -378,7 +409,7 @@ fn fill_claimqueue_fills() { run_to_block(2, |_| None); { - assert_eq!(Scheduler::claimqueue_len(), 3); + assert_eq!(Scheduler::claim_queue_len(), 3); let scheduled: BTreeMap<_, _> = scheduled_entries().collect(); // Was added a block later, note the TTL. @@ -488,9 +519,8 @@ fn schedule_schedules_including_just_freed() { .for_each(|(_core_idx, core_queue)| assert_eq!(core_queue.len(), 0)) } - // add a couple more para claims - the claim on `b` will go to the 3rd core - // (2) and the claim on `d` will go back to the 1st para core (0). The claim on `e` - // then will go for core `1`. + MockAssigner::add_test_assignment(assignment_a.clone()); + MockAssigner::add_test_assignment(assignment_c.clone()); MockAssigner::add_test_assignment(assignment_b.clone()); MockAssigner::add_test_assignment(assignment_d.clone()); MockAssigner::add_test_assignment(assignment_e.clone()); @@ -500,8 +530,7 @@ fn schedule_schedules_including_just_freed() { { let scheduled: BTreeMap<_, _> = scheduled_entries().collect(); - // cores 0 and 1 are occupied by claims. core 2 was free. - assert_eq!(scheduled.len(), 1); + assert_eq!(scheduled.len(), 3); assert_eq!( scheduled.get(&CoreIndex(2)).unwrap(), &ParasEntry { @@ -519,7 +548,7 @@ fn schedule_schedules_including_just_freed() { ] .into_iter() .collect(); - Scheduler::free_cores_and_fill_claimqueue(just_updated, now); + Scheduler::free_cores_and_fill_claim_queue(just_updated, now); { let scheduled: BTreeMap<_, _> = scheduled_entries().collect(); @@ -529,17 +558,28 @@ fn schedule_schedules_including_just_freed() { assert_eq!( scheduled.get(&CoreIndex(0)).unwrap(), &ParasEntry { - assignment: Assignment::Bulk(para_d), + // Next entry in queue is `a` again: + assignment: Assignment::Bulk(para_a), availability_timeouts: 0, ttl: 8 }, ); // Although C was descheduled, the core `2` was occupied so C goes back to the queue. + assert_eq!( + scheduler::ClaimQueue::::get()[&CoreIndex(1)][1], + ParasEntry { + assignment: Assignment::Bulk(para_c), + // End of the queue should be the pushed back entry: + availability_timeouts: 1, + // ttl 1 higher: + ttl: 9 + }, + ); assert_eq!( scheduled.get(&CoreIndex(1)).unwrap(), &ParasEntry { assignment: Assignment::Bulk(para_c), - availability_timeouts: 1, + availability_timeouts: 0, ttl: 8 }, ); @@ -552,8 +592,6 @@ fn schedule_schedules_including_just_freed() { }, ); - // Para A claim should have been wiped, but para C claim should remain. - assert!(!claimqueue_contains_para_ids::(vec![para_a])); assert!(claimqueue_contains_para_ids::(vec![para_c])); assert!(!availability_cores_contains_para_ids::(vec![para_a, para_c])); } @@ -627,12 +665,13 @@ fn schedule_clears_availability_cores() { // Add more assignments MockAssigner::add_test_assignment(assignment_a.clone()); + MockAssigner::add_test_assignment(assignment_b.clone()); MockAssigner::add_test_assignment(assignment_c.clone()); run_to_block(3, |_| None); // now note that cores 0 and 2 were freed. - Scheduler::free_cores_and_fill_claimqueue( + Scheduler::free_cores_and_fill_claim_queue( vec![(CoreIndex(0), FreedReason::Concluded), (CoreIndex(2), FreedReason::Concluded)] .into_iter() .collect::>(), @@ -807,7 +846,7 @@ fn on_demand_claims_are_pruned_after_timing_out() { ] .into_iter() .collect(); - Scheduler::free_cores_and_fill_claimqueue(just_updated, now); + Scheduler::free_cores_and_fill_claim_queue(just_updated, now); // ParaId a exists in the claim queue until max_retries is reached. if n < max_timeouts + now { @@ -854,7 +893,7 @@ fn on_demand_claims_are_pruned_after_timing_out() { } } - Scheduler::free_cores_and_fill_claimqueue(just_updated, now); + Scheduler::free_cores_and_fill_claim_queue(just_updated, now); // ParaId a exists in the claim queue until groups are rotated. if n < 31 { @@ -943,12 +982,12 @@ fn next_up_on_available_uses_next_scheduled_or_none() { ttl: 5 as u32, }; - Scheduler::add_to_claimqueue(CoreIndex(0), entry_a.clone()); + Scheduler::add_to_claim_queue(CoreIndex(0), entry_a.clone()); run_to_block(2, |_| None); { - assert_eq!(Scheduler::claimqueue_len(), 1); + assert_eq!(Scheduler::claim_queue_len(), 1); assert_eq!(scheduler::AvailabilityCores::::get().len(), 1); let mut map = BTreeMap::new(); @@ -963,7 +1002,7 @@ fn next_up_on_available_uses_next_scheduled_or_none() { assert!(Scheduler::next_up_on_available(CoreIndex(0)).is_none()); - Scheduler::add_to_claimqueue(CoreIndex(0), entry_b); + Scheduler::add_to_claim_queue(CoreIndex(0), entry_b); assert_eq!( Scheduler::next_up_on_available(CoreIndex(0)).unwrap(), @@ -1032,7 +1071,7 @@ fn next_up_on_time_out_reuses_claim_if_nothing_queued() { MockAssigner::add_test_assignment(assignment_b.clone()); // Pop assignment_b into the claimqueue - Scheduler::free_cores_and_fill_claimqueue(BTreeMap::new(), 2); + Scheduler::free_cores_and_fill_claim_queue(BTreeMap::new(), 2); //// Now that there is an earlier next-up, we use that. assert_eq!( @@ -1113,7 +1152,7 @@ fn session_change_requires_reschedule_dropping_removed_paras() { _ => None, }); - Scheduler::free_cores_and_fill_claimqueue(BTreeMap::new(), 3); + Scheduler::free_cores_and_fill_claim_queue(BTreeMap::new(), 3); assert_eq!( scheduler::ClaimQueue::::get(), @@ -1161,7 +1200,7 @@ fn session_change_requires_reschedule_dropping_removed_paras() { let groups = ValidatorGroups::::get(); assert_eq!(groups.len(), 5); - Scheduler::free_cores_and_fill_claimqueue(BTreeMap::new(), 4); + Scheduler::free_cores_and_fill_claim_queue(BTreeMap::new(), 4); assert_eq!( scheduler::ClaimQueue::::get(), diff --git a/prdoc/pr_4662.prdoc b/prdoc/pr_4662.prdoc new file mode 100644 index 000000000000..50f8a5bfd011 --- /dev/null +++ b/prdoc/pr_4662.prdoc @@ -0,0 +1,17 @@ +# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 +# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json + +title: Cleanup PVF artifact by cache limit and stale time + +doc: + - audience: Node Operator + description: | + Extend the PVF artifacts cleanup strategy. Previously, we pruned artifacts that were stale more than 24 hours. + After this change we attempt pruning artifacts only when they reach the 10 GB cache limit. If the least used + artifact is stale less than 24 hours we don't remove it. + +crates: + - name: polkadot-node-core-pvf-common + bump: patch + - name: polkadot-node-core-pvf + bump: patch diff --git a/prdoc/pr_4691.prdoc b/prdoc/pr_4691.prdoc new file mode 100644 index 000000000000..18cbb2296d43 --- /dev/null +++ b/prdoc/pr_4691.prdoc @@ -0,0 +1,14 @@ +# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 +# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json + +title: Fix claim queue size + +doc: + - audience: Runtime User + description: | + Ensure claim queue size is always the number configured by ` scheduler_params.lookahead`. Previously the claim queue of a core was shortened by 1 if the core was occupied. + + +crates: + - name: polkadot-runtime-parachains + bump: minor diff --git a/substrate/frame/conviction-voting/src/tests.rs b/substrate/frame/conviction-voting/src/tests.rs index 74baeace898b..0e985e25290f 100644 --- a/substrate/frame/conviction-voting/src/tests.rs +++ b/substrate/frame/conviction-voting/src/tests.rs @@ -49,6 +49,7 @@ impl Contains for BaseFilter { #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Test { + type BaseCallFilter = BaseFilter; type Block = Block; type AccountData = pallet_balances::AccountData; } diff --git a/substrate/frame/examples/multi-block-migrations/src/mock.rs b/substrate/frame/examples/multi-block-migrations/src/mock.rs index 9da1d2051fa1..b2a946e1c505 100644 --- a/substrate/frame/examples/multi-block-migrations/src/mock.rs +++ b/substrate/frame/examples/multi-block-migrations/src/mock.rs @@ -59,7 +59,7 @@ impl pallet_migrations::Config for Runtime { type MaxServiceWeight = MigratorServiceWeight; } -#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] +#[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Runtime { type Block = Block; type MultiBlockMigrator = Migrator; diff --git a/substrate/frame/fast-unstake/src/mock.rs b/substrate/frame/fast-unstake/src/mock.rs index d876f9f6171e..9238a085141d 100644 --- a/substrate/frame/fast-unstake/src/mock.rs +++ b/substrate/frame/fast-unstake/src/mock.rs @@ -23,10 +23,7 @@ use frame_support::{ traits::{ConstU64, Currency}, weights::constants::WEIGHT_REF_TIME_PER_SECOND, }; -use sp_runtime::{ - traits::{Convert, IdentityLookup}, - BuildStorage, -}; +use sp_runtime::{traits::IdentityLookup, BuildStorage}; use pallet_staking::{Exposure, IndividualExposure, StakerStatus}; use sp_std::prelude::*; @@ -147,20 +144,6 @@ impl pallet_staking::Config for Runtime { type DisablingStrategy = pallet_staking::UpToLimitDisablingStrategy; } -pub struct BalanceToU256; -impl Convert for BalanceToU256 { - fn convert(n: Balance) -> sp_core::U256 { - n.into() - } -} - -pub struct U256ToBalance; -impl Convert for U256ToBalance { - fn convert(n: sp_core::U256) -> Balance { - n.try_into().unwrap() - } -} - parameter_types! { pub static Deposit: u128 = 7; pub static BatchSize: u32 = 1; diff --git a/substrate/frame/im-online/src/mock.rs b/substrate/frame/im-online/src/mock.rs index 2aff9a0e26df..882581702ea1 100644 --- a/substrate/frame/im-online/src/mock.rs +++ b/substrate/frame/im-online/src/mock.rs @@ -25,10 +25,9 @@ use frame_support::{ weights::Weight, }; use pallet_session::historical as pallet_session_historical; -use sp_core::H256; use sp_runtime::{ testing::{TestXt, UintAuthorityId}, - traits::{BlakeTwo256, ConvertInto, IdentityLookup}, + traits::ConvertInto, BuildStorage, Permill, }; use sp_staking::{ @@ -114,28 +113,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Runtime { - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = (); - type RuntimeOrigin = RuntimeOrigin; - type Nonce = u64; - type RuntimeCall = RuntimeCall; - type Hash = H256; - type Hashing = BlakeTwo256; - type AccountId = u64; - type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = (); - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; } parameter_types! { diff --git a/substrate/frame/indices/src/mock.rs b/substrate/frame/indices/src/mock.rs index 87b8d79a7f83..7a8ff98f6d4a 100644 --- a/substrate/frame/indices/src/mock.rs +++ b/substrate/frame/indices/src/mock.rs @@ -20,11 +20,7 @@ #![cfg(test)] use crate::{self as pallet_indices, Config}; -use frame_support::{ - derive_impl, - traits::{ConstU32, ConstU64}, -}; -use sp_core::H256; +use frame_support::{derive_impl, traits::ConstU64}; use sp_runtime::BuildStorage; type Block = frame_system::mocking::MockBlock; @@ -40,28 +36,10 @@ frame_support::construct_runtime!( #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Test { - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = (); - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; type Nonce = u64; - type Hash = H256; - type Hashing = ::sp_runtime::traits::BlakeTwo256; - type AccountId = u64; type Lookup = Indices; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type Version = (); - type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; } impl pallet_balances::Config for Test { diff --git a/substrate/frame/nomination-pools/benchmarking/src/mock.rs b/substrate/frame/nomination-pools/benchmarking/src/mock.rs index def98b4d2945..7cbb61e00a31 100644 --- a/substrate/frame/nomination-pools/benchmarking/src/mock.rs +++ b/substrate/frame/nomination-pools/benchmarking/src/mock.rs @@ -24,35 +24,15 @@ use sp_runtime::{ }; type AccountId = u128; -type Nonce = u32; type BlockNumber = u64; type Balance = u128; #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Runtime { - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = (); - type RuntimeOrigin = RuntimeOrigin; - type Nonce = Nonce; - type RuntimeCall = RuntimeCall; - type Hash = sp_core::H256; - type Hashing = sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = (); - type Version = (); - type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; } impl pallet_timestamp::Config for Runtime { diff --git a/substrate/frame/nomination-pools/src/mock.rs b/substrate/frame/nomination-pools/src/mock.rs index b659c975a839..93fe6aa56054 100644 --- a/substrate/frame/nomination-pools/src/mock.rs +++ b/substrate/frame/nomination-pools/src/mock.rs @@ -240,29 +240,11 @@ impl sp_staking::StakingInterface for StakingMock { #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Runtime { - type SS58Prefix = (); - type BaseCallFilter = frame_support::traits::Everything; - type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; - type RuntimeCall = RuntimeCall; - type Hash = sp_core::H256; - type Hashing = sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = (); - type DbWeight = (); - type BlockLength = (); - type BlockWeights = (); - type Version = (); - type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; } parameter_types! { diff --git a/substrate/frame/nomination-pools/test-delegate-stake/src/mock.rs b/substrate/frame/nomination-pools/test-delegate-stake/src/mock.rs index 501823263598..820f2b7718ce 100644 --- a/substrate/frame/nomination-pools/test-delegate-stake/src/mock.rs +++ b/substrate/frame/nomination-pools/test-delegate-stake/src/mock.rs @@ -45,29 +45,11 @@ pub(crate) const POOL1_REWARD: AccountId = 20397359637244482196168876781421u128; #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Runtime { - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = (); - type RuntimeOrigin = RuntimeOrigin; type Nonce = Nonce; - type RuntimeCall = RuntimeCall; - type Hash = sp_core::H256; - type Hashing = sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = (); - type Version = (); - type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; } impl pallet_timestamp::Config for Runtime { diff --git a/substrate/frame/nomination-pools/test-transfer-stake/src/mock.rs b/substrate/frame/nomination-pools/test-transfer-stake/src/mock.rs index 0970570453b4..eb9d463424c8 100644 --- a/substrate/frame/nomination-pools/test-transfer-stake/src/mock.rs +++ b/substrate/frame/nomination-pools/test-transfer-stake/src/mock.rs @@ -29,7 +29,6 @@ use sp_runtime::{ }; type AccountId = u128; -type Nonce = u32; type BlockNumber = u64; type Balance = u128; @@ -40,29 +39,10 @@ pub(crate) const POOL1_REWARD: AccountId = 20397359637244482196168876781421u128; #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Runtime { - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = (); - type RuntimeOrigin = RuntimeOrigin; - type Nonce = Nonce; - type RuntimeCall = RuntimeCall; - type Hash = sp_core::H256; - type Hashing = sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = (); - type Version = (); - type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; } impl pallet_timestamp::Config for Runtime { diff --git a/substrate/frame/offences/benchmarking/src/mock.rs b/substrate/frame/offences/benchmarking/src/mock.rs index eeaa1364504a..6cbdde578528 100644 --- a/substrate/frame/offences/benchmarking/src/mock.rs +++ b/substrate/frame/offences/benchmarking/src/mock.rs @@ -29,39 +29,16 @@ use frame_system as system; use pallet_session::historical as pallet_session_historical; use sp_runtime::{ testing::{Header, UintAuthorityId}, - traits::IdentityLookup, BuildStorage, Perbill, }; type AccountId = u64; -type Nonce = u32; type Balance = u64; #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Test { - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = (); - type RuntimeOrigin = RuntimeOrigin; - type Nonce = Nonce; - type RuntimeCall = RuntimeCall; - type Hash = sp_core::H256; - type Hashing = ::sp_runtime::traits::BlakeTwo256; - type AccountId = AccountId; - type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = (); - type Version = (); - type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; } impl pallet_balances::Config for Test { diff --git a/substrate/frame/offences/src/mock.rs b/substrate/frame/offences/src/mock.rs index 1725f4158d33..6796837637ae 100644 --- a/substrate/frame/offences/src/mock.rs +++ b/substrate/frame/offences/src/mock.rs @@ -27,11 +27,7 @@ use frame_support::{ traits::ConstU32, weights::{constants::RocksDbWeight, Weight}, }; -use sp_core::H256; -use sp_runtime::{ - traits::{BlakeTwo256, IdentityLookup}, - BuildStorage, Perbill, -}; +use sp_runtime::{traits::IdentityLookup, BuildStorage, Perbill}; use sp_staking::{ offence::{self, Kind, OffenceDetails}, SessionIndex, @@ -75,27 +71,11 @@ frame_support::construct_runtime!( #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Runtime { - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = RocksDbWeight; - type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; - type RuntimeCall = RuntimeCall; - type Hash = H256; - type Hashing = BlakeTwo256; - type AccountId = u64; type Lookup = IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = (); - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); + type DbWeight = RocksDbWeight; type MaxConsumers = ConstU32<16>; } diff --git a/substrate/frame/paged-list/src/mock.rs b/substrate/frame/paged-list/src/mock.rs index e086b4ba2b27..3e4903200c3d 100644 --- a/substrate/frame/paged-list/src/mock.rs +++ b/substrate/frame/paged-list/src/mock.rs @@ -20,12 +20,8 @@ #![cfg(feature = "std")] use crate::{paged_list::StoragePagedListMeta, Config, ListPrefix}; -use frame_support::{derive_impl, traits::ConstU16}; -use sp_core::H256; -use sp_runtime::{ - traits::{BlakeTwo256, IdentityLookup}, - BuildStorage, -}; +use frame_support::derive_impl; +use sp_runtime::{traits::IdentityLookup, BuildStorage}; type Block = frame_system::mocking::MockBlock; @@ -40,28 +36,11 @@ frame_support::construct_runtime!( #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Test { - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = (); - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; type Nonce = u64; - type Hash = H256; - type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; type Block = Block; type RuntimeEvent = RuntimeEvent; - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = (); - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = ConstU16<42>; - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; } frame_support::parameter_types! { diff --git a/substrate/frame/session/benchmarking/src/mock.rs b/substrate/frame/session/benchmarking/src/mock.rs index 6cefa8f39a8c..5cba79ef5b9a 100644 --- a/substrate/frame/session/benchmarking/src/mock.rs +++ b/substrate/frame/session/benchmarking/src/mock.rs @@ -47,29 +47,11 @@ frame_support::construct_runtime!( #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Test { - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = (); - type RuntimeOrigin = RuntimeOrigin; type Nonce = Nonce; - type RuntimeCall = RuntimeCall; - type Hash = sp_core::H256; - type Hashing = ::sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = (); - type Version = (); - type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; } impl pallet_balances::Config for Test { diff --git a/substrate/frame/sudo/src/mock.rs b/substrate/frame/sudo/src/mock.rs index a3a786c4af39..67f896e1c021 100644 --- a/substrate/frame/sudo/src/mock.rs +++ b/substrate/frame/sudo/src/mock.rs @@ -106,6 +106,7 @@ impl Contains for BlockEverything { #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Test { + type BaseCallFilter = BlockEverything; type Block = Block; } diff --git a/substrate/frame/system/benches/bench.rs b/substrate/frame/system/benches/bench.rs index b3029630409f..1b0f459c9792 100644 --- a/substrate/frame/system/benches/bench.rs +++ b/substrate/frame/system/benches/bench.rs @@ -16,12 +16,8 @@ // limitations under the License. use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use frame_support::{derive_impl, traits::ConstU32}; -use sp_core::H256; -use sp_runtime::{ - traits::{BlakeTwo256, IdentityLookup}, - BuildStorage, Perbill, -}; +use frame_support::derive_impl; +use sp_runtime::{BuildStorage, Perbill}; #[frame_support::pallet] mod module { use frame_support::pallet_prelude::*; @@ -59,28 +55,8 @@ frame_support::parameter_types! { #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Runtime { - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = (); - type BlockLength = BlockLength; - type DbWeight = (); - type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; - type RuntimeCall = RuntimeCall; - type Hash = H256; - type Hashing = BlakeTwo256; - type AccountId = u64; - type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = (); - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; } impl module::Config for Runtime { diff --git a/substrate/frame/system/benchmarking/src/mock.rs b/substrate/frame/system/benchmarking/src/mock.rs index 39a64ff6177c..42e4aa0eaf4b 100644 --- a/substrate/frame/system/benchmarking/src/mock.rs +++ b/substrate/frame/system/benchmarking/src/mock.rs @@ -21,10 +21,7 @@ use codec::Encode; use frame_support::derive_impl; -use sp_runtime::{traits::IdentityLookup, BuildStorage}; - -type AccountId = u64; -type Nonce = u32; +use sp_runtime::BuildStorage; type Block = frame_system::mocking::MockBlock; @@ -37,29 +34,7 @@ frame_support::construct_runtime!( #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Test { - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = (); - type RuntimeOrigin = RuntimeOrigin; - type Nonce = Nonce; - type RuntimeCall = RuntimeCall; - type Hash = sp_core::H256; - type Hashing = ::sp_runtime::traits::BlakeTwo256; - type AccountId = AccountId; - type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = (); - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = (); - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; } impl crate::Config for Test {} diff --git a/substrate/frame/system/rpc/runtime-api/Cargo.toml b/substrate/frame/system/rpc/runtime-api/Cargo.toml index b134cc3b6173..8b71ca2a1395 100644 --- a/substrate/frame/system/rpc/runtime-api/Cargo.toml +++ b/substrate/frame/system/rpc/runtime-api/Cargo.toml @@ -18,6 +18,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { package = "parity-scale-codec", version = "3.6.12", default-features = false } sp-api = { path = "../../../../primitives/api", default-features = false } +docify = "0.2.0" [features] default = ["std"] diff --git a/substrate/frame/system/rpc/runtime-api/src/lib.rs b/substrate/frame/system/rpc/runtime-api/src/lib.rs index f59988d818f0..67adeb5cb9da 100644 --- a/substrate/frame/system/rpc/runtime-api/src/lib.rs +++ b/substrate/frame/system/rpc/runtime-api/src/lib.rs @@ -23,6 +23,7 @@ #![cfg_attr(not(feature = "std"), no_std)] +#[docify::export(AccountNonceApi)] sp_api::decl_runtime_apis! { /// The API to query account nonce. pub trait AccountNonceApi where diff --git a/substrate/frame/transaction-payment/asset-conversion-tx-payment/src/mock.rs b/substrate/frame/transaction-payment/asset-conversion-tx-payment/src/mock.rs index 0cafb35d52e1..cc43cffd7deb 100644 --- a/substrate/frame/transaction-payment/asset-conversion-tx-payment/src/mock.rs +++ b/substrate/frame/transaction-payment/asset-conversion-tx-payment/src/mock.rs @@ -38,9 +38,8 @@ use frame_system as system; use frame_system::{EnsureRoot, EnsureSignedBy}; use pallet_asset_conversion::{Ascending, Chain, WithFirstAsset}; use pallet_transaction_payment::FungibleAdapter; -use sp_core::H256; use sp_runtime::{ - traits::{AccountIdConversion, BlakeTwo256, IdentityLookup, SaturatedConversion}, + traits::{AccountIdConversion, IdentityLookup, SaturatedConversion}, Permill, }; @@ -87,28 +86,12 @@ parameter_types! { #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Runtime { - type BaseCallFilter = frame_support::traits::Everything; type BlockWeights = BlockWeights; - type BlockLength = (); - type DbWeight = (); - type RuntimeOrigin = RuntimeOrigin; type Nonce = u64; - type RuntimeCall = RuntimeCall; - type Hash = H256; - type Hashing = BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type Version = (); - type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; } parameter_types! { diff --git a/substrate/frame/transaction-payment/asset-tx-payment/src/mock.rs b/substrate/frame/transaction-payment/asset-tx-payment/src/mock.rs index f27fcd53fecd..fce712c3eba3 100644 --- a/substrate/frame/transaction-payment/asset-tx-payment/src/mock.rs +++ b/substrate/frame/transaction-payment/asset-tx-payment/src/mock.rs @@ -29,8 +29,7 @@ use frame_support::{ use frame_system as system; use frame_system::EnsureRoot; use pallet_transaction_payment::FungibleAdapter; -use sp_core::H256; -use sp_runtime::traits::{BlakeTwo256, ConvertInto, IdentityLookup, SaturatedConversion}; +use sp_runtime::traits::{ConvertInto, SaturatedConversion}; type Block = frame_system::mocking::MockBlock; type Balance = u64; @@ -73,28 +72,9 @@ parameter_types! { #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Runtime { - type BaseCallFilter = frame_support::traits::Everything; type BlockWeights = BlockWeights; - type BlockLength = (); - type DbWeight = (); - type RuntimeOrigin = RuntimeOrigin; - type Nonce = u64; - type RuntimeCall = RuntimeCall; - type Hash = H256; - type Hashing = BlakeTwo256; - type AccountId = AccountId; - type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type Version = (); - type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; } parameter_types! { diff --git a/substrate/frame/transaction-payment/src/mock.rs b/substrate/frame/transaction-payment/src/mock.rs index 1ef95128f2a8..7b731eeb8250 100644 --- a/substrate/frame/transaction-payment/src/mock.rs +++ b/substrate/frame/transaction-payment/src/mock.rs @@ -17,15 +17,11 @@ use super::*; use crate as pallet_transaction_payment; - -use sp_core::H256; -use sp_runtime::traits::{BlakeTwo256, IdentityLookup}; - use frame_support::{ derive_impl, dispatch::DispatchClass, parameter_types, - traits::{fungible, ConstU32, ConstU64, Imbalance, OnUnbalanced}, + traits::{fungible, ConstU64, Imbalance, OnUnbalanced}, weights::{Weight, WeightToFee as WeightToFeeT}, }; use frame_system as system; @@ -72,28 +68,9 @@ parameter_types! { #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Runtime { - type BaseCallFilter = frame_support::traits::Everything; type BlockWeights = BlockWeights; - type BlockLength = (); - type DbWeight = (); - type RuntimeOrigin = RuntimeOrigin; - type Nonce = u64; - type RuntimeCall = RuntimeCall; - type Hash = H256; - type Hashing = BlakeTwo256; - type AccountId = u64; - type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; + type AccountData = pallet_balances::AccountData; } impl pallet_balances::Config for Runtime { diff --git a/substrate/frame/tx-pause/src/mock.rs b/substrate/frame/tx-pause/src/mock.rs index 7245fe7d5d72..f42d4cb58a2a 100644 --- a/substrate/frame/tx-pause/src/mock.rs +++ b/substrate/frame/tx-pause/src/mock.rs @@ -27,36 +27,13 @@ use frame_support::{ traits::{ConstU64, Everything, InsideBoth, InstanceFilter}, }; use frame_system::EnsureSignedBy; -use sp_core::H256; -use sp_runtime::{ - traits::{BlakeTwo256, IdentityLookup}, - BuildStorage, -}; +use sp_runtime::{traits::BlakeTwo256, BuildStorage}; #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Test { type BaseCallFilter = InsideBoth; - type BlockWeights = (); - type BlockLength = (); - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Nonce = u64; - type Hash = H256; - type Hashing = BlakeTwo256; - type AccountId = u64; - type Lookup = IdentityLookup; - type RuntimeEvent = RuntimeEvent; type Block = Block; - type DbWeight = (); - type Version = (); - type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; } parameter_types! { diff --git a/substrate/test-utils/runtime/src/lib.rs b/substrate/test-utils/runtime/src/lib.rs index ab87db0e7006..0aab6d3f01ca 100644 --- a/substrate/test-utils/runtime/src/lib.rs +++ b/substrate/test-utils/runtime/src/lib.rs @@ -355,29 +355,12 @@ parameter_types! { #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::pallet::Config for Runtime { - type BaseCallFilter = frame_support::traits::Everything; type BlockWeights = RuntimeBlockWeights; - type BlockLength = (); - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; type Nonce = Nonce; - type Hash = H256; - type Hashing = Hashing; type AccountId = AccountId; type Lookup = sp_runtime::traits::IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = ConstU64<2400>; - type DbWeight = (); - type Version = (); - type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; } pub mod currency { diff --git a/substrate/utils/frame/rpc/system/Cargo.toml b/substrate/utils/frame/rpc/system/Cargo.toml index 6829d753ed71..75d24e8e210f 100644 --- a/substrate/utils/frame/rpc/system/Cargo.toml +++ b/substrate/utils/frame/rpc/system/Cargo.toml @@ -16,9 +16,14 @@ workspace = true targets = ["x86_64-unknown-linux-gnu"] [dependencies] -codec = { package = "parity-scale-codec", version = "3.6.12" } -jsonrpsee = { version = "0.22.5", features = ["client-core", "macros", "server-core"] } futures = "0.3.30" +codec = { package = "parity-scale-codec", version = "3.6.12" } +docify = "0.2.0" +jsonrpsee = { version = "0.22.5", features = [ + "client-core", + "macros", + "server-core", +] } log = { workspace = true, default-features = true } frame-system-rpc-runtime-api = { path = "../../../../frame/system/rpc/runtime-api" } sc-rpc-api = { path = "../../../../client/rpc-api" } diff --git a/substrate/utils/frame/rpc/system/src/lib.rs b/substrate/utils/frame/rpc/system/src/lib.rs index bb0592599b2a..8cb7b785bc7c 100644 --- a/substrate/utils/frame/rpc/system/src/lib.rs +++ b/substrate/utils/frame/rpc/system/src/lib.rs @@ -37,6 +37,7 @@ use sp_runtime::{legacy, traits}; pub use frame_system_rpc_runtime_api::AccountNonceApi; /// System RPC methods. +#[docify::export] #[rpc(client, server)] pub trait SystemApi { /// Returns the next valid index (aka nonce) for given account. diff --git a/templates/minimal/node/Cargo.toml b/templates/minimal/node/Cargo.toml index d07c7b6dd9b5..a10364a2854a 100644 --- a/templates/minimal/node/Cargo.toml +++ b/templates/minimal/node/Cargo.toml @@ -14,6 +14,7 @@ build = "build.rs" targets = ["x86_64-unknown-linux-gnu"] [dependencies] +docify = "0.2.0" clap = { version = "4.5.3", features = ["derive"] } futures = { version = "0.3.30", features = ["thread-pool"] } futures-timer = "3.0.1" diff --git a/templates/minimal/node/src/rpc.rs b/templates/minimal/node/src/rpc.rs index d0c417a93d7a..4b283bb2a66f 100644 --- a/templates/minimal/node/src/rpc.rs +++ b/templates/minimal/node/src/rpc.rs @@ -27,7 +27,6 @@ use runtime::interface::{AccountId, Nonce, OpaqueBlock}; use sc_transaction_pool_api::TransactionPool; use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; use std::sync::Arc; -use substrate_frame_rpc_system::{System, SystemApiServer}; pub use sc_rpc_api::DenyUnsafe; @@ -41,6 +40,7 @@ pub struct FullDeps { pub deny_unsafe: DenyUnsafe, } +#[docify::export] /// Instantiate all full RPC extensions. pub fn create_full( deps: FullDeps, @@ -57,6 +57,7 @@ where C::Api: substrate_frame_rpc_system::AccountNonceApi, P: TransactionPool + 'static, { + use substrate_frame_rpc_system::{System, SystemApiServer}; let mut module = RpcModule::new(()); let FullDeps { client, pool, deny_unsafe } = deps; diff --git a/templates/parachain/pallets/template/src/mock.rs b/templates/parachain/pallets/template/src/mock.rs index 9a907f616605..ebb0598df97b 100644 --- a/templates/parachain/pallets/template/src/mock.rs +++ b/templates/parachain/pallets/template/src/mock.rs @@ -1,10 +1,6 @@ -use frame_support::{derive_impl, parameter_types, traits::Everything}; +use frame_support::{derive_impl, parameter_types}; use frame_system as system; -use sp_core::H256; -use sp_runtime::{ - traits::{BlakeTwo256, IdentityLookup}, - BuildStorage, -}; +use sp_runtime::BuildStorage; type Block = frame_system::mocking::MockBlock; @@ -23,28 +19,7 @@ parameter_types! { #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl system::Config for Test { - type BaseCallFilter = Everything; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = (); - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Nonce = u64; - type Hash = H256; - type Hashing = BlakeTwo256; - type AccountId = u64; - type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = (); - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = SS58Prefix; - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; } impl crate::Config for Test { diff --git a/templates/solochain/pallets/template/src/mock.rs b/templates/solochain/pallets/template/src/mock.rs index 09081dae0625..0c2a247e802b 100644 --- a/templates/solochain/pallets/template/src/mock.rs +++ b/templates/solochain/pallets/template/src/mock.rs @@ -1,10 +1,6 @@ use crate as pallet_template; -use frame_support::{derive_impl, traits::ConstU16}; -use sp_core::H256; -use sp_runtime::{ - traits::{BlakeTwo256, IdentityLookup}, - BuildStorage, -}; +use frame_support::derive_impl; +use sp_runtime::BuildStorage; type Block = frame_system::mocking::MockBlock; @@ -19,28 +15,7 @@ frame_support::construct_runtime!( #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Test { - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = (); - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Nonce = u64; - type Hash = H256; - type Hashing = BlakeTwo256; - type AccountId = u64; - type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = (); - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = ConstU16<42>; - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; } impl pallet_template::Config for Test {