Skip to content

[Taproot API project] move several files and tighten up iterator API #807

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

Merged
merged 6 commits into from
Apr 14, 2025

Conversation

apoelstra
Copy link
Member

This PR mostly just moves files around, but it includes two nontrivial API changes:

  • It renames the iter_scripts iterator to leaves on Tr and Taptree
  • It yields a dedicated struct rather than just a (u8, Script) tuple

In the next PRs we will completely rewrite this iterator, and Taptree and these preparatory commits help to reduce the diff throughout the rest of the codebase.

Verified

This commit was signed with the committer’s verified signature.
apoelstra Andrew Poelstra

Verified

This commit was signed with the committer’s verified signature.
apoelstra Andrew Poelstra
All this does is wrap the existing (depth, script) return value in a
structure that has a pile of accessors on it. The accessors include
a couple of expensive computations which are currently done manually.

A later commit/PR will introduce a `SpendInfo` structure which will
cache these computations and amortize much of the hashing needed to
produce control blocks. But these new accessors simplify some things.
@apoelstra apoelstra force-pushed the 2025-04--taproot-2 branch from 9479891 to dd17df5 Compare April 10, 2025 19:43
@apoelstra apoelstra marked this pull request as draft April 10, 2025 19:57
@apoelstra
Copy link
Member Author

Drafting for a bit -- I need to test all feature combinations.

Verified

This commit was signed with the committer’s verified signature.
apoelstra Andrew Poelstra
We are going to move TapTree into the module (hence the name), and
before we can do this we need to move the iterator.

Verified

This commit was signed with the committer’s verified signature.
apoelstra Andrew Poelstra
This completes the move of all the taptree-related stuff into its own
module, where it will be easier to mess around with this stuff.

Verified

This commit was signed with the committer’s verified signature.
apoelstra Andrew Poelstra
Moving this separately from the rest of the TapTree stuff because I
changed the Policy import to Semantic and the Error import to just
crate::Error (since this is the only place that type is used in the
taptree module, and I don't really like this type).

So this is a move-only diff but it might not look like it, so I figured
I should at least make the diff small.

Verified

This commit was signed with the committer’s verified signature.
apoelstra Andrew Poelstra
The name `iter_scripts` is dumb and undiscoverable. More importantly,
it's misleading -- this iterator does not yield scripts. It yields
Miniscripts, which can be converted to scripts if you have ToPublicKey
and are willing to pay a cost.
@apoelstra apoelstra force-pushed the 2025-04--taproot-2 branch from dd17df5 to 8e5d809 Compare April 10, 2025 20:41
@apoelstra apoelstra marked this pull request as ready for review April 10, 2025 21:12
Copy link
Member Author

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

On 8e5d809 successfully ran local tests

Copy link
Member

@sanket1729 sanket1729 left a comment

Choose a reason for hiding this comment

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

code review ACK 8e5d809.

Thanks for the helpful commit messages.

///
/// This function is potentially expensive.
#[inline]
pub fn compute_script(&self) -> bitcoin::ScriptBuf { self.node.encode() }
Copy link
Member

Choose a reason for hiding this comment

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

I like this idea of potentially naming all functions that could be expensive with compute prefix.

@apoelstra apoelstra merged commit e49c1db into rust-bitcoin:master Apr 14, 2025
31 checks passed
@apoelstra apoelstra deleted the 2025-04--taproot-2 branch April 14, 2025 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants