Skip to content

Implement linked-list LocalChain and update chain-src crates/examples#1034

Merged
evanlinjin merged 8 commits intobitcoindevkit:masterfrom
evanlinjin:local_chain_linked_list
Aug 3, 2023
Merged

Implement linked-list LocalChain and update chain-src crates/examples#1034
evanlinjin merged 8 commits intobitcoindevkit:masterfrom
evanlinjin:local_chain_linked_list

Conversation

@evanlinjin
Copy link
Copy Markdown
Member

@evanlinjin evanlinjin commented Jul 19, 2023

Fixes #997
Replaces #1002

Description

This PR changes the LocalChain implementation to have blocks stored as a linked-list. This allows the data-src thread to hold a shared ref to a single checkpoint and have access to the whole history of checkpoints without cloning or keeping a lock on LocalChain.

The APIs of bdk::Wallet, esplora and electrum are also updated to reflect these changes. Note that the esplora crate is rewritten to anchor txs in the confirmation block (using the esplora API's tx status block_hash). This guarantees 100% consistency between anchor blocks and their transactions (instead of anchoring txs to the latest tip). ExploraExt now has separate methods for updating the TxGraph and LocalChain.

A new method TxGraph::missing_blocks is introduced for finding "floating anchors" of a TxGraph update (given a chain).

Additional changes:

  • test_local_chain.rs is refactored to make test cases easier to write. Additional tests are also added.
  • Examples are updated.
  • Exclude example-cli *.db files in .gitignore.
  • Rm duplicate bdk_tmp_plan module.

Notes to the reviewers

This is the smallest possible division of #1002 without resulting in PRs that do not compile. Since we have changed the API of LocalChain, we also need to change esplora, electrum crates and examples alongside bdk::Wallet.

Changelog notice

  • Implement linked-list LocalChain. This allows the data-src thread to hold a shared ref to a single checkpoint and have access to the whole history of checkpoints without cloning or keeping a lock on LocalChain.
  • Rewrote esplora chain-src crate to anchor txs to their confirmation blocks (using esplora API's tx-status block_hash).

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

LocalChain should be implemented as a cheaply cloneable singly linked list

5 participants