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 "sortedmulti" descriptor support #171

Merged
merged 1 commit into from Nov 11, 2020

Conversation

justinmoon
Copy link
Contributor

@justinmoon justinmoon commented Nov 6, 2020

Closes #164

src/descriptor/mod.rs Outdated Show resolved Hide resolved
src/descriptor/mod.rs Outdated Show resolved Hide resolved
src/descriptor/mod.rs Outdated Show resolved Hide resolved
src/descriptor/mod.rs Outdated Show resolved Hide resolved
src/descriptor/mod.rs Outdated Show resolved Hide resolved
src/descriptor/mod.rs Outdated Show resolved Hide resolved
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.

Awesome, thanks for doing this. There had been lot for support of this descriptor.

The PR looks clean, left a couple of remarks.
The CI failures are because of rust MSRV 1.29

@justinmoon justinmoon force-pushed the sortedmulti branch 3 times, most recently from 1c09823 to e09d8f8 Compare November 8, 2020 20:27
src/lib.rs Outdated Show resolved Hide resolved
@justinmoon
Copy link
Contributor Author

@sanket1729 Thanks for your review. Addressed the comments that I could and got CI passing.

src/descriptor/mod.rs Outdated Show resolved Hide resolved
src/descriptor/mod.rs Outdated Show resolved Hide resolved
src/descriptor/mod.rs Outdated Show resolved Hide resolved
src/descriptor/mod.rs Outdated Show resolved Hide resolved
let mut pks: Vec<bitcoin::PublicKey> =
self.pks.iter().map(|pk| pk.to_public_key()).collect();
// Sort pubkeys lexigraphically according to BIP 67
pks.sort_by(|a, b| a.to_string().partial_cmp(&b.to_string()).unwrap());
Copy link
Member

Choose a reason for hiding this comment

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

Then with the above, this should just become pks.sort_by_key(Bip67Sorted).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did you mean pks.sort_by_key(|pk| Bip67Sorted(pk))?

According to the docs, the argument to sort_by_key needs to be FnMut, which we haven't implemented.

If I use a lambda, then it complains that return value of Bip67Sorted(pk) may outlive pk ... not sure how to fix that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it would be best to just use this for now:

pks.sort_by(|a, b| {
    a.to_public_key()
        .serialize()
        .partial_cmp(&b.to_public_key().serialize())
        .unwrap()
});

But get the upstream change merged and switch to pks.sort() as soon as upstream change is released.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't make sense to create a new public struct to implement behavior that should be in rust-libsecp256k1

Copy link
Member

Choose a reason for hiding this comment

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

pks.sort_by_key(|pk| Bip67Sorted(pk)) is identical to pks.sort_by_key(Bip67Sorted) except the latter uses fewer symbols. And struct constructors always implement all of the Fn traits.

Using a lambda or not should have no effect on this. What is the error you are getting?

Copy link
Member

Choose a reason for hiding this comment

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

I can reproduce the lifetime error. The issue is that sort_by_key and sort_key_cached_key have their lifetimes set incorrectly by stdlib, so we do indeed need to use sort_by

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh sorry, should have posted the full error message.

Copy link
Member

Choose a reason for hiding this comment

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

Unresolving this for now since there is opposition from upstream to including a nonsense Core ordering in rust-bitcoin.

src/descriptor/mod.rs Outdated Show resolved Hide resolved
src/miniscript/context.rs Outdated Show resolved Hide resolved
@justinmoon
Copy link
Contributor Author

justinmoon commented Nov 10, 2020

Thanks for the review @apoelstra. I added a few commits addressing most of your comments.

Commit messages aren't very good because I imagine I'll squash all these commits once we're done making changes?

src/descriptor/mod.rs Outdated Show resolved Hide resolved
@apoelstra
Copy link
Member

Ok @justinmoon can you rebase on master and squash everything? You can break up all the commits however you want ... one big commit is fine ... but please make sure that every commit compiles by itself.

@justinmoon
Copy link
Contributor Author

justinmoon commented Nov 11, 2020

Rebased and squashed to one big commit

@apoelstra apoelstra merged commit 62d07d5 into rust-bitcoin:master Nov 11, 2020
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.

Support for sortedmulti descriptor script expression?
3 participants