Fix bloomchain on blockchain repair
This commit is contained in:
parent
420f2ad6c4
commit
80d59949ff
@ -298,16 +298,28 @@ impl BlockChain {
|
|||||||
Some(best) => {
|
Some(best) => {
|
||||||
let best = H256::from_slice(&best);
|
let best = H256::from_slice(&best);
|
||||||
let mut b = best.clone();
|
let mut b = best.clone();
|
||||||
|
let mut removed = 0;
|
||||||
|
let mut best_num = 0;
|
||||||
while !bc.blocks_db.get(&b).unwrap().is_some() {
|
while !bc.blocks_db.get(&b).unwrap().is_some() {
|
||||||
// track back to the best block we have in the blocks database
|
// track back to the best block we have in the blocks database
|
||||||
let extras: BlockDetails = bc.extras_db.read(&b).unwrap();
|
let extras: BlockDetails = bc.extras_db.read(&b).unwrap();
|
||||||
type DetailsKey = Key<BlockDetails, Target=H264>;
|
type DetailsKey = Key<BlockDetails, Target=H264>;
|
||||||
bc.extras_db.delete(&(DetailsKey::key(&b))).unwrap();
|
bc.extras_db.delete(&(DetailsKey::key(&b))).unwrap();
|
||||||
b = extras.parent;
|
b = extras.parent;
|
||||||
|
best_num = extras.number;
|
||||||
|
removed += 1;
|
||||||
}
|
}
|
||||||
if b != best {
|
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());
|
info!("Restored mismatched best block. Was: {}, new: {}", best.hex(), b.hex());
|
||||||
bc.extras_db.put(b"best", &b).unwrap();
|
|
||||||
}
|
}
|
||||||
b
|
b
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user