pub latest_update_time: u64,
}
+impl MempoolEvent {
+ /// Returns an iterator of `(txid, evicted_at)` pairs for all evicted transactions.
+ pub fn evicted_ats(&self) -> impl ExactSizeIterator<Item = (Txid, u64)> + '_ {
+ let time = self.latest_update_time;
+ self.evicted_txids.iter().map(move |&txid| (txid, time))
+ }
+}
+
/// A newly emitted block from [`Emitter`].
#[derive(Debug)]
pub struct BlockEvent<B> {
assert!(mempool_event.evicted_txids.contains(&txid_1));
// Update graph with evicted tx.
- for txid in mempool_event.evicted_txids {
- if graph.graph().get_tx_node(txid).is_some() {
- let _ = graph.insert_evicted_at(txid, mempool_event.latest_update_time);
- }
- }
+ let _ = graph.batch_insert_relevant_evicted_at(mempool_event.evicted_ats());
let canonical_txids = graph
.graph()
}
}
+ /// Batch inserts `(txid, evicted_at)` pairs for `txid`s that the graph is tracking.
+ ///
+ /// The `evicted_at` timestamp represents the last known time when the transaction was observed
+ /// to be missing from the mempool. If `txid` was previously recorded with an earlier
+ /// `evicted_at` value, it is updated only if the new value is greater.
+ pub fn batch_insert_relevant_evicted_at(
+ &mut self,
+ evicted_ats: impl IntoIterator<Item = (Txid, u64)>,
+ ) -> ChangeSet<A, I::ChangeSet> {
+ let tx_graph = self.graph.batch_insert_relevant_evicted_at(evicted_ats);
+ ChangeSet {
+ tx_graph,
+ ..Default::default()
+ }
+ }
+
/// Batch insert transactions, filtering out those that are irrelevant.
///
/// Relevancy is determined by the [`Indexer::is_tx_relevant`] implementation of `I`. Irrelevant
changeset
}
+ /// Batch inserts `(txid, evicted_at)` pairs into [`TxGraph`] for `txid`s that the graph is
+ /// tracking.
+ ///
+ /// The `evicted_at` timestamp represents the last known time when the transaction was observed
+ /// to be missing from the mempool. If `txid` was previously recorded with an earlier
+ /// `evicted_at` value, it is updated only if the new value is greater.
+ pub fn batch_insert_relevant_evicted_at(
+ &mut self,
+ evicted_ats: impl IntoIterator<Item = (Txid, u64)>,
+ ) -> ChangeSet<A> {
+ let mut changeset = ChangeSet::default();
+ for (txid, evicted_at) in evicted_ats {
+ // Only record evictions for transactions the graph is tracking.
+ if self.txs.contains_key(&txid) {
+ changeset.merge(self.insert_evicted_at(txid, evicted_at));
+ }
+ }
+ changeset
+ }
+
/// Extends this graph with the given `update`.
///
/// The returned [`ChangeSet`] is the set difference between `update` and `self` (transactions that
Emission::Mempool(mempool_txs) => {
let mut graph_changeset =
graph.batch_insert_relevant_unconfirmed(mempool_txs.new_txs.clone());
- for txid in mempool_txs.evicted_txids {
- graph_changeset.merge(
- graph.insert_evicted_at(txid, mempool_txs.latest_update_time),
- );
- }
+ graph_changeset.merge(
+ graph.batch_insert_relevant_evicted_at(mempool_txs.evicted_ats()),
+ );
(local_chain::ChangeSet::default(), graph_changeset)
}
Emission::Tip(h) => {