From 877270c35fe68adb967a5d0714d5c3e15eaf91fc Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 2 Mar 2016 18:32:54 +0100 Subject: [PATCH] Fixes. --- ethcore/src/blockchain/blockchain.rs | 31 +++++++++++++++++----------- ethcore/src/client.rs | 4 ++-- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/ethcore/src/blockchain/blockchain.rs b/ethcore/src/blockchain/blockchain.rs index 6779051e2..6b0939df5 100644 --- a/ethcore/src/blockchain/blockchain.rs +++ b/ethcore/src/blockchain/blockchain.rs @@ -491,15 +491,20 @@ impl BlockChain { self.extras_db.write(batch).unwrap(); } + /// Iterator that lists `first` and then all of `first`'s ancestors, by hash. pub fn ancestry_iter(&self, first: H256) -> Option { - AncestryIter { - current: first, - chain: &self, + if self.is_known(&first) { + Some(AncestryIter { + current: first, + chain: &self, + }) + } else { + None } } /// Given a block's `parent`, find every block header which represents a valid uncle. - pub fn find_uncle_headers(&self, parent: &H256) -> Vec
{ + pub fn find_uncle_headers(&self, parent: &H256) -> Option> { let uncle_generations = 6usize; /* { @@ -524,13 +529,15 @@ impl BlockChain { } } */ - let _excluded = self - .ancestry_iter(parent.clone()) - .take(uncle_generations) - .flat_map(|h| self.uncle_hashes(&h).iter().chain(&[h])) - .collect::>(); - - Vec::new() + if !self.is_known(parent) { return None; } + let mut _excluded = HashSet::new(); + for a in self.ancestry_iter(parent.clone()).unwrap().take(uncle_generations) { + for u in self.uncle_hashes(&a).unwrap().into_iter() { + _excluded.insert(u); + } + _excluded.insert(a); + } + None } /// Get inserted block info which is critical to preapre extras updates. @@ -882,7 +889,7 @@ mod tests { block_hashes.reverse(); - assert_eq!(bc.ancestry_iter(block_hashes[0].clone()).collect::>(), block_hashes) + assert_eq!(bc.ancestry_iter(block_hashes[0].clone()).unwrap().collect::>(), block_hashes) } #[test] diff --git a/ethcore/src/client.rs b/ethcore/src/client.rs index cc5e23869..105090580 100644 --- a/ethcore/src/client.rs +++ b/ethcore/src/client.rs @@ -200,7 +200,7 @@ pub struct Client { extra_data: RwLock, } -const HISTORY: u64 = 1000; +const HISTORY: u64 = 2000000; const CLIENT_DB_VER_STR: &'static str = "4.0"; impl Client { @@ -457,7 +457,7 @@ impl Client { self.extra_data() ); - self.chain.read().unwrap().find_uncle_headers(&h).into_iter().foreach(|h| { b.push_uncle(h).unwrap(); }); + self.chain.read().unwrap().find_uncle_headers(&h).unwrap().into_iter().foreach(|h| { b.push_uncle(h).unwrap(); }); // TODO: push transactions.