Merge branch 'master' of github.com:ethcore/parity-bitcoin

This commit is contained in:
NikVolf 2016-11-30 13:36:51 +03:00
commit 0f96c0cc76
2 changed files with 11 additions and 4 deletions

View File

@ -224,7 +224,7 @@ impl Storage {
/// all transaction meta is removed
/// DOES NOT update best block
fn decanonize_block(&self, context: &mut UpdateContext, hash: &H256) -> Result<(), Error> {
trace!(target: "reorg", "Decanonizing block {}", hash.to_reversed_str());
trace!(target: "db", "Decanonizing block {}", hash.to_reversed_str());
// ensure that block is of the main chain
try!(self.block_number(hash).ok_or(Error::not_main(hash)));
@ -299,6 +299,8 @@ impl Storage {
}
fn canonize_block(&self, context: &mut UpdateContext, at_height: u32, hash: &H256) -> Result<(), Error> {
trace!(target: "db", "Canonizing block {}", hash.to_reversed_str());
let block = try!(self.block_by_hash(hash).ok_or(Error::unknown_hash(hash)));
try!(self.update_transactions_meta(context, at_height, &mut block.transactions()));
@ -377,7 +379,7 @@ impl Storage {
// lock will be held until the end of the routine
let mut best_block = self.best_block.write();
let mut context = UpdateContext::new(&self.database);
let mut context = UpdateContext::new(&self.database, hash);
let mut result = Vec::new();
let mut best_number = try!(self.best_number().ok_or(Error::Consistency(ConsistencyError::NoBestBlock)));
loop {
@ -454,7 +456,7 @@ impl BlockStapler for Storage {
// ! lock will be held during the entire insert routine
let mut best_block = self.best_block.write();
let mut context = UpdateContext::new(&self.database);
let mut context = UpdateContext::new(&self.database, block.hash());
let block_hash = block.hash();
@ -577,6 +579,7 @@ impl BlockStapler for Storage {
// write accumulated transactions meta
try!(context.apply(&self.database));
trace!(target: "db", "Best block now ({}, {})", &new_best_hash, &new_best_number);
// updating locked best block
*best_block = Some(BestBlock { hash: new_best_hash, number: new_best_number });

View File

@ -9,14 +9,16 @@ pub struct UpdateContext {
pub meta: HashMap<H256, TransactionMeta>,
pub db_transaction: DBTransaction,
meta_snapshot: Option<HashMap<H256, TransactionMeta>>,
target: H256,
}
impl UpdateContext {
pub fn new(db: &Database) -> Self {
pub fn new(db: &Database, target: &H256) -> Self {
UpdateContext {
meta: HashMap::new(),
db_transaction: db.transaction(),
meta_snapshot: None,
target: target.clone(),
}
}
@ -27,6 +29,8 @@ impl UpdateContext {
}
try!(db.write(self.db_transaction));
trace!("Applied transaction for block {:?}", &self.target);
Ok(())
}