Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ctrl-c bug #41

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion simnode/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sc-simnode"
version = "1.6.1"
version = "1.6.2"
authors = ["Polytope Labs <hello@polytope.technology>"]
edition = "2021"
license = "Apache-2.0"
Expand Down
70 changes: 35 additions & 35 deletions simnode/src/client/aura.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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::<C>::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::<C>::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();

run_manual_seal(ManualSealParams {
let task = run_manual_seal(ManualSealParams {
block_import,
env,
client: client.clone(),
Expand Down Expand Up @@ -215,8 +210,13 @@ where
}
}
},
})
.await;
});

task_manager.spawn_essential_handle().spawn_essential(
"manual-consensus-task",
None,
Box::pin(task),
);

Ok(task_manager)
}
71 changes: 36 additions & 35 deletions simnode/src/client/babe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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::<C>::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::<C>::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(),
Expand All @@ -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(),
Expand Down Expand Up @@ -228,8 +224,13 @@ where
}
}
},
})
.await;
});

task_manager.spawn_essential_handle().spawn_essential(
"manual-consensus-task",
None,
Box::pin(task),
);

Ok(task_manager)
}
81 changes: 40 additions & 41 deletions simnode/src/client/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -354,8 +348,13 @@ where
}
}
},
})
.await;
});

task_manager.spawn_essential_handle().spawn_essential(
"manual-consensus-task",
None,
Box::pin(task),
);

Ok(task_manager)
}
Loading