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: Detect pending code in storage and send go ahead signal in dev-mode. #6885

Merged
merged 4 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 8 additions & 5 deletions cumulus/client/parachain-inherent/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -68,10 +68,12 @@ pub struct MockValidationDataInherentDataProvider<R = ()> {
pub xcm_config: MockXcmConfig,
/// Inbound downward XCM messages to be injected into the block.
pub raw_downward_messages: Vec<Vec<u8>>,
// Inbound Horizontal messages sorted by channel.
/// Inbound Horizontal messages sorted by channel.
pub raw_horizontal_messages: Vec<(ParaId, Vec<u8>)>,
// Additional key-value pairs that should be injected.
/// Additional key-value pairs that should be injected.
pub additional_key_values: Option<Vec<(Vec<u8>, Vec<u8>)>>,
/// Whether upgrade go ahead should be set.
pub upgrade_go_ahead: Option<UpgradeGoAhead>,
}

/// Something that can generate randomness.
Expand Down Expand Up @@ -176,6 +178,7 @@ impl<R: Send + Sync + GenerateRandomness<u64>> 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);
Expand Down
22 changes: 21 additions & 1 deletion cumulus/polkadot-omni-node/lib/src/nodes/manual_seal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ 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_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};

Expand Down Expand Up @@ -147,6 +149,18 @@ impl<NodeSpec: NodeSpecT> ManualSealNode<NodeSpec> {
.header(block)
.expect("Header lookup should succeed")
.expect("Header passed in as parent should be present in backend.");

let should_send_go_ahead = match client_for_cidp
.runtime_api()
.collect_collation_info(block, &current_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()));
let client_for_xcm = client_for_cidp.clone();
Expand All @@ -169,6 +183,12 @@ impl<NodeSpec: NodeSpecT> ManualSealNode<NodeSpec> {
raw_downward_messages: vec![],
raw_horizontal_messages: vec![],
additional_key_values: None,
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
Expand Down
11 changes: 11 additions & 0 deletions prdoc/pr_6885.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
title: 'Omni-node: Detect pending code in storage and send go ahead signal in dev-mode.'
doc:
- audience: Runtime Dev
description: |-
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: major
- name: polkadot-omni-node-lib
bump: patch
Loading