Merge bugfixes from master to beta (#1605)

* Attempt to fix blochchain DB sync

* Fix bloomchain on blockchain repair

* Make sure reserved peers are in the node table

* fixed #1606 (#1615)
This commit is contained in:
Arkadiy Paronyan
2016-07-14 12:52:07 +02:00
committed by Gav Wood
parent 69847e3b8b
commit ed5d797662
7 changed files with 46 additions and 17 deletions

View File

@@ -30,7 +30,7 @@ use blockchain::best_block::BestBlock;
use types::tree_route::TreeRoute;
use blockchain::update::ExtrasUpdate;
use blockchain::{CacheSize, ImportRoute, Config};
use db::{Writable, Readable, CacheUpdatePolicy};
use db::{Writable, Readable, CacheUpdatePolicy, Key};
const LOG_BLOOMS_LEVELS: usize = 3;
const LOG_BLOOMS_ELEMENTS_PER_INDEX: usize = 16;
@@ -295,7 +295,34 @@ impl BlockChain {
// load best block
let best_block_hash = match bc.extras_db.get(b"best").unwrap() {
Some(best) => H256::from_slice(&best),
Some(best) => {
let best = H256::from_slice(&best);
let mut b = best.clone();
let mut removed = 0;
let mut best_num = 0;
while !bc.blocks_db.get(&b).unwrap().is_some() {
// track back to the best block we have in the blocks database
let extras: BlockDetails = bc.extras_db.read(&b).unwrap();
type DetailsKey = Key<BlockDetails, Target=H264>;
bc.extras_db.delete(&(DetailsKey::key(&b))).unwrap();
b = extras.parent;
best_num = extras.number;
removed += 1;
}
if b != best {
let batch = DBTransaction::new();
let range = (best_num + 1) as bc::Number .. (best_num + removed) as bc::Number;
let chain = bc::group::BloomGroupChain::new(bc.blooms_config, &bc);
let changes = chain.replace(&range, vec![]);
for (k, v) in changes.into_iter() {
batch.write(&LogGroupPosition::from(k), &BloomGroup::from(v));
}
batch.put(b"best", &b).unwrap();
bc.extras_db.write(batch).unwrap();
info!("Restored mismatched best block. Was: {}, new: {}", best.hex(), b.hex());
}
b
}
None => {
// best block does not exist
// we need to insert genesis into the cache

View File

@@ -20,7 +20,7 @@ use util::HeapSizeOf;
use basic_types::LogBloom;
/// Helper structure representing bloom of the trace.
#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct Bloom(LogBloom);
impl From<LogBloom> for Bloom {

View File

@@ -20,7 +20,7 @@ use util::HeapSizeOf;
use super::Bloom;
/// Represents group of X consecutive blooms.
#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct BloomGroup {
blooms: Vec<Bloom>,
}

View File

@@ -15,7 +15,6 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! Trace database.
use std::ptr;
use std::ops::{Deref, DerefMut};
use std::collections::HashMap;
use std::sync::{RwLock, Arc};
@@ -47,9 +46,7 @@ impl Key<BlockTraces> for H256 {
fn key(&self) -> H264 {
let mut result = H264::default();
result[0] = TraceDBIndex::BlockTraces as u8;
unsafe {
ptr::copy(self.as_ptr(), result.as_mut_ptr().offset(1), 32);
}
result[1..33].copy_from_slice(self);
result
}
}
@@ -84,9 +81,9 @@ impl Key<blooms::BloomGroup> for TraceGroupPosition {
result[0] = TraceDBIndex::BloomGroups as u8;
result[1] = self.0.level;
result[2] = self.0.index as u8;
result[3] = (self.0.index << 8) as u8;
result[4] = (self.0.index << 16) as u8;
result[5] = (self.0.index << 24) as u8;
result[3] = (self.0.index >> 8) as u8;
result[4] = (self.0.index >> 16) as u8;
result[5] = (self.0.index >> 24) as u8;
TraceGroupKey(result)
}
}

View File

@@ -30,7 +30,7 @@ use std::collections::VecDeque;
/// Addresses filter.
///
/// Used to create bloom possibilities and match filters.
#[derive(Binary)]
#[derive(Debug, Binary)]
pub struct AddressesFilter {
list: Vec<Address>
}
@@ -76,7 +76,7 @@ impl AddressesFilter {
}
}
#[derive(Binary)]
#[derive(Debug, Binary)]
/// Traces filter.
pub struct Filter {
/// Block range.