db traces
This commit is contained in:
parent
bd07583fb9
commit
9fcfe7dee2
|
@ -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()));
|
||||
|
||||
|
@ -455,6 +457,7 @@ impl BlockStapler for Storage {
|
|||
let mut best_block = self.best_block.write();
|
||||
|
||||
let mut context = UpdateContext::new(&self.database);
|
||||
context.target(block.hash());
|
||||
|
||||
let block_hash = block.hash();
|
||||
|
||||
|
@ -577,6 +580,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 });
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ pub struct UpdateContext {
|
|||
pub meta: HashMap<H256, TransactionMeta>,
|
||||
pub db_transaction: DBTransaction,
|
||||
meta_snapshot: Option<HashMap<H256, TransactionMeta>>,
|
||||
target: Option<H256>,
|
||||
}
|
||||
|
||||
impl UpdateContext {
|
||||
|
@ -17,9 +18,15 @@ impl UpdateContext {
|
|||
meta: HashMap::new(),
|
||||
db_transaction: db.transaction(),
|
||||
meta_snapshot: None,
|
||||
target: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn target(&mut self, hash: &H256) {
|
||||
self.target = Some(hash.clone());
|
||||
trace!("Initialized transaction for block {:?}", self.target);
|
||||
}
|
||||
|
||||
pub fn apply(mut self, db: &Database) -> Result<(), Error> {
|
||||
// actually saving meta
|
||||
for (hash, meta) in self.meta.drain() {
|
||||
|
@ -27,6 +34,8 @@ impl UpdateContext {
|
|||
}
|
||||
|
||||
try!(db.write(self.db_transaction));
|
||||
|
||||
trace!("Applied transaction for block {:?}", self.target);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue