basic --light parameter

This commit is contained in:
Robert Habermeier 2016-12-16 21:45:51 +01:00
parent 8b88ef1844
commit 8970946b74
5 changed files with 88 additions and 27 deletions

View File

@ -12,6 +12,7 @@ base_path = "$HOME/.parity"
db_path = "$HOME/.parity/chains"
keys_path = "$HOME/.parity/keys"
identity = ""
light = false
[account]
unlock = ["0xdeadbeefcafe0000000000000000000000000000"]

View File

@ -94,6 +94,7 @@ usage! {
flag_db_path: String = "$BASE/chains", or |c: &Config| otry!(c.parity).db_path.clone(),
flag_keys_path: String = "$BASE/keys", or |c: &Config| otry!(c.parity).keys_path.clone(),
flag_identity: String = "", or |c: &Config| otry!(c.parity).identity.clone(),
flag_light: bool = false, or |c: &Config| otry!(c.parity).light.clone(),
// -- Account Options
flag_unlock: Option<String> = None,
@ -323,6 +324,7 @@ struct Operating {
db_path: Option<String>,
keys_path: Option<String>,
identity: Option<String>,
light: Option<bool>,
}
#[derive(Default, Debug, PartialEq, RustcDecodable)]
@ -552,6 +554,7 @@ mod tests {
flag_db_path: "$HOME/.parity/chains".into(),
flag_keys_path: "$HOME/.parity/keys".into(),
flag_identity: "".into(),
flag_light: false,
// -- Account Options
flag_unlock: Some("0xdeadbeefcafe0000000000000000000000000000".into()),

View File

@ -66,6 +66,8 @@ Operating Options:
--keys-path PATH Specify the path for JSON key files to be found
(default: {flag_keys_path}).
--identity NAME Specify your node's name. (default: {flag_identity})
--light Run in light client mode. Very experimental.
(default: {flag_light})
Account Options:
--unlock ACCOUNTS Unlock ACCOUNTS for the duration of the execution.

View File

@ -342,6 +342,7 @@ impl Configuration {
check_seal: !self.args.flag_no_seal_check,
download_old_blocks: !self.args.flag_no_ancient_blocks,
serve_light: self.args.flag_serve_light,
light: self.args.flag_light,
verifier_settings: verifier_settings,
};
Cmd::Run(run_cmd)
@ -1034,6 +1035,7 @@ mod tests {
download_old_blocks: true,
serve_light: false,
verifier_settings: Default::default(),
light: false,
}));
}

View File

@ -97,6 +97,7 @@ pub struct RunCmd {
pub download_old_blocks: bool,
pub serve_light: bool,
pub verifier_settings: VerifierSettings,
pub light: bool,
}
pub fn open_ui(dapps_conf: &dapps::Configuration, signer_conf: &signer::Configuration) -> Result<(), String> {
@ -116,6 +117,56 @@ pub fn open_ui(dapps_conf: &dapps::Configuration, signer_conf: &signer::Configur
Ok(())
}
// Execute in light client mode.
pub fn execute_light(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<bool, String> {
use light::client::{Config as ClientConfig, Service as LightClientService};
use ethsync::{LightSync, LightSyncParams, ManageNetwork};
let panic_handler = PanicHandler::new_in_arc();
info!(
"Configured in {} mode. Note that this feature is {}.",
Colour::White.bold().paint("Light Client"),
Colour::Red.bold().paint("experimental"),
);
let mut client_config = ClientConfig::default();
let queue_size = cmd.cache_config.queue();
client_config.queue.max_queue_size = queue_size as usize;
client_config.queue.verifier_settings = cmd.verifier_settings;
let spec = try!(cmd.spec.spec());
let service = try!(LightClientService::start(client_config, &spec)
.map_err(|e| format!("Error starting light client service: {}", e)));
let net_conf = try!(cmd.net_conf.into_basic()
.map_err(|e| format!("Failed to create network config: {}", e)));
let sync_params = LightSyncParams {
network_config: net_conf,
client: service.client().clone(),
network_id: cmd.network_id.unwrap_or(spec.network_id()),
subprotocol_name: *b"les",
};
let sync = try!(LightSync::new(sync_params)
.map_err(|e| format!("Failed to initialize sync service: {}", e)));
sync.start_network();
let log_client = service.client().clone();
::std::thread::spawn(move || {
loop {
::std::thread::sleep(::std::time::Duration::from_secs(5));
println!("Best block: #{}", log_client.chain_info().best_block_number);
}
});
wait_for_exit(panic_handler, None, false);
Ok(false)
}
pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> Result<bool, String> {
if cmd.ui && cmd.dapps_conf.enabled {
// Check if Parity is already running
@ -125,6 +176,10 @@ pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> R
}
}
if cmd.light {
return execute_light(cmd, logger);
}
// set up panic handler
let panic_handler = PanicHandler::new_in_arc();
@ -416,7 +471,7 @@ pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> R
}
// Handle exit
let restart = wait_for_exit(panic_handler, http_server, ipc_server, dapps_server, signer_server, updater, can_restart);
let restart = wait_for_exit(panic_handler, Some(updater), can_restart);
info!("Finishing work, please wait...");
@ -471,11 +526,7 @@ fn prepare_account_provider(dirs: &Directories, data_dir: &str, cfg: AccountsCon
fn wait_for_exit(
panic_handler: Arc<PanicHandler>,
_http_server: Option<HttpServer>,
_ipc_server: Option<IpcServer>,
_dapps_server: Option<WebappServer>,
_signer_server: Option<SignerServer>,
updater: Arc<Updater>,
updater: Option<Arc<Updater>>,
can_restart: bool
) -> bool {
let exit = Arc::new((Mutex::new(false), Condvar::new()));
@ -488,12 +539,14 @@ fn wait_for_exit(
let e = exit.clone();
panic_handler.on_panic(move |_reason| { e.1.notify_all(); });
// Handle updater wanting to restart us
if can_restart {
let e = exit.clone();
updater.set_exit_handler(move || { *e.0.lock() = true; e.1.notify_all(); });
} else {
updater.set_exit_handler(|| info!("Update installed; ready for restart."));
if let Some(updater) = updater {
// Handle updater wanting to restart us
if can_restart {
let e = exit.clone();
updater.set_exit_handler(move || { *e.0.lock() = true; e.1.notify_all(); });
} else {
updater.set_exit_handler(|| info!("Update installed; ready for restart."));
}
}
// Wait for signal