pub last_evicted: Option<u64>,
}
+impl<T, A> TxNode<'_, T, A> {
+ /// Whether the transaction has been evicted from the mempool.
+ ///
+ /// Only mempool observation timestamps are considered; anchors have no effect. A transaction
+ /// is evicted when its last-evicted timestamp is at least as recent as its last-seen timestamp.
+ pub fn is_evicted(&self) -> bool {
+ match (self.last_seen, self.last_evicted) {
+ (_, None) => false,
+ (Some(last_seen), Some(last_evicted)) => last_evicted >= last_seen,
+ (None, Some(_)) => true,
+ }
+ }
+}
+
impl<T, A> Deref for TxNode<'_, T, A> {
type Target = T;
}
}
+#[test]
+fn tx_node_is_evicted() {
+ let anchors = [block_id!(1, "A")].into();
+ let test_cases = [
+ (None, None, false),
+ (Some(10), None, false),
+ (None, Some(10), true),
+ (Some(10), Some(9), false),
+ (Some(10), Some(10), true),
+ (Some(10), Some(11), true),
+ ];
+
+ for (last_seen, last_evicted, expected) in test_cases {
+ let node = tx_graph::TxNode {
+ txid: hash!("tx"),
+ tx: (),
+ anchors: &anchors,
+ first_seen: None,
+ last_seen,
+ last_evicted,
+ };
+
+ assert_eq!(node.is_evicted(), expected);
+ }
+}
+
#[test]
fn test_seen_at_updates() {
// Update both first_seen and last_seen