Skip to content

Remove Anchor trait and make anchors unique to (Txid, BlockId) #90

Open
bitcoindevkit/bdk
#1515
@evanlinjin

Description

@evanlinjin

The Problem

Why remove Anchor trait?

We don't need it. Confirmation block and anchor block will be the same block after bitcoindevkit/bdk#1489 is merged.

Anchor representation in TxGraph and tx_graph::ChangeSet is bad

This is how anchors are represented now.

pub struct TxGraph<A = ()> {
    anchors: BTreeSet<(A, Txid)>,
    // ... OTHER FIELDS
}

pub struct ChangeSet<A = ()> {
    pub anchors: BTreeSet<(A, Txid)>,
    // ... OTHER FIELDS
}

However, we can have multiple As that have the same anchor block BlockId for the same Txid. This is not ideal. Ideally, we want one anchor per (BlockId, Txid).

The Proposal

pub type Anchor = (Txid, BlockId);

pub struct TxGraph<AM> {
    anchors: BTreeMap<Anchor, AM>,
}

pub struct ChangeSet<AM> {
    anchors: BTreeMap<Anchor, AM>,
}

Where AM is "anchor metadata". I.e. You can store block time here (u32).

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

In Progress

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions