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

Custom spk iterator #927

Merged
merged 1 commit into from
May 2, 2023

Conversation

LagginTimes
Copy link
Contributor

@LagginTimes LagginTimes commented Mar 24, 2023

PR for #904

What is done:

  • Added SpkIterator with new and new_with_range constructors, along with its own nth() and next() implementations
  • Replaced all instances of range_descriptor_spks with the new SpkIterator::new_with_range constructor
  • Created wildcard and non-wildcard unit tests for nth() and next() functions for SpkIterator

What is in-progress:

  • @evanlinjin: Discussing the necessity of Cow<> in this implementation
  • @LagginTimes: Documentation for the new functions

@LLFourn LLFourn mentioned this pull request Apr 4, 2023
3 tasks
@benthecarman
Copy link
Contributor

@LagginTimes any updates here, this is blocking #894

crates/chain/src/keychain/txout_index.rs Outdated Show resolved Hide resolved
crates/chain/tests/test_keychain_txout_index.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
@evanlinjin
Copy link
Member

I think the next step would be to squash all these commits in this PR into one commit and cherry-pick it onto #894 to see if we can fix #894 (comment).

@LagginTimes LagginTimes force-pushed the custom_spk_iterator branch 9 times, most recently from 005456e to b21d369 Compare April 19, 2023 10:23
@evanlinjin evanlinjin force-pushed the custom_spk_iterator branch from b21d369 to 475ca29 Compare April 19, 2023 10:31
@LagginTimes LagginTimes force-pushed the custom_spk_iterator branch 2 times, most recently from 1217917 to 7c3d439 Compare April 19, 2023 17:50
@LagginTimes LagginTimes force-pushed the custom_spk_iterator branch from 7c3d439 to dbfb666 Compare April 19, 2023 18:14
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.

Looking good. I don't think we want new_with_range.

I think once it's ready we should just merge this. No need to cherry pick. You can make a test checking whether this has done its job by making a dummy trait in a test like trait TestSendStatic: Send + 'static {} and impl TestSendStatic for SpkIterator<Descriptor<DescriptorPublicKey>> { }. This will fail to compile if it didn't work.
Put the SpkIterator into its own spk_iter.mod file. Put tests for it at the end of the module.
Make sure methods that return an SpkIterator return it and not an impl Iterator.

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/keychain/txout_index.rs Outdated Show resolved Hide resolved
crates/chain/src/keychain/txout_index.rs Show resolved Hide resolved
@LagginTimes LagginTimes force-pushed the custom_spk_iterator branch 2 times, most recently from 10fb618 to 881df40 Compare April 20, 2023 14:25
@evanlinjin
Copy link
Member

@LLFourn Here is my argument for leaving SpkIterator::new_with_range in.

KeychainTxOutIndex::reveal_to_target, in this PR, now returns an explicit concrete type of SpkIterator. This cannot be achieved if we depend on .skip and .take. Instead we would need to return an implicit impl Iterator<...>.

For me, this justifies leaving it as is, since it provides a better API.

@evanlinjin evanlinjin force-pushed the custom_spk_iterator branch 2 times, most recently from cd42bba to 8b75559 Compare April 28, 2023 18:39
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 8b75559

This looks good to me. I guess the last thing to do is to do the "dummy trait" test as mentioned by @LLFourn: #927 (review).

There is also a small nit.

Also note that I rebased for you (sorry!), so you need to force pull.

crates/chain/src/spk_iter.rs Outdated Show resolved Hide resolved
@LLFourn
Copy link
Contributor

LLFourn commented May 1, 2023

ACK 8b75559

This looks good to me. I guess the last thing to do is to do the "dummy trait" test as mentioned by @LLFourn: #927 (review).

I agree.

@LLFourn Here is my argument for leaving SpkIterator::new_with_range in.

KeychainTxOutIndex::reveal_to_target, in this PR, now returns an explicit concrete type of SpkIterator. This cannot be achieved if we depend on .skip and .take. Instead we would need to return an implicit impl Iterator<...>.

For me, this justifies leaving it as is, since it provides a better API.

Do you mean it provides a API internally? Then I suggest we make it a private function and remove the documentation for it.

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.

Nits aside LGTM

@LagginTimes LagginTimes force-pushed the custom_spk_iterator branch from 8b75559 to 0a7ab72 Compare May 2, 2023 08:37
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.

We need to make this build with:

$ cargo build --no-default-features -p bdk_chain

To fix this, only include spk_iter module if cargo feature "miniscript" is enabled.

Also a nit: move keychain::BIP32_MAX_INDEX into spk_iter module.

@LagginTimes LagginTimes force-pushed the custom_spk_iterator branch from 0a7ab72 to b604303 Compare May 2, 2023 09:22
@LagginTimes LagginTimes requested a review from evanlinjin May 2, 2023 09:28
SpkIterator was created with its own nth() and next() implementations
and its own new() and new_with_range() constructors.

Co-authored-by: 志宇 <[email protected]>
@evanlinjin evanlinjin force-pushed the custom_spk_iterator branch from b604303 to 10fe32e Compare May 2, 2023 09:31
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 10fe32e

@evanlinjin evanlinjin merged commit c61995c into bitcoindevkit:master May 2, 2023
@notmandatory notmandatory added this to the 1.0.0-alpha.1 milestone May 4, 2023
@notmandatory notmandatory mentioned this pull request Jul 4, 2023
24 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.

5 participants