diff --git a/ethcore/src/blockchain/blockchain.rs b/ethcore/src/blockchain/blockchain.rs index 3ff030ca0..897fb0605 100644 --- a/ethcore/src/blockchain/blockchain.rs +++ b/ethcore/src/blockchain/blockchain.rs @@ -298,16 +298,28 @@ impl BlockChain { 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; 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()); - bc.extras_db.put(b"best", &b).unwrap(); } b }