From 3c162ac867404951011b1caf9f7b4ec3848ec33d Mon Sep 17 00:00:00 2001 From: NikVolf Date: Thu, 15 Dec 2016 14:33:17 +0100 Subject: [PATCH 1/3] best block resolve fix --- db/src/storage.rs | 4 ++-- db/src/transaction_meta.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/db/src/storage.rs b/db/src/storage.rs index 9d4d7307..58c7b97b 100644 --- a/db/src/storage.rs +++ b/db/src/storage.rs @@ -156,8 +156,8 @@ impl Storage { if best_number.is_some() { *storage.best_block.write() = Some( BestBlock { - number: best_number.expect("is_some() is checked above for block number"), - hash: best_hash.expect("is_some() is checked above for block hash"), + number: best_number.expect("best.number.is_some() is checked above; qed"), + hash: best_hash.expect("best_number.is_some() is equal to best_hash.is_some(); best_number.is_some() = true checked above; so best_hash.is_some() is also true; qed"), } ); } diff --git a/db/src/transaction_meta.rs b/db/src/transaction_meta.rs index ddbd9d67..f941f247 100644 --- a/db/src/transaction_meta.rs +++ b/db/src/transaction_meta.rs @@ -70,7 +70,7 @@ impl TransactionMeta { } pub fn is_spent(&self, idx: usize) -> Option { - self.bits.get(idx + 1) //.expect("Index should be verified by the caller") + self.bits.get(idx + 1) } pub fn is_fully_spent(&self) -> bool { From 2da8f24cf6b0ced75d5549e6dc847ed8dbd478a0 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Thu, 15 Dec 2016 14:40:23 +0100 Subject: [PATCH 2/3] further sanitize the storage code --- db/src/storage.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/db/src/storage.rs b/db/src/storage.rs index 58c7b97b..53507275 100644 --- a/db/src/storage.rs +++ b/db/src/storage.rs @@ -204,7 +204,7 @@ impl Storage { fn block_transactions_by_hash(&self, h: &H256) -> Vec { self.block_transaction_hashes_by_hash(h) .iter() - .map(|tx_hash| self.transaction(tx_hash).expect("Missing transaction, possible db corruption")) + .map(|tx_hash| self.transaction(tx_hash).expect("Missing transaction that is referenced by block transaction index, possible db corruption")) .collect() } @@ -219,7 +219,7 @@ impl Storage { let tx_hashes = self.block_transaction_hashes_by_hash(h); let txs = tx_hashes.into_iter() .map(|tx_hash| { - let tx = self.transaction(&tx_hash).expect("Missing transaction, possible db corruption"); + let tx = self.transaction(&tx_hash).expect("Missing transaction referenced by block transaction index, possible db corruption"); IndexedTransaction::new(tx_hash, tx) }) .collect::>(); @@ -295,7 +295,7 @@ impl Storage { let tx_hashes = self.block_transaction_hashes_by_hash(hash); for (tx_hash_num, tx_hash) in tx_hashes.iter().enumerate() { let tx = self.transaction(tx_hash) - .expect("Transaction in the saved block should exist as a separate entity indefinitely"); + .expect("Block hash is proved to exist above; all transaction of the known hash never deleted from database; so transaction should exist in database; qed"); // remove meta & meta cache context.db_transaction.delete(Some(COL_TRANSACTIONS_META), &**tx_hash); @@ -315,7 +315,7 @@ impl Storage { }, Entry::Vacant(entry) => { let mut meta = self.transaction_meta(&input.previous_output.hash) - .expect("No transaction metadata! Possible db corruption"); + .expect("Block hash is proven to be canonical above by requesting it's number; Transaction meta for each transaction of the canonical block is guaranteed to be saved; So the transaction meta should exist; qed"); meta.denote_unused(input.previous_output.index as usize); entry.insert(meta); }, @@ -600,7 +600,7 @@ impl BlockStapler for Storage { }, ConsistencyError::UnknownSpending(hash) => { warn!( - target: "reorg", + target: "db", "Failed to reorganize to {} due to spending unknown transaction {}", block_hash.to_reversed_str(), hash.to_reversed_str() @@ -612,7 +612,7 @@ impl BlockStapler for Storage { // this is orphan block inserted or disconnected chain head updated, we allow that (by now) // so it is no-op warn!( - target: "reorg", + target: "db", "Disconnected chain head {} updated with {}", hash.to_reversed_str(), block_hash.to_reversed_str() From 0a7f30d6b9453baa73087fef212b09743bedf9ad Mon Sep 17 00:00:00 2001 From: NikVolf Date: Thu, 15 Dec 2016 14:48:41 +0100 Subject: [PATCH 3/3] memory pool expect explanation --- miner/src/memory_pool.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/miner/src/memory_pool.rs b/miner/src/memory_pool.rs index fda41156..5a2afe1b 100644 --- a/miner/src/memory_pool.rs +++ b/miner/src/memory_pool.rs @@ -146,7 +146,7 @@ pub struct HashedOutPoint { out_point: OutPoint, } -/// Result of checking double spend with +/// Result of checking double spend with #[derive(Debug, PartialEq)] pub enum DoubleSpendCheckResult { /// No double spend @@ -411,7 +411,8 @@ impl Storage { // forget that all inputs of this transaction are spent for input in &entry.transaction.inputs { - let spent_in_tx = self.by_previous_output.remove(&input.previous_output.clone().into()).expect("every spent output must be indexed"); + let spent_in_tx = self.by_previous_output.remove(&input.previous_output.clone().into()) + .expect("by_spent_output is filled for each incoming transaction inputs; so the drained value should exist; qed"); assert_eq!(&spent_in_tx, h); }