Skip to content

Commit

Permalink
common new_partial for tanssi and simple (not frontier)
Browse files Browse the repository at this point in the history
  • Loading branch information
nanocryk committed Nov 3, 2023
1 parent aef9a7f commit 5dfb323
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 171 deletions.
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.

105 changes: 94 additions & 11 deletions client/node-common/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@
// You should have received a copy of the GNU General Public License
// along with Tanssi. If not, see <http://www.gnu.org/licenses/>.

use {sp_api::ConstructRuntimeApi, sp_transaction_pool::runtime_api::TaggedTransactionQueue};
use sp_block_builder::BlockBuilder;

use {
cumulus_client_consensus_common::ParachainBlockImport as TParachainBlockImport,
sc_executor::{NativeElseWasmExecutor, NativeExecutionDispatch},
sc_executor::{
HeapAllocStrategy, NativeElseWasmExecutor, NativeExecutionDispatch, WasmExecutor,
DEFAULT_HEAP_ALLOC_STRATEGY,
},
sc_service::{Configuration, PartialComponents, TFullBackend, TFullClient},
sc_telemetry::{Telemetry, TelemetryWorkerHandle},
sc_transaction_pool::ChainApi,
sc_telemetry::{Telemetry, TelemetryWorker, TelemetryWorkerHandle},
sp_api::ConstructRuntimeApi,
sp_transaction_pool::runtime_api::TaggedTransactionQueue,
std::sync::Arc,
};

Expand All @@ -35,14 +39,12 @@ pub type ParachainBlockImport<Block, RuntimeApi, ParachainNativeExecutor> = TPar
Arc<ParachainClient<Block, RuntimeApi, ParachainNativeExecutor>>,
ParachainBackend<Block>,
>;

type ConstructedRuntimeApi<Block, Client, RuntimeApi> =
pub type ConstructedRuntimeApi<Block, Client, RuntimeApi> =
<RuntimeApi as ConstructRuntimeApi<Block, Client>>::RuntimeApi;

pub trait BlockT: cumulus_primitives_core::BlockT {}

pub fn new_partial<Block, RuntimeApi, ParachainNativeExecutor, SelectChain>(
config: &Configuration,
select_chain: SelectChain,
) -> Result<
PartialComponents<
ParachainClient<Block, RuntimeApi, ParachainNativeExecutor>,
Expand All @@ -62,7 +64,7 @@ pub fn new_partial<Block, RuntimeApi, ParachainNativeExecutor, SelectChain>(
sc_service::Error,
>
where
Block: BlockT,
Block: cumulus_primitives_core::BlockT,
ParachainNativeExecutor: NativeExecutionDispatch + 'static,
RuntimeApi: ConstructRuntimeApi<Block, ParachainClient<Block, RuntimeApi, ParachainNativeExecutor>>
+ Sync
Expand All @@ -72,7 +74,88 @@ where
Block,
ParachainClient<Block, RuntimeApi, ParachainNativeExecutor>,
RuntimeApi,
>: TaggedTransactionQueue<Block>,
>: TaggedTransactionQueue<Block> + BlockBuilder<Block>,
{
todo!()
let telemetry = config
.telemetry_endpoints
.clone()
.filter(|x| !x.is_empty())
.map(|endpoints| -> Result<_, sc_telemetry::Error> {
let worker = TelemetryWorker::new(16)?;
let telemetry = worker.handle().new_telemetry(endpoints);
Ok((worker, telemetry))
})
.transpose()?;

let heap_pages = config
.default_heap_pages
.map_or(DEFAULT_HEAP_ALLOC_STRATEGY, |h| HeapAllocStrategy::Static {
extra_pages: h as _,
});

// Default runtime_cache_size is 2
// For now we can work with this, but it will likely need
// to change once we start having runtime_cache_sizes, or
// run nodes with the maximum for this value
let wasm = WasmExecutor::builder()
.with_execution_method(config.wasm_method)
.with_onchain_heap_alloc_strategy(heap_pages)
.with_offchain_heap_alloc_strategy(heap_pages)
.with_max_runtime_instances(config.max_runtime_instances)
.with_runtime_cache_size(config.runtime_cache_size)
.build();

let executor: ParachainExecutor<ParachainNativeExecutor> =
ParachainExecutor::new_with_wasm_executor(wasm);

let (client, backend, keystore_container, task_manager) =
sc_service::new_full_parts::<Block, RuntimeApi, _>(
config,
telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),
executor,
)?;
let client = Arc::new(client);

let telemetry_worker_handle = telemetry.as_ref().map(|(worker, _)| worker.handle());

let telemetry = telemetry.map(|(worker, telemetry)| {
task_manager
.spawn_handle()
.spawn("telemetry", None, worker.run());
telemetry
});

let transaction_pool = sc_transaction_pool::BasicPool::new_full(
config.transaction_pool.clone(),
config.role.is_authority().into(),
config.prometheus_registry(),
task_manager.spawn_essential_handle(),
client.clone(),
);

let block_import = ParachainBlockImport::new(client.clone(), backend.clone());

let import_queue = nimbus_consensus::import_queue(
client.clone(),
block_import.clone(),
move |_, _| async move {
let time = sp_timestamp::InherentDataProvider::from_system_time();

Ok((time,))
},
&task_manager.spawn_essential_handle(),
config.prometheus_registry(),
false,
)?;

Ok(PartialComponents {
backend,
client,
import_queue,
keystore_container,
task_manager,
transaction_pool,
select_chain,
other: (block_import, telemetry, telemetry_worker_handle),
})
}
1 change: 1 addition & 0 deletions container-chains/templates/simple/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ parity-scale-codec = { workspace = true }
serde = { workspace = true, features = [ "derive" ] }

