mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 21:01:05 +00:00
Preparing light client structure [v2] (#150)
* light client structure + remote call requests
This commit is contained in:
committed by
GitHub
parent
4808077674
commit
58ba901ccc
@@ -37,6 +37,10 @@ args:
|
||||
long: validator
|
||||
help: Enable validator mode
|
||||
takes_value: false
|
||||
- light:
|
||||
long: light
|
||||
help: Run in light client mode
|
||||
takes_value: false
|
||||
- port:
|
||||
long: port
|
||||
value_name: PORT
|
||||
|
||||
@@ -23,12 +23,18 @@ use tokio_core::reactor;
|
||||
use network::{SyncState, SyncProvider};
|
||||
use runtime_support::Hashable;
|
||||
use primitives::block::HeaderHash;
|
||||
use client::BlockchainEvents;
|
||||
use state_machine;
|
||||
use client::{self, BlockchainEvents};
|
||||
|
||||
const TIMER_INTERVAL_MS: u64 = 5000;
|
||||
|
||||
/// Spawn informant on the event loop
|
||||
pub fn start(service: &Service, handle: reactor::Handle) {
|
||||
pub fn start<B, E>(service: &Service<B, E>, handle: reactor::Handle)
|
||||
where
|
||||
B: client::backend::Backend + Send + Sync + 'static,
|
||||
E: client::CallExecutor + Send + Sync + 'static,
|
||||
client::error::Error: From<<<B as client::backend::Backend>::State as state_machine::backend::Backend>::Error>
|
||||
{
|
||||
let interval = reactor::Interval::new_at(Instant::now(), Duration::from_millis(TIMER_INTERVAL_MS), &handle)
|
||||
.expect("Error creating informant timer");
|
||||
|
||||
|
||||
@@ -107,16 +107,7 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
|
||||
I: IntoIterator<Item = T>,
|
||||
T: Into<std::ffi::OsString> + Clone,
|
||||
{
|
||||
let mut core = reactor::Core::new().expect("tokio::Core could not be created");
|
||||
let exit = {
|
||||
// can't use signal directly here because CtrlC takes only `Fn`.
|
||||
let (exit_send, exit) = mpsc::channel(1);
|
||||
ctrlc::CtrlC::set_handler(move || {
|
||||
exit_send.clone().send(()).wait().expect("Error sending exit notification");
|
||||
});
|
||||
|
||||
exit
|
||||
};
|
||||
let core = reactor::Core::new().expect("tokio::Core could not be created");
|
||||
|
||||
let yaml = load_yaml!("./cli.yml");
|
||||
let matches = match clap::App::from_yaml(yaml).version(crate_version!()).get_matches_from_safe(args) {
|
||||
@@ -152,10 +143,12 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
|
||||
if matches.is_present("collator") {
|
||||
info!("Starting collator.");
|
||||
role = service::Role::COLLATOR;
|
||||
}
|
||||
else if matches.is_present("validator") {
|
||||
} else if matches.is_present("validator") {
|
||||
info!("Starting validator.");
|
||||
role = service::Role::VALIDATOR;
|
||||
} else if matches.is_present("light") {
|
||||
info!("Starting light.");
|
||||
role = service::Role::LIGHT;
|
||||
}
|
||||
|
||||
match matches.value_of("chain") {
|
||||
@@ -195,13 +188,33 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
|
||||
|
||||
config.keys = matches.values_of("key").unwrap_or_default().map(str::to_owned).collect();
|
||||
|
||||
let service = service::Service::new(config)?;
|
||||
match role == service::Role::LIGHT {
|
||||
true => run_until_exit(core, service::new_light(config)?, &matches),
|
||||
false => run_until_exit(core, service::new_full(config)?, &matches),
|
||||
}
|
||||
}
|
||||
|
||||
fn run_until_exit<B, E>(mut core: reactor::Core, service: service::Service<B, E>, matches: &clap::ArgMatches) -> error::Result<()>
|
||||
where
|
||||
B: client::backend::Backend + Send + Sync + 'static,
|
||||
E: client::CallExecutor + Send + Sync + 'static,
|
||||
client::error::Error: From<<<B as client::backend::Backend>::State as state_machine::backend::Backend>::Error>
|
||||
{
|
||||
let exit = {
|
||||
// can't use signal directly here because CtrlC takes only `Fn`.
|
||||
let (exit_send, exit) = mpsc::channel(1);
|
||||
ctrlc::CtrlC::set_handler(move || {
|
||||
exit_send.clone().send(()).wait().expect("Error sending exit notification");
|
||||
});
|
||||
|
||||
exit
|
||||
};
|
||||
|
||||
informant::start(&service, core.handle());
|
||||
|
||||
let _rpc_servers = {
|
||||
let http_address = parse_address("127.0.0.1:9933", "rpc-port", &matches)?;
|
||||
let ws_address = parse_address("127.0.0.1:9944", "ws-port", &matches)?;
|
||||
let http_address = parse_address("127.0.0.1:9933", "rpc-port", matches)?;
|
||||
let ws_address = parse_address("127.0.0.1:9944", "ws-port", matches)?;
|
||||
|
||||
let handler = || {
|
||||
let chain = rpc::apis::chain::Chain::new(service.client(), core.remote());
|
||||
|
||||
Reference in New Issue
Block a user