Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

omni-node: add metadata checks for runtime/parachain compatibility #6450

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
9cd1a7c
(wip) cumulus/omninode-lib: parachain system check
iulianbarbu Oct 5, 2024
0053b5a
polish a bit the pallet existance check
iulianbarbu Oct 23, 2024
f0055ea
break line length
iulianbarbu Oct 24, 2024
8b99816
adjust message length
iulianbarbu Oct 24, 2024
350985d
wip: testing why metadata decoding doesn't work
iulianbarbu Oct 29, 2024
40141d1
fix runtime metadata decoding
iulianbarbu Nov 11, 2024
0631349
remove left over chain spec
iulianbarbu Nov 12, 2024
00757ef
merge with master
iulianbarbu Nov 12, 2024
5cbcb26
Merge branch 'master' into ib-omni-node-ps-check
iulianbarbu Nov 14, 2024
149defd
made small adjustments with comments
iulianbarbu Nov 14, 2024
1f8128a
check frame-metadata storage block number
iulianbarbu Nov 15, 2024
bbe6e42
Merge branch 'master' into ib-omni-node-ps-check
iulianbarbu Nov 15, 2024
f869f32
added tests
iulianbarbu Nov 17, 2024
36861c0
Merge branch 'master' into ib-omni-node-ps-check
iulianbarbu Nov 17, 2024
6740b97
Merge branch 'master' into ib-omni-node-ps-check
iulianbarbu Nov 18, 2024
fe0887c
add docs for runtime conventions
iulianbarbu Nov 18, 2024
337ac48
add prdoc & remove leftover dir
iulianbarbu Nov 18, 2024
2d40797
remove decode feature
iulianbarbu Nov 18, 2024
5849e12
fix some weird Cargo.toml changes
iulianbarbu Nov 18, 2024
3dc55ad
fix compilation
iulianbarbu Nov 19, 2024
5583014
some more fixes
iulianbarbu Nov 19, 2024
8945e9d
fix linting
iulianbarbu Nov 19, 2024
cc0b3d1
fix typo
iulianbarbu Nov 19, 2024
c30917d
Merge branch 'master' into ib-omni-node-ps-check
iulianbarbu Nov 19, 2024
18aa6c7
Merge branch 'master' into ib-omni-node-ps-check
iulianbarbu Nov 27, 2024
993d264
Merge branch 'master' into ib-omni-node-ps-check
iulianbarbu Nov 27, 2024
6e747c1
udpate Cargo.lock
iulianbarbu Nov 27, 2024
f3a779f
revert litep2p version
iulianbarbu Nov 27, 2024
5f969cd
fix Cargo.lock
iulianbarbu Nov 27, 2024
08576d5
Merge branch 'master' of github.com:paritytech/polkadot-sdk into ib-o…
iulianbarbu Nov 28, 2024
3f2cef3
revert Cargo.toml
iulianbarbu Nov 28, 2024
ab564ba
Merge branch 'master' into ib-omni-node-ps-check
iulianbarbu Nov 28, 2024
58790cc
Merge branch 'master' into ib-omni-node-ps-check
iulianbarbu Nov 29, 2024
ba0096a
Merge branch 'master' into ib-omni-node-ps-check
iulianbarbu Nov 29, 2024
c5a6d09
revert to master Cargo.lock
iulianbarbu Nov 29, 2024
b657f81
corrected doc link
iulianbarbu Nov 29, 2024
fcfa988
Merge branch 'master' into ib-omni-node-ps-check
iulianbarbu Nov 30, 2024
8df94e5
update prdoc
iulianbarbu Nov 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions cumulus/polkadot-omni-node/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ workspace = true
path = "src/lib.rs"

[dependencies]
anyhow = { workspace = true }
async-trait = { workspace = true }
clap = { features = ["derive"], workspace = true }
codec = { workspace = true, default-features = true }
Expand All @@ -26,6 +27,9 @@ docify = { workspace = true }
# Local
jsonrpsee = { features = ["server"], workspace = true }
parachains-common = { workspace = true, default-features = true }
frame-metadata = { workspace = true, default-features = true, features = [
"decode",
lexnv marked this conversation as resolved.
Show resolved Hide resolved
] }

# Substrate
frame-benchmarking = { optional = true, workspace = true, default-features = true }
Expand Down Expand Up @@ -94,12 +98,8 @@ wait-timeout = { workspace = true }