# Local
node-common = { workspace = true }
container-chain-template-simple-runtime = { workspace = true, features = [ "std" ] }
tc-consensus = { workspace = true }

Expand Down
78 changes: 1 addition & 77 deletions container-chains/templates/simple/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,83 +92,7 @@ pub fn new_partial(
>,
sc_service::Error,
> {
let telemetry = config
.telemetry_endpoints
.clone()
.filter(|x| !x.is_empty())
.map(|endpoints| -> Result<_, sc_telemetry::Error> {
let worker = TelemetryWorker::new(16)?;
let telemetry = worker.handle().new_telemetry(endpoints);
Ok((worker, telemetry))
})
.transpose()?;

let heap_pages = config
.default_heap_pages
.map_or(DEFAULT_HEAP_ALLOC_STRATEGY, |h| HeapAllocStrategy::Static {
extra_pages: h as _,
});

let wasm = WasmExecutor::builder()
.with_execution_method(config.wasm_method)
.with_onchain_heap_alloc_strategy(heap_pages)
.with_offchain_heap_alloc_strategy(heap_pages)
.with_max_runtime_instances(config.max_runtime_instances)
.with_runtime_cache_size(config.runtime_cache_size)
.build();

let executor = ParachainExecutor::new_with_wasm_executor(wasm);

let (client, backend, keystore_container, task_manager) =
sc_service::new_full_parts::<Block, RuntimeApi, _>(
config,
telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),
executor,
)?;
let client = Arc::new(client);

let telemetry_worker_handle = telemetry.as_ref().map(|(worker, _)| worker.handle());

let telemetry = telemetry.map(|(worker, telemetry)| {
task_manager
.spawn_handle()
.spawn("telemetry", None, worker.run());
telemetry
});

let transaction_pool = sc_transaction_pool::BasicPool::new_full(
config.transaction_pool.clone(),
config.role.is_authority().into(),
config.prometheus_registry(),
task_manager.spawn_essential_handle(),
client.clone(),
);

let block_import = ParachainBlockImport::new(client.clone(), backend.clone());

let import_queue = nimbus_consensus::import_queue(
client.clone(),
block_import.clone(),
move |_, _| async move {
let time = sp_timestamp::InherentDataProvider::from_system_time();

Ok((time,))
},
&task_manager.spawn_essential_handle(),
config.prometheus_registry(),
false,
)?;

Ok(PartialComponents {
backend,
client,
import_queue,
keystore_container,
task_manager,
transaction_pool,
select_chain: (),
other: (block_import, telemetry, telemetry_worker_handle),
})
node_common::service::new_partial(config, ())
}

