Taproot-related 0.28.0 RC2 fixes#922
Taproot-related 0.28.0 RC2 fixes#922dr-orlovsky wants to merge 12 commits intorust-bitcoin:masterfrom BP-WG:taproot/rc2-fixes
Conversation
LeafInfo structure is a useful form of representing leaf script information (script, leaf version and merkle proof).
Previously used depth and script tuple missed information about the leaf version. All three comprises already existing type `LeafInfo` which was made public in previous commits.
|
@dr-orlovsky, are any of these really really needed? I don't think there is anything that you cannot do downstream. This is not a bug in RC. These are clearly new features that we can add later. I am saying this because these are non-trivial changes to review. I disagree with some of them (make an API for I know it might long for the next release, but as @tcharding said we can do another taproot fixes release soon after. This release does not need to perfect, but it needs to happen soon. If we don't release this before Friday, we will have to wait another 7-10 before the release. |
| impl TapTree { | ||
| /// Convenience method to retrieve number of script leafs in the tree. | ||
| #[inline] | ||
| pub fn scripts_count(&self) -> usize { |
There was a problem hiding this comment.
I think we should implement ExactSizeIterator instead of Iterator
| pub(crate) ver: LeafVersion, | ||
| // The merkle proof(hashing partners) to get this node | ||
| pub(crate) merkle_branch: TaprootMerkleBranch, | ||
| pub struct LeafInfo { |
There was a problem hiding this comment.
I am not sure this is easy to review. I agree that this might be good to have, but I will need to review whether allowing setting member fields from the user can break weird invariants in the builder.
What if the user creates Merkle proofs for two different leaves that are not a part of the same tree. In general, even tough making something pub is simple change, making it's members public requires new reasoning and re-reviewing all previous code.
There was a problem hiding this comment.
Yes, better to provide an accesor methods.
| // Compute a leaf hash for the given leaf | ||
| fn hash(&self) -> sha256::Hash { | ||
| /// Compute a leaf hash for the given leaf | ||
| pub fn hash(&self) -> sha256::Hash { |
There was a problem hiding this comment.
Earlier this was okay to return sha256::Hash because it was internal used now. Now this should return TapLeafHash
|
|
||
| impl TapBranchHash { | ||
| /// Computes branch hash given two hashes of the nodes underneath it. | ||
| pub fn from_node_hashes(a: sha256::Hash, b: sha256::Hash) -> TapBranchHash { |
There was a problem hiding this comment.
This is unsafe, we have a taproot hashjes type system(LeafHash/NodeHash) for a reason. This code can be mis-used. As such I don't see any reason why this code needs to be public.
There was a problem hiding this comment.
There are three main hashes in taptree hash type system:
TapLeafHash, which is for the script leaf,TapBranchHash, which is for the script branch,sha256::Hash, when we do not known what it is (branch or a leaf, i.e. hidden nodes).
I am following that convention here. And of course, we can have a type alias for sha256::Hash, like TapNodeHash.
But I do not see how this breaks the existing type system in taproot module.
|
In your mind @dr-orlovsky can we do a |
|
I have removed RC label. I am up for the release ASAP. |
Thanks a lot |
4cdff06 Add convenience method TapTree:to_builder (Dr Maxim Orlovsky) a12e7c7 Implement From<TapTree> for TaprootBuilder (Dr Maxim Orlovsky) 410412f Rename TapTree::from_builder (Dr Maxim Orlovsky) 2192737 Rename TapTree::into_builder (Dr Maxim Orlovsky) f9d8d0d Make TapTree::node_info public (Dr Maxim Orlovsky) Pull request description: These are trivial fixes from extracted from now closed #922 ACKs for top commit: Kixunil: ACK 4cdff06 sanket1729: ACK 4cdff06 apoelstra: ACK 4cdff06 Tree-SHA512: 6132e8c214edc6f199a5550309daf4ed5035f24f545c793d6396c393bd2f55940dc418af62aed9aff25c0c90b74ee384ace986f7201db4018c6fd52710006126
I m collecting here different fixes which are really useful downstream while I am playing with Taproot implementation in my projects.
Once I will have everything downstream working I will remove this PR draft status.