From 2bc06d07be5a433745d5ba5431ca92cf235ed428 Mon Sep 17 00:00:00 2001 From: Seun Lanlege Date: Tue, 30 Apr 2024 10:48:52 +0000 Subject: [PATCH 1/2] fix ctrl-c bug --- simnode/Cargo.toml | 2 +- simnode/src/client/aura.rs | 68 +++++++++++++-------------- simnode/src/client/babe.rs | 71 +++++++++++++++-------------- simnode/src/client/parachain.rs | 81 ++++++++++++++++----------------- 4 files changed, 111 insertions(+), 111 deletions(-) diff --git a/simnode/Cargo.toml b/simnode/Cargo.toml index e18aa1e..cce313d 100644 --- a/simnode/Cargo.toml +++ b/simnode/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sc-simnode" -version = "1.6.1" +version = "1.6.2" authors = ["Polytope Labs "] edition = "2021" license = "Apache-2.0" diff --git a/simnode/src/client/aura.rs b/simnode/src/client/aura.rs index cf511f8..4b3f6d5 100644 --- a/simnode/src/client/aura.rs +++ b/simnode/src/client/aura.rs @@ -36,7 +36,7 @@ use simnode_runtime_api::CreateTransactionApi; use sp_api::{ApiExt, ConstructRuntimeApi, Core}; use sp_block_builder::BlockBuilder; use sp_consensus::SelectChain; -use sp_core::crypto::AccountId32; +use sp_core::{crypto::AccountId32, traits::SpawnEssentialNamed}; use sp_runtime::traits::{Block as BlockT, Header}; use sp_transaction_pool::runtime_api::TaggedTransactionQueue; /// Set up and run simnode @@ -141,42 +141,37 @@ where let rpc_sink = command_sink.clone(); - let rpc_handlers = { - let client = client.clone(); - let backend = backend.clone(); - let pool = pool.clone(); - let params = SpawnTasksParams { - config, - client: client.clone(), - backend: backend.clone(), - task_manager: &mut task_manager, - keystore: keystore_container.keystore(), - transaction_pool: pool.clone(), - rpc_builder: Box::new(move |deny_unsafe, subscription_executor| { - let mut io = rpc_builder(deny_unsafe, subscription_executor)?; - - io.merge(SimnodeRpcHandler::::new(client.clone(), backend.clone()).into_rpc()) - .map_err(|_| { - sc_service::Error::Other("Unable to merge simnode rpc api".to_string()) - })?; - io.merge(ManualSeal::new(rpc_sink.clone()).into_rpc()).map_err(|_| { - sc_service::Error::Other("Unable to merge manual seal rpc api".to_string()) + let (client_clone, backend_clone) = (client.clone(), backend.clone()); + let params = SpawnTasksParams { + config, + client: client.clone(), + backend: backend.clone(), + task_manager: &mut task_manager, + keystore: keystore_container.keystore(), + transaction_pool: pool.clone(), + rpc_builder: Box::new(move |deny_unsafe, subscription_executor| { + let mut io = rpc_builder(deny_unsafe, subscription_executor)?; + + io.merge(SimnodeRpcHandler::::new(client_clone.clone(), backend_clone.clone()).into_rpc()) + .map_err(|_| { + sc_service::Error::Other("Unable to merge simnode rpc api".to_string()) })?; - Ok(io) - }), - network, - system_rpc_tx, - tx_handler_controller, - sync_service, - telemetry: telemetry.as_mut(), - }; - spawn_tasks(params)? + io.merge(ManualSeal::new(rpc_sink.clone()).into_rpc()).map_err(|_| { + sc_service::Error::Other("Unable to merge manual seal rpc api".to_string()) + })?; + Ok(io) + }), + network, + system_rpc_tx, + tx_handler_controller, + sync_service, + telemetry: telemetry.as_mut(), }; + spawn_tasks(params)?; _network_starter.start_network(); - let _rpc_handler = rpc_handlers.handle(); - run_manual_seal(ManualSealParams { + let task = run_manual_seal(ManualSealParams { block_import, env, client: client.clone(), @@ -215,8 +210,13 @@ where } } }, - }) - .await; + }); + + task_manager.spawn_essential_handle().spawn_essential( + "manual-consensus-task", + None, + Box::pin(task), + ); Ok(task_manager) } diff --git a/simnode/src/client/babe.rs b/simnode/src/client/babe.rs index 9f3fece..f32eb2b 100644 --- a/simnode/src/client/babe.rs +++ b/simnode/src/client/babe.rs @@ -36,7 +36,7 @@ use sp_api::{ApiExt, ConstructRuntimeApi, Core}; use sp_block_builder::BlockBuilder; use sp_consensus::SelectChain; use sp_consensus_babe::AuthorityId; -use sp_core::crypto::AccountId32; +use sp_core::{crypto::AccountId32, traits::SpawnEssentialNamed}; use sp_keyring::Sr25519Keyring::Alice; use sp_runtime::traits::{Block as BlockT, Header}; use sp_transaction_pool::runtime_api::TaggedTransactionQueue; @@ -146,40 +146,36 @@ where let (command_sink, commands_stream) = mpsc::channel(10); let rpc_sink = command_sink.clone(); - let rpc_handlers = { - let client = client.clone(); - let backend = backend.clone(); - let pool = pool.clone(); - let params = SpawnTasksParams { - config, - client: client.clone(), - backend: backend.clone(), - task_manager: &mut task_manager, - keystore: keystore_container.keystore(), - transaction_pool: pool.clone(), - rpc_builder: Box::new(move |deny_unsafe, subscription_executor| { - let mut io = rpc_builder(deny_unsafe, subscription_executor)?; - - io.merge(SimnodeRpcHandler::::new(client.clone(), backend.clone()).into_rpc()) - .map_err(|_| { - sc_service::Error::Other("Unable to merge simnode rpc api".to_string()) - })?; - io.merge(ManualSeal::new(rpc_sink.clone()).into_rpc()).map_err(|_| { - sc_service::Error::Other("Unable to merge manual seal rpc api".to_string()) - })?; - Ok(io) - }), - network, - system_rpc_tx, - tx_handler_controller, - sync_service, - telemetry: telemetry.as_mut(), - }; - spawn_tasks(params)? + let (client_clone, backend_clone) = (client.clone(), backend.clone()); + + let params = SpawnTasksParams { + config, + client: client.clone(), + backend: backend.clone(), + task_manager: &mut task_manager, + keystore: keystore_container.keystore(), + transaction_pool: pool.clone(), + rpc_builder: Box::new(move |deny_unsafe, subscription_executor| { + let mut io = rpc_builder(deny_unsafe, subscription_executor)?; + + io.merge( + SimnodeRpcHandler::::new(client_clone.clone(), backend_clone.clone()).into_rpc(), + ) + .map_err(|_| sc_service::Error::Other("Unable to merge simnode rpc api".to_string()))?; + io.merge(ManualSeal::new(rpc_sink.clone()).into_rpc()).map_err(|_| { + sc_service::Error::Other("Unable to merge manual seal rpc api".to_string()) + })?; + Ok(io) + }), + network, + system_rpc_tx, + tx_handler_controller, + sync_service, + telemetry: telemetry.as_mut(), }; + spawn_tasks(params)?; _network_starter.start_network(); - let _rpc_handler = rpc_handlers.handle(); let babe_consensus = BabeConsensusDataProvider::new( client.clone(), @@ -189,7 +185,7 @@ where ) .map_err(|e| sc_service::Error::Application(Box::new(e)))?; - run_manual_seal(ManualSealParams { + let task = run_manual_seal(ManualSealParams { block_import, env, client: client.clone(), @@ -228,8 +224,13 @@ where } } }, - }) - .await; + }); + + task_manager.spawn_essential_handle().spawn_essential( + "manual-consensus-task", + None, + Box::pin(task), + ); Ok(task_manager) } diff --git a/simnode/src/client/parachain.rs b/simnode/src/client/parachain.rs index 3286440..75190a9 100644 --- a/simnode/src/client/parachain.rs +++ b/simnode/src/client/parachain.rs @@ -47,6 +47,7 @@ use sp_core::{crypto::AccountId32, Bytes}; use sp_runtime::traits::{Block as BlockT, Header}; use sp_transaction_pool::runtime_api::TaggedTransactionQueue; +use sp_core::traits::SpawnEssentialNamed; use std::sync::Arc; /// Parachain handler implementation for Simnode RPC API. @@ -266,49 +267,42 @@ where let rpc_sink = command_sink.clone(); let parachain_inherent_provider_clone = parachain_inherent_provider.clone(); - let rpc_handlers = { - let client = client.clone(); - let backend = backend.clone(); - let pool = pool.clone(); - let params = SpawnTasksParams { - config, - client: client.clone(), - backend: backend.clone(), - task_manager: &mut task_manager, - keystore: keystore_container.keystore(), - transaction_pool: pool.clone(), - rpc_builder: Box::new(move |deny_unsafe, subscription_executor| { - let mut io = rpc_builder(deny_unsafe, subscription_executor)?; - - io.merge( - ParachainRPCHandler { - inner: SimnodeRpcHandler::new(client.clone(), backend.clone()), - sink: rpc_sink.clone(), - parachain: parachain_inherent_provider_clone.clone(), - } - .into_rpc(), - ) - .map_err(|_| { - sc_service::Error::Other("Unable to merge simnode rpc api".to_string()) - })?; - io.merge(ManualSeal::new(rpc_sink.clone()).into_rpc()).map_err(|_| { - sc_service::Error::Other("Unable to merge manual seal rpc api".to_string()) - })?; - Ok(io) - }), - network, - system_rpc_tx, - tx_handler_controller, - sync_service, - telemetry: telemetry.as_mut(), - }; - spawn_tasks(params)? + let (client_clone, backend_clone) = (client.clone(), backend.clone()); + let params = SpawnTasksParams { + config, + client: client.clone(), + backend: backend.clone(), + task_manager: &mut task_manager, + keystore: keystore_container.keystore(), + transaction_pool: pool.clone(), + rpc_builder: Box::new(move |deny_unsafe, subscription_executor| { + let mut io = rpc_builder(deny_unsafe, subscription_executor)?; + + io.merge( + ParachainRPCHandler { + inner: SimnodeRpcHandler::new(client_clone.clone(), backend_clone.clone()), + sink: rpc_sink.clone(), + parachain: parachain_inherent_provider_clone.clone(), + } + .into_rpc(), + ) + .map_err(|_| sc_service::Error::Other("Unable to merge simnode rpc api".to_string()))?; + io.merge(ManualSeal::new(rpc_sink.clone()).into_rpc()).map_err(|_| { + sc_service::Error::Other("Unable to merge manual seal rpc api".to_string()) + })?; + Ok(io) + }), + network, + system_rpc_tx, + tx_handler_controller, + sync_service, + telemetry: telemetry.as_mut(), }; + spawn_tasks(params)?; _network_starter.start_network(); - let _rpc_handler = rpc_handlers.handle(); - run_manual_seal(ManualSealParams { + let task = run_manual_seal(ManualSealParams { block_import, env, client: client.clone(), @@ -354,8 +348,13 @@ where } } }, - }) - .await; + }); + + task_manager.spawn_essential_handle().spawn_essential( + "manual-consensus-task", + None, + Box::pin(task), + ); Ok(task_manager) } From 2ee8aca7e029968a10d548466cf8bd2480705948 Mon Sep 17 00:00:00 2001 From: Seun Lanlege Date: Tue, 30 Apr 2024 10:51:13 +0000 Subject: [PATCH 2/2] cargo fmt --- simnode/src/client/aura.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/simnode/src/client/aura.rs b/simnode/src/client/aura.rs index 4b3f6d5..dc0ba31 100644 --- a/simnode/src/client/aura.rs +++ b/simnode/src/client/aura.rs @@ -152,10 +152,10 @@ where rpc_builder: Box::new(move |deny_unsafe, subscription_executor| { let mut io = rpc_builder(deny_unsafe, subscription_executor)?; - io.merge(SimnodeRpcHandler::::new(client_clone.clone(), backend_clone.clone()).into_rpc()) - .map_err(|_| { - sc_service::Error::Other("Unable to merge simnode rpc api".to_string()) - })?; + io.merge( + SimnodeRpcHandler::::new(client_clone.clone(), backend_clone.clone()).into_rpc(), + ) + .map_err(|_| sc_service::Error::Other("Unable to merge simnode rpc api".to_string()))?; io.merge(ManualSeal::new(rpc_sink.clone()).into_rpc()).map_err(|_| { sc_service::Error::Other("Unable to merge manual seal rpc api".to_string()) })?;