/// Start a node with the given parachain `Configuration` and relay chain `Configuration`.
Expand Down
1 change: 1 addition & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ serde_json = { workspace = true }
tokio = { workspace = true }

# Local
node-common = { workspace = true }
ccp-authorities-noting-inherent = { workspace = true, features = [ "std" ] }
dancebox-runtime = { workspace = true, features = [ "std" ] }
manual-xcm-rpc = { workspace = true }
Expand Down
6 changes: 4 additions & 2 deletions node/src/container_chain_spawner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ use {
time::Instant,
},
tc_orchestrator_chain_interface::OrchestratorChainInterface,
tokio::sync::{mpsc, oneshot},
tokio::time::{sleep, Duration},
tokio::{
sync::{mpsc, oneshot},
time::{sleep, Duration},
},
};

/// Struct with all the params needed to start a container chain node given the CLI arguments,
Expand Down
82 changes: 1 addition & 81 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,87 +137,7 @@ pub fn new_partial(
>,
sc_service::Error,
> {
let telemetry = config
.telemetry_endpoints
.clone()
.filter(|x| !x.is_empty())
.map(|endpoints| -> Result<_, sc_telemetry::Error> {
let worker = TelemetryWorker::new(16)?;
let telemetry = worker.handle().new_telemetry(endpoints);
Ok((worker, telemetry))
})
.transpose()?;

let heap_pages = config
.default_heap_pages
.map_or(DEFAULT_HEAP_ALLOC_STRATEGY, |h| HeapAllocStrategy::Static {
extra_pages: h as _,
});

let wasm = WasmExecutor::builder()
.with_execution_method(config.wasm_method)
.with_onchain_heap_alloc_strategy(heap_pages)
.with_offchain_heap_alloc_strategy(heap_pages)
.with_max_runtime_instances(config.max_runtime_instances)
.with_runtime_cache_size(config.runtime_cache_size)
.build();

let executor = ParachainExecutor::new_with_wasm_executor(wasm);

let (client, backend, keystore_container, task_manager) =
sc_service::new_full_parts::<Block, RuntimeApi, _>(
config,
telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),
executor,
)?;
let client = Arc::new(client);

let telemetry_worker_handle = telemetry.as_ref().map(|(worker, _)| worker.handle());

let telemetry = telemetry.map(|(worker, telemetry)| {
task_manager
.spawn_handle()
.spawn("telemetry", None, worker.run());
telemetry
});

let transaction_pool = sc_transaction_pool::BasicPool::new_full(
config.transaction_pool.clone(),
config.role.is_authority().into(),
config.prometheus_registry(),
task_manager.spawn_essential_handle(),
client.clone(),
);

let block_import = ParachainBlockImport::new(client.clone(), backend.clone());
// The nimbus import queue ONLY checks the signature correctness
// Any other checks corresponding to the author-correctness should be done
// in the runtime
let import_queue = nimbus_consensus::import_queue(
client.clone(),
block_import.clone(),
move |_, _| async move {
let time = sp_timestamp::InherentDataProvider::from_system_time();

Ok((time,))
},
&task_manager.spawn_essential_handle(),
config.prometheus_registry(),
false,
)?;

let maybe_select_chain = None;

Ok(PartialComponents {
backend,
client,
import_queue,
keystore_container,
task_manager,
transaction_pool,
select_chain: maybe_select_chain,
other: (block_import, telemetry, telemetry_worker_handle),
})
node_common::service::new_partial(config, None)
}

/// Background task used to detect changes to container chain assignment,
Expand Down

0 comments on commit 5dfb323

Please sign in to comment.