mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 03:21:08 +03:00
Faster tx known check (#1468)
* fast check for known tx when adding to pool * rustfmt
This commit is contained in:
parent
544a296f77
commit
0cbfeaab94
2 changed files with 11 additions and 0 deletions
|
@ -57,6 +57,11 @@ impl Pool {
|
|||
}
|
||||
}
|
||||
|
||||
/// Does the transaction pool contain an entry for the given transaction?
|
||||
pub fn contains_tx(&self, tx: &Transaction) -> bool {
|
||||
self.entries.iter().any(|x| x.tx.hash() == tx.hash())
|
||||
}
|
||||
|
||||
/// Query the tx pool for all known txs based on kernel short_ids
|
||||
/// from the provided compact_block.
|
||||
/// Note: does not validate that we return the full set of required txs.
|
||||
|
|
|
@ -101,6 +101,12 @@ impl TransactionPool {
|
|||
stem: bool,
|
||||
block_hash: &Hash,
|
||||
) -> Result<(), PoolError> {
|
||||
// Quick check to deal with common case of seeing the *same* tx
|
||||
// broadcast from multiple peers simultaneously.
|
||||
if !stem && self.txpool.contains_tx(&tx) {
|
||||
return Err(PoolError::DuplicateTx);
|
||||
}
|
||||
|
||||
// Do we have the capacity to accept this transaction?
|
||||
self.is_acceptable(&tx)?;
|
||||
|
||||
|
|
Loading…
Reference in a new issue