Skip to content

Commit 1990d22

Browse files
committed
feat(graph): add convenience function for inserting relevant evicted_ats
1 parent 8074550 commit 1990d22

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

crates/bitcoind_rpc/tests/test_emitter.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -835,11 +835,10 @@ fn test_expect_tx_evicted() -> anyhow::Result<()> {
835835
assert!(mempool_event.evicted_txids.contains(&txid_1));
836836

837837
// Update graph with evicted tx.
838-
for txid in mempool_event.evicted_txids {
839-
if graph.graph().get_tx_node(txid).is_some() {
840-
let _ = graph.insert_evicted_at(txid, mempool_event.latest_update_time);
841-
}
842-
}
838+
let _ = graph.insert_relevant_evicted_ats(
839+
mempool_event.evicted_txids,
840+
mempool_event.latest_update_time,
841+
);
843842

844843
let canonical_txids = graph
845844
.graph()

crates/chain/src/indexed_tx_graph.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,23 @@ where
145145
}
146146
}
147147

148+
/// Inserts the given `evicted_at` for a set of `txid`s that the graph is tracking.
149+
///
150+
/// The `evicted_at` timestamp represents the last known time when the transaction was observed
151+
/// to be missing from the mempool. If `txid` was previously recorded with an earlier
152+
/// `evicted_at` value, it is updated only if the new value is greater.
153+
pub fn insert_relevant_evicted_ats(
154+
&mut self,
155+
txids: impl IntoIterator<Item = Txid>,
156+
evicted_at: u64,
157+
) -> ChangeSet<A, I::ChangeSet> {
158+
let tx_graph = self.graph.insert_relevant_evicted_ats(txids, evicted_at);
159+
ChangeSet {
160+
tx_graph,
161+
..Default::default()
162+
}
163+
}
164+
148165
/// Batch insert transactions, filtering out those that are irrelevant.
149166
///
150167
/// Relevancy is determined by the [`Indexer::is_tx_relevant`] implementation of `I`. Irrelevant

crates/chain/src/tx_graph.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,27 @@ impl<A: Anchor> TxGraph<A> {
777777
changeset
778778
}
779779

780+
/// Inserts the given `evicted_at` into [`TxGraph`] for a set of `txid`s that the graph is
781+
/// tracking.
782+
///
783+
/// The `evicted_at` timestamp represents the last known time when the transaction was observed
784+
/// to be missing from the mempool. If `txid` was previously recorded with an earlier
785+
/// `evicted_at` value, it is updated only if the new value is greater.
786+
pub fn insert_relevant_evicted_ats(
787+
&mut self,
788+
txids: impl IntoIterator<Item = Txid>,
789+
evicted_at: u64,
790+
) -> ChangeSet<A> {
791+
let mut changeset = ChangeSet::default();
792+
for txid in txids {
793+
// Only record evictions for transactions the graph is tracking.
794+
if self.get_tx_node(txid).is_some() {
795+
changeset.merge(self.insert_evicted_at(txid, evicted_at));
796+
}
797+
}
798+
changeset
799+
}
800+
780801
/// Extends this graph with the given `update`.
781802
///
782803
/// The returned [`ChangeSet`] is the set difference between `update` and `self` (transactions that

0 commit comments

Comments
 (0)