[features]
default = []
rococo-native = [
"polkadot-cli/rococo-native",
]
westend-native = [
"polkadot-cli/westend-native",
]
rococo-native = ["polkadot-cli/rococo-native"]
westend-native = ["polkadot-cli/westend-native"]
runtime-benchmarks = [
"cumulus-primitives-core/runtime-benchmarks",
"frame-benchmarking-cli/runtime-benchmarks",
Expand Down
25 changes: 25 additions & 0 deletions cumulus/polkadot-omni-node/lib/src/common/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,28 @@ impl RuntimeResolver for DefaultRuntimeResolver {
Ok(Runtime::Omni(BlockNumber::U32, Consensus::Aura(AuraConsensusId::Sr25519)))
}
}

/// Logic that inspects runtime's metadata for Omni Node compatibility.
pub mod metadata {
use frame_metadata::{RuntimeMetadata, RuntimeMetadataPrefixed};
use sp_core::Decode;

/// Checks if pallet exists in runtime's metadata.
///
/// Metadata (as plain byte array) is decoded with `frame_metadata::Decode` and
/// pallets existance is checked by looking for pallets with certain names.
pub fn pallet_exists<'a>(
mut metadata: &'a [u8],
name: &str,
) -> Result<bool, sc_service::error::Error> {
let decoded_metadata = RuntimeMetadataPrefixed::decode(&mut metadata)
.map_err(|e| sc_service::error::Error::Application(Box::new(e) as Box<_>))?;
match decoded_metadata.1 {
RuntimeMetadata::V14(inner) => Ok(inner.pallets.iter().any(|p| p.name == name)),
RuntimeMetadata::V15(inner) => Ok(inner.pallets.iter().any(|p| p.name == name)),
_ => Err(sc_service::error::Error::Application(
anyhow::anyhow!("Metadata version lower than 14 not supported.").into(),
)),
}
}
}
40 changes: 31 additions & 9 deletions cumulus/polkadot-omni-node/lib/src/common/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@
// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.

use crate::common::{
command::NodeCommandRunner,
rpc::BuildRpcExtensions,
types::{
ParachainBackend, ParachainBlockImport, ParachainClient, ParachainHostFunctions,
ParachainService,
use crate::{
common::{
command::NodeCommandRunner,
rpc::BuildRpcExtensions,
types::{
ParachainBackend, ParachainBlockImport, ParachainClient, ParachainHostFunctions,
ParachainService,
},
ConstructNodeRuntimeApi, NodeBlock, NodeExtraArgs,
},
ConstructNodeRuntimeApi, NodeBlock, NodeExtraArgs,
runtime::metadata::pallet_exists,
};
use cumulus_client_cli::CollatorOptions;
use cumulus_client_service::{
Expand All @@ -41,9 +44,12 @@ use sc_sysinfo::HwBench;
use sc_telemetry::{TelemetryHandle, TelemetryWorker};
use sc_tracing::tracing::Instrument;
use sc_transaction_pool::TransactionPoolHandle;
use sp_api::{Metadata, ProvideRuntimeApi};
use sp_keystore::KeystorePtr;
use std::{future::Future, pin::Pin, sync::Arc, time::Duration};

const DEFAULT_PARACHAIN_SYSTEM_PALLET_NAME: &str = "ParachainSystem";

pub(crate) trait BuildImportQueue<Block: BlockT, RuntimeApi> {
fn build_import_queue(
client: Arc<ParachainClient<Block, RuntimeApi>>,
Expand Down Expand Up @@ -214,10 +220,26 @@ pub(crate) trait NodeSpec: BaseNodeSpec {

let params = Self::new_partial(&parachain_config)?;
let (block_import, mut telemetry, telemetry_worker_handle) = params.other;

let client = params.client.clone();
let backend = params.backend.clone();

// Best effort check of parachain-system pallet by pallet name.
let best_block = client.chain_info().finalized_hash;
let metadata = client
.runtime_api()
.metadata(best_block)
.map_err(|e| sc_service::Error::Application(Box::new(e) as Box<_>))?;

if !pallet_exists(metadata.as_slice(), DEFAULT_PARACHAIN_SYSTEM_PALLET_NAME)? {
log::warn!(
r#"⚠️ The parachain system pallet (https://docs.rs/crate/cumulus-pallet-parachain-system/latest) is
missing from the runtime’s metadata. Omni Node requires this pallet to be defined as `ParachainSystem`
in your runtime. If your setup uses a different name for the `cumulus_parachain_system_pallet`, Omni Node
might still work, but it's recommended to name it `ParachainSystem`. Not following this naming convention
could cause issues, as future development expects the type to be named `ParachainSystem`."#,
);
}

let backend = params.backend.clone();
let mut task_manager = params.task_manager;
let (relay_chain_interface, collator_key) = build_relay_chain_interface(
polkadot_config,
Expand Down
Loading