8000 Make NodeInfo API public by sanket1729 · Pull Request #910 · rust-bitcoin/rust-bitcoin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Make NodeInfo API public #910

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 1 commit into from
Mar 28, 2022
Merged

Conversation

sanket1729
Copy link
Member

Reported by @shesek. Users might find it convenient to manually construct the tree using NodeInfo API

let leaf1 = NodeInfo::from_leaf_with_ver();
let leaf2 = NodeInfo::from_leaf_with_ver();

let root = NodeInfo::combine(leaf1, leaf2);
let spend_info = TaprootSpendInfo::from_node_info(&secp, internal_key, root);

@sanket1729 sanket1729 added the trivial Obvious, easy and quick to review (few lines or doc-only...) label Mar 27, 2022
@sanket1729
Copy link
Member Author

It is a fairly small change, but don't want to add anything else to the already pending rust-bitcoin release.

@dr-orlovsky
Copy link
Collaborator

I think this is needed for this release

dr-orlovsky
dr-orlovsky previously approved these changes Mar 27, 2022
Copy link
Collaborator
@dr-orlovsky dr-orlovsky left a comment

Choose a reason for hiding this comment

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

ACK d840614b1e71a8ad5f1c1702738003694eda610b

Regarding my nits, here and everywhere: I think the main challenge is to get ACKs, so all nits should be better addressed as a follow-up PR(s), if the author agrees with them - and not as a force-pushes discarding existing ACKs and taking reviewers time on non-important stuff once again.

fn from_node_info<C: secp256k1::Verification>(
/// Compute [`TaprootSpendInfo`] from [`NodeInfo`], and internal key.
/// This is useful when you want to manually build a taproot tree wihtout
/// using [`TaprootBuilder`]
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit:

Suggested change
/// using [`TaprootBuilder`]
/// using [`TaprootBuilder`].

/// Merkle Hash for this node
pub(crate) hash: sha256::Hash,
/// information about leaves inside this node
pub(crate) leaves: Vec<LeafInfo>,
}

impl NodeInfo {
// Create a new NodeInfo with omitted/hidden info
fn new_hidden(hash: sha256::Hash) -> Self {
/// Create a new [`NodeInfo`] with omitted/hidden info
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit

Suggested change
/// Create a new [`NodeInfo`] with omitted/hidden info
/// Creates a new [`NodeInfo`] with omitted/hidden info

Copy link
Member

Choose a reason for hiding this comment

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

nit: nit:

Suggested change
/// Create a new [`NodeInfo`] with omitted/hidden info
/// Creates a new [`NodeInfo`] with omitted/hidden info.

Self {
hash: hash,
leaves: vec![],
}
}

// Create a new leaf with NodeInfo
fn new_leaf_with_ver(script: Script, ver: LeafVersion) -> Self {
/// Create a new leaf [`NodeInfo`] with given [`Script`] and [`LeafVersion`]
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit

Suggested change
/// Create a new leaf [`NodeInfo`] with given [`Script`] and [`LeafVersion`]
/// Creates a new leaf [`NodeInfo`] with given [`Script`] and [`LeafVersion`]

8000
Copy link
Member

Choose a reason for hiding this comment

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

nit: nit:

Suggested change
/// Create a new leaf [`NodeInfo`] with given [`Script`] and [`LeafVersion`]
/// Create a new leaf [`NodeInfo`] with given [`Script`] and [`LeafVersion`].

Phew, docs are hard to do meticulously :)

let leaf = LeafInfo::new(script, ver);
Self {
hash: leaf.hash(),
leaves: vec![leaf],
}
}

// Combine two NodeInfo's to create a new parent
fn combine(a: Self, b: Self) -> Result<Self, TaprootBuilderError> {
/// Combine two [`NodeInfo`] to create a new parent
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit

Suggested change
/// Combine two [`NodeInfo`] to create a new parent
/// Combines two [`NodeInfo`] to create a new parent

Copy link
Member

Choose a reason for hiding this comment

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

As above.

@JeremyRubin
Copy link
Contributor

ACK

@sanket1729
Copy link
Member Author
sanket1729 commented Mar 27, 2022

This is good to have, but not mandatory! This can be emulated using the TaprootBuilder API. Don't necessarily want to make it release-blocking if it does have to be. I really want to get this release out before bitcoin 2022 at Miami.

@dr-orlovsky
Copy link
Collaborator

Well, it's quite trivial and requires just a single ACK more...

@dr-orlovsky dr-orlovsky added the one ack PRs that have one ACK, so one more can progress them label Mar 27, 2022
@tcharding
Copy link
Member

Regarding my nits, here and everywhere: I think the main challenge is to get ACKs, so all nits should be better addressed as a follow-up PR(s), if the author agrees with them - and not as a force-pushes discarding existing ACKs and taking reviewers time on non-important stuff once again.

I agree with you that all this re-acking is adding seemingly unnecessary work for reviewers.

Idea: what if we pushed the burden onto the merger instead of the dev or reviewer? By that I mean, merger could decide that changes since ACK where trivial (e.g., docs, non-logic-changing refactor) and therefore the ACK is still valid? That way if reviewer gets to the PR and wants to re-ack, fine, if merger gets to the PR and sees nit-only fixes, then fine too.

@sanket1729
Copy link
Member Author

Idea: what if we pushed the burden onto the merger instead of the dev or reviewer? By that I mean, merger could decide that changes since ACK where trivial (e.g., docs, non-logic-changing refactor) and therefore the ACK is still valid? That way if reviewer gets to the PR and wants to re-ack, fine, if merger gets to the PR and sees nit-only fixes, then fine too.

This is possible, but I think we should keep this to a bare minimum, comment fixes, variable renames etc. I don't think code move refactors fall here because that has a big diff. I would be okay in doing this if the diff is fairly small(< 10-15 lines) and no code changes.

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.

The NodeInfo struct is now public but the fields are private and there are no getters/setters, are users able to use this struct as expected? I noticed that non of the util::taproot types are re-exported out of util, is that what we want? I am about to try and do the 'add taproot example' issue, perhaps I'll add a bunch of rustdoc examples to the taproot module to test the public API?

/// Merkle Hash for this node
pub(crate) hash: sha256::Hash,
/// information about leaves inside this node
pub(crate) leaves: Vec<LeafInfo>,
}

