From a969a041273005bc3aab42edacaafd7c644e9945 Mon Sep 17 00:00:00 2001 From: debris Date: Wed, 30 Nov 2016 13:55:03 +0100 Subject: [PATCH] small fixes for importing unordered blocks --- db/src/storage.rs | 2 +- import/src/blk.rs | 7 +++++-- import/src/fs.rs | 15 ++++++++++++++- network/src/consensus.rs | 4 ++-- sync/src/blocks_writer.rs | 2 +- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/db/src/storage.rs b/db/src/storage.rs index 7fe2c402..d12abec1 100644 --- a/db/src/storage.rs +++ b/db/src/storage.rs @@ -579,7 +579,7 @@ impl BlockStapler for Storage { // write accumulated transactions meta try!(context.apply(&self.database)); - trace!(target: "db", "Best block now ({}, {})", &new_best_hash, &new_best_number); + trace!(target: "db", "Best block now ({}, {})", &new_best_hash.to_reversed_str(), &new_best_number); // updating locked best block *best_block = Some(BestBlock { hash: new_best_hash, number: new_best_number }); diff --git a/import/src/blk.rs b/import/src/blk.rs index 8d2a4ec8..85d71c5b 100644 --- a/import/src/blk.rs +++ b/import/src/blk.rs @@ -1,4 +1,5 @@ use std::{io, fs, path}; +use std::collections::BTreeSet; use ser::{ReadIterator, deserialize_iterator, Error as ReaderError}; use block::Block; use fs::read_blk_dir; @@ -25,9 +26,11 @@ impl Iterator for BlkFile { } pub fn open_blk_dir

(path: P) -> Result where P: AsRef { - let iter = try!(read_blk_dir(path)) + let files = read_blk_dir(path)?.collect::, _>>()?; + + let iter = files.into_iter() // flatten results... - .flat_map(|entry| entry.and_then(|file| open_blk_file(file.path))) + .flat_map(|file| open_blk_file(file.path)) // flat iterators over each block in each file .flat_map(|file| file); diff --git a/import/src/fs.rs b/import/src/fs.rs index d10b749c..1933bdfe 100644 --- a/import/src/fs.rs +++ b/import/src/fs.rs @@ -1,4 +1,4 @@ -use std::{io, fs, path}; +use std::{io, fs, path, cmp}; /// Creates an iterator over all blk .dat files pub fn read_blk_dir

(path: P) -> Result where P: AsRef { @@ -13,10 +13,23 @@ pub struct ReadBlkDir { read_dir: fs::ReadDir, } +#[derive(PartialEq, Eq)] pub struct BlkEntry { pub path: path::PathBuf, } +impl cmp::PartialOrd for BlkEntry { + fn partial_cmp(&self, other: &Self) -> Option { + cmp::PartialOrd::partial_cmp(&self.path, &other.path) + } +} + +impl cmp::Ord for BlkEntry { + fn cmp(&self, other: &Self) -> cmp::Ordering { + cmp::Ord::cmp(&self.path, &other.path) + } +} + fn is_blk_file_name(file_name: &str) -> bool { if file_name.len() != 12 || !file_name.starts_with("blk") || !file_name.ends_with(".dat") { return false; diff --git a/network/src/consensus.rs b/network/src/consensus.rs index 3890a73f..be7629d7 100644 --- a/network/src/consensus.rs +++ b/network/src/consensus.rs @@ -31,8 +31,8 @@ impl ConsensusParams { } pub fn is_bip30_exception(&self, hash: &H256, height: u32) -> bool { - (height == 91842 && hash == &H256::from_reversed_str("0x00000000000a4d0a398161ffc163c503763b1f4360639393e0e4c8e300e0caec")) || - (height == 91880 && hash == &H256::from_reversed_str("0x00000000000743f190a18c5577a3c2d2a1f610ae9601ac046a38084ccb7cd721")) + (height == 91842 && hash == &H256::from_reversed_str("00000000000a4d0a398161ffc163c503763b1f4360639393e0e4c8e300e0caec")) || + (height == 91880 && hash == &H256::from_reversed_str("00000000000743f190a18c5577a3c2d2a1f610ae9601ac046a38084ccb7cd721")) } } diff --git a/sync/src/blocks_writer.rs b/sync/src/blocks_writer.rs index 32807ffd..0dc9c76d 100644 --- a/sync/src/blocks_writer.rs +++ b/sync/src/blocks_writer.rs @@ -9,7 +9,7 @@ use synchronization_verifier::{Verifier, SyncVerifier, VerificationSink}; use primitives::hash::H256; use super::Error; -pub const MAX_ORPHANED_BLOCKS: usize = 64; +pub const MAX_ORPHANED_BLOCKS: usize = 1024; pub struct BlocksWriter { storage: db::SharedStore,