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

Merged
merged 71 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
71 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
8c2c693
check metadata earlier
iulianbarbu Dec 4, 2024
ea95f47
update benchmarking-cli
iulianbarbu Dec 4, 2024
ccd8187
fixed scrambled code
iulianbarbu Dec 4, 2024
a5c71ef
style fixes
iulianbarbu Dec 4, 2024
55d84d1
add sp-io dev dep
iulianbarbu Dec 5, 2024
4523b1c
Merge branch 'master' into ib-omni-node-ps-check
iulianbarbu Dec 5, 2024
384bc82
updated Cargo.toml
iulianbarbu Dec 5, 2024
ce713f9
fix umbrella
iulianbarbu Dec 5, 2024
7e97c7a
update cargo.lock
iulianbarbu Dec 5, 2024
3581f46
more style fixes
iulianbarbu Dec 5, 2024
0c5f785
redo import
iulianbarbu Dec 5, 2024
11c39dd
taplo format
iulianbarbu Dec 5, 2024
e064430
umbrella fixes
iulianbarbu Dec 5, 2024
c858bfe
Merge branch 'master' into ib-omni-node-ps-check
iulianbarbu Dec 5, 2024
b425b6c
more umbrella Cargo.toml fmt
iulianbarbu Dec 5, 2024
08e63bd
Merge branch 'master' into ib-omni-node-ps-check
iulianbarbu Dec 5, 2024
ec9b04b
Update cumulus/polkadot-omni-node/lib/src/common/runtime.rs
iulianbarbu Dec 5, 2024
0ed4f59
Update cumulus/polkadot-omni-node/lib/src/common/runtime.rs
iulianbarbu Dec 5, 2024
9279e6e
add new crate to prdoc
iulianbarbu Dec 6, 2024
cf29ed2
Merge branch 'master' into ib-omni-node-ps-check
iulianbarbu Dec 6, 2024
0ba6ecb
fixes from seb & michal reviews
iulianbarbu Dec 10, 2024
5e1ef1e
update prdoc
iulianbarbu Dec 10, 2024
1aa4d3d
rephrased public do
iulianbarbu Dec 10, 2024
c6e9f8c
remove redundant dependency
iulianbarbu Dec 11, 2024
0261c3b
avoid exposing APIs around metadata inspection for now
iulianbarbu Dec 11, 2024
1cb5361
Update docs/sdk/src/reference_docs/omni_node.rs
iulianbarbu Dec 11, 2024
4d469da
Update docs/sdk/src/reference_docs/omni_node.rs
iulianbarbu Dec 11, 2024
6354748
this builds fine too
iulianbarbu Dec 11, 2024
16a43e5
Merge branch 'master' into ib-omni-node-ps-check
iulianbarbu Dec 11, 2024
4fd9df5
updated prdoc
iulianbarbu Dec 11, 2024
2a7b404
Merge branch 'master' into ib-omni-node-ps-check
iulianbarbu Dec 12, 2024
6ae6615
Merge branch 'master' into ib-omni-node-ps-check
iulianbarbu Dec 12, 2024
7deb995
change back formatting in Cargo.toml
iulianbarbu Dec 12, 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
2 changes: 2 additions & 0 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 `sp_core::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(),
)),
}
}
}
47 changes: 38 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,33 @@ 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;
// The `Metadata::metadata()` API returns only metadata according
// to V14 schema. It would be great to return the latest stable
// version in the future. There is an alternative to pick the latest
// by going through `metadata_versions` and then pick the maximum
// with `metadata_at_version`, but that's more code for no real benefit.
// The following code is fine with whichever metadata version
// contains pallet information, includding their names.
iulianbarbu marked this conversation as resolved.
Show resolved Hide resolved
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