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

Introduce tx_graph::Update and simplify TxGraph update logic #1568

Merged
merged 6 commits into from
Aug 25, 2024

Conversation

evanlinjin
Copy link
Member

@evanlinjin evanlinjin commented Aug 23, 2024

Part of #1543
Closes #1550

Description

Instead of updating a TxGraph with another TxGraph in .apply_update(), we introduce tx_graph::Update. tx_graph::Update is a simple data object. This is the first step of #1543. This also makes it slightly less expensive to create an update.

Additionally, we simplify the update logic of TxGraph by containing most of the update logic in .insert_{}-esc methods. .apply_update and .apply_changeset will call .insert_{} methods internally and is greatly simplified. Thus, we also get rid of .determine_changeset.

We change .apply_update methods of TxGraph,IndexedTxGraph and Wallet to implicitly set seen_at to the current timestamp for unconfirmed update transactions. This makes these methods only available when the "std" cargo feature is enabled. For a non-std environment, we introduce .apply_update_at (as shown below).

pub fn apply_update_at(&mut self, update: Update<A>, seen_at: Option<u64>) -> ChangeSet<A> {
    todo!()
}

During this process, I've fixed some tests that didn't make much sense.

Notes to the reviewers

There is a slight scope-creep, but they all address the update logic of TxGraph and structures that build on top.

Changelog notice

  • Changed update API (.apply_update) of TxGraph to take in a simple data object (tx_graph::Update).
  • Changed .apply_update methods of TxGraph, IndexedTxGraph and Wallet to implicitly set the seen_at to the current timestamp for unconfirmed update transactions (this making them depend on the "std" cargo feature).
  • Add .apply_update_at which is the no-std version of .apply_update.

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

Contain most of the insertion logic in `.insert_{}` methods, thus
simplifying `.apply_{}` methods. We can also get rid of
`.determine_changeset`.
@evanlinjin evanlinjin force-pushed the tx_graph_update branch 5 times, most recently from f2d09e7 to 2897492 Compare August 23, 2024 12:16
@evanlinjin evanlinjin marked this pull request as ready for review August 23, 2024 12:49
evanlinjin and others added 5 commits August 23, 2024 13:42
Instead of updating a `TxGraph` with a `TxGraph`, we introduce a
dedicated data object (`tx_graph::Update`). This brings us closer to
completing bitcoindevkit#1543.

Co-authored-by: Wei Chen <[email protected]>
Change `apply_update` to use the current timestamp as `seen_at` for
unanchored transactions of the update. This makes `apply_update` only
avaliable with the "std" feature.

Introduce `apply_update_at` which includes an optional `seen_at` input.
This is the no-std version of `apply_update`.

Also update docs.
This is no longer needed as `TxGraph::apply_update` now automatically
adds `seen_at` timestamps for unanchored transactions.
Copy link
Member

@notmandatory notmandatory left a comment

Choose a reason for hiding this comment

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

ACK ccb8c79

Looks good and I can see how this will help decouple the blockchain clients from the wallet once tx_graph:Update is moved to a new crate.

I ran all the examples also as a little smoke test and they worked fine.

@evanlinjin evanlinjin mentioned this pull request Aug 24, 2024
3 tasks
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 ccb8c79

@LLFourn LLFourn merged commit dad9545 into bitcoindevkit:master Aug 25, 2024
20 checks passed
evanlinjin added a commit that referenced this pull request Aug 25, 2024
a5d076f chore(core)!: s/tx_graph::Update/TxUpdate/ (LLFourn)
dafb9aa feat(bitcoind_rpc)!: depend on `bdk_core` instead of `bdk_chain` (志宇)
fea8eed feat(esplora)!: depend on `bdk_core` instead of `bdk_chain` (志宇)
0d302f5 feat(electrum)!: depend on `bdk_core` instead of `bdk_chain` (志宇)
ab0315d feat!: move `spk_client`s to `bdk_core` (志宇)
bdea871 feat!: move `tx_graph::Update` to `bdk_core` (志宇)
77e31c7 feat!: move `CheckPoint` to `bdk_core` (志宇)
a86c878 refactor(chain): change `CheckPoint::apply_changeset` (志宇)
6f7626a feat!: introduce `bdk_core` (志宇)

Pull request description:

  Based on #1568
  Closes #1543

  ### Description

  Introduce `bdk_core` crate. Move types over from `bdk_chain`. Chain sources (`bdk_electrum`, `bdk_esplora` and `bdk_bitcoind_rpc`) now only depend on `bdk_core`.

  ### Notes to the reviewers

  Please review commit-by-commit. I've moved things over, but slight API changes were necessary (mentioned in the commit messages).

  ### Changelog notice

  * Add `bdk_core` crate which contains core types that were previously in `bdk_chain`. Including: `BlockId`, `ConfirmationBlockTime`, `CheckPoint`, `CheckPointIter`, `tx_graph::Update` and `spk_client`-types.
  * Change chain sources (`bdk_esplora`, `bdk_electrum` and `bdk_bitcoind_rpc`) to only depend on `bdk_core`.

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

ACKs for top commit:
  LLFourn:
    Self-ACK: a5d076f
  evanlinjin:
    ACK a5d076f

Tree-SHA512: 13ecd0a2d2fc840b281977f07dc11fed27459f77c676af470134d2184db4a1fc352073ef82b1622e04fc60edb885e587ae8b9909c9bafb4ae63fcd51325d1cad
@notmandatory notmandatory mentioned this pull request Aug 25, 2024
31 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.

Should bdk_electrum sync/full_scan set last_seen?
3 participants