Skip to content

Commit da0c43e

Browse files
committed
refactor(chain)!: Rename LastSeenIn to ObservedIn
Also removed extra derives on `ObservedIn` and updated docs for `CanonicalTx`.
1 parent d4102b4 commit da0c43e

2 files changed

Lines changed: 32 additions & 30 deletions

File tree

crates/chain/src/canonical_iter.rs

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -155,16 +155,16 @@ impl<'g, A: Anchor, C: ChainOracle> Iterator for CanonicalIter<'g, A, C> {
155155

156156
if let Some((txid, tx, last_seen)) = self.pending_last_seen.next() {
157157
if !self.is_canonicalized(txid) {
158-
let lsi = LastSeenIn::Mempool(last_seen);
159-
self.mark_canonical(tx, CanonicalReason::from_last_seen(lsi));
158+
let observed_in = ObservedIn::Mempool(last_seen);
159+
self.mark_canonical(tx, CanonicalReason::from_observed_in(observed_in));
160160
}
161161
continue;
162162
}
163163

164164
if let Some((txid, tx, height)) = self.pending_remaining.pop_front() {
165165
if !self.is_canonicalized(txid) {
166-
let lsi = LastSeenIn::Block(height);
167-
self.mark_canonical(tx, CanonicalReason::from_last_seen(lsi));
166+
let observed_in = ObservedIn::Block(height);
167+
self.mark_canonical(tx, CanonicalReason::from_observed_in(observed_in));
168168
}
169169
continue;
170170
}
@@ -174,13 +174,12 @@ impl<'g, A: Anchor, C: ChainOracle> Iterator for CanonicalIter<'g, A, C> {
174174
}
175175
}
176176

177-
/// Represents when and where a given transaction is last seen.
178-
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, core::hash::Hash)]
179-
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
180-
pub enum LastSeenIn {
181-
/// The transaction was last seen in a block of height.
177+
/// Represents when and where a transaction was last observed in.
178+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
179+
pub enum ObservedIn {
180+
/// The transaction was last observed in a block of height.
182181
Block(u32),
183-
/// The transaction was last seen in the mempool at the given unix timestamp.
182+
/// The transaction was last observed in the mempool at the given unix timestamp.
184183
Mempool(u64),
185184
}
186185

@@ -194,12 +193,12 @@ pub enum CanonicalReason<A> {
194193
/// Whether the anchor is of the transaction's descendant.
195194
descendant: Option<Txid>,
196195
},
197-
/// This transaction does not conflict with any other transaction with a more recent `last_seen`
198-
/// value or one that is anchored in the best chain.
199-
LastSeen {
200-
/// The [`LastSeenIn`] value of the transaction.
201-
last_seen: LastSeenIn,
202-
/// Whether the [`LastSeenIn`] value is of the transaction's descendant.
196+
/// This transaction does not conflict with any other transaction with a more recent
197+
/// [`ObservedIn`] value or one that is anchored in the best chain.
198+
ObservedIn {
199+
/// The [`ObservedIn`] value of the transaction.
200+
observed_in: ObservedIn,
201+
/// Whether the [`ObservedIn`] value is of the transaction's descendant.
203202
descendant: Option<Txid>,
204203
},
205204
}
@@ -214,36 +213,39 @@ impl<A: Clone> CanonicalReason<A> {
214213
}
215214

216215
/// Constructs a [`CanonicalReason`] from a `last_seen` value.
217-
pub fn from_last_seen(last_seen: LastSeenIn) -> Self {
218-
Self::LastSeen {
219-
last_seen,
216+
pub fn from_observed_in(observed_in: ObservedIn) -> Self {
217+
Self::ObservedIn {
218+
observed_in,
220219
descendant: None,
221220
}
222221
}
223222

224223
/// Contruct a new [`CanonicalReason`] from the original which is transitive to `descendant`.
225224
///
226-
/// This signals that either the [`LastSeenIn`] or [`Anchor`] value belongs to the transaction's
225+
/// This signals that either the [`ObservedIn`] or [`Anchor`] value belongs to the transaction's
227226
/// descendant, but is transitively relevant.
228227
pub fn to_transitive(&self, descendant: Txid) -> Self {
229228
match self {
230229
CanonicalReason::Anchor { anchor, .. } => Self::Anchor {
231230
anchor: anchor.clone(),
232231
descendant: Some(descendant),
233232
},
234-
CanonicalReason::LastSeen { last_seen, .. } => Self::LastSeen {
235-
last_seen: *last_seen,
233+
CanonicalReason::ObservedIn {
234+
observed_in: last_seen,
235+
..
236+
} => Self::ObservedIn {
237+
observed_in: *last_seen,
236238
descendant: Some(descendant),
237239
},
238240
}
239241
}
240242

241-
/// This signals that either the [`LastSeenIn`] or [`Anchor`] value belongs to the transaction's
243+
/// This signals that either the [`ObservedIn`] or [`Anchor`] value belongs to the transaction's
242244
/// descendant.
243245
pub fn descendant(&self) -> &Option<Txid> {
244246
match self {
245247
CanonicalReason::Anchor { descendant, .. } => descendant,
246-
CanonicalReason::LastSeen { descendant, .. } => descendant,
248+
CanonicalReason::ObservedIn { descendant, .. } => descendant,
247249
}
248250
}
249251
}

crates/chain/src/tx_graph.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ use crate::collections::*;
9494
use crate::BlockId;
9595
use crate::CanonicalIter;
9696
use crate::CanonicalReason;
97-
use crate::LastSeenIn;
97+
use crate::ObservedIn;
9898
use crate::{Anchor, Balance, ChainOracle, ChainPosition, FullTxOut, Merge};
9999
use alloc::collections::vec_deque::VecDeque;
100100
use alloc::sync::Arc;
@@ -207,10 +207,10 @@ impl Default for TxNodeInternal {
207207
}
208208
}
209209

210-
/// A transaction that is included in the chain, or is still in mempool.
210+
/// A transaction that is deemed to be part of the canonical history.
211211
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
212212
pub struct CanonicalTx<'a, T, A> {
213-
/// How the transaction is observed as (confirmed or unconfirmed).
213+
/// How the transaction is observed in the canonical chain (confirmed or unconfirmed).
214214
pub chain_position: ChainPosition<A>,
215215
/// The transaction node (as part of the graph).
216216
pub tx_node: TxNode<'a, T, A>,
@@ -840,11 +840,11 @@ impl<A: Anchor> TxGraph<A> {
840840
transitively: None,
841841
},
842842
},
843-
CanonicalReason::LastSeen { last_seen, .. } => match last_seen {
844-
LastSeenIn::Mempool(last_seen) => ChainPosition::Unconfirmed {
843+
CanonicalReason::ObservedIn { observed_in, .. } => match observed_in {
844+
ObservedIn::Mempool(last_seen) => ChainPosition::Unconfirmed {
845845
last_seen: Some(last_seen),
846846
},
847-
LastSeenIn::Block(_) => ChainPosition::Unconfirmed { last_seen: None },
847+
ObservedIn::Block(_) => ChainPosition::Unconfirmed { last_seen: None },
848848
},
849849
};
850850
Ok(CanonicalTx {

0 commit comments

Comments
 (0)