diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index e8cd0ec10..7c87a0fc1 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -755,13 +755,16 @@ impl BlockChainClient for Client where V: Verifier { } fn take_snapshot(&self) { - let best_header = HeaderView::(&self.best_block_header()); + let best_header_bytes = self.best_block_header(); + let best_header = HeaderView::new(&best_header_bytes); let hash = best_header.hash(); let state_root = best_header.state_root(); - // lock the state db to keep it consistent with the best block. - // clone the arc so we can loan out self to the block chunker. - let state_db = self.state_db.clone().lock().unwrap(); + // lock the state db while we create the state chunks. + { + let state_db = self.state_db.lock().unwrap(); + // todo [rob] actually create the state chunks. + } } } diff --git a/ethcore/src/client/test_client.rs b/ethcore/src/client/test_client.rs index 17905a905..ec48810c5 100644 --- a/ethcore/src/client/test_client.rs +++ b/ethcore/src/client/test_client.rs @@ -501,4 +501,8 @@ impl BlockChainClient for TestBlockChainClient { fn all_transactions(&self) -> Vec { self.miner.all_transactions() } + + fn take_snapshot(&self) { + unimplemented!() + } } diff --git a/ethcore/src/pv64/mod.rs b/ethcore/src/pv64/mod.rs index 062f1be7d..3b3cb02de 100644 --- a/ethcore/src/pv64/mod.rs +++ b/ethcore/src/pv64/mod.rs @@ -25,13 +25,13 @@ const SIZE_TOLERANCE: usize = 250 * 1024; use std::collections::VecDeque; use std::fs::File; use std::io::Write; -use std::path::{Path, PathBuf}; +use std::path::Path use client::BlockChainClient; use ids::BlockID; use views::{BlockView, HeaderView}; -use util::Hashable; +use util::{Bytes, Hashable}; use util::hash::H256; use util::rlp::{Stream, RlpStream}; @@ -50,7 +50,7 @@ impl<'a> BlockChunker<'a> { // Todo [rob]: find a way to reuse rlp allocations BlockChunker { client: client, - rlps: VecDeque<(Bytes, Bytes)> + rlps: VecDeque::new(), genesis_hash: genesis_hash, current_hash: HeaderView::new(&client.best_block_header()).hash(), } @@ -68,6 +68,9 @@ impl<'a> BlockChunker<'a> { let receipts = self.client.block_receipts(&self.current_hash).unwrap(); let new_loaded_size = loaded_size + (block.len() + receipts.len()); + + // todo [rob]: find a better chunking strategy -- this will likely + // result in the last chunk created being small. if new_loaded_size > PREFERRED_CHUNK_SIZE + SIZE_TOLERANCE { return true; } else { @@ -91,11 +94,16 @@ impl<'a> BlockChunker<'a> { } let raw_data = rlp_stream.out(); - let hash_str = raw_data.sha3().to_string(); + let hash = raw_data.sha3(); + let hash_str = hash.to_string(); + + let mut file_path = path.to_owned(); + file_path.push(&hash_str[2..]); - let file_path = PathBuf::new(path).push(&hash_str[2..]); let mut file = File::create(file_path).unwrap(); file.write_all(&raw_data); + + hash } /// Create and write out all block chunks to disk, returning a vector of all @@ -103,12 +111,13 @@ impl<'a> BlockChunker<'a> { /// /// The path parameter is the directory to store the block chunks in. /// This function assumes the directory exists already. - pub fn chunk_all(self, best_block_hash: H256, path: &Path) -> Vec { - let mut hash = best_block_hash; + pub fn chunk_all(mut self, path: &Path) -> Vec { let mut chunk_hashes = Vec::new(); while self.fill_buffers() { chunk_hashes.push(self.write_chunk(path)); } + + chunk_hashes } } \ No newline at end of file