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

Add the planning module (updated PR) #592

Merged
merged 6 commits into from
Sep 22, 2023

Conversation

danielabrozzoni
Copy link
Contributor

This PR builds on top of #481, fixing all the review comments.

I didn't squash my last commits on purpose to make review easier, I can squash them before merging if preferred.

@danielabrozzoni danielabrozzoni force-pushed the feat/planning-module branch 2 times, most recently from b0c2fd4 to 4400f85 Compare August 18, 2023 12:07
Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

Looks good!

Code reveiw only, I'm not super knowledgeable on this code base.

ACK 4400f85

src/plan.rs Show resolved Hide resolved
src/plan.rs Outdated Show resolved Hide resolved
@tcharding
Copy link
Member

Looks like this is waiting for review please @sanket1729 and/or @apoelstra

@danielabrozzoni
Copy link
Contributor Author

d097867 - rebased and fixed review comments. CI is failing due to (I think) unrelated reasons, it's broken on master as well.

@tcharding
Copy link
Member

#597 should fix CI

@danielabrozzoni
Copy link
Contributor Author

Nice, rebased!

@apoelstra
Copy link
Member

Can you run through each commit and make sure that cargo test passes?

@danielabrozzoni
Copy link
Contributor Author

Can you run through each commit and make sure that cargo test passes?

Should be cleaner now, sorry!

CI is failing, but #598 should fix it.

afilini and others added 6 commits September 18, 2023 10:11
The Satisfaction struct now contains `relative_timelock` and
`absolute_timelock`, which represent the needed timelocks for
that particular spending path.
This is useful for the plan module.

Co-authored-by: Daniela Brozzoni <[email protected]>
Add a `plan` module that contains utilities to calculate the
cheapest spending path given an AssetProvider (that could
keys, preimages, or timelocks). Adds a `get_plan` method on the
various descriptor types.

Co-authored-by: Daniela Brozzoni <[email protected]>
Co-authored-by: Alekos Filini <[email protected]>
@danielabrozzoni
Copy link
Contributor Author

a358076 - rebased on master

Descriptor::Wsh(ref wsh) => wsh.plan_satisfaction(provider),
Descriptor::Sh(ref sh) => sh.plan_satisfaction(provider),
Descriptor::Tr(ref tr) => tr.plan_satisfaction(provider),
};
Copy link
Member

Choose a reason for hiding this comment

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

In d29c298:

In a followup PR, these are easy candidates to un-recursify (using iter.rs from #567 which was created long after this PR but merged long before).

Copy link
Member

Choose a reason for hiding this comment

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

For more context, what he means is what I'm doing in #594. The iter module implements a pretty hard core data structure, if you don't have the time or inclination to work it out right now just holla at me and I'll hack it up for you.

///
/// NOTE: If a descriptor mixes time-based and height-based timelocks, the implementation of
/// this method MUST only allow timelocks of either unit, but not both. Allowing both could cause
/// miniscript to construct an invalid witness.
Copy link
Member

Choose a reason for hiding this comment

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

In d29c298:

nit: I would suggest

NOTE: this method must ONLY allow time-based or height-based relative timelocks, except for the value
zero which is valid as both a height or a time. Allowing both could cause miniscript to consruct an invalid
witness for descriptors which mix height- and time-based timelocks. (We do not consider such descriptors
to be "sane" but they can still be processed by this library, e.g. by using `parse_insane` to parse them.)

And same below (but change "relative" to "absolute").

But I'm not certain about the zero comment. Can somebody more familiar with timelocks check on that?

Copy link
Member

Choose a reason for hiding this comment

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

My main concern with the existing comment is that it doesn't make it clear that absolute and relative timelocks are considered separately; so you can have a height-based relative timelock and a time-based absolute timelock, for example.

Copy link
Member

Choose a reason for hiding this comment

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

Also, these comments are currently on Satisfier::check_older and Satisfier::check_after. Should they also be on the equivalent methods in AssetProvider?

#[derive(Debug, Clone)]
pub struct Plan {
/// This plan's witness template
pub(crate) template: Vec<Placeholder<DefiniteDescriptorKey>>,
Copy link
Member

Choose a reason for hiding this comment

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

In d29c298:

Maybe this was discussed in the other thread, but should we make this generic over Pk rather than using a DefiniteDescriptorKey?

@apoelstra
Copy link
Member

a358076 looks amazing! I appreciate the detailed type-guided API with structs like TaprootCanSign.

I haven't tried to use this yet so there may be pain points but reading the code, this looks great. My comments are only nits.

Copy link
Member

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

ACK a358076

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.

ACK a358076

I have quite a bit with this PR in Summer of bitcoin project with @Harshil-Jani who wrote some example programs using this API in #559. Thanks a lot for sticking with this PR for over a year :)

@sanket1729 sanket1729 merged commit 780dbc6 into rust-bitcoin:master Sep 22, 2023
16 checks passed
@tcharding
Copy link
Member

Party! This one was open for a long time huh.

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.

5 participants