From 9fcfe7dee2b818d6d12c99fea5944e7194d43af5 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Wed, 30 Nov 2016 12:43:49 +0300 Subject: [PATCH 1/3] db traces --- db/src/storage.rs | 6 +++++- db/src/update_context.rs | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/db/src/storage.rs b/db/src/storage.rs index e4d7ae4a..8f23356e 100644 --- a/db/src/storage.rs +++ b/db/src/storage.rs @@ -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 }); diff --git a/db/src/update_context.rs b/db/src/update_context.rs index 7a2537f9..2dddbc64 100644 --- a/db/src/update_context.rs +++ b/db/src/update_context.rs @@ -9,6 +9,7 @@ pub struct UpdateContext { pub meta: HashMap, pub db_transaction: DBTransaction, meta_snapshot: Option>, + target: Option, } 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(()) } From 71044f208f0ac94ec47f2b69732ea1abc0dd96dd Mon Sep 17 00:00:00 2001 From: NikVolf Date: Wed, 30 Nov 2016 13:06:26 +0300 Subject: [PATCH 2/3] trace only if target is set --- db/src/update_context.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/db/src/update_context.rs b/db/src/update_context.rs index 2dddbc64..82a703b0 100644 --- a/db/src/update_context.rs +++ b/db/src/update_context.rs @@ -35,7 +35,9 @@ impl UpdateContext { try!(db.write(self.db_transaction)); - trace!("Applied transaction for block {:?}", self.target); + if let Some(target) = self.target { + trace!("Applied transaction for block {:?}", target); + } Ok(()) } From 62a687177ca0e18b18656a589f92023ee4d0d597 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Wed, 30 Nov 2016 13:17:51 +0300 Subject: [PATCH 3/3] always set target --- db/src/storage.rs | 5 ++--- db/src/update_context.rs | 15 ++++----------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/db/src/storage.rs b/db/src/storage.rs index 8f23356e..f47888f1 100644 --- a/db/src/storage.rs +++ b/db/src/storage.rs @@ -379,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 { @@ -456,8 +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); - context.target(block.hash()); + let mut context = UpdateContext::new(&self.database, block.hash()); let block_hash = block.hash(); diff --git a/db/src/update_context.rs b/db/src/update_context.rs index 82a703b0..be563f6c 100644 --- a/db/src/update_context.rs +++ b/db/src/update_context.rs @@ -9,24 +9,19 @@ pub struct UpdateContext { pub meta: HashMap, pub db_transaction: DBTransaction, meta_snapshot: Option>, - target: Option, + 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: None, + target: target.clone(), } } - 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() { @@ -35,9 +30,7 @@ impl UpdateContext { try!(db.write(self.db_transaction)); - if let Some(target) = self.target { - trace!("Applied transaction for block {:?}", target); - } + trace!("Applied transaction for block {:?}", &self.target); Ok(()) }