remove impossible panickers related to infallible db transaction (#1947)

This commit is contained in:
Robert Habermeier
2016-08-18 09:43:56 +02:00
committed by Gav Wood
parent 108024e98d
commit 57dbdaada9
12 changed files with 60 additions and 68 deletions

View File

@@ -366,12 +366,12 @@ impl BlockChain {
};
let batch = DBTransaction::new(&db);
batch.put(DB_COL_HEADERS, &hash, block.header_rlp().as_raw()).unwrap();
batch.put(DB_COL_BODIES, &hash, &Self::block_to_body(genesis)).unwrap();
batch.put(DB_COL_HEADERS, &hash, block.header_rlp().as_raw());
batch.put(DB_COL_BODIES, &hash, &Self::block_to_body(genesis));
batch.write(DB_COL_EXTRA, &hash, &details);
batch.write(DB_COL_EXTRA, &header.number(), &hash);
batch.put(DB_COL_EXTRA, b"best", &hash).unwrap();
batch.put(DB_COL_EXTRA, b"best", &hash);
bc.db.write(batch).expect("Low level database error. Some issue with disk?");
hash
}
@@ -415,7 +415,7 @@ impl BlockChain {
}
if let Some(extras) = self.db.read(DB_COL_EXTRA, &best_block_hash) as Option<BlockDetails> {
type DetailsKey = Key<BlockDetails, Target=H264>;
batch.delete(DB_COL_EXTRA, &(DetailsKey::key(&best_block_hash))).unwrap();
batch.delete(DB_COL_EXTRA, &(DetailsKey::key(&best_block_hash)));
let hash = extras.parent;
let range = extras.number as bc::Number .. extras.number as bc::Number;
let chain = bc::group::BloomGroupChain::new(self.blooms_config, self);
@@ -423,7 +423,7 @@ impl BlockChain {
for (k, v) in changes.into_iter() {
batch.write(DB_COL_EXTRA, &LogGroupPosition::from(k), &BloomGroup::from(v));
}
batch.put(DB_COL_EXTRA, b"best", &hash).unwrap();
batch.put(DB_COL_EXTRA, b"best", &hash);
let best_block_total_difficulty = self.block_details(&hash).unwrap().total_difficulty;
let best_block_rlp = self.block(&hash).unwrap();
@@ -566,8 +566,8 @@ impl BlockChain {
let compressed_body = UntrustedRlp::new(&Self::block_to_body(bytes)).compress(RlpType::Blocks);
// store block in db
batch.put(DB_COL_HEADERS, &hash, &compressed_header).unwrap();
batch.put(DB_COL_BODIES, &hash, &compressed_body).unwrap();
batch.put(DB_COL_HEADERS, &hash, &compressed_header);
batch.put(DB_COL_BODIES, &hash, &compressed_body);
let maybe_parent = self.block_details(&header.parent_hash());
@@ -669,8 +669,8 @@ impl BlockChain {
assert!(self.pending_best_block.read().is_none());
// store block in db
batch.put_compressed(DB_COL_HEADERS, &hash, block.header_rlp().as_raw().to_vec()).unwrap();
batch.put_compressed(DB_COL_BODIES, &hash, Self::block_to_body(bytes)).unwrap();
batch.put_compressed(DB_COL_HEADERS, &hash, block.header_rlp().as_raw().to_vec());
batch.put_compressed(DB_COL_BODIES, &hash, Self::block_to_body(bytes));
let info = self.block_info(&header);
@@ -768,7 +768,7 @@ impl BlockChain {
match update.info.location {
BlockLocation::Branch => (),
_ => if is_best {
batch.put(DB_COL_EXTRA, b"best", &update.info.hash).unwrap();
batch.put(DB_COL_EXTRA, b"best", &update.info.hash);
*best_block = Some(BestBlock {
hash: update.info.hash,
number: update.info.number,

View File

@@ -454,7 +454,7 @@ impl Client {
retracted: route.retracted.len()
});
// Final commit to the DB
self.db.write_buffered(batch).expect("DB write failed.");
self.db.write_buffered(batch);
self.chain.commit();
self.update_last_hashes(&parent, hash);

View File

@@ -149,10 +149,7 @@ pub trait Readable {
impl Writable for DBTransaction {
fn write<T, R>(&self, col: Option<u32>, key: &Key<T, Target = R>, value: &T) where T: Encodable, R: Deref<Target = [u8]> {
let result = self.put(col, &key.key(), &encode(value));
if let Err(err) = result {
panic!("db put failed, key: {:?}, err: {:?}", &key.key() as &[u8], err);
}
self.put(col, &key.key(), &encode(value));
}
}

View File

@@ -144,8 +144,8 @@ impl<T> TraceDB<T> where T: DatabaseExtras {
};
let batch = DBTransaction::new(&tracesdb);
batch.put(DB_COL_TRACE, b"enabled", &encoded_tracing).unwrap();
batch.put(DB_COL_TRACE, b"version", TRACE_DB_VER).unwrap();
batch.put(DB_COL_TRACE, b"enabled", &encoded_tracing);
batch.put(DB_COL_TRACE, b"version", TRACE_DB_VER);
tracesdb.write(batch).unwrap();
let db = TraceDB {