From 0155c6e4efc08efc93b156d1908483ec82630c5b Mon Sep 17 00:00:00 2001 From: debris Date: Sun, 9 Apr 2017 14:10:40 +0800 Subject: [PATCH] revert is_double_spent -> is_spent --- db/src/block_chain_db.rs | 2 +- db/src/block_impls.rs | 6 +++--- db/src/transaction_provider.rs | 2 +- miner/src/block_assembler.rs | 2 +- miner/src/memory_pool.rs | 2 +- sync/src/utils/memory_pool_transaction_provider.rs | 10 +++++----- verification/src/accept_transaction.rs | 2 +- verification/src/duplex_store.rs | 6 +++--- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/db/src/block_chain_db.rs b/db/src/block_chain_db.rs index 51946438..9b1275ad 100644 --- a/db/src/block_chain_db.rs +++ b/db/src/block_chain_db.rs @@ -471,7 +471,7 @@ impl TransactionOutputProvider for BlockChainDatabase where T: KeyValueDat .and_then(|tx| tx.outputs.into_iter().nth(prevout.index as usize)) } - fn is_double_spent(&self, prevout: &OutPoint) -> bool { + fn is_spent(&self, prevout: &OutPoint) -> bool { self.transaction_meta(&prevout.hash) .and_then(|meta| meta.is_spent(prevout.index as usize)) .unwrap_or(false) diff --git a/db/src/block_impls.rs b/db/src/block_impls.rs index 279c6b1d..1c1468fd 100644 --- a/db/src/block_impls.rs +++ b/db/src/block_impls.rs @@ -9,7 +9,7 @@ fn transaction_output(transactions: &[IndexedTransaction], prevout: &OutPoint) - .cloned() } -fn is_double_spent(transactions: &[IndexedTransaction], prevout: &OutPoint) -> bool { +fn is_spent(transactions: &[IndexedTransaction], prevout: &OutPoint) -> bool { // the code below is valid, but has rather poor performance // if previous transaction output appears more than once than we can safely @@ -29,7 +29,7 @@ impl TransactionOutputProvider for IndexedBlock { transaction_output(&self.transactions[..take], outpoint) } - fn is_double_spent(&self, outpoint: &OutPoint) -> bool { - is_double_spent(&self.transactions, outpoint) + fn is_spent(&self, outpoint: &OutPoint) -> bool { + is_spent(&self.transactions, outpoint) } } diff --git a/db/src/transaction_provider.rs b/db/src/transaction_provider.rs index 6ad2b8a3..c16b626a 100644 --- a/db/src/transaction_provider.rs +++ b/db/src/transaction_provider.rs @@ -23,7 +23,7 @@ pub trait TransactionOutputProvider: Send + Sync { fn transaction_output(&self, outpoint: &OutPoint, transaction_index: usize) -> Option; /// Returns true if we know that output is double spent. - fn is_double_spent(&self, outpoint: &OutPoint) -> bool; + fn is_spent(&self, outpoint: &OutPoint) -> bool; } /// Transaction meta provider stores transaction meta information diff --git a/miner/src/block_assembler.rs b/miner/src/block_assembler.rs index 06afa215..b76bb323 100644 --- a/miner/src/block_assembler.rs +++ b/miner/src/block_assembler.rs @@ -180,7 +180,7 @@ impl<'a, T> TransactionOutputProvider for FittingTransactionsIterator<'a, T> whe }) } - fn is_double_spent(&self, _outpoint: &OutPoint) -> bool { + fn is_spent(&self, _outpoint: &OutPoint) -> bool { unimplemented!(); } } diff --git a/miner/src/memory_pool.rs b/miner/src/memory_pool.rs index b9634aae..2c568251 100644 --- a/miner/src/memory_pool.rs +++ b/miner/src/memory_pool.rs @@ -819,7 +819,7 @@ impl TransactionOutputProvider for MemoryPool { .cloned() } - fn is_double_spent(&self, outpoint: &OutPoint) -> bool { + fn is_spent(&self, outpoint: &OutPoint) -> bool { self.is_spent(outpoint) } } diff --git a/sync/src/utils/memory_pool_transaction_provider.rs b/sync/src/utils/memory_pool_transaction_provider.rs index 32b03cda..c676aa35 100644 --- a/sync/src/utils/memory_pool_transaction_provider.rs +++ b/sync/src/utils/memory_pool_transaction_provider.rs @@ -75,7 +75,7 @@ impl TransactionOutputProvider for MemoryPoolTransactionOutputProvider { self.storage_provider.transaction_output(prevout, transaction_index) } - fn is_double_spent(&self, prevout: &OutPoint) -> bool { + fn is_spent(&self, prevout: &OutPoint) -> bool { // check if this output is spent by some non-final mempool transaction if let Some(ref nonfinal_spends) = self.nonfinal_spends { if nonfinal_spends.double_spends.contains(&prevout.clone().into()) { @@ -85,7 +85,7 @@ impl TransactionOutputProvider for MemoryPoolTransactionOutputProvider { // we can omit memory_pool check here, because it has been completed in `for_transaction` method // => just check spending in storage - self.storage_provider.is_double_spent(prevout) + self.storage_provider.is_spent(prevout) } } @@ -126,9 +126,9 @@ mod tests { // => // if t3 is also depending on t1[0] || t2[0], it will be rejected by verification as missing inputs let provider = MemoryPoolTransactionOutputProvider::for_transaction(storage, &memory_pool, &dchain.at(3)).unwrap(); - assert_eq!(provider.is_double_spent(&OutPoint { hash: dchain.at(0).hash(), index: 0, }), false); - assert_eq!(provider.is_double_spent(&OutPoint { hash: dchain.at(1).hash(), index: 0, }), false); - assert_eq!(provider.is_double_spent(&OutPoint { hash: dchain.at(2).hash(), index: 0, }), false); + assert_eq!(provider.is_spent(&OutPoint { hash: dchain.at(0).hash(), index: 0, }), false); + assert_eq!(provider.is_spent(&OutPoint { hash: dchain.at(1).hash(), index: 0, }), false); + assert_eq!(provider.is_spent(&OutPoint { hash: dchain.at(2).hash(), index: 0, }), false); assert_eq!(provider.transaction_output(&OutPoint { hash: dchain.at(0).hash(), index: 0, }, 0), Some(dchain.at(0).outputs[0].clone())); assert_eq!(provider.transaction_output(&OutPoint { hash: dchain.at(1).hash(), index: 0, }, 0), None); assert_eq!(provider.transaction_output(&OutPoint { hash: dchain.at(2).hash(), index: 0, }, 0), None); diff --git a/verification/src/accept_transaction.rs b/verification/src/accept_transaction.rs index 5daf0da4..c80dcf7f 100644 --- a/verification/src/accept_transaction.rs +++ b/verification/src/accept_transaction.rs @@ -338,7 +338,7 @@ impl<'a> TransactionDoubleSpend<'a> { fn check(&self) -> Result<(), TransactionError> { for input in &self.transaction.raw.inputs { - if self.store.is_double_spent(&input.previous_output) { + if self.store.is_spent(&input.previous_output) { return Err(TransactionError::UsingSpentOutput( input.previous_output.hash.clone(), input.previous_output.index diff --git a/verification/src/duplex_store.rs b/verification/src/duplex_store.rs index ecae4647..4cd87ea3 100644 --- a/verification/src/duplex_store.rs +++ b/verification/src/duplex_store.rs @@ -25,8 +25,8 @@ impl<'a> TransactionOutputProvider for DuplexTransactionOutputProvider<'a> { .or_else(|| self.second.transaction_output(prevout, transaction_index)) } - fn is_double_spent(&self, prevout: &OutPoint) -> bool { - self.first.is_double_spent(prevout) || self.second.is_double_spent(prevout) + fn is_spent(&self, prevout: &OutPoint) -> bool { + self.first.is_spent(prevout) || self.second.is_spent(prevout) } } @@ -37,7 +37,7 @@ impl TransactionOutputProvider for NoopStore { None } - fn is_double_spent(&self, _prevout: &OutPoint) -> bool { + fn is_spent(&self, _prevout: &OutPoint) -> bool { false } }