Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplified EsploraExt API #1380

Merged
merged 13 commits into from Apr 22, 2024
Merged

Conversation

evanlinjin
Copy link
Member

@evanlinjin evanlinjin commented Mar 21, 2024

Fixes #1354

Description

Built on top of both #1369 and #1373, we simplify the EsploraExt API by removing the update_local_chain method and having full_scan and sync update the local chain in the same call. The full_scan and sync methods now takes in an additional input (local_tip) which provides us with the view of the LocalChain before the update. These methods now return structs FullScanUpdate and SyncUpdate.

The examples are updated to use this new API. TxGraph::missing_heights and tx_graph::ChangeSet::missing_heights_from are no longer needed, therefore they are removed.

Additionally, we used this opportunity to simplify the logic which updates LocalChain. We got rid of the local_chain::Update struct (which contained the update CheckPoint tip and a bool which signaled whether we want to introduce blocks below point of agreement). It turns out we can use something like CheckPoint::insert so the chain source can craft an update based on the old tip. This way, we can make better use of merge_chains' optimization that compares the Arc pointers of the local and update chain (before we were crafting the update chain NOT based on top of the previous local chain). With this, we no longer need the Update::introduce_older_block field since the logic will naturally break when we reach a matching Arc pointer.

Notes to the reviewers

  • Obtaining the LocalChain's update now happens within EsploraExt::full_scan and EsploraExt::sync. Creating the LocalChain update is now split into two methods (fetch_latest_blocks and chain_update) that are called before and after fetching transactions and anchors.
  • We need to duplicate code for bdk_esplora. One for blocking and one for async.

Changelog notice

  • Changed EsploraExt API so that sync only requires one round of fetching data. The local_chain_update method is removed and the local_tip parameter is added to the full_scan and sync methods.
  • Removed TxGraph::missing_heights and tx_graph::ChangeSet::missing_heights_from methods.
  • Introduced CheckPoint::insert which allows convenient checkpoint-insertion. This is intended for use by chain-sources when crafting an update.
  • Refactored merge_chains to also return the resultant CheckPoint tip.
  • Optimized the update LocalChain logic - use the update CheckPoint as the new CheckPoint tip when possible.

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

@notmandatory notmandatory added this to the 1.0.0-alpha milestone Mar 21, 2024
@notmandatory notmandatory added the api A breaking API change label Mar 21, 2024
@evanlinjin evanlinjin force-pushed the clean_esplora branch 11 times, most recently from 1bb6193 to abddc33 Compare March 26, 2024 15:00
@evanlinjin evanlinjin marked this pull request as ready for review March 26, 2024 15:01
@evanlinjin
Copy link
Member Author

@notmandatory ready for you to base #1194 on!

Copy link
Contributor

@LLFourn LLFourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments so I can understand a few things better before giving a full review.

crates/esplora/src/blocking_ext.rs Outdated Show resolved Hide resolved
crates/esplora/src/blocking_ext.rs Outdated Show resolved Hide resolved
crates/esplora/src/blocking_ext.rs Outdated Show resolved Hide resolved
crates/esplora/src/blocking_ext.rs Outdated Show resolved Hide resolved
crates/esplora/src/blocking_ext.rs Outdated Show resolved Hide resolved
@notmandatory
Copy link
Member

@notmandatory ready for you to base #1194 on!

I finished rebasing #1194 on this PR and everything is working fine.

@evanlinjin
Copy link
Member Author

@notmandatory I forgot to mention I also need to rebase this PR on master 😬

@evanlinjin evanlinjin force-pushed the clean_esplora branch 5 times, most recently from e59a142 to a9aa7c4 Compare April 2, 2024 13:23
evanlinjin and others added 7 commits April 16, 2024 17:51
This creates a checkpoint linked list which contains all blocks.
Previously, we would update the `TxGraph` and `KeychainTxOutIndex`
first, then create a second update for `LocalChain`. This required
locking the receiving structures 3 times (instead of twice, which
is optimal).

This PR eliminates this requirement by making use of the new `query`
method of `CheckPoint`.

Examples are also updated to use the new API.
These methods are no longer needed as we can determine missing heights
directly from the `CheckPoint` tip.
This gets the genesis hash of the env blockchain.
We ensure that calling `finalize_chain_update` does not result in a
chain which removed previous heights and all anchor heights are
included.
Since we want to keep these methods private.
Co-authored-by: LLFourn <lloyd.fourn@gmail.com>
Co-authored-by: LLFourn <lloyd.fourn@gmail.com>
@evanlinjin evanlinjin force-pushed the clean_esplora branch 2 times, most recently from 690cccb to a504a1d Compare April 17, 2024 02:56
The intention is to remove the `Update::introduce_older_blocks`
parameter and update the local chain directly with `CheckPoint`.

This simplifies the API and there is a way to do this efficiently.
`merge_chains` now returns a tuple of the resultant checkpoint AND
changeset. This is arguably a more readable/understandable setup.

To do this, we had to create `CheckPoint::apply_changeset` which is kept
as a private method.

Thank you @ValuedMammal for the suggestion.

Co-authored-by: valuedvalued mammal <valuedmammal@protonmail.com>
Copy link
Contributor

@LLFourn LLFourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 96a9aa6

@evanlinjin evanlinjin merged commit 8e73998 into bitcoindevkit:master Apr 22, 2024
12 checks passed
@danielabrozzoni danielabrozzoni mentioned this pull request May 2, 2024
28 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api A breaking API change module-blockchain
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

The TxGraph::missing_heights implementation is problematic.
4 participants