impl NodeInfo {
// Create a new NodeInfo with omitted/hidden info
fn new_hidden(hash: sha256::Hash) -> Self {
/// Create a new [`NodeInfo`] with omitted/hidden info
Copy link
Member

Choose a reason for hiding this comment

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

nit: nit:

Suggested change
/// Create a new [`NodeInfo`] with omitted/hidden info
/// Creates a new [`NodeInfo`] with omitted/hidden info.

Self {
hash: hash,
leaves: vec![],
}
}

// Create a new leaf with NodeInfo
fn new_leaf_with_ver(script: Script, ver: LeafVersion) -> Self {
/// Create a new leaf [`NodeInfo`] with given [`Script`] and [`LeafVersion`]
Copy link
Member

Choose a reason for hiding this comment

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

nit: nit:

Suggested change
/// Create a new leaf [`NodeInfo`] with given [`Script`] and [`LeafVersion`]
/// Create a new leaf [`NodeInfo`] with given [`Script`] and [`LeafVersion`].

Phew, docs are hard to do meticulously :)

let leaf = LeafInfo::new(script, ver);
Self {
hash: leaf.hash(),
leaves: vec![leaf],
}
}

// Combine two NodeInfo's to create a new parent
fn combine(a: Self, b: Self) -> Result<Self, TaprootBuilderError> {
/// Combine two [`NodeInfo`] to create a new parent
Copy link
Member

Choose a reason for hiding this comment

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

As above.

@tcharding
Copy link
Member

I really want to get this release out before bitcoin 2022 at Miami

This! @apoelstra do you think we can do this, would be very cool but also even more pressure not to get egg on our face :) I think we can handle it, what do you rekon?

shesek added a commit to shesek/minsc that referenced this pull request Mar 27, 2022
For example:

    H_POINT+[
      pk(A),
      [
        `1 OP_ADD 2 OP_EQUAL`,
        0x51
      ]
    ]

Depends on rust-bitcoin/rust-bitcoin#910
@shesek
Copy link
Contributor
shesek commented Mar 28, 2022

Thanks! That's exactly what I wanted.

I wasn't able to test directly with this PR branch because I'm also using rust-miniscript which isn't compatible with rust-bitcoin's master (Prevouts "expected 1 generic argument"), but I was able to cherry-pick the changes on top of 0.28.0-rc1 and use the new public api in minsc.

With this in place, minsc now allows to construct custom taproot trees like in the first example (previously only huffman trees were supported, like in the second).

@tcharding
Copy link
Member

Legend @shesek, thank you.

This allows users to create TaprootSpendInfo using NodeInfo. This
offers an alternative to TaprootBuilder.
@sanket1729
Copy link
Member Author
sanket1729 commented Mar 28, 2022

The NodeInfo struct is now public but the fields are private and there are no getters/setters, are users able to use this struct as expected?

I have only made the minimal things pub so that the above example in the PR description works. Thankfully, Shesek is able to confirm that this works.

I noticed that non of the util::taproot types are re-exported out of util, is that what we want?

I don't have super strong opinions about this. But I have a preference that these should be re-exported from util. If we have an established convention, I would be happy to adhere to it. So far, I see some things are re-exported out of util and some are not (eg sighash module). I also support pub use util::* in lib.rs.

I am about to try and do the 'add taproot example' issue, perhaps I'll add a bunch of rustdoc examples to the taproot module to test the public API?

Yes, please. I will also make a point to add rustdoc examples for future APIs. They are really handy.

@sanket1729
Copy link
Member Author

Force pushed again addressing all the doc-comment nits.

@tcharding
Copy link
Member

ACK all the docs stuff, I have more docs fixes for the taproot module queued up. From my perspective we can put this one in and I"ll rebase on top of it. FTR I hadn't done that PR this morning when I requested changes on this one :) Thanks.

Copy link
Collaborator
@dr-orlovsky dr-orlovsky left a comment

Choose a reason for hiding this comment

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

ACK 208eb65

@dr-orlovsky
Copy link
Collaborator

@shesek I did a PR rust-bitcoin/rust-miniscript#324 that brings miniscript on the version of rust-bitcoin having all RC fixes merged, such that downstream can test and fix all APIs. Even if non-merged RC-fix PRs here will be modified, it will be a very tiny changes.

So, you can add this section to all of your projects:

[patch.crates-io]
bitcoin = { git = "https://github.com/LNP-BP/rust-bitcoin", branch = "canary" }
miniscript = { git = "https://github.com/LNP-BP/rust-miniscript", branch = "canary" }

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 208eb65

Yeah, we can get a release out before Miami. I think today?

@apoelstra apoelstra merged commit 10949b7 into rust-bitcoin:master Mar 28, 2022
shesek added a commit to shesek/minsc that referenced this pull request Apr 5, 2022
For example:

    H_POINT+[
      pk(A),
      [
        `1 OP_ADD 2 OP_EQUAL`,
        0x51
      ]
    ]

Depends on rust-bitcoin/rust-bitcoin#910
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
one ack PRs that have one ACK, so one more can progress them trivial Obvious, easy and quick to review (few lines or doc-only...)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
0