Skip to content

Remove persist submodule#1473

Merged
notmandatory merged 3 commits intobitcoindevkit:masterfrom
evanlinjin:remove-persist
Jun 15, 2024
Merged

Remove persist submodule#1473
notmandatory merged 3 commits intobitcoindevkit:masterfrom
evanlinjin:remove-persist

Conversation

@evanlinjin
Copy link
Copy Markdown
Member

Description

@LLFourn suggested these changes which greatly simplifies the amount of code we have to maintain and removes the async-trait dependency. We remove PersistBackend, PersistBackendAsync, StageExt and StageExtAsync completely. Instead, we introduce Wallet::take_staged(&mut self) -> Option<ChangeSet>.

The original intention to keep a staging area (StageExt, StageExtAsync) is to enforce:

  1. The caller will not persist an empty changeset.
  2. The caller does not take the staged changeset if the database (PersistBackend) fails.

We achieve 1. by returning None if the staged changeset is empty.

2. is not too important. The caller can try figure out what to do with the changeset if persisting to db fails.

Notes to the reviewers

I added a take convenience method to the Append trait. I thought it would be handy for the caller to do a staging area with this.

Changelog notice

  • Remove persist submodule from bdk_chain.
  • Change Wallet to outsource it's persistence logic by introducing Wallet::take_staged.
  • Add take convenience method to Append trait.

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

Remove `PersistBackend`, `PersistBackendAsync`, `StageExt` and
`StageExtAsync`. Remove `async` feature flag and dependency. Update
examples and wallet.
This is useful if the caller wishes to use the type as a staging area.

This is breaking as `Append` has a `Default` bound now.
@evanlinjin evanlinjin marked this pull request as ready for review June 14, 2024 16:53
@evanlinjin evanlinjin self-assigned this Jun 14, 2024
@evanlinjin evanlinjin added the api A breaking API change label Jun 14, 2024
@evanlinjin evanlinjin added this to the 1.0.0-alpha milestone Jun 14, 2024
Copy link
Copy Markdown
Collaborator

@ValuedMammal ValuedMammal left a comment

Choose a reason for hiding this comment

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

Approach ACK

Comment thread crates/chain/src/changeset.rs Outdated
bdk_chain::persist::StageExtAsync::commit_to(&mut self.stage, persist_backend).await?;
Ok(committed.is_some())
/// Get a reference of the staged [`ChangeSet`] that are yet to be committed (if any).
pub fn staged(&self) -> Option<&ChangeSet> {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I thought the previous implementation of this was fine too.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You mean without the option?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think I was worried that people will try persist using this and then call take_staged only after saving to db succeeded.

Copy link
Copy Markdown
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 a0bf45b


/// Trait that makes an object appendable.
pub trait Append {
pub trait Append: Default {
Copy link
Copy Markdown
Member

@notmandatory notmandatory Jun 14, 2024

Choose a reason for hiding this comment

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

👍 This has the added benefit that it should solve #1103 by requiring all change set fields implement Default. So if we load a wallet data file from an older bdk version we should gracefully handle fields added in newer bdk versions since they must have a reasonable default value.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This doesn't really solve #1033. Backwards compatibility is only important for wallet, and we need the wallet's changeset to impl default already. Solving #1033 requires the serialized changeset to be deserializable with newer versions

Comment thread crates/chain/src/changeset.rs Outdated
@notmandatory
Copy link
Copy Markdown
Member

I pushed a commit to fix some docs that still mentioned PersistBackend and updated the bdk_wallet README example.

@notmandatory notmandatory mentioned this pull request Jun 14, 2024
31 tasks
Copy link
Copy Markdown
Member Author

@evanlinjin evanlinjin left a comment

Choose a reason for hiding this comment

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

self-ACK a0bf45b

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

Labels

api A breaking API change

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants