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

Enhance bdk chain structures #1084

Merged

Conversation

vladimirfomene
Copy link
Contributor

Description

Fixes #1061

Changelog notice

  • Move WalletUpdate to the wallet module
  • Remove ForEachTxout trait completely
  • Refactor ElectrumExt to not use WalletUpdate.

Checklists

All Submissions:

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

@vladimirfomene vladimirfomene changed the title Enhance bdk chain structures WIP: Enhance bdk chain structures Aug 21, 2023
@LLFourn
Copy link
Contributor

LLFourn commented Aug 22, 2023

What's the motivation for removing ForEachTxOut? I think it serves a purpose in that it allows you to scan several things that are bunches of txouts (including things that are not transactions).

@evanlinjin
Copy link
Member

What's the motivation for removing ForEachTxOut? I think it serves a purpose in that it allows you to scan several things that are bunches of txouts (including things that are not transactions).

This was my suggestion and I wrote it on the ticket. I don't think it is needed? The Indexer trait has the method Indexer::index_txout(&mut self, outpoint: OutPoint, txout: &TxOut) -> Self::ChangeSet, and we can have another method:

pub trait Indexer {
    /* ... */

    fn index_txouts<'a>(
        &mut self,
        txouts: impl IntoIterator<Item = (OutPoint, &'a TxOut)>,
    ) -> Self::ChangeSet
    where
        Self::ChangeSet: Append + Default,
    {
        let mut changeset = Self::ChangeSet::default();
        for (outpoint, txout) in txouts {
            Append::append(&mut changeset, self.index_txout(outpoint, txout));
        }
        changeset
    }
}

Now anything that implements IntoIterator<Item = (OutPoint, &TxOut)> will work.

@vladimirfomene vladimirfomene force-pushed the enhance-bdk-chain-structures branch 4 times, most recently from 2f3b9d9 to d640543 Compare August 22, 2023 13:35
@vladimirfomene vladimirfomene marked this pull request as ready for review August 22, 2023 13:38
@vladimirfomene
Copy link
Contributor Author

Will rebase this once MSRV fixes make it to master.

@nondiremanuel nondiremanuel added this to the 1.0.0-alpha.3 milestone Aug 22, 2023
@vladimirfomene vladimirfomene changed the title WIP: Enhance bdk chain structures Enhance bdk chain structures Aug 23, 2023
Copy link
Member

@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.

Thanks for the work so far. Sorry about my incremental reviews.

crates/bdk/src/wallet/mod.rs Outdated Show resolved Hide resolved
crates/bdk/src/wallet/mod.rs Outdated Show resolved Hide resolved
crates/electrum/src/electrum_ext.rs Show resolved Hide resolved
crates/electrum/src/electrum_ext.rs Show resolved Hide resolved
@LLFourn
Copy link
Contributor

LLFourn commented Aug 25, 2023

What's the motivation for removing ForEachTxOut? I think it serves a purpose in that it allows you to scan several things that are bunches of txouts (including things that are not transactions).

This was my suggestion and I wrote it on the ticket. I don't think it is needed? The Indexer trait has the method Indexer::index_txout(&mut self, outpoint: OutPoint, txout: &TxOut) -> Self::ChangeSet, and we can have another method:

So if I want to index a Block what should I do?. I can iterate manually over every TxOut and call this but that seems much more cumbersome than it needs to be?

@vladimirfomene
Copy link
Contributor Author

@LLFourn I'm thinking you will use index_tx here instead of index_txout.

@LLFourn
Copy link
Contributor

LLFourn commented Aug 25, 2023

@LLFourn I'm thinking you will use index_tx here instead of index_txout.

Understood. I think might be as easy as we need to make it. Thanks.

@vladimirfomene vladimirfomene force-pushed the enhance-bdk-chain-structures branch 2 times, most recently from 0c2ddec to 2d482fd Compare August 25, 2023 18:56
crates/electrum/src/electrum_ext.rs Outdated Show resolved Hide resolved
@evanlinjin evanlinjin force-pushed the enhance-bdk-chain-structures branch 3 times, most recently from 74f213e to 2377826 Compare August 26, 2023 12:35
evanlinjin and others added 2 commits September 3, 2023 01:51
We remove `ElectrumUpdate` and return tuples instead for `ElectrumExt`
methods. We introduce the `IncompleteTxGraph` structure to specifically
hodl the incomplete `TxGraph`.

This change is motivated by @LLFourn's comment: bitcoindevkit@794bf37#r1305432603
@evanlinjin evanlinjin force-pushed the enhance-bdk-chain-structures branch 2 times, most recently from 905101d to c56728f Compare September 2, 2023 18:22
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 c56728f

I confirmed example_electrum and example_esplora scan and sync commands still work. Used my test signet descriptors:

cargo run -- --network signet "wpkh(tprv8ZgxMBicQKsPdy6LMhUtFHAgpocR8GC6QmwMSFpZs7h6Eziw3SpThFfczTDh5rW2krkqffa11UpX3XkeTTB2FvzZKWXqPY54Y6Rq4AQ5R8L/84'/1'/0'/0/*)" "wpkh(tprv8ZgxMBicQKsPdy6LMhUtFHAgpocR8GC6QmwMSFpZs7h6Eziw3SpThFfczTDh5rW2krkqffa11UpX3XkeTTB2FvzZKWXqPY54Y6Rq4AQ5R8L/84'/1'/0'/1/*)" scan

@notmandatory
Copy link
Member

notmandatory commented Sep 2, 2023

One small nit, it looks like most of the commits include breaking changes so commit messages should include a ! to denote commit breaks old APIs. Doesn't need to be fixed for this PR but to keep in mind for future.

@evanlinjin
Copy link
Member

ACK c56728f

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.

Hey @vladimirfomene thanks for doing this refactoring.

I've pointed out a bunch of ways we can simplify things in both wallet types and electrum_ext. Many of the changes requested are not to do with this PR but I think this is the place to do them.

[edit] I also pushed 4104206

crates/bdk/src/wallet/mod.rs Outdated Show resolved Hide resolved
crates/bdk/src/wallet/mod.rs Outdated Show resolved Hide resolved
crates/bdk/src/wallet/mod.rs Outdated Show resolved Hide resolved
crates/bdk/src/wallet/mod.rs Outdated Show resolved Hide resolved
crates/bdk/src/wallet/mod.rs Outdated Show resolved Hide resolved
crates/chain/src/keychain/txout_index.rs Outdated Show resolved Hide resolved
crates/chain/src/keychain/txout_index.rs Outdated Show resolved Hide resolved
crates/chain/src/lib.rs Outdated Show resolved Hide resolved
crates/electrum/src/electrum_ext.rs Outdated Show resolved Hide resolved
crates/electrum/src/electrum_ext.rs Outdated Show resolved Hide resolved
@vladimirfomene vladimirfomene force-pushed the enhance-bdk-chain-structures branch 2 times, most recently from f8d3070 to ee01b0f Compare September 6, 2023 07:55
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.

This LGTM! ACK ee01b0f

left a couple of small comments.

crates/electrum/src/electrum_ext.rs Outdated Show resolved Hide resolved
@vladimirfomene vladimirfomene force-pushed the enhance-bdk-chain-structures branch 3 times, most recently from 1b1eb8f to 1530568 Compare September 8, 2023 14:18
Copy link
Member

@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.

Mostly nits and documentation suggestions.

crates/chain/src/indexed_tx_graph.rs Outdated Show resolved Hide resolved
crates/chain/src/indexed_tx_graph.rs Outdated Show resolved Hide resolved
crates/chain/src/spk_txout_index.rs Outdated Show resolved Hide resolved
crates/chain/src/spk_txout_index.rs Outdated Show resolved Hide resolved
@vladimirfomene vladimirfomene force-pushed the enhance-bdk-chain-structures branch 2 times, most recently from 0ad05a6 to 69d6825 Compare September 13, 2023 09:55
And signature of `example_cli::KeychainChangeSet` is changed.
Copy link
Member

@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.

ACK 1ff806c

@evanlinjin evanlinjin merged commit c20a4da into bitcoindevkit:master Sep 15, 2023
12 checks passed
@notmandatory notmandatory mentioned this pull request Oct 11, 2023
12 tasks
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.

Further enhancements to Update and ChangeSet structures
5 participants