-
Notifications
You must be signed in to change notification settings - Fork 156
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
ZIP 302: Structured memos #638
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.
ACK
zip-0302.rst
Outdated
+ Interpret the next few bytes (1 to 9 of them) as a 64-bit unsigned variable-length | ||
integer [#Bitcoin-CompactSize]_, and use it as an arbitrary application-defined | ||
"type" field. | ||
+ Interpret the next 1 or 2 bytes as a CompactSize value constrained to the range 0..510, and use |
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.
Strictly speaking this can't be more than 507, because the 0xF5 || type || length is encoded as at least 3 bytes for length <= 252 and 5 bytes for lengths > 252, therefore the maximum is 512 - 5. But it's correct as stated because we only need a conservative upper bound.
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’s probably not worth squeezing out the extra couple bytes, but we could store 512 - length
instead of storing length
, which gets us a range 0..509, so then payloads over 260 bytes only require one byte for the “length”, and smaller payloads require three (which they aren’t using anyway).
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 think the ZIP mixes up the encodings it mentions – the type is stored as CompactSize (1–9 bytes), and the length is stored as VarInt (which fits a value of 508 in 2 bytes, not 3). I found https://bitcoin.stackexchange.com/a/114585, which explains the encodings better than the Bitcoin docs do.
However, just using a regular 2-byte length
- also leaves 508 bytes for the memo;
- is simpler; and
- is consistent with the nested type || length in [ZIP ???] Multipart Memos #247, which says “Total length of encoded multipart memo (2 bytes, as a 16-bit little-endian integer)”.
The multipart length obviously gets no benefit from a variable-length encoding, so I think we should just use a non-variable length 2-byte uint here as well.
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
In ZIP Sync today, we decided that:
|
ef5529a
to
2824c4b
Compare
I've replaced the old contents of this PR (which just reverted the prior content that was removed from the original ZIP 302 PR) with an initial draft following what was decided in ZIP Sync almost 2 years ago. |
2824c4b
to
ff9b60e
Compare
No description provided.