-
Notifications
You must be signed in to change notification settings - Fork 492
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 CompactSize fundamental type #1062
Conversation
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.
Thanks!
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.
ACK 5b66a55, I verified the test vectors against eclair 👍
Will squash the fix up quick :) |
The CompactSize (compactsize) fundamental type is added to allow the use of Bitcoin consensus serialization where desired, for example, a list of witnesses. The definition is reproduced in BOLT 1 for convenience and necessarily matches that of CompactSize (VarInt), defined for Bitcoin at: https://en.bitcoin.it/wiki/Protocol_documentation#Variable_length_integer.
5b66a55
to
349353b
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.
ACK 349353b
Why not just use I think it would make sense only if people are actually taking the raw bytes, and stuffing it as raw bytes directly into some optimized sighash function. Otherwise, I'm assuming everyone would take the encoded witness, put the raw byte slice/vector into some struct, then use that to serialize the sighash, etc. |
The point is to be able to explicitly specify the bitcoin consensus encoding for structures such as witnesses in BOLTs (instead of just saying "encoding used in bitcoin"). It's not used for anything other than bitcoin types that need it. We want to avoid re-implementing (efficient) encoders/decoders for bitcoin types with |
No, this is wrong. If lightning has to deal with it, we'll use the same endian everywhere please. But, if we really just want a "witness blob" here which we don't deal with, we should use a simpler encoding:
You might use simple referential language like so:
|
This also works. If less explicit is fine then that's ok. |
@rustyrussell's suggestion works for me, this also makes the |
Great, closing this as we have no issues with it being defined with a reference. |
@dunxen can you open a PR on https://github.com/niftynei/lightning-rfc/tree/nifty/dual-fund to update the |
Modified the draft one I had there and made it ready for review at niftynei#14 :) |
Nice, I missed that you already had one open ;) |
The CompactSize (compactsize) fundamental type is added to allow the use of Bitcoin consensus serialization where desired, for example, a list of witnesses.
The definition is reproduced in BOLT 1 for convenience and necessarily matches that of CompactSize (VarInt), defined for Bitcoin at: https://en.bitcoin.it/wiki/Protocol_documentation#Variable_length_integer.
Note: Kept the test vectors and example test code the same as for BigSize, but just inverted the endianness. Checked against consensus serialization using
rust-bitcoin
locally. Thought it was better to keep things as explicit as possible, but I can remove something if it's a bit too redundant.Motivation: This is especially useful for cases such as for a list of witnesses mentioned above as seen in the
tx_signatures
message in #851. See here for more context.