Skip to content

Commit 7568867

Browse files
evanlinjinLagginTimes
authored andcommitted
docs(crate): Update tx_graph module docs
* Remove duplicate paragraphs about `ChangeSet`s. * Add "Canonicalization" section which expands on methods that require canonicalization and the associated data types used in the canonicalization algorithm.
1 parent 88e4310 commit 7568867

File tree

1 file changed

+40
-11
lines changed

1 file changed

+40
-11
lines changed

crates/chain/src/tx_graph.rs

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,52 @@
1616
//! documentation for more details), and the timestamp of the last time we saw the transaction as
1717
//! unconfirmed.
1818
//!
19-
//! Conflicting transactions are allowed to coexist within a [`TxGraph`]. This is useful for
20-
//! identifying and traversing conflicts and descendants of a given transaction. Some [`TxGraph`]
21-
//! methods only consider transactions that are "canonical" (i.e., in the best chain or in mempool).
22-
//! We decide which transactions are canonical based on the transaction's anchors and the
23-
//! `last_seen` (as unconfirmed) timestamp.
19+
//! # Canonicalization
2420
//!
25-
//! The [`ChangeSet`] reports changes made to a [`TxGraph`]; it can be used to either save to
26-
//! persistent storage, or to be applied to another [`TxGraph`].
21+
//! Conflicting transactions are allowed to coexist within a [`TxGraph`]. A process called
22+
//! canonicalization is required to get a conflict-free history of transactions.
23+
//!
24+
//! * [`list_canonical_txs`](TxGraph::list_canonical_txs) lists canonical transactions.
25+
//! * [`filter_chain_txouts`](TxGraph::filter_chain_txouts) filters out canonical outputs from a
26+
//! list of outpoints.
27+
//! * [`filter_chain_unspents`](TxGraph::filter_chain_unspents) filters out canonical unspent
28+
//! outputs from a list of outpoints.
29+
//! * [`balance`](TxGraph::balance) gets the total sum of unspent outputs filtered from a list of
30+
//! outpoints.
31+
//! * [`canonical_iter`](TxGraph::canonical_iter) returns the [`CanonicalIter`] which contains all
32+
//! of the canonicalization logic.
33+
//!
34+
//! All these methods require a `chain` and `chain_tip` argument. The `chain` must be a
35+
//! [`ChainOracle`] implementation (such as [`LocalChain`](crate::local_chain::LocalChain)) which
36+
//! identifies which blocks exist under a given `chain_tip`.
37+
//!
38+
//! The canonicalization algorithm uses the following associated data to determine which
39+
//! transactions have precedence over others:
2740
//!
28-
//! Lastly, you can use [`TxAncestors`]/[`TxDescendants`] to traverse ancestors and descendants of
29-
//! a given transaction, respectively.
41+
//! * [`Anchor`] - This bit of data represents that a transaction is anchored in a given block. If
42+
//! the transaction is anchored in chain of `chain_tip`, or is an ancestor of a transaction
43+
//! anchored in chain of `chain_tip`, then the transaction must be canonical.
44+
//! * `last_seen` - This is the timestamp of when a transaction is last-seen in the mempool. This
45+
//! value is updated by [`insert_seen_at`](TxGraph::insert_seen_at) and
46+
//! [`apply_update`](TxGraph::apply_update). Transactions that are seen later have higher
47+
//! priority than those that are seen earlier. `last_seen` values are transitive. Meaning that
48+
//! the actual `last_seen` value of a transaction is the max of all the `last_seen` values of
49+
//! it's descendants.
50+
//! * `last_evicted` - This is the timestamp of when a transaction is last-seen as evicted in the
51+
//! mempool. If this value is equal to or higher than the transaction's `last_seen` value, then
52+
//! it will not be considered canonical.
53+
//!
54+
//! # Graph traversal
55+
//!
56+
//! You can use [`TxAncestors`]/[`TxDescendants`] to traverse ancestors and descendants of a given
57+
//! transaction, respectively.
3058
//!
3159
//! # Applying changes
3260
//!
61+
//! The [`ChangeSet`] reports changes made to a [`TxGraph`]; it can be used to either save to
62+
//! persistent storage, or to be applied to another [`TxGraph`].
63+
//!
3364
//! Methods that change the state of [`TxGraph`] will return [`ChangeSet`]s.
34-
//! [`ChangeSet`]s can be applied back to a [`TxGraph`] or be used to inform persistent storage
35-
//! of the changes to [`TxGraph`].
3665
//!
3766
//! # Generics
3867
//!

0 commit comments

Comments
 (0)