Skip to content

Commit 2897492

Browse files
committed
revert(chain)!: rm TxGraph::update_last_seen_unconfirmed
This is no longer needed as `TxGraph::apply_update` now automatically adds `seen_at` timestamps for unanchored transactions.
1 parent 1fb42db commit 2897492

File tree

2 files changed

+1
-100
lines changed

2 files changed

+1
-100
lines changed

crates/chain/src/tx_graph.rs

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -671,11 +671,7 @@ impl<A: Clone + Ord> TxGraph<A> {
671671

672672
/// Inserts the given `seen_at` for `txid` into [`TxGraph`].
673673
///
674-
/// Note that [`TxGraph`] only keeps track of the latest `seen_at`. To batch
675-
/// update all unconfirmed transactions with the latest `seen_at`, see
676-
/// [`update_last_seen_unconfirmed`].
677-
///
678-
/// [`update_last_seen_unconfirmed`]: Self::update_last_seen_unconfirmed
674+
/// Note that [`TxGraph`] only keeps track of the latest `seen_at`.
679675
pub fn insert_seen_at(&mut self, txid: Txid, seen_at: u64) -> ChangeSet<A> {
680676
let mut changeset = ChangeSet::<A>::default();
681677
let last_seen = self.last_seen.entry(txid).or_default();
@@ -686,65 +682,6 @@ impl<A: Clone + Ord> TxGraph<A> {
686682
changeset
687683
}
688684

689-
/// Update the last seen time for all unconfirmed transactions.
690-
///
691-
/// This method updates the last seen unconfirmed time for this [`TxGraph`] by inserting
692-
/// the given `seen_at` for every transaction not yet anchored to a confirmed block,
693-
/// and returns the [`ChangeSet`] after applying all updates to `self`.
694-
///
695-
/// This is useful for keeping track of the latest time a transaction was seen
696-
/// unconfirmed, which is important for evaluating transaction conflicts in the same
697-
/// [`TxGraph`]. For details of how [`TxGraph`] resolves conflicts, see the docs for
698-
/// [`try_get_chain_position`].
699-
///
700-
/// A normal use of this method is to call it with the current system time. Although
701-
/// block headers contain a timestamp, using the header time would be less effective
702-
/// at tracking mempool transactions, because it can drift from actual clock time, plus
703-
/// we may want to update a transaction's last seen time repeatedly between blocks.
704-
///
705-
/// # Example
706-
///
707-
/// ```rust
708-
/// # use bdk_chain::example_utils::*;
709-
/// # use std::time::UNIX_EPOCH;
710-
/// # let tx = tx_from_hex(RAW_TX_1);
711-
/// # let mut tx_graph = bdk_chain::TxGraph::<()>::new([tx]);
712-
/// let now = std::time::SystemTime::now()
713-
/// .duration_since(UNIX_EPOCH)
714-
/// .expect("valid duration")
715-
/// .as_secs();
716-
/// let changeset = tx_graph.update_last_seen_unconfirmed(now);
717-
/// assert!(!changeset.last_seen.is_empty());
718-
/// ```
719-
///
720-
/// Note that [`TxGraph`] only keeps track of the latest `seen_at`, so the given time must
721-
/// by strictly greater than what is currently stored for a transaction to have an effect.
722-
/// To insert a last seen time for a single txid, see [`insert_seen_at`].
723-
///
724-
/// [`insert_seen_at`]: Self::insert_seen_at
725-
/// [`try_get_chain_position`]: Self::try_get_chain_position
726-
pub fn update_last_seen_unconfirmed(&mut self, seen_at: u64) -> ChangeSet<A> {
727-
let mut changeset = ChangeSet::default();
728-
let unanchored_txs: Vec<Txid> = self
729-
.txs
730-
.iter()
731-
.filter_map(
732-
|(&txid, (_, anchors))| {
733-
if anchors.is_empty() {
734-
Some(txid)
735-
} else {
736-
None
737-
}
738-
},
739-
)
740-
.collect();
741-
742-
for txid in unanchored_txs {
743-
changeset.merge(self.insert_seen_at(txid, seen_at));
744-
}
745-
changeset
746-
}
747-
748685
/// Extends this graph with the given `update`.
749686
///
750687
/// The returned [`ChangeSet`] is the set difference between `update` and `self` (transactions that

crates/chain/tests/test_tx_graph.rs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,42 +1013,6 @@ fn test_changeset_last_seen_merge() {
10131013
}
10141014
}
10151015

1016-
#[test]
1017-
fn update_last_seen_unconfirmed() {
1018-
let mut graph = TxGraph::<()>::default();
1019-
let tx = new_tx(0);
1020-
let txid = tx.compute_txid();
1021-
1022-
// insert a new tx
1023-
// initially we have a last_seen of None and no anchors
1024-
let _ = graph.insert_tx(tx);
1025-
let tx = graph.full_txs().next().unwrap();
1026-
assert_eq!(tx.last_seen_unconfirmed, None);
1027-
assert!(tx.anchors.is_empty());
1028-
1029-
// higher timestamp should update last seen
1030-
let changeset = graph.update_last_seen_unconfirmed(2);
1031-
assert_eq!(changeset.last_seen.get(&txid).unwrap(), &2);
1032-
1033-
// lower timestamp has no effect
1034-
let changeset = graph.update_last_seen_unconfirmed(1);
1035-
assert!(changeset.last_seen.is_empty());
1036-
1037-
// once anchored, last seen is not updated
1038-
let _ = graph.insert_anchor(txid, ());
1039-
let changeset = graph.update_last_seen_unconfirmed(4);
1040-
assert!(changeset.is_empty());
1041-
assert_eq!(
1042-
graph
1043-
.full_txs()
1044-
.next()
1045-
.unwrap()
1046-
.last_seen_unconfirmed
1047-
.unwrap(),
1048-
2
1049-
);
1050-
}
1051-
10521016
#[test]
10531017
fn transactions_inserted_into_tx_graph_are_not_canonical_until_they_have_an_anchor_in_best_chain() {
10541018
let txs = vec![new_tx(0), new_tx(1)];

0 commit comments

Comments
 (0)