Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Insert PROOF messages for some cases in blockchain #9141

Merged
merged 5 commits into from
Jul 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions ethcore/src/blockchain/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ impl BlockProvider for BlockChain {

// Read from DB and populate cache
let b = self.db.key_value().get(db::COL_HEADERS, hash)
.expect("Low level database error. Some issue with disk?")?;
.expect("Low level database error when fetching block header data. Some issue with disk?")?;

let header = encoded::Header::new(decompress(&b, blocks_swapper()).into_vec());
let mut write = self.block_headers.write();
Expand Down Expand Up @@ -300,7 +300,7 @@ impl BlockProvider for BlockChain {

// Read from DB and populate cache
let b = self.db.key_value().get(db::COL_BODIES, hash)
.expect("Low level database error. Some issue with disk?")?;
.expect("Low level database error when fetching block body data. Some issue with disk?")?;

let body = encoded::Body::new(decompress(&b, blocks_swapper()).into_vec());
let mut write = self.block_bodies.write();
Expand Down Expand Up @@ -346,7 +346,7 @@ impl BlockProvider for BlockChain {
I: Iterator<Item = B> {
self.db.blooms()
.filter(from_block, to_block, blooms)
.expect("Low level database error. Some issue with disk?")
.expect("Low level database error when searching blooms. Some issue with disk?")
}

/// Returns logs matching given filter. The order of logs returned will be the same as the order of the blocks
Expand Down Expand Up @@ -536,7 +536,9 @@ impl BlockChain {
};

// load best block
let best_block_hash = match bc.db.key_value().get(db::COL_EXTRA, b"best").unwrap() {
let best_block_hash = match bc.db.key_value().get(db::COL_EXTRA, b"best")
.expect("Low-level database error when fetching 'best' block. Some issue with disk?")
{
Some(best) => {
H256::from_slice(&best)
}
Expand Down Expand Up @@ -564,15 +566,18 @@ impl BlockChain {
batch.write(db::COL_EXTRA, &header.number(), &hash);

batch.put(db::COL_EXTRA, b"best", &hash);
bc.db.key_value().write(batch).expect("Low level database error. Some issue with disk?");
bc.db.key_value().write(batch).expect("Low level database error when fetching 'best' block. Some issue with disk?");
hash
}
};

{
// Fetch best block details
let best_block_total_difficulty = bc.block_details(&best_block_hash).unwrap().total_difficulty;
let best_block_rlp = bc.block(&best_block_hash).unwrap();
let best_block_total_difficulty = bc.block_details(&best_block_hash)
.expect("Best block is from a known block hash; a known block hash always comes with a known block detail; qed")
.total_difficulty;
let best_block_rlp = bc.block(&best_block_hash)
.expect("Best block is from a known block hash; qed");

// and write them
let mut best_block = bc.best_block.write();
Expand All @@ -586,8 +591,12 @@ impl BlockChain {
{
let best_block_number = bc.best_block.read().header.number();
// Fetch first and best ancient block details
let raw_first = bc.db.key_value().get(db::COL_EXTRA, b"first").unwrap().map(|v| v.into_vec());
let mut best_ancient = bc.db.key_value().get(db::COL_EXTRA, b"ancient").unwrap().map(|h| H256::from_slice(&h));
let raw_first = bc.db.key_value().get(db::COL_EXTRA, b"first")
.expect("Low level database error when fetching 'first' block. Some issue with disk?")
.map(|v| v.into_vec());
let mut best_ancient = bc.db.key_value().get(db::COL_EXTRA, b"ancient")
.expect("Low level database error when fetching 'best ancient' block. Some issue with disk?")
.map(|h| H256::from_slice(&h));
let best_ancient_number;
if best_ancient.is_none() && best_block_number > 1 && bc.block_hash(1).is_none() {
best_ancient = Some(bc.genesis_hash());
Expand Down Expand Up @@ -618,7 +627,7 @@ impl BlockChain {
trace!("First block calculated: {:?}", hash);
let mut batch = db.key_value().transaction();
batch.put(db::COL_EXTRA, b"first", &hash);
db.key_value().write(batch).expect("Low level database error.");
db.key_value().write(batch).expect("Low level database error when writing 'first' block. Some issue with disk?");
bc.first_block = Some(hash);
}
},
Expand Down Expand Up @@ -1072,7 +1081,7 @@ impl BlockChain {
if let Some((block, blooms)) = update.blocks_blooms {
self.db.blooms()
.insert_blooms(block, blooms.iter())
.expect("Low level database error. Some issue with disk?");
.expect("Low level database error when updating blooms. Some issue with disk?");
}

// These cached values must be updated last with all four locks taken to avoid
Expand Down Expand Up @@ -1350,11 +1359,13 @@ impl BlockChain {
}
},
BlockLocation::BranchBecomingCanonChain(ref data) => {
let ancestor_number = self.block_number(&data.ancestor).unwrap();
let ancestor_number = self.block_number(&data.ancestor)
.expect("hash belongs to an ancestor of an inserted block; this branch is only reachable for normal block insertion (non-ancient); ancestors of an inserted block are always available for normal block insertion; block number of an inserted block is always available; qed");
let start_number = ancestor_number + 1;

let mut blooms: Vec<Bloom> = data.enacted.iter()
.map(|hash| self.block_header_data(hash).unwrap())
.map(|hash| self.block_header_data(hash)
.expect("hash belongs to an inserted block; block header data of an inserted block is always available; qed"))
.map(|h| h.log_bloom())
.collect();

Expand Down