Skip to content

Commit

Permalink
Take control of recovered snapshots, start restoration asynchronously (
Browse files Browse the repository at this point in the history
…openethereum#2010)

* take control of given snapshot

* start snapshot restoration asynchronously,
  • Loading branch information
rphmeier authored and arkpar committed Aug 25, 2016
1 parent 2aef81c commit 1c19a80
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 84 deletions.
8 changes: 8 additions & 0 deletions ethcore/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use spec::Spec;
use error::*;
use client::{Client, ClientConfig, ChainNotify};
use miner::Miner;
use snapshot::ManifestData;
use snapshot::service::Service as SnapshotService;
use std::sync::atomic::AtomicBool;

Expand All @@ -39,6 +40,8 @@ pub enum ClientIoMessage {
BlockVerified,
/// New transaction RLPs are ready to be imported
NewTransactions(Vec<Bytes>),
/// Begin snapshot restoration
BeginRestoration(ManifestData),
/// Feed a state chunk to the snapshot service
FeedStateChunk(H256, Bytes),
/// Feed a block chunk to the snapshot service
Expand Down Expand Up @@ -160,6 +163,11 @@ impl IoHandler<ClientIoMessage> for ClientIoHandler {
match *net_message {
ClientIoMessage::BlockVerified => { self.client.import_verified_blocks(); }
ClientIoMessage::NewTransactions(ref transactions) => { self.client.import_queued_transactions(transactions); }
ClientIoMessage::BeginRestoration(ref manifest) => {
if let Err(e) = self.snapshot.init_restore(manifest.clone()) {
warn!("Failed to initialize snapshot restoration: {}", e);
}
}
ClientIoMessage::FeedStateChunk(ref hash, ref chunk) => self.snapshot.feed_state_chunk(*hash, chunk),
ClientIoMessage::FeedBlockChunk(ref hash, ref chunk) => self.snapshot.feed_block_chunk(*hash, chunk),
_ => {} // ignore other messages
Expand Down
8 changes: 4 additions & 4 deletions ethcore/src/snapshot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ impl StateRebuilder {

/// Check for accounts missing code. Once all chunks have been fed, there should
/// be none.
pub fn check_missing(&self) -> Result<(), Error> {
pub fn check_missing(self) -> Result<(), Error> {
let missing = self.missing_code.keys().cloned().collect::<Vec<_>>();
match missing.is_empty() {
true => Ok(()),
Expand Down Expand Up @@ -640,16 +640,16 @@ impl BlockRebuilder {
}

/// Glue together any disconnected chunks. To be called at the end.
pub fn glue_chunks(&mut self) {
for &(ref first_num, ref first_hash) in &self.disconnected {
pub fn glue_chunks(self) {
for (first_num, first_hash) in self.disconnected {
let parent_num = first_num - 1;

// check if the parent is even in the chain.
// since we don't restore every single block in the chain,
// the first block of the first chunks has nothing to connect to.
if let Some(parent_hash) = self.chain.block_hash(parent_num) {
// if so, add the child to it.
self.chain.add_child(parent_hash, *first_hash);
self.chain.add_child(parent_hash, first_hash);
}
}
}
Expand Down
Loading

0 comments on commit 1c19a80

Please sign in to comment.