Skip to content

Commit

Permalink
Merge branch 'master' into snow-umbrella-crate-pallet-babe
Browse files Browse the repository at this point in the history
  • Loading branch information
snowmead authored Nov 12, 2024
2 parents 3c6fcf7 + aff3a07 commit 0f25d98
Show file tree
Hide file tree
Showing 51 changed files with 1,153 additions and 498 deletions.
4 changes: 1 addition & 3 deletions cumulus/client/relay-chain-minimal-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ async fn new_minimal_relay_chain<Block: BlockT, Network: NetworkBackend<RelayBlo
.chain_get_header(None)
.await?
.ok_or_else(|| RelayChainError::RpcCallError("Unable to fetch best header".to_string()))?;
let (network, network_starter, sync_service) = build_collator_network::<Network>(
let (network, sync_service) = build_collator_network::<Network>(
&config,
net_config,
task_manager.spawn_handle(),
Expand Down Expand Up @@ -262,8 +262,6 @@ async fn new_minimal_relay_chain<Block: BlockT, Network: NetworkBackend<RelayBlo
let overseer_handle =
collator_overseer::spawn_overseer(overseer_args, &task_manager, relay_chain_rpc_client)?;

network_starter.start_network();

Ok(NewMinimalNode { task_manager, overseer_handle })
}

Expand Down
26 changes: 4 additions & 22 deletions cumulus/client/relay-chain-minimal-node/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use sc_network::{

use sc_network::{config::FullNetworkConfiguration, NetworkBackend, NotificationService};
use sc_network_common::{role::Roles, sync::message::BlockAnnouncesHandshake};
use sc_service::{error::Error, Configuration, NetworkStarter, SpawnTaskHandle};
use sc_service::{error::Error, Configuration, SpawnTaskHandle};

use std::{iter, sync::Arc};

Expand All @@ -41,10 +41,7 @@ pub(crate) fn build_collator_network<Network: NetworkBackend<Block, Hash>>(
genesis_hash: Hash,
best_header: Header,
notification_metrics: NotificationMetrics,
) -> Result<
(Arc<dyn NetworkService>, NetworkStarter, Arc<dyn sp_consensus::SyncOracle + Send + Sync>),
Error,
> {
) -> Result<(Arc<dyn NetworkService>, Arc<dyn sp_consensus::SyncOracle + Send + Sync>), Error> {
let protocol_id = config.protocol_id();
let (block_announce_config, _notification_service) = get_block_announce_proto_config::<Network>(
protocol_id.clone(),
Expand Down Expand Up @@ -85,31 +82,16 @@ pub(crate) fn build_collator_network<Network: NetworkBackend<Block, Hash>>(
let network_worker = Network::new(network_params)?;
let network_service = network_worker.network_service();

let (network_start_tx, network_start_rx) = futures::channel::oneshot::channel();

// The network worker is responsible for gathering all network messages and processing
// them. This is quite a heavy task, and at the time of the writing of this comment it
// frequently happens that this future takes several seconds or in some situations
// even more than a minute until it has processed its entire queue. This is clearly an
// issue, and ideally we would like to fix the network future to take as little time as
// possible, but we also take the extra harm-prevention measure to execute the networking
// future using `spawn_blocking`.
spawn_handle.spawn_blocking("network-worker", Some("networking"), async move {
if network_start_rx.await.is_err() {
tracing::warn!(
"The NetworkStart returned as part of `build_network` has been silently dropped"
);
// This `return` might seem unnecessary, but we don't want to make it look like
// everything is working as normal even though the user is clearly misusing the API.
return
}

network_worker.run().await;
});

let network_starter = NetworkStarter::new(network_start_tx);
spawn_handle.spawn_blocking("network-worker", Some("networking"), network_worker.run());

Ok((network_service, network_starter, Arc::new(SyncOracle {})))
Ok((network_service, Arc::new(SyncOracle {})))
}

fn adjust_network_config_light_in_peers(config: &mut NetworkConfiguration) {
Expand Down
3 changes: 1 addition & 2 deletions cumulus/client/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use sc_consensus::{
use sc_network::{config::SyncMode, service::traits::NetworkService, NetworkBackend};
use sc_network_sync::SyncingService;
use sc_network_transactions::TransactionsHandlerController;
use sc_service::{Configuration, NetworkStarter, SpawnTaskHandle, TaskManager, WarpSyncConfig};
use sc_service::{Configuration, SpawnTaskHandle, TaskManager, WarpSyncConfig};
use sc_telemetry::{log, TelemetryWorkerHandle};
use sc_utils::mpsc::TracingUnboundedSender;
use sp_api::ProvideRuntimeApi;
Expand Down Expand Up @@ -439,7 +439,6 @@ pub async fn build_network<'a, Block, Client, RCInterface, IQ, Network>(
Arc<dyn NetworkService>,
TracingUnboundedSender<sc_rpc::system::Request<Block>>,
TransactionsHandlerController<Block::Hash>,
NetworkStarter,
Arc<SyncingService<Block>>,
)>
where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ use xcm_builder::{
use xcm_executor::XcmExecutor;

parameter_types! {
pub const RootLocation: Location = Location::here();
pub const TokenLocation: Location = Location::parent();
pub const RelayNetwork: NetworkId = NetworkId::ByGenesis(ROCOCO_GENESIS_HASH);
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
Expand Down Expand Up @@ -315,6 +316,7 @@ pub type ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger =
/// either execution or delivery.
/// We only waive fees for system functions, which these locations represent.
pub type WaivedLocations = (
Equals<RootLocation>,
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
Equals<RelayTreasuryLocation>,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ use xcm_builder::{
use xcm_executor::XcmExecutor;

parameter_types! {
pub const RootLocation: Location = Location::here();
pub const WestendLocation: Location = Location::parent();
pub const RelayNetwork: Option<NetworkId> = Some(NetworkId::ByGenesis(WESTEND_GENESIS_HASH));
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
Expand Down Expand Up @@ -336,6 +337,7 @@ pub type ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger =
/// either execution or delivery.
/// We only waive fees for system functions, which these locations represent.
pub type WaivedLocations = (
Equals<RootLocation>,
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
Equals<RelayTreasuryLocation>,
FellowshipEntities,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ use xcm_executor::{
};

parameter_types! {
pub const RootLocation: Location = Location::here();
pub const TokenLocation: Location = Location::parent();
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
pub RelayNetwork: NetworkId = NetworkId::ByGenesis(ROCOCO_GENESIS_HASH);
Expand Down Expand Up @@ -164,6 +165,7 @@ pub type Barrier = TrailingSetTopicAsId<
/// either execution or delivery.
/// We only waive fees for system functions, which these locations represent.
pub type WaivedLocations = (
Equals<RootLocation>,
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
Equals<RelayTreasuryLocation>,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ use xcm_executor::{
};

parameter_types! {
pub const RootLocation: Location = Location::here();
pub const WestendLocation: Location = Location::parent();
pub const RelayNetwork: NetworkId = NetworkId::ByGenesis(WESTEND_GENESIS_HASH);
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
Expand Down Expand Up @@ -161,6 +162,7 @@ pub type Barrier = TrailingSetTopicAsId<
/// either execution or delivery.
/// We only waive fees for system functions, which these locations represent.
pub type WaivedLocations = (
Equals<RootLocation>,
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
Equals<RelayTreasuryLocation>,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ use xcm_builder::{
use xcm_executor::XcmExecutor;

parameter_types! {
pub const RootLocation: Location = Location::here();
pub const RelayLocation: Location = Location::parent();
pub const RelayNetwork: NetworkId = NetworkId::ByGenesis(ROCOCO_GENESIS_HASH);
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
Expand Down Expand Up @@ -166,6 +167,7 @@ pub type Barrier = TrailingSetTopicAsId<
/// either execution or delivery.
/// We only waive fees for system functions, which these locations represent.
pub type WaivedLocations = (
Equals<RootLocation>,
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
Equals<RelayTreasuryLocation>,
);
Expand Down
22 changes: 21 additions & 1 deletion cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
pub use sp_runtime::BuildStorage;
use sp_runtime::{
generic, impl_opaque_keys,
traits::{BlakeTwo256, Block as BlockT},
traits::{BlakeTwo256, Block as BlockT, BlockNumberProvider},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, DispatchError, MultiAddress, Perbill, RuntimeDebug,
};
Expand Down Expand Up @@ -124,6 +124,7 @@ pub type Migrations = (
pallet_broker::migration::MigrateV0ToV1<Runtime>,
pallet_broker::migration::MigrateV1ToV2<Runtime>,
pallet_broker::migration::MigrateV2ToV3<Runtime>,
pallet_broker::migration::MigrateV3ToV4<Runtime, BrokerMigrationV4BlockConversion>,
// permanent
pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>,
);
Expand Down Expand Up @@ -591,6 +592,25 @@ impl pallet_sudo::Config for Runtime {
type WeightInfo = pallet_sudo::weights::SubstrateWeight<Runtime>;
}

pub struct BrokerMigrationV4BlockConversion;

impl pallet_broker::migration::v4::BlockToRelayHeightConversion<Runtime>
for BrokerMigrationV4BlockConversion
{
fn convert_block_number_to_relay_height(input_block_number: u32) -> u32 {
let relay_height = pallet_broker::RCBlockNumberProviderOf::<
<Runtime as pallet_broker::Config>::Coretime,
>::current_block_number();
let parachain_block_number = frame_system::Pallet::<Runtime>::block_number();
let offset = relay_height - parachain_block_number * 2;
offset + input_block_number * 2
}

fn convert_block_length_to_relay_length(input_block_length: u32) -> u32 {
input_block_length * 2
}
}

// Create the runtime by composing the FRAME pallets that were previously configured.
construct_runtime!(
pub enum Runtime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ use xcm_builder::{
use xcm_executor::XcmExecutor;

parameter_types! {
pub const RootLocation: Location = Location::here();
pub const RocRelayLocation: Location = Location::parent();
pub const RelayNetwork: Option<NetworkId> = Some(NetworkId::ByGenesis(ROCOCO_GENESIS_HASH));
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
Expand Down Expand Up @@ -177,6 +178,7 @@ parameter_types! {
/// Locations that will not be charged fees in the executor, neither for execution nor delivery.
/// We only waive fees for system functions, which these locations represent.
pub type WaivedLocations = (
Equals<RootLocation>,
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
Equals<RelayTreasuryLocation>,
);
Expand Down
22 changes: 21 additions & 1 deletion cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
pub use sp_runtime::BuildStorage;
use sp_runtime::{
generic, impl_opaque_keys,
traits::{BlakeTwo256, Block as BlockT},
traits::{BlakeTwo256, Block as BlockT, BlockNumberProvider},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, DispatchError, MultiAddress, Perbill, RuntimeDebug,
};
Expand Down Expand Up @@ -124,6 +124,7 @@ pub type Migrations = (
pallet_broker::migration::MigrateV0ToV1<Runtime>,
pallet_broker::migration::MigrateV1ToV2<Runtime>,
pallet_broker::migration::MigrateV2ToV3<Runtime>,
pallet_broker::migration::MigrateV3ToV4<Runtime, BrokerMigrationV4BlockConversion>,
// permanent
pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>,
);
Expand Down Expand Up @@ -586,6 +587,25 @@ impl pallet_utility::Config for Runtime {
type WeightInfo = weights::pallet_utility::WeightInfo<Runtime>;
}

pub struct BrokerMigrationV4BlockConversion;

impl pallet_broker::migration::v4::BlockToRelayHeightConversion<Runtime>
for BrokerMigrationV4BlockConversion
{
fn convert_block_number_to_relay_height(input_block_number: u32) -> u32 {
let relay_height = pallet_broker::RCBlockNumberProviderOf::<
<Runtime as pallet_broker::Config>::Coretime,
>::current_block_number();
let parachain_block_number = frame_system::Pallet::<Runtime>::block_number();
let offset = relay_height - parachain_block_number * 2;
offset + input_block_number * 2
}

fn convert_block_length_to_relay_length(input_block_length: u32) -> u32 {
input_block_length * 2
}
}

// Create the runtime by composing the FRAME pallets that were previously configured.
construct_runtime!(
pub enum Runtime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ use xcm_builder::{
use xcm_executor::XcmExecutor;

parameter_types! {
pub const RootLocation: Location = Location::here();
pub const TokenRelayLocation: Location = Location::parent();
pub const RelayNetwork: Option<NetworkId> = Some(NetworkId::ByGenesis(WESTEND_GENESIS_HASH));
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
Expand Down Expand Up @@ -185,6 +186,7 @@ parameter_types! {
/// Locations that will not be charged fees in the executor, neither for execution nor delivery.
/// We only waive fees for system functions, which these locations represent.
pub type WaivedLocations = (
Equals<RootLocation>,
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
Equals<RelayTreasuryLocation>,
);
Expand Down
6 changes: 4 additions & 2 deletions cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use core::marker::PhantomData;
use frame_support::{
parameter_types,
traits::{
tokens::imbalance::ResolveAssetTo, ConstU32, Contains, ContainsPair, Everything,
tokens::imbalance::ResolveAssetTo, ConstU32, Contains, ContainsPair, Equals, Everything,
EverythingBut, Get, Nothing, PalletInfoAccess,
},
weights::Weight,
Expand Down Expand Up @@ -210,6 +210,7 @@ pub type XcmOriginToTransactDispatchOrigin = (
);

parameter_types! {
pub const RootLocation: Location = Location::here();
// One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate.
pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, 64 * 1024);
pub const MaxInstructions: u32 = 100;
Expand Down Expand Up @@ -336,6 +337,7 @@ pub type TrustedReserves = (
pub type TrustedTeleporters =
(AssetFromChain<LocalTeleportableToAssetHub, SystemAssetHubLocation>,);

pub type WaivedLocations = Equals<RootLocation>;
/// `AssetId`/`Balance` converter for `TrustBackedAssets`.
pub type TrustBackedAssetsConvertedConcreteId =
assets_common::TrustBackedAssetsConvertedConcreteId<AssetsPalletLocation, Balance>;
Expand Down Expand Up @@ -399,7 +401,7 @@ impl xcm_executor::Config for XcmConfig {
type AssetLocker = ();
type AssetExchanger = PoolAssetsExchanger;
type FeeManager = XcmFeeManagerFromComponents<
(),
WaivedLocations,
SendXcmFeeToAccount<Self::AssetTransactor, TreasuryAccount>,
>;
type MessageExporter = ();
Expand Down
4 changes: 1 addition & 3 deletions cumulus/polkadot-omni-node/lib/src/common/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ pub(crate) trait NodeSpec: BaseNodeSpec {
prometheus_registry.clone(),
);

let (network, system_rpc_tx, tx_handler_controller, start_network, sync_service) =
let (network, system_rpc_tx, tx_handler_controller, sync_service) =
build_network(BuildNetworkParams {
parachain_config: &parachain_config,
net_config,
Expand Down Expand Up @@ -346,8 +346,6 @@ pub(crate) trait NodeSpec: BaseNodeSpec {
)?;
}

start_network.start_network();

Ok(task_manager)
}
.instrument(sc_tracing::tracing::info_span!(
Expand Down
3 changes: 1 addition & 2 deletions cumulus/polkadot-omni-node/lib/src/nodes/manual_seal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl<NodeSpec: NodeSpecT> ManualSealNode<NodeSpec> {
config.prometheus_config.as_ref().map(|cfg| &cfg.registry),
);

let (network, system_rpc_tx, tx_handler_controller, start_network, sync_service) =
let (network, system_rpc_tx, tx_handler_controller, sync_service) =
sc_service::build_network(sc_service::BuildNetworkParams {
config: &config,
client: client.clone(),
Expand Down Expand Up @@ -219,7 +219,6 @@ impl<NodeSpec: NodeSpecT> ManualSealNode<NodeSpec> {
telemetry: telemetry.as_mut(),
})?;

start_network.start_network();
Ok(task_manager)
}
}
4 changes: 1 addition & 3 deletions cumulus/test/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ where
prometheus_registry.clone(),
);

let (network, system_rpc_tx, tx_handler_controller, start_network, sync_service) =
let (network, system_rpc_tx, tx_handler_controller, sync_service) =
build_network(BuildNetworkParams {
parachain_config: &parachain_config,
net_config,
Expand Down Expand Up @@ -542,8 +542,6 @@ where
}
}

start_network.start_network();

Ok((task_manager, client, network, rpc_handlers, transaction_pool, backend))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ impl BackedChain {
) -> impl Iterator<Item = FragmentNode> + 'a {
let mut found_index = None;
for index in 0..self.chain.len() {
let node = &self.chain[0];
let node = &self.chain[index];

if found_index.is_some() {
self.by_parent_head.remove(&node.parent_head_data_hash);
Expand Down
Loading

0 comments on commit 0f25d98

Please sign in to comment.