Snapshot sync (#2047)
* PV64 sync * Tests * Client DB restore * Snapshot restoration over IPC * Upating test * Minor tweaks * Upating test
This commit is contained in:
@@ -99,9 +99,11 @@ mod modules;
|
||||
mod account;
|
||||
mod blockchain;
|
||||
mod presale;
|
||||
mod run;
|
||||
mod sync;
|
||||
mod snapshot;
|
||||
mod run;
|
||||
#[cfg(feature="ipc")]
|
||||
mod sync;
|
||||
#[cfg(feature="ipc")]
|
||||
mod boot;
|
||||
|
||||
#[cfg(feature="stratum")]
|
||||
@@ -158,10 +160,24 @@ mod stratum_optional {
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
#[cfg(not(feature="ipc"))]
|
||||
fn sync_main() -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
#[cfg(feature="ipc")]
|
||||
fn sync_main() -> bool {
|
||||
// just redirect to the sync::main()
|
||||
if std::env::args().nth(1).map_or(false, |arg| arg == "sync") {
|
||||
sync::main();
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
if sync_main() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ use std::sync::Arc;
|
||||
use ethcore::client::BlockChainClient;
|
||||
use hypervisor::Hypervisor;
|
||||
use ethsync::{SyncConfig, NetworkConfiguration, NetworkError};
|
||||
use ethcore::snapshot::SnapshotService;
|
||||
#[cfg(not(feature="ipc"))]
|
||||
use self::no_ipc_deps::*;
|
||||
#[cfg(feature="ipc")]
|
||||
@@ -25,10 +26,12 @@ use self::ipc_deps::*;
|
||||
use ethcore_logger::Config as LogConfig;
|
||||
use std::path::Path;
|
||||
|
||||
#[cfg(feature="ipc")]
|
||||
pub mod service_urls {
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub const CLIENT: &'static str = "parity-chain.ipc";
|
||||
pub const SNAPSHOT: &'static str = "parity-snapshot.ipc";
|
||||
pub const SYNC: &'static str = "parity-sync.ipc";
|
||||
pub const SYNC_NOTIFY: &'static str = "parity-sync-notify.ipc";
|
||||
pub const NETWORK_MANAGER: &'static str = "parity-manage-net.ipc";
|
||||
@@ -119,6 +122,7 @@ pub fn sync
|
||||
sync_cfg: SyncConfig,
|
||||
net_cfg: NetworkConfiguration,
|
||||
_client: Arc<BlockChainClient>,
|
||||
_snapshot_service: Arc<SnapshotService>,
|
||||
log_settings: &LogConfig,
|
||||
)
|
||||
-> Result<SyncModules, NetworkError>
|
||||
@@ -148,10 +152,11 @@ pub fn sync
|
||||
sync_cfg: SyncConfig,
|
||||
net_cfg: NetworkConfiguration,
|
||||
client: Arc<BlockChainClient>,
|
||||
snapshot_service: Arc<SnapshotService>,
|
||||
_log_settings: &LogConfig,
|
||||
)
|
||||
-> Result<SyncModules, NetworkError>
|
||||
{
|
||||
let eth_sync = try!(EthSync::new(sync_cfg, client, net_cfg));
|
||||
let eth_sync = try!(EthSync::new(sync_cfg, client, snapshot_service, net_cfg));
|
||||
Ok((eth_sync.clone() as Arc<SyncProvider>, eth_sync.clone() as Arc<ManageNetwork>, eth_sync.clone() as Arc<ChainNotify>))
|
||||
}
|
||||
|
||||
@@ -179,13 +179,14 @@ pub fn execute(cmd: RunCmd) -> Result<(), String> {
|
||||
|
||||
// take handle to client
|
||||
let client = service.client();
|
||||
let snapshot_service = service.snapshot_service();
|
||||
|
||||
// create external miner
|
||||
let external_miner = Arc::new(ExternalMiner::default());
|
||||
|
||||
// create sync object
|
||||
let (sync_provider, manage_network, chain_notify) = try!(modules::sync(
|
||||
&mut hypervisor, sync_config, net_conf.into(), client.clone(), &cmd.logger_config,
|
||||
&mut hypervisor, sync_config, net_conf.into(), client.clone(), snapshot_service, &cmd.logger_config,
|
||||
).map_err(|e| format!("Sync error: {}", e)));
|
||||
|
||||
service.add_notify(chain_notify.clone());
|
||||
|
||||
@@ -129,10 +129,9 @@ impl SnapshotCommand {
|
||||
|
||||
let informant_handle = snapshot.clone();
|
||||
::std::thread::spawn(move || {
|
||||
while let RestorationStatus::Ongoing = informant_handle.status() {
|
||||
let (state_chunks, block_chunks) = informant_handle.chunks_done();
|
||||
while let RestorationStatus::Ongoing { state_chunks_done, block_chunks_done } = informant_handle.status() {
|
||||
info!("Processed {}/{} state chunks and {}/{} block chunks.",
|
||||
state_chunks, num_state, block_chunks, num_blocks);
|
||||
state_chunks_done, num_state, block_chunks_done, num_blocks);
|
||||
|
||||
::std::thread::sleep(Duration::from_secs(5));
|
||||
}
|
||||
@@ -161,7 +160,7 @@ impl SnapshotCommand {
|
||||
}
|
||||
|
||||
match snapshot.status() {
|
||||
RestorationStatus::Ongoing => Err("Snapshot file is incomplete and missing chunks.".into()),
|
||||
RestorationStatus::Ongoing { .. } => Err("Snapshot file is incomplete and missing chunks.".into()),
|
||||
RestorationStatus::Failed => Err("Snapshot restoration failed.".into()),
|
||||
RestorationStatus::Inactive => {
|
||||
info!("Restoration complete.");
|
||||
|
||||
@@ -20,6 +20,7 @@ use std::sync::Arc;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use hypervisor::{SYNC_MODULE_ID, HYPERVISOR_IPC_URL, ControlService};
|
||||
use ethcore::client::{RemoteClient, ChainNotify};
|
||||
use ethcore::snapshot::{RemoteSnapshotService};
|
||||
use ethsync::{SyncProvider, EthSync, ManageNetwork, ServiceConfiguration};
|
||||
use modules::service_urls;
|
||||
use boot;
|
||||
@@ -45,8 +46,9 @@ pub fn main() {
|
||||
.unwrap_or_else(|e| panic!("Fatal: error reading boot arguments ({:?})", e));
|
||||
|
||||
let remote_client = dependency!(RemoteClient, &service_urls::with_base(&service_config.io_path, service_urls::CLIENT));
|
||||
let remote_snapshot = dependency!(RemoteSnapshotService, &service_urls::with_base(&service_config.io_path, service_urls::SNAPSHOT));
|
||||
|
||||
let sync = EthSync::new(service_config.sync, remote_client.service().clone(), service_config.net).unwrap();
|
||||
let sync = EthSync::new(service_config.sync, remote_client.service().clone(), remote_snapshot.service().clone(), service_config.net).unwrap();
|
||||
|
||||
let _ = boot::main_thread();
|
||||
let service_stop = Arc::new(AtomicBool::new(false));
|
||||
|
||||
Reference in New Issue
Block a user