|
16 | 16 | //! documentation for more details), and the timestamp of the last time we saw the transaction as |
17 | 17 | //! unconfirmed. |
18 | 18 | //! |
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 |
24 | 20 | //! |
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: |
27 | 40 | //! |
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. |
30 | 58 | //! |
31 | 59 | //! # Applying changes |
32 | 60 | //! |
| 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 | +//! |
33 | 64 | //! 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`]. |
36 | 65 | //! |
37 | 66 | //! # Generics |
38 | 67 | //! |
|
0 commit comments