Skip to content

Commit

Permalink
fix runtime and collator node to support async backing without activa…
Browse files Browse the repository at this point in the history
…ting it.
  • Loading branch information
clangenb committed Apr 17, 2024
1 parent 791a3ad commit b2a18fd
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 75 deletions.
2 changes: 1 addition & 1 deletion node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ pub fn run() -> Result<()> {
#[allow(clippy::match_single_binding)]
match config.chain_spec.runtime()? {
Runtime::Default => {
crate::service::start_generic_aura_node(config, polkadot_config, collator_options, id, hwbench)
crate::service::start_generic_aura_lookahead_node(config, polkadot_config, collator_options, id, hwbench)
.await
.map(|r| r.0)
}
Expand Down
129 changes: 66 additions & 63 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

use cumulus_client_cli::CollatorOptions;
use cumulus_client_collator::service::CollatorService;
use cumulus_client_consensus_aura::collators::basic::{
self as basic_aura, Params as BasicAuraParams,
};
use cumulus_client_consensus_aura::collators::lookahead::{self as aura, Params as AuraParams};
use cumulus_client_consensus_common::{
ParachainBlockImport as TParachainBlockImport, ParachainCandidate, ParachainConsensus,
};
Expand All @@ -28,7 +26,7 @@ use cumulus_client_service::{
BuildNetworkParams, CollatorSybilResistance, DARecoveryProfile, StartRelayChainTasksParams,
};
use cumulus_primitives_core::{
relay_chain::{Hash as PHash, PersistedValidationData},
relay_chain::{Hash as PHash, PersistedValidationData, ValidationCode},
ParaId,
};
use cumulus_relay_chain_interface::{OverseerHandle, RelayChainInterface};
Expand Down Expand Up @@ -607,8 +605,10 @@ where
Ok(BasicQueue::new(verifier, Box::new(block_import), None, &spawner, registry))
}

/// Uses the lookahead collator to support async backing.
///
/// Start an aura powered parachain node. Some system chains use this.
pub async fn start_generic_aura_node(
pub async fn start_generic_aura_lookahead_node(
parachain_config: Configuration,
polkadot_config: Configuration,
collator_options: CollatorOptions,
Expand All @@ -623,69 +623,72 @@ pub async fn start_generic_aura_node(
para_id,
build_parachain_rpc_extensions::<FakeRuntimeApi>,
build_relay_to_aura_import_queue::<_, AuraId>,
|client,
block_import,
prometheus_registry,
telemetry,
task_manager,
relay_chain_interface,
transaction_pool,
sync_oracle,
keystore,
relay_chain_slot_duration,
para_id,
collator_key,
overseer_handle,
announce_block,
_backend| {
let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;

let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(
task_manager.spawn_handle(),
client.clone(),
transaction_pool,
prometheus_registry,
telemetry.clone(),
);
let proposer = Proposer::new(proposer_factory);

let collator_service = CollatorService::new(
client.clone(),
Arc::new(task_manager.spawn_handle()),
announce_block,
client.clone(),
);

let params = BasicAuraParams {
create_inherent_data_providers: move |_, ()| async move { Ok(()) },
block_import,
para_client: client,
relay_client: relay_chain_interface,
sync_oracle,
keystore,
collator_key,
para_id,
overseer_handle,
slot_duration,
relay_chain_slot_duration,
proposer,
collator_service,
// Very limited proposal time.
authoring_duration: Duration::from_millis(500),
collation_request_receiver: None,
};

let fut =
basic_aura::run::<Block, <AuraId as AppCrypto>::Pair, _, _, _, _, _, _, _>(params);
task_manager.spawn_essential_handle().spawn("aura", None, fut);

Ok(())
},
start_lookahead_aura_consensus,
hwbench,
)
.await
}

/// Start consensus using the lookahead aura collator.
fn start_lookahead_aura_consensus(
client: Arc<ParachainClient<FakeRuntimeApi>>,
block_import: ParachainBlockImport<FakeRuntimeApi>,
prometheus_registry: Option<&Registry>,
telemetry: Option<TelemetryHandle>,
task_manager: &TaskManager,
relay_chain_interface: Arc<dyn RelayChainInterface>,
transaction_pool: Arc<sc_transaction_pool::FullPool<Block, ParachainClient<FakeRuntimeApi>>>,
sync_oracle: Arc<SyncingService<Block>>,
keystore: KeystorePtr,
relay_chain_slot_duration: Duration,
para_id: ParaId,
collator_key: CollatorPair,
overseer_handle: OverseerHandle,
announce_block: Arc<dyn Fn(Hash, Option<Vec<u8>>) + Send + Sync>,
backend: Arc<ParachainBackend>,
) -> Result<(), sc_service::Error> {
let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(
task_manager.spawn_handle(),
client.clone(),
transaction_pool,
prometheus_registry,
telemetry.clone(),
);

let collator_service = CollatorService::new(
client.clone(),
Arc::new(task_manager.spawn_handle()),
announce_block,
client.clone(),
);

let params = AuraParams {
create_inherent_data_providers: move |_, ()| async move { Ok(()) },
block_import,
para_client: client.clone(),
para_backend: backend,
relay_client: relay_chain_interface,
code_hash_provider: move |block_hash| {
client.code_at(block_hash).ok().map(|c| ValidationCode::from(c).hash())
},
sync_oracle,
keystore,
collator_key,
para_id,
overseer_handle,
relay_chain_slot_duration,
proposer: Proposer::new(proposer_factory),
collator_service,
authoring_duration: Duration::from_millis(1500),
reinitialize: false,
};

let fut = aura::run::<Block, <AuraId as AppCrypto>::Pair, _, _, _, _, _, _, _, _, _>(params);
task_manager.spawn_essential_handle().spawn("aura", None, fut);

Ok(())
}

/// Checks that the hardware meets the requirements and print a warning otherwise.
fn warn_if_slow_hardware(hwbench: &sc_sysinfo::HwBench) {
// Polkadot para-chains should generally use these requirements to ensure that the relay-chain
Expand Down
18 changes: 7 additions & 11 deletions runtime/bajun/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
state_version: 1,
};

/// This determines the average expected block time that we are targeting.
/// Blocks will be produced at a minimum duration defined by `SLOT_DURATION`.
/// `SLOT_DURATION` is picked up by `pallet_timestamp` which is in turn picked
/// up by `pallet_aura` to implement `fn slot_duration()`.
Expand Down Expand Up @@ -272,14 +271,14 @@ const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(
cumulus_primitives_core::relay_chain::MAX_POV_SIZE as u64,
);

/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included
/// into the relay chain.
const UNINCLUDED_SEGMENT_CAPACITY: u32 = 3;
/// How many parachain blocks are processed by the relay chain per parent. Limits the
/// number of blocks authored per slot.
const BLOCK_PROCESSING_VELOCITY: u32 = 1;
/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included into the
/// relay chain.
pub const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1;
/// How many parachain blocks are processed by the relay chain per parent. Limits the number of
/// blocks authored per slot.
pub const BLOCK_PROCESSING_VELOCITY: u32 = 1;
/// Relay chain slot duration, in milliseconds.
const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6_000;
pub const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;

/// The version information used to identify this runtime when compiled natively.
#[cfg(feature = "std")]
Expand Down Expand Up @@ -397,10 +396,7 @@ impl pallet_timestamp::Config for Runtime {
/// A timestamp: milliseconds since the unix epoch.
type Moment = u64;
type OnTimestampSet = Aura;
#[cfg(feature = "experimental")]
type MinimumPeriod = ConstU64<0>;
#[cfg(not(feature = "experimental"))]
type MinimumPeriod = ConstU64<{ SLOT_DURATION / 2 }>;
type WeightInfo = weights::pallet_timestamp::WeightInfo<Runtime>;
}

Expand Down

0 comments on commit b2a18fd

Please sign in to comment.