Skip to content

[chain] Consider Merging IndexedTxGraph and TxGraph into one thing #130

@LLFourn

Description

@LLFourn

currently:

#[derive(Debug)]
pub struct IndexedTxGraph<A, I> {
    /// Transaction index.
    pub index: I,
    graph: TxGraph<A>,
}

But it could also just be:

#[derive(Clone, Debug, PartialEq)]
pub struct TxGraph<A = (), I = ()> {
    // all transactions that the graph is aware of in format: `(tx_node, tx_anchors, tx_last_seen)`
    txs: HashMap<Txid, (TxNodeInternal, BTreeSet<A>, u64)>,
    spends: BTreeMap<OutPoint, HashSet<Txid>>,
    anchors: BTreeSet<(A, Txid)>,

    // This atrocity exists so that `TxGraph::outspends()` can return a reference.
    // FIXME: This can be removed once `HashSet::new` is a const fn.
    empty_outspends: HashSet<Txid>,
    pub index: I
}

But we would have to give up the derive PartialEq on TxGraph because I don't think we want to force indexes to implement it.

The motivation is avoiding having to duplicate every mutating API on TxGraph to IndexedTxGraph. We seem to have some trouble doing this. For example, IndexedTxGraph and TxGraph both have insert_tx but they have different arguments atm but they should be the same. Also in bitcoindevkit/bdk#1041 I a method is being added to IndexedTxGraph but it should also be on TxGraph but the PR author forgot.

The downside is that TxGraph would not longer be a pure data structure but since we don't use it like that I don't think this matters.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions