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

Change methods of IndexedTxGraph/TxGraph/Wallet that insert txs to be more generic #1586

Merged
merged 3 commits into from
Sep 9, 2024

Conversation

evanlinjin
Copy link
Member

@evanlinjin evanlinjin commented Sep 2, 2024

Description

We want to reuse the Arc pointer whenever possible. However, some methods on TxGraph and IndexedTxGraph that insert transactions take in &Transaction or Transaction (thus forcing us to create a new Arc<Transaction> internally by cloning, even if the input tx is under a Arc).

This PR changes these methods to take in a generic parameter, T: Into<Arc<Transaction>>, allowing us to reuse the Arc pointer whenever possible.

Notes to the reviewers

Methods that previously took in Transaction can be changed to take in T: Into<Arc<Transaction>> and be non-breaking (since Arc<T> impls From<T> automatically). These changes are contained in the first two commits.

Methods that previously took in &Transaction will break. However, I think these api changes are small and the improvements are substantial enough to be worth it. These changes are contained in the last commit.

Changelog notice

  • Changed IndexedTxGraph methods insert_tx, batch_insert_relevant, batch_insert_relevant_unconfirmed, batch_insert_unconfirmed to take in T: Into<Arc<Transaction>> instead of Transaction or &Transaction.
  • Changed TxGraph method batch_insert_unconfirmed to take in T: Into<Arc<Transaction>> instead of Transaction.
  • Changed Wallet methods insert_tx, apply_unconfirmed_txs to take in T: Into<Arc<Transaction>> instead of Transaction or &Transaction.

Checklists

All Submissions:

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

@evanlinjin evanlinjin force-pushed the tx_graph_generic_tx branch 2 times, most recently from b178493 to 74b14a7 Compare September 3, 2024 05:47
Instead of having `Transaction` as input, we have a generic parameter
where the bound is `Into<Arc<Transaction>>` for the following methods:

* `IndexedTxGraph::insert_tx`
* `IndexedTxGraph::batch_insert_unconfirmed`
* `TxGraph::batch_insert_unconfirmed`
Instead of having `Transaction` as input, have
`T: Into<Arc<Transaction>>`.
…ransaction`

* `Wallet::apply_unconfirmed_txs`
* `IndexedTxGraph::batch_insert_relevant`
* `IndexedTxGraph::batch_insert_relevant_unconfirmed`
@evanlinjin evanlinjin marked this pull request as ready for review September 3, 2024 06:14
@evanlinjin evanlinjin changed the title Change IndexedTxGraph and TxGraph methods that insert txs to be more generic Change methods of IndexedTxGraph/TxGraph/Wallet that insert txs to be more generic Sep 3, 2024
@evanlinjin evanlinjin self-assigned this Sep 3, 2024
@evanlinjin evanlinjin added new feature New feature or request api A breaking API change labels Sep 3, 2024
@evanlinjin evanlinjin added this to the 1.0.0-beta milestone Sep 3, 2024
Copy link
Contributor

@oleonardolima oleonardolima left a comment

Choose a reason for hiding this comment

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

utACK 87e6121

Looks good! I do agree that it definitely helps being able to reuse the Arc pointer. It looks fine to me, but I wonder what others think about the breaking changes.

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 87e6121

This minor API change also works better with the UniFFI language bindings where all return types are wrapped in an Arc.

@notmandatory notmandatory merged commit 8760653 into bitcoindevkit:master Sep 9, 2024
21 checks passed
This was referenced Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api A breaking API change new feature New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants