From 88b3c5c087a1b5c8877a527e15799406d6b38011 Mon Sep 17 00:00:00 2001 From: Sebastian Kunert Date: Fri, 13 Dec 2024 15:45:47 +0100 Subject: [PATCH 1/4] Detect pending code in storage and send go ahead signal. --- cumulus/client/parachain-inherent/src/mock.rs | 13 +++++++----- .../lib/src/nodes/manual_seal.rs | 21 +++++++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/cumulus/client/parachain-inherent/src/mock.rs b/cumulus/client/parachain-inherent/src/mock.rs index 950cba2aaa7d..e08aca932564 100644 --- a/cumulus/client/parachain-inherent/src/mock.rs +++ b/cumulus/client/parachain-inherent/src/mock.rs @@ -17,17 +17,17 @@ use crate::{ParachainInherentData, INHERENT_IDENTIFIER}; use codec::Decode; use cumulus_primitives_core::{ - relay_chain, InboundDownwardMessage, InboundHrmpMessage, ParaId, PersistedValidationData, + relay_chain, relay_chain::UpgradeGoAhead, InboundDownwardMessage, InboundHrmpMessage, ParaId, + PersistedValidationData, }; use cumulus_primitives_parachain_inherent::MessageQueueChain; +use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder; use sc_client_api::{Backend, StorageProvider}; use sp_crypto_hashing::twox_128; use sp_inherents::{InherentData, InherentDataProvider}; use sp_runtime::traits::Block; use std::collections::BTreeMap; -use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder; - /// Relay chain slot duration, in milliseconds. pub const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000; @@ -68,10 +68,12 @@ pub struct MockValidationDataInherentDataProvider { pub xcm_config: MockXcmConfig, /// Inbound downward XCM messages to be injected into the block. pub raw_downward_messages: Vec>, - // Inbound Horizontal messages sorted by channel. + /// Inbound Horizontal messages sorted by channel. pub raw_horizontal_messages: Vec<(ParaId, Vec)>, - // Additional key-value pairs that should be injected. + /// Additional key-value pairs that should be injected. pub additional_key_values: Option, Vec)>>, + /// Whether upgrade go ahead should be set. + pub upgrade_go_ahead: Option, } /// Something that can generate randomness. @@ -176,6 +178,7 @@ impl> InherentDataProvider sproof_builder.current_slot = ((relay_parent_number / RELAY_CHAIN_SLOT_DURATION_MILLIS) as u64).into(); + sproof_builder.upgrade_go_ahead = self.upgrade_go_ahead; // Process the downward messages and set up the correct head let mut downward_messages = Vec::new(); let mut dmq_mqc = MessageQueueChain::new(self.xcm_config.starting_dmq_mqc_head); diff --git a/cumulus/polkadot-omni-node/lib/src/nodes/manual_seal.rs b/cumulus/polkadot-omni-node/lib/src/nodes/manual_seal.rs index 7e36ce735af3..4cc21f28a090 100644 --- a/cumulus/polkadot-omni-node/lib/src/nodes/manual_seal.rs +++ b/cumulus/polkadot-omni-node/lib/src/nodes/manual_seal.rs @@ -22,6 +22,8 @@ use crate::common::{ use codec::Encode; use cumulus_client_parachain_inherent::{MockValidationDataInherentDataProvider, MockXcmConfig}; use cumulus_primitives_core::ParaId; +use polkadot_primitives::UpgradeGoAhead; +use sc_client_api::{StorageKey, StorageProvider}; use sc_consensus::{DefaultImportQueue, LongestChain}; use sc_consensus_manual_seal::rpc::{ManualSeal, ManualSealApiServer}; use sc_network::NetworkBackend; @@ -30,6 +32,13 @@ use sc_telemetry::TelemetryHandle; use sp_runtime::traits::Header; use std::{marker::PhantomData, sync::Arc}; +// Storage key to check for pending validation code. +// If this storage item is present, we will simulate a go-ahead signal from the relay chain. +pub const PENDING_VALIDATION_CODE_KEY: &[u8] = &[ + 69, 50, 61, 247, 204, 71, 21, 11, 57, 48, 226, 102, 107, 10, 163, 19, 144, 209, 113, 248, 64, + 24, 135, 207, 6, 251, 67, 167, 50, 153, 76, 50, +]; + pub struct ManualSealNode(PhantomData); impl BuildImportQueue @@ -147,6 +156,17 @@ impl ManualSealNode { .header(block) .expect("Header lookup should succeed") .expect("Header passed in as parent should be present in backend."); + + // If there is a pending validation code in storage, send the go-ahead signal. + let should_send_go_ahead = client_for_cidp + .storage(block, &StorageKey(PENDING_VALIDATION_CODE_KEY.to_vec())) + .ok() + .flatten() + .inspect(|_| { + log::info!("Detected pending validation code, sending go-ahead signal.") + }) + .is_some(); + let current_para_block_head = Some(polkadot_primitives::HeadData(current_para_head.encode())); let client_for_xcm = client_for_cidp.clone(); @@ -169,6 +189,7 @@ impl ManualSealNode { raw_downward_messages: vec![], raw_horizontal_messages: vec![], additional_key_values: None, + upgrade_go_ahead: should_send_go_ahead.then(|| UpgradeGoAhead::GoAhead), }; Ok(( // This is intentional, as the runtime that we expect to run against this From e0718c6bdec96b4235dbbe12f55f098acd138a7c Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Fri, 13 Dec 2024 15:02:28 +0000 Subject: [PATCH 2/4] Update from skunert running command 'prdoc --bump patch --audience runtime_dev' --- prdoc/pr_6885.prdoc | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 prdoc/pr_6885.prdoc diff --git a/prdoc/pr_6885.prdoc b/prdoc/pr_6885.prdoc new file mode 100644 index 000000000000..b7efd71bacbb --- /dev/null +++ b/prdoc/pr_6885.prdoc @@ -0,0 +1,12 @@ +title: 'Omni-node: Detect pending code in storage and send go ahead signal in dev-mode.' +doc: +- audience: Runtime Dev + description: |- + We check if there is a pending validation code in storage. If there is, add the go-ahead signal in the relay chain storage proof. + + Not super elegant, but should get the job done for development. +crates: +- name: cumulus-client-parachain-inherent + bump: patch +- name: polkadot-omni-node-lib + bump: patch From d4e8936ed45b8dacb2e6b20a68d44eeed683d382 Mon Sep 17 00:00:00 2001 From: Sebastian Kunert Date: Fri, 13 Dec 2024 16:32:57 +0100 Subject: [PATCH 3/4] Use `collect_collation_info` --- .../lib/src/nodes/manual_seal.rs | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/cumulus/polkadot-omni-node/lib/src/nodes/manual_seal.rs b/cumulus/polkadot-omni-node/lib/src/nodes/manual_seal.rs index 4cc21f28a090..c8be7979a739 100644 --- a/cumulus/polkadot-omni-node/lib/src/nodes/manual_seal.rs +++ b/cumulus/polkadot-omni-node/lib/src/nodes/manual_seal.rs @@ -21,24 +21,17 @@ use crate::common::{ }; use codec::Encode; use cumulus_client_parachain_inherent::{MockValidationDataInherentDataProvider, MockXcmConfig}; -use cumulus_primitives_core::ParaId; +use cumulus_primitives_core::{CollectCollationInfo, ParaId}; use polkadot_primitives::UpgradeGoAhead; -use sc_client_api::{StorageKey, StorageProvider}; use sc_consensus::{DefaultImportQueue, LongestChain}; use sc_consensus_manual_seal::rpc::{ManualSeal, ManualSealApiServer}; use sc_network::NetworkBackend; use sc_service::{Configuration, PartialComponents, TaskManager}; use sc_telemetry::TelemetryHandle; +use sp_api::ProvideRuntimeApi; use sp_runtime::traits::Header; use std::{marker::PhantomData, sync::Arc}; -// Storage key to check for pending validation code. -// If this storage item is present, we will simulate a go-ahead signal from the relay chain. -pub const PENDING_VALIDATION_CODE_KEY: &[u8] = &[ - 69, 50, 61, 247, 204, 71, 21, 11, 57, 48, 226, 102, 107, 10, 163, 19, 144, 209, 113, 248, 64, - 24, 135, 207, 6, 251, 67, 167, 50, 153, 76, 50, -]; - pub struct ManualSealNode(PhantomData); impl BuildImportQueue @@ -157,15 +150,16 @@ impl ManualSealNode { .expect("Header lookup should succeed") .expect("Header passed in as parent should be present in backend."); - // If there is a pending validation code in storage, send the go-ahead signal. - let should_send_go_ahead = client_for_cidp - .storage(block, &StorageKey(PENDING_VALIDATION_CODE_KEY.to_vec())) - .ok() - .flatten() - .inspect(|_| { - log::info!("Detected pending validation code, sending go-ahead signal.") - }) - .is_some(); + let should_send_go_ahead = match client_for_cidp + .runtime_api() + .collect_collation_info(block, ¤t_para_head) + { + Ok(info) => info.new_validation_code.is_some(), + Err(e) => { + log::error!("Failed to collect collation info: {:?}", e); + false + }, + }; let current_para_block_head = Some(polkadot_primitives::HeadData(current_para_head.encode())); @@ -189,7 +183,12 @@ impl ManualSealNode { raw_downward_messages: vec![], raw_horizontal_messages: vec![], additional_key_values: None, - upgrade_go_ahead: should_send_go_ahead.then(|| UpgradeGoAhead::GoAhead), + upgrade_go_ahead: should_send_go_ahead.then(|| { + log::info!( + "Detected pending validation code, sending go-ahead signal." + ); + UpgradeGoAhead::GoAhead + }), }; Ok(( // This is intentional, as the runtime that we expect to run against this From 71688556b75db93c6fc3a2bcc77c730e594683d6 Mon Sep 17 00:00:00 2001 From: Sebastian Kunert Date: Fri, 13 Dec 2024 16:59:28 +0100 Subject: [PATCH 4/4] PRDOC --- prdoc/pr_6885.prdoc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/prdoc/pr_6885.prdoc b/prdoc/pr_6885.prdoc index b7efd71bacbb..986d76962289 100644 --- a/prdoc/pr_6885.prdoc +++ b/prdoc/pr_6885.prdoc @@ -2,11 +2,10 @@ title: 'Omni-node: Detect pending code in storage and send go ahead signal in de doc: - audience: Runtime Dev description: |- - We check if there is a pending validation code in storage. If there is, add the go-ahead signal in the relay chain storage proof. - - Not super elegant, but should get the job done for development. + When using the polkadot-omni-node with manual seal (`--dev-block-time`), it is now possible to perform runtime + upgrades. The node will detect the pending validation code and send a go-ahead signal to the parachain. crates: - name: cumulus-client-parachain-inherent - bump: patch + bump: major - name: polkadot-omni-node-lib bump: patch