fn replace_previous(&mut self, tx: &Transaction<Hash, Ex>) -> error::Result<Vec<Arc<Transaction<Hash, Ex>>>> {
		let mut to_remove = {
			// check if we are replacing a transaction
			let replace_hashes = tx.provides
				.iter()
				.filter_map(|tag| self.provided_tags.get(tag))
				.collect::<HashSet<_>>();

			// early exit if we are not replacing anything.
			if replace_hashes.is_empty() {
				return Ok(vec![]);
			}

			// now check if collective priority is lower than the replacement transaction.
			let old_priority = {
				let ready = self.ready.read();
				replace_hashes
					.iter()
					.filter_map(|hash| ready.get(hash))
					.fold(0u64, |total, tx| total.saturating_add(tx.transaction.transaction.priority))
			};

			// bail - the transaction has too low priority to replace the old ones
			if old_priority >= tx.priority {
				bail!(error::ErrorKind::TooLowPriority(old_priority, tx.priority))
			}

			replace_hashes.into_iter().cloned().collect::<Vec<_>>()
		};

		let new_provides = tx.provides.iter().cloned().collect::<HashSet<_>>();
		let mut removed = vec![];
		loop {
			let hash = match to_remove.pop() {
				Some(hash) => hash,
				None => return Ok(removed),
			};

			let tx = self.ready.write().remove(&hash).expect(HASH_READY);
			// check if this transaction provides stuff that is not provided by the new one.
			let (mut unlocks, tx) = (tx.unlocks, tx.transaction.transaction);
			{
				let invalidated = tx.provides
					.iter()
					.filter(|tag| !new_provides.contains(&**tag));

				for tag in invalidated {
					// remove the tag since it's no longer provided by any transaction
					self.provided_tags.remove(tag);
					// add more transactions to remove
					to_remove.append(&mut unlocks);
				}
			}

			removed.push(tx);
		}
	}
/// Checks if the transaction is providing the same tags as other transactions.
///
/// In case that's true it determines if the priority of transactions that
/// we are about to replace is lower than the priority of the replacement transaction.
/// We remove/replace old transactions in case they have lower priority.
///
/// In case replacement is succesful returns a list of removed transactions.
Checks if the transaction is providing the same tags as other transactions.
In case that's true it determines if the priority of transactions that
we are about to replace is lower than the priority of the replacement transaction.
We remove/replace old transactions in case they have lower priority.

In case replacement is succesful returns a list of removed transactions.
Checks if the transaction is providing the same tags as other transactions . In case that ' s true it determines if the priority of transactions that we are about to replace is lower than the priority of the replacement transaction . We remove / replace old transactions in case they have lower priority . In case replacement is succesful returns a list of removed transactions .
fn replace_previous(&mut self, tx: &Transaction<Hash, Ex>) -> error::Result<Vec<Arc<Transaction<Hash, Ex>>>> {
		let mut to_remove = {
			// check if we are replacing a transaction
			let replace_hashes = tx.provides
				.iter()
				.filter_map(|tag| self.provided_tags.get(tag))
				.collect::<HashSet<_>>();
			// early exit if we are not replacing anything.
			if replace_hashes.is_empty() {
				return Ok(vec![]);
			}
			// now check if collective priority is lower than the replacement transaction.
			let old_priority = {
				let ready = self.ready.read();
				replace_hashes
					.iter()
					.filter_map(|hash| ready.get(hash))
					.fold(0u64, |total, tx| total.saturating_add(tx.transaction.transaction.priority))
			};
			// bail - the transaction has too low priority to replace the old ones
			if old_priority >= tx.priority {
				bail!(error::ErrorKind::TooLowPriority(old_priority, tx.priority))
			}
			replace_hashes.into_iter().cloned().collect::<Vec<_>>()
		};
		let new_provides = tx.provides.iter().cloned().collect::<HashSet<_>>();
		let mut removed = vec![];
		loop {
			let hash = match to_remove.pop() {
				Some(hash) => hash,
				None => return Ok(removed),
			};
			let tx = self.ready.write().remove(&hash).expect(HASH_READY);
			// check if this transaction provides stuff that is not provided by the new one.
			let (mut unlocks, tx) = (tx.unlocks, tx.transaction.transaction);
			{
				let invalidated = tx.provides
					.iter()
					.filter(|tag| !new_provides.contains(&**tag));
				for tag in invalidated {
					// remove the tag since it's no longer provided by any transaction
					self.provided_tags.remove(tag);
					// add more transactions to remove
					to_remove.append(&mut unlocks);
				}
			}
			removed.push(tx);
		}
	}
fn replace_previous ( & mut self , tx : & Transaction < Hash , Ex > ) -> error :: Result < Vec < Arc < Transaction < Hash , Ex > > > > { let mut to_remove = { // check if we are replacing a transaction let replace_hashes = tx . provides . iter ( ) . filter_map ( | tag | self . provided_tags . get ( tag ) ) . collect :: < HashSet < _ > > ( ) ; // early exit if we are not replacing anything. if replace_hashes . is_empty ( ) { return Ok ( vec ! [ ] ) ; } // now check if collective priority is lower than the replacement transaction. let old_priority = { let ready = self . ready . read ( ) ; replace_hashes . iter ( ) . filter_map ( | hash | ready . get ( hash ) ) . fold ( 0u64 , | total , tx | total . saturating_add ( tx . transaction . transaction . priority ) ) } ; // bail - the transaction has too low priority to replace the old ones if old_priority >= tx . priority { bail ! ( error ErrorKind TooLowPriority ( old_priority tx priority ) ) } replace_hashes . into_iter ( ) . cloned ( ) . collect :: < Vec < _ > > ( ) } ; let new_provides = tx . provides . iter ( ) . cloned ( ) . collect :: < HashSet < _ > > ( ) ; let mut removed = vec ! [ ] ; loop { let hash = match to_remove . pop ( ) { Some ( hash ) => hash , None => return Ok ( removed ) , } ; let tx = self . ready . write ( ) . remove ( & hash ) . expect ( HASH_READY ) ; // check if this transaction provides stuff that is not provided by the new one. let ( mut unlocks , tx ) = ( tx . unlocks , tx . transaction . transaction ) ; { let invalidated = tx . provides . iter ( ) . filter ( | tag | ! new_provides . contains ( & * * tag ) ) ; for tag in invalidated { // remove the tag since it's no longer provided by any transaction self . provided_tags . remove ( tag ) ; // add more transactions to remove to_remove . append ( & mut unlocks ) ; } } removed . push ( tx ) ; } }
Checks if the transaction is providing the same tags as other transactions.
Checks if the transaction is providing the same tags as other transactions .
&mut self
tx
&Transaction<Hash, Ex>
&mut self
tx
&Transaction<Hash, Ex>