Skip to content

Commit

Permalink
can sync a couple of parachains, and is now configurable :)
Browse files Browse the repository at this point in the history
  • Loading branch information
kianenigma committed May 9, 2024
1 parent 2bf9080 commit 40fbf47
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 15 deletions.
38 changes: 34 additions & 4 deletions cumulus/service/src/aura.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,16 @@ where
+ Send
+ Sync
+ 'static,
// TODO: here and in other places, double check if all of these trait bounds are ndeded. Prob
// not. Is there a tool for this?
RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>
+ sp_api::Metadata<Block>
+ sp_session::SessionKeys<Block>
+ sp_api::ApiExt<Block>
+ sp_offchain::OffchainWorkerApi<Block>
+ sp_block_builder::BlockBuilder<Block>
+ cumulus_primitives_core::CollectCollationInfo<Block>
+ sp_consensus_aura::AuraApi<Block, sp_consensus_aura::sr25519::AuthorityId>, /* TODO: double check if needs to be generic. */
+ sp_consensus_aura::AuraApi<Block, sp_consensus_aura::sr25519::AuthorityId>, /* TODO: double check if needs to be generic, because of AH. */
{
let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;

Expand Down Expand Up @@ -140,7 +142,7 @@ pub fn build_import_queue<Block: BlockT, RuntimeApi, HostFns>(
client: Arc<ParachainClient<Block, RuntimeApi, HostFns>>,
block_import: ParachainBlockImport<Block, RuntimeApi, HostFns>,
config: &Configuration,
_: Option<TelemetryHandle>,
telemetry: Option<TelemetryHandle>,
task_manager: &TaskManager,
) -> Result<sc_consensus::DefaultImportQueue<Block>, sc_service::Error>
where
Expand All @@ -150,7 +152,35 @@ where
+ Send
+ Sync
+ 'static,
RuntimeApi::RuntimeApi: sp_block_builder::BlockBuilder<Block>,
RuntimeApi::RuntimeApi: sp_block_builder::BlockBuilder<Block>
+ sp_consensus_aura::AuraApi<Block, sp_consensus_aura::sr25519::AuthorityId>,
{
todo!();
let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;

cumulus_client_consensus_aura::import_queue::<
sp_consensus_aura::sr25519::AuthorityPair,
_,
_,
_,
_,
_,
>(cumulus_client_consensus_aura::ImportQueueParams {
block_import,
client,
create_inherent_data_providers: move |_, _| async move {
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();

let slot =
sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
*timestamp,
slot_duration,
);

Ok((slot, timestamp))
},
registry: config.prometheus_registry(),
spawner: &task_manager.spawn_essential_handle(),
telemetry,
})
.map_err(Into::into)
}
2 changes: 1 addition & 1 deletion cumulus/service/src/aura_async_backing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use sp_runtime::{
use std::{marker::PhantomData, sync::Arc, time::Duration};
use substrate_prometheus_endpoint::Registry;

fn start_consensus<Block, RuntimeApi, HostFns>(
pub fn start_consensus<Block, RuntimeApi, HostFns>(
client: Arc<ParachainClient<Block, RuntimeApi, HostFns>>,
block_import: ParachainBlockImport<Block, RuntimeApi, HostFns>,
prometheus_registry: Option<&Registry>,
Expand Down
2 changes: 1 addition & 1 deletion cumulus/service/src/relay_to_aura.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use sp_runtime::{
use std::{marker::PhantomData, sync::Arc, time::Duration};
use substrate_prometheus_endpoint::Registry;

fn start_consensus<Block, RuntimeApi, HostFns>(
pub fn start_consensus<Block, RuntimeApi, HostFns>(
client: Arc<ParachainClient<Block, RuntimeApi, HostFns>>,
block_import: ParachainBlockImport<Block, RuntimeApi, HostFns>,
prometheus_registry: Option<&Registry>,
Expand Down
9 changes: 8 additions & 1 deletion omni-nodes/parachain/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
use crate::{rpc::DenyUnsafe, service::parachain_service, standards::OpaqueBlock as Block};
use cumulus_client_cli::CollatorOptions;
use omni_node_common::fake_runtime::RuntimeApi;
use std::sync::Arc;

use crate::{command, rpc};
Expand Down Expand Up @@ -103,6 +102,14 @@ impl Builder {
self
}

pub fn parachain_consensus(mut self, consensus: ParachainConsensus) -> Self {
match &mut self.node_type {
NodeType::Parachain(config) => config.consensus = consensus,
_ => panic!("Cannot set parachain consensus on a non-parachain node"),
}
self
}

fn validate(&self) -> sc_cli::Result<()> {
// TODO: anything that might need checking here.
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions omni-nodes/parachain/src/command.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::cli::{Cli, RelayChainCli, Subcommand};
use clap::builder;
use cumulus_client_service::CollatorSybilResistance;
use cumulus_primitives_core::ParaId;
use log::info;
Expand Down Expand Up @@ -246,9 +245,10 @@ pub fn run(builder_config: crate::builder::Builder) -> Result<()> {
);

use crate::{
builder::{NodeType, ParachainConsensus, SolochainConsensus},
builder::{NodeType, ParachainConsensus},
service::parachain_service::start_node_impl,
};

match builder_config.node_type {
NodeType::Parachain(parachain_builder_config) =>
match parachain_builder_config.consensus {
Expand Down
7 changes: 4 additions & 3 deletions omni-nodes/parachain/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ mod standards;

use crate::builder::Builder;

// TODO: for statemint and statemine, inject a custon on_load that will rename some things.

fn main() -> sc_cli::Result<()> {
let node = Builder::default().build()?;
let node = Builder::default()
// .parachain_consensus(builder::ParachainConsensus::Relay(12))
.parachain_consensus(builder::ParachainConsensus::Aura(12))
.build()?;
node.run()
}
2 changes: 0 additions & 2 deletions omni-nodes/parachain/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@

use crate::standards::{AccountId, Balance, Nonce, OpaqueBlock as Block};
use cumulus_service::BuildRpcDeps as FullDeps;
use jsonrpsee::RpcModule;
pub use sc_rpc::DenyUnsafe;
use sc_transaction_pool_api::TransactionPool;
use sp_api::ProvideRuntimeApi;
use sp_block_builder::BlockBuilder;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
use std::sync::Arc;

/// A type representing all RPC extensions.
pub type RpcExtension = jsonrpsee::RpcModule<()>;
Expand Down
2 changes: 1 addition & 1 deletion omni-nodes/parachain/src/service.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Service and ServiceFactory implementation. Specialized wrapper over substrate service.
use crate::standards::{self, AccountId, Balance, Hash, Nonce, OpaqueBlock as Block};
use crate::standards::{self};
use cumulus_client_cli::CollatorOptions;
use cumulus_client_collator::service::CollatorService;
use cumulus_client_consensus_common::ParachainBlockImport as TParachainBlockImport;
Expand Down

0 comments on commit 40fbf47

Please sign in to comment.