Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
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.

1 change: 1 addition & 0 deletions cumulus/client/consensus/aura/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ sc-consensus = { workspace = true, default-features = true }
sc-consensus-aura = { workspace = true, default-features = true }
sc-consensus-babe = { workspace = true, default-features = true }
sc-consensus-slots = { workspace = true, default-features = true }
sc-network-types = { workspace = true, default-features = true }
sc-telemetry = { workspace = true, default-features = true }
sc-utils = { workspace = true, default-features = true }
sp-api = { workspace = true, default-features = true }
Expand Down
7 changes: 7 additions & 0 deletions cumulus/client/consensus/aura/src/collator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use crate::collators::RelayParentData;
use futures::prelude::*;
use sc_consensus::{BlockImport, BlockImportParams, ForkChoiceStrategy, StateAction};
use sc_consensus_aura::standalone as aura_internal;
use sc_network_types::PeerId;
use sp_api::ProvideRuntimeApi;
use sp_application_crypto::AppPublic;
use sp_consensus::BlockOrigin;
Expand All @@ -69,6 +70,8 @@ pub struct Params<BI, CIDP, RClient, Proposer, CS> {
pub relay_client: RClient,
/// The keystore handle used for accessing parachain key material.
pub keystore: KeystorePtr,
/// The collator network peer id.
pub collator_peer_id: PeerId,
/// The identifier of the parachain within the relay-chain.
pub para_id: ParaId,
/// The block proposer used for building blocks.
Expand Down Expand Up @@ -128,6 +131,7 @@ where
parent_hash: Block::Hash,
timestamp: impl Into<Option<Timestamp>>,
relay_parent_descendants: Option<RelayParentData>,
collator_peer_id: PeerId,
) -> Result<(ParachainInherentData, InherentData), Box<dyn Error + Send + Sync + 'static>> {
let paras_inherent_data = ParachainInherentDataProvider::create_at(
relay_parent,
Expand All @@ -138,6 +142,7 @@ where
.map(RelayParentData::into_inherent_descendant_list)
.unwrap_or_default(),
Vec::new(),
collator_peer_id,
)
.await;

