File tree Expand file tree Collapse file tree 3 files changed +42
-5
lines changed
Expand file tree Collapse file tree 3 files changed +42
-5
lines changed Original file line number Diff line number Diff 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 ( )
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments