-
Notifications
You must be signed in to change notification settings - Fork 496
Migration to new bitcoin hash type system; bumping to the latest rust-bitcoin release #238
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
Conversation
All types are replaced; only work on merkle types left, which requires addition of the code
This commits contains fixes to merklization function arguments and return types. New hash type system from bitcoin crate does not cover all cases for merkle values; and the same function may be applied to different hash types. Thus, I have used generic types to abstract the logic. `Txid` merklization operates with TxMerkleNode type; `BlockHash` merklization does not introduce a new type: the same design decision was made in the original work on new bitcoin crate type system since it is used in a single case, and there is no point in introducing a special designated hash type. Script hashes (used in RPC queries) are left of Sha256dHash type since there is no corresponding type defined in bitcoin crate; this type is specific to Electrum X protocol. Corresponding new type can be implemented in the project later with `hash_newtype!` macro in the same way it was done in bitcoin crate.
d71e14a
to
0ccdf44
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
let tx_nodes: Vec<TxMerkleNode> = txids | ||
.into_iter() | ||
.map(|txid| TxMerkleNode::from_inner(txid.into_inner())) | ||
.collect(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this allocation, but removing it is not trivial. I might look at it later and see if I can optimize it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I think it will be nice to have direction conversion functions for such cases which are optimized by performance – and make them part of the hash type system in rust-bitcoin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking more in terms of replacing vecs with iterators, but not really sure how applicable it is in this case. I managed to refactor those in the past, so I might try again. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that have to be a PR to rust-bitcoin though...
Many thanks for the contribution, much appreciated! |
After my work on new bitcoin crate hash type system last year rust-bitcoin/rust-bitcoin#349 I find many project depending on the upstream
bitcoin
crate being unable to update to the latest version without spending a lot of effort on type replacements (plus some additional code editing in cases like merklization). Due to my work on adding support to Signet (which was implemented in rust-bitcoin fork containing the new type system) I had to do this work, so I propose it for your consideration as a PR here. Pls review it before significant changes to the master, since it will take many hours of my time again to do any rebase, which I do not have.New hash type system from bitcoin crate does not cover all cases for merkle values; and the same function may be applied to different hash types. Thus, I have used generic types to abstract the logic.
Txid
merklization operates with TxMerkleNode type;BlockHash
merklization does not introduce a new type: the same design decision was made in the original work on new bitcoin crate type system since it is used in a single case, and there is no point in introducing a special designated hash type."Script hashes" met through the code are in fact has nothing to do with P2SH script hashes and
ScripHash
type; but instead are custom pubkeyScript hashes used in RPC queries. This data structures are left of Sha256dHash type since there is no corresponding type defined in bitcoin crate; this type is specific to Electrum X protocol. Corresponding new type can be implemented in the project later withhash_newtype!
macro in the same way it was done in bitcoin crate.