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 1 commit
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
21 changes: 21 additions & 0 deletions cumulus/polkadot-omni-node/lib/src/nodes/manual_seal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<NodeSpec>(PhantomData<NodeSpec>);

impl<NodeSpec: NodeSpecT> BuildImportQueue<NodeSpec::Block, NodeSpec::RuntimeApi>
Expand Down Expand Up @@ -147,6 +156,17 @@ impl<NodeSpec: NodeSpecT> ManualSealNode<NodeSpec> {
.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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone names ParachainSystem differently in construct_runtime!, this will fail.

IMO it is better to call collect_collation_info at block and check if new_validation_code is Some(_).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was totally willing to take that risk :D. But yeah your idea is better. Not checking the runtime api version though, 3 year old runtimes with the manual seal of omni node seems exotic.

.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();
Expand All @@ -169,6 +189,7 @@ 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(|| UpgradeGoAhead::GoAhead),
};
Ok((
// This is intentional, as the runtime that we expect to run against this
Expand Down
Loading