Expand Down Expand Up @@ -173,13 +178,15 @@ where
validation_data: &PersistedValidationData,
parent_hash: Block::Hash,
timestamp: impl Into<Option<Timestamp>>,
collator_peer_id: PeerId,
) -> Result<(ParachainInherentData, InherentData), Box<dyn Error + Send + Sync + 'static>> {
self.create_inherent_data_with_rp_offset(
relay_parent,
validation_data,
parent_hash,
timestamp,
None,
collator_peer_id,
)
.await
}
Expand Down
5 changes: 5 additions & 0 deletions cumulus/client/consensus/aura/src/collators/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use polkadot_primitives::{CollatorPair, Id as ParaId, ValidationCode};
use futures::{channel::mpsc::Receiver, prelude::*};
use sc_client_api::{backend::AuxStore, BlockBackend, BlockOf};
use sc_consensus::BlockImport;
use sc_network_types::PeerId;
use sp_api::{CallApiAt, ProvideRuntimeApi};
use sp_application_crypto::AppPublic;
use sp_blockchain::HeaderBackend;
Expand Down Expand Up @@ -68,6 +69,8 @@ pub struct Params<BI, CIDP, Client, RClient, Proposer, CS> {
pub keystore: KeystorePtr,
/// The collator key used to sign collations before submitting to validators.
pub collator_key: CollatorPair,
/// The collator network peer id.
pub collator_peer_id: PeerId,
/// The para's ID.
pub para_id: ParaId,
/// A handle to the relay-chain client's "Overseer" or task orchestrator.
Expand Down Expand Up @@ -130,6 +133,7 @@ where
block_import: params.block_import,
relay_client: params.relay_client.clone(),
keystore: params.keystore.clone(),
collator_peer_id: params.collator_peer_id,
para_id: params.para_id,
proposer: params.proposer,
collator_service: params.collator_service,
Expand Down Expand Up @@ -234,6 +238,7 @@ where
&validation_data,
parent_hash,
claim.timestamp(),
params.collator_peer_id,
)
.await
);
Expand Down
5 changes: 5 additions & 0 deletions cumulus/client/consensus/aura/src/collators/lookahead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ use crate::{collator as collator_util, collators::claim_queue_at, export_pov_to_
use futures::prelude::*;
use sc_client_api::{backend::AuxStore, BlockBackend, BlockOf};
use sc_consensus::BlockImport;
use sc_network_types::PeerId;
use sp_api::ProvideRuntimeApi;
use sp_application_crypto::AppPublic;
use sp_blockchain::HeaderBackend;
Expand Down Expand Up @@ -79,6 +80,8 @@ pub struct Params<BI, CIDP, Client, Backend, RClient, CHP, Proposer, CS> {
pub keystore: KeystorePtr,
/// The collator key used to sign collations before submitting to validators.
pub collator_key: CollatorPair,
/// The collator network peer id.
pub collator_peer_id: PeerId,
/// The para's ID.
pub para_id: ParaId,
/// A handle to the relay-chain client's "Overseer" or task orchestrator.
Expand Down Expand Up @@ -207,6 +210,7 @@ where
block_import: params.block_import,
relay_client: params.relay_client.clone(),
keystore: params.keystore.clone(),
collator_peer_id: params.collator_peer_id,
para_id: params.para_id,
proposer: params.proposer,
collator_service: params.collator_service,
Expand Down Expand Up @@ -345,6 +349,7 @@ where
&validation_data,
parent_hash,
slot_claim.timestamp(),
params.collator_peer_id,
)
.await
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ use polkadot_primitives::{
use sc_client_api::{backend::AuxStore, BlockBackend, BlockOf, UsageProvider};
use sc_consensus::BlockImport;
use sc_consensus_aura::SlotDuration;
use sc_network_types::PeerId;
use sp_api::ProvideRuntimeApi;
use sp_application_crypto::AppPublic;
use sp_blockchain::HeaderBackend;
Expand Down Expand Up @@ -84,6 +85,8 @@ pub struct BuilderTaskParams<
pub code_hash_provider: CHP,
/// The underlying keystore, which should contain Aura consensus keys.
pub keystore: KeystorePtr,
/// The collator network peer id.
pub collator_peer_id: PeerId,
/// The para's ID.
pub para_id: ParaId,
/// The underlying block proposer this should call into.
Expand Down Expand Up @@ -146,6 +149,7 @@ where
para_client,
keystore,
block_import,
collator_peer_id,
para_id,
proposer,
collator_service,
Expand All @@ -170,6 +174,7 @@ where
block_import,
relay_client: relay_client.clone(),
keystore: keystore.clone(),
collator_peer_id,
para_id,
proposer,
collator_service,
Expand Down Expand Up @@ -350,6 +355,7 @@ where
parent_hash,
slot_claim.timestamp(),
Some(rp_data),
collator_peer_id,
)
.await
{
Expand Down
5 changes: 5 additions & 0 deletions cumulus/client/consensus/aura/src/collators/slot_based/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ use polkadot_primitives::{
};
use sc_client_api::{backend::AuxStore, BlockBackend, BlockOf, UsageProvider};
use sc_consensus::BlockImport;
use sc_network_types::PeerId;
use sc_utils::mpsc::tracing_unbounded;
use sp_api::ProvideRuntimeApi;
use sp_application_crypto::AppPublic;
Expand Down Expand Up @@ -122,6 +123,8 @@ pub struct Params<Block, BI, CIDP, Client, Backend, RClient, CHP, Proposer, CS,
pub keystore: KeystorePtr,
/// The collator key used to sign collations before submitting to validators.
pub collator_key: CollatorPair,
/// The collator network peer id.
pub collator_peer_id: PeerId,
/// The para's ID.
pub para_id: ParaId,
/// The underlying block proposer this should call into.
Expand Down Expand Up @@ -186,6 +189,7 @@ pub fn run<Block, P, BI, CIDP, Client, Backend, RClient, CHP, Proposer, CS, Spaw
code_hash_provider,
keystore,
collator_key,
collator_peer_id,
para_id,
proposer,
collator_service,
Expand Down Expand Up @@ -221,6 +225,7 @@ pub fn run<Block, P, BI, CIDP, Client, Backend, RClient, CHP, Proposer, CS, Spaw
relay_client,
code_hash_provider,
keystore,
collator_peer_id,
para_id,
proposer,
collator_service,
Expand Down
1 change: 1 addition & 0 deletions cumulus/client/parachain-inherent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ tracing = { workspace = true, default-features = true }
# Substrate
sc-client-api = { workspace = true, default-features = true }
sc-consensus-babe = { workspace = true, default-features = true }
sc-network-types = { workspace = true, default-features = true }
sp-crypto-hashing = { workspace = true, default-features = true }
sp-inherents = { workspace = true, default-features = true }
sp-runtime = { workspace = true, default-features = true }
Expand Down
27 changes: 20 additions & 7 deletions cumulus/client/parachain-inherent/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@

//! Client side code for generating the parachain inherent.

mod mock;

use codec::Decode;
use cumulus_primitives_core::{
relay_chain::{self, Block as RelayBlock, Hash as PHash, HrmpChannelId},
relay_chain::{
self, ApprovedPeerId, Block as RelayBlock, Hash as PHash, Header as RelayHeader,
HrmpChannelId,
},
ParaId, PersistedValidationData,
};
use cumulus_relay_chain_interface::RelayChainInterface;

mod mock;

use cumulus_primitives_core::relay_chain::Header as RelayHeader;
pub use cumulus_primitives_parachain_inherent::{ParachainInherentData, INHERENT_IDENTIFIER};
use cumulus_relay_chain_interface::RelayChainInterface;
pub use mock::{MockValidationDataInherentDataProvider, MockXcmConfig};
use sc_network_types::PeerId;

const LOG_TARGET: &str = "parachain-inherent";

Expand Down Expand Up @@ -168,7 +170,18 @@ impl ParachainInherentDataProvider {
para_id: ParaId,
relay_parent_descendants: Vec<RelayHeader>,
additional_relay_state_keys: Vec<Vec<u8>>,
collator_peer_id: PeerId,
) -> Option<ParachainInherentData> {
let collator_peer_id = ApprovedPeerId::try_from(collator_peer_id.to_bytes())
.inspect_err(|_e| {
tracing::error!(
target: LOG_TARGET,
"Could not convert collator_peer_id into ApprovedPeerId. The collator_peer_id \
should contain a sequence of at most 64 bytes",
);
})
.ok();

// Only include next epoch authorities when the descendants include an epoch digest.
// Skip the first entry because this is the relay parent itself.
let include_next_authorities = relay_parent_descendants.iter().skip(1).any(|header| {
Expand Down Expand Up @@ -218,7 +231,7 @@ impl ParachainInherentDataProvider {
validation_data: validation_data.clone(),
relay_chain_state,
relay_parent_descendants,
collator_peer_id: None,
collator_peer_id,
})
}
}
64 changes: 40 additions & 24 deletions cumulus/pallets/parachain-system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ use alloc::{collections::btree_map::BTreeMap, vec, vec::Vec};
use codec::{Decode, DecodeLimit, Encode};
use core::cmp;
use cumulus_primitives_core::{
relay_chain, AbridgedHostConfiguration, ChannelInfo, ChannelStatus, CollationInfo,
CumulusDigestItem, GetChannelInfo, ListChannelInfos, MessageSendError, OutboundHrmpMessage,
ParaId, PersistedValidationData, UpwardMessage, UpwardMessageSender, XcmpMessageHandler,
relay_chain::{self, UMPSignal, UMP_SEPARATOR},
AbridgedHostConfiguration, ChannelInfo, ChannelStatus, CollationInfo, CumulusDigestItem,
GetChannelInfo, ListChannelInfos, MessageSendError, OutboundHrmpMessage, ParaId,
PersistedValidationData, UpwardMessage, UpwardMessageSender, XcmpMessageHandler,
XcmpMessageSource,
};
use cumulus_primitives_parachain_inherent::{v0, MessageQueueChain, ParachainInherentData};
Expand Down Expand Up @@ -361,8 +362,19 @@ pub mod pallet {
UpwardMessages::<T>::put(&up[..num as usize]);
*up = up.split_off(num as usize);

// Send the core selector UMP signal.
Self::send_ump_signal();
if let Some(core_info) =
CumulusDigestItem::find_core_info(&frame_system::Pallet::<T>::digest())
{
PendingUpwardSignals::<T>::mutate(|signals| {
signals.push(
UMPSignal::SelectCore(core_info.selector, core_info.claim_queue_offset)
.encode(),
);
});
}

// Send the pending UMP signals.
Self::send_ump_signals();

// If the total size of the pending messages is less than the threshold,
// we decrease the fee factor, since the queue is less congested.
Expand Down Expand Up @@ -585,7 +597,7 @@ pub mod pallet {
validation_data: vfp,
relay_chain_state,
relay_parent_descendants,
collator_peer_id: _,
collator_peer_id,
} = data;

// Check that the associated relay chain block number is as expected.
Expand Down Expand Up @@ -693,6 +705,12 @@ pub mod pallet {

<T::OnSystemEvent as OnSystemEvent>::on_validation_data(&vfp);

if let Some(collator_peer_id) = collator_peer_id {
PendingUpwardSignals::<T>::mutate(|signals| {
signals.push(UMPSignal::ApprovedPeer(collator_peer_id).encode());
});
}

total_weight.saturating_accrue(Self::enqueue_inbound_downward_messages(
relevant_messaging_state.dmq_mqc_head,
inbound_messages_data.downward_messages,
Expand Down Expand Up @@ -905,14 +923,20 @@ pub mod pallet {

/// Upward messages that were sent in a block.
///
/// This will be cleared in `on_initialize` of each new block.
/// This will be cleared in `on_initialize` for each new block.
#[pallet::storage]
pub type UpwardMessages<T: Config> = StorageValue<_, Vec<UpwardMessage>, ValueQuery>;

/// Upward messages that are still pending and not yet send to the relay chain.
/// Upward messages that are still pending and not yet sent to the relay chain.
#[pallet::storage]
pub type PendingUpwardMessages<T: Config> = StorageValue<_, Vec<UpwardMessage>, ValueQuery>;

/// Upward signals that are still pending and not yet sent to the relay chain.
///
/// This will be cleared in `on_finalize` for each block.
#[pallet::storage]
pub type PendingUpwardSignals<T: Config> = StorageValue<_, Vec<UpwardMessage>, ValueQuery>;

/// The factor to multiply the base delivery fee by for UMP.
#[pallet::storage]
pub type UpwardDeliveryFeeFactor<T: Config> =
Expand Down Expand Up @@ -1507,23 +1531,15 @@ impl<T: Config> Pallet<T> {
CustomValidationHeadData::<T>::put(head_data);
}

/// Send the ump signals
fn send_ump_signal() {
use cumulus_primitives_core::relay_chain::{UMPSignal, UMP_SEPARATOR};

UpwardMessages::<T>::mutate(|up| {
if let Some(core_info) =
CumulusDigestItem::find_core_info(&frame_system::Pallet::<T>::digest())
{
/// Send the pending ump signals
fn send_ump_signals() {
let mut ump_signals = PendingUpwardSignals::<T>::take();
if !ump_signals.is_empty() {
UpwardMessages::<T>::mutate(|up| {
up.push(UMP_SEPARATOR);

// Send the core selector signal.
up.push(
UMPSignal::SelectCore(core_info.selector, core_info.claim_queue_offset)
.encode(),
);
}
});
up.append(&mut ump_signals);
});
}
}

/// Open HRMP channel for using it in benchmarks or tests.
Expand Down
Loading