Repository navigation
BIPs 455–457: SwiftSync Specification - #2152
rustaceanrob wants to merge 3 commits into
Conversation
murchandamus
left a comment
There was a problem hiding this comment.
Just a quick first glance, but could you please break your text into shorter lines? That makes it easier to leave review and track what changed between commits. Either 100 or 120 characters per line seems to work well enough.
|
FWIW, I don't mind the unbroken lines and even prefer them. Avoids rejigging line lengths to keep them consistent when updating or having lines with very different lengths. |
danielabrozzoni
left a comment
There was a problem hiding this comment.
I did an initial pass and left some comments. I read the BIPs in the commit order (block undo -> histfile -> swiftsync) and it was pretty easy to follow.
jurraca
left a comment
There was a problem hiding this comment.
some writing nits but overall the concept is clear enough.
92093e1 to
f4cd99a
Compare
|
Thanks for the review, @danielabrozzoni and @jurraca, as well as the quick turnaround @rustaceanrob. I notice that this pull request is still marked as a Draft PR. Are you still planning significant changes? If your submission is ready for another BIP Editor review, please mark the PR as "ready for review". |
|
I will keep these as a draft as the hintsfile format is subject to change. |
| | Amount | 64 bit unsigned integer | Defined above | Satoshi denominated value | | ||
| ### Messages | ||
|
|
||
| #### MSG_GET_SPENT_COINS |
There was a problem hiding this comment.
Is the idea that a peer would issue this request for every block in the chain? If we assume mainnet at height, and a 150 ms round trip time, then a peer would spend nearly 80 hours just downloading this undo data.
You may want to consider a batched variant, similar to the way messages like getheaders works.
There was a problem hiding this comment.
We've found that bandwidth throughput is the limiting factor when downloading blocks in parallel. Not all spent coins have to be downloaded if a client keeps a cache, as this document describes. In the batched variant, the cache is not possible and the bandwidth requirement increases significantly.
|
|
||
| | Field | Value | | ||
| | :----------------- | :---------- | | ||
| | `NODE_BLOCK_UNDO` | `1 << ???` | |
There was a problem hiding this comment.
Rationale should be added for the choice of a new node version over the more common place (as of the past few years) exchange of a sendX message during the version handshake.
IMO a version makes sense here, as it can be used to filter out peers upfront that support sending this undo data over the network.
There was a problem hiding this comment.
I opted for a BIP-434 feature message, which has a similar mechanism for the sendX
|
|
||
| #### MSG_SPENT_COINS | ||
|
|
||
| `MSG_SPENT_COINS` defines the data structure for inputs of a block. |
There was a problem hiding this comment.
Probably not really y'all's intended use case, but if you optionally make it possible to include merkle proofs for the set of coins, then this message can be used to obtain a proof that an output was spent in a given block.
There was a problem hiding this comment.
It would actually also be useful for BIP 157+158 peers, as the final version that shipped includes the script spent (instead of the outpoint), which means that if you're using the filters to find a block where a given script has been spent, you need to make some assumptions about what the prev script is for a given transaction.
There was a problem hiding this comment.
The most recent response on this mailing list post mentions commitment to the UTXO set as part of the block header. There are additional ways to do this outside of a soft fork as well, i.e. utreexo proofs. For now I think it best to leave this unspecified in this version of the message while the community shares ideas, but I do think this is interesting.
f4cd99a to
e4f8172
Compare
|
Wrapped text and standardized formatting with |
|
Great, thanks! I’ll give it a read when you’re done with that. |
hintsfile.js implements the SwiftSync hintsfile (bitcoin/bips#2152 'Hints for unspent coins'): per-block unspent output indices encoded with Elias-Fano (CompactSize(n) || CompactSize(m) || L || H; low bits LSB-first, unary gap high bits), plus the 'UTXO' magic/version/height/vector container. This is the ONE cross-compatibility artifact (per Somsen), so it's validated byte-for-byte against the BIP's own elias_fano.json vectors — all three match, plus round-trips, edge cases, and a container round-trip. Exported from index + package exports (./hintsfile).
…matches BIP vectors undo.js implements the full-validation spent-coin data (bitcoin/bips#2152 'Peer sharing of block spent coins'): Core's CompressAmount/DecompressAmount, the reconstructable-script prefix table (P2PKH/P2SH/P2PK/P2WPKH/P2WSH/P2TR/raw), the height code (height<<1|coinbase), and a spent-coin record. Amount + script compression validated byte-for-byte against the BIP's compressed_amount.json and reconstructable_script.json vectors (+ round-trips). Also factored CompactSize/concat into varint.js, shared by hintsfile + undo. Full suite: 21 pass / 0 fail.
e4f8172 to
e5ec578
Compare
|
Given there are a few clients that have started implementations of SwiftSync, and new hintsfile encodings may simply increment the file version, I am moving these out of draft. Some outstanding comments addressed, others require some additional thought. |
24ae4e7 to
ecbda2a
Compare
edilmedeiros
left a comment
There was a problem hiding this comment.
Thanks for documenting the protocol in this draft.
Did a deep dive together with the guys from @vinteumorg and left many comments concerning conceptual aspects of the BIPs. I have many editing suggestions, but left them for a second round after the higher-level aspects are more mature.
| in Bitcoin Core, and reasonable for most clients to hold directly in memory. This encoding represents elements in $2n + | ||
| n \\lceil \\log_2(m/n) \\rceil$ bits, which is within a reasonable bound of the theoretical optimum. | ||
|
|
||
| Partitioning the hints by block is an intuitive choice, and allows for efficient random access of hints. Groupings of |
There was a problem hiding this comment.
Partitioning the hints by block is an intuitive choice, and allows for efficient random access of hints.
I don't see how this can be true: the bistream has a header (magic, version, height) followed by a sequence of EliasFano items, each of which are composed by N, M (fixed size info), L, H (variable size info).
So, imagine I have a hintsfile. To find data for block k, one do need to (minimally) process data for block 1 to discover the size of the first EliasFano item (because of the variable size parts). Then, block 2 and so forth, until the intended block target. This would be true if the EliasFano items were fixed size among all blocks to allow for offset arithmetic, but the amount of padding would be prohibitively high.
Thus, the hints payload works more like a List<EliasFano> (requires sequential access) than a vector<EliasFano> (allows random access). Of course, the decoder could create an index of offsets, but this is not only an implementation detail, but also something that will add to the required resources to process the hintsfile.
There was a problem hiding this comment.
Good catch, the original version had a header section, but was removed as it could be reconstructed as you described. I will remove that note.
There was a problem hiding this comment.
I wonder if having more blocks taken together will not improve compression sensibly (I'll experiment with it). We can add a counter in the bitstream to allow the encoder to choose it freely (at the cost of having more bytes in the bitstream) but we potentially gain:
- Less
H, Lpairs in the bitstream. - More data to feed to the Elias-fano process (tends to push it closer to the theoretical entropy).
3631bcb to
0776320
Compare
|
Updated |
|
Thanks, looks great |
|
Going though a round of review now. Sorry for being lagging behind this days. |
aa09bb0 to
35d283a
Compare
|
@murchandamus about bip 456, I reworked the document to address your comments:
You didn't mentioned specifically, but I also made the variables names more consistent among the mathematical notation and code ( Added this to a separate commit to make the review (and rollback, if needed) easier. Can squash before merging. |
|
Thanks @edilmedeiros sounds great. I’m going to take another look soon. |
murchandamus
left a comment
There was a problem hiding this comment.
I gave BIP455 another read. I did not compare in detail to the previous feedback, but it was a smooth read and looks great. I just have a few nits.
35d283a to
4ab9455
Compare
Fixed those, thanks. |
edilmedeiros
left a comment
There was a problem hiding this comment.
Just noticed we are lacking BIP324 message type definitions in these two spots. I prefer to let @rustaceanrob pick them. Happy to do the rebase stuff if you just want to put them in this chat.
|
I think it makes sense to just use the next in the sequence, so 38 and 39 for |
murchandamus
left a comment
There was a problem hiding this comment.
I gave BIP456 and BIP457 another full read. Well done, I don’t have any additional remarks beyond noticing that the todos that @edilmedeiros raised still seem to be unaddressed and there being a merge conflict on the README.mediawiki.
|
|
||
| Inputs of a Bitcoin block are referenced by the outpoint data structure. This commonly poses a limitation during initial | ||
| block download (IBD), such that a client must process blocks sequentially to validate the chain history. The SwiftSync | ||
| protocol allows blocks to be evaluated in arbitrary order, however additional data is required that must be served over |
There was a problem hiding this comment.
I think it should be mentioned that there is more than "additional data" required to reap the aforementioned benefit of this proposal. Namely, that this enhancement requires the transmission of a new file (a hints file) from an un-trusted source. As the Abstract, Motivation and Specification and remainder of document read, you may be lead to believe that no such hints file is needed, which makes the entire spec incomprehensible from a high-level without at least mention of this detail.
|
Going to rebase and squash with after addressing some todos next week. Thanks for the re-read @murchandamus! |
4ab9455 to
b5a69cb
Compare
Co-authored-by: Edil Medeiros <[email protected]>
b5a69cb to
3613b09
Compare
Co-authored-by: Edil Medeiros <[email protected]>
Co-authored-by: Edil Medeiros <[email protected]>
3613b09 to
6da605e
Compare
murchandamus
left a comment
There was a problem hiding this comment.
This jumped out at me, looking at the diff from the prior version. Will take another look when I get back to a computer.
| Bitstrings are serialized to bytes by packing bits least-significant-bit first: bit $j$ of a bitstring is stored at bit | ||
| position $j \bmod 8$ of byte $\lfloor j / 8 \rfloor$, where bit position 0 is the least significant bit of a byte. Any | ||
| unused bits in the final byte are set to `0`. |
There was a problem hiding this comment.
It’s probably mostly a me-issue, but I had to read lines 126–128 five times to grok what you mean with the first sentence.
My first attempt at feedback was “Huh, bitststrings don’t have ‘least-significant-bits’ because they are not numbers?!”.
I thought that least-significant-bits was referring to the “last bit of the bitstring” and figured that if I were to put the last bit of the bitstring as the first bit of a byte, for a bitstring 111100 the byte would start with 001111…. If that were zero padded, 111100 would become 0x3C (the last bit 0 becomes the first bit of the byte, followed by another 0, then the four ones, and then two zeros padding are added).
The more formal explanation that follows is clearer, but it’s not obvious to me whether byte 0 would refer to the left-most or right-most byte. Presumably, the right most?
After several reads, and comparing to the examples in lines 171–172, I now interpret the first sentence as:
Bitstrings are serialized to bytes by putting the first bit of the bitstring into the the least-significant-bit of the last byte, the second bit into the next-least-significant-bit, etc.
I was unable to clarify the byte order, because all example bitstrings are fewer than 8 bits.
Do I understand right, that right-padding the bitstring with zeroes to the next multiple of 8, and then populating the bytes with the reverse would be equivalent to what you are specifying?
Given what a mess Bitcoin is regarding endianness, perhaps the phrasing here could be clarified?
There was a problem hiding this comment.
To say it more concisely, this bit seems ambiguous to me regarding byte-order and serialization. How would a bitstring 11010010001 be serialized as bytes? 0x084b, 0x4b08, or something else again?
There was a problem hiding this comment.
For this example, here's what I have in mind:
- Split
11010010001into 8 bit portions11010010001 - Pad
001to00100000 - Iterate those chunks, staring with
11010010 - Pack the bits in LSB order into the byte, which gives
0x4B - Do it again for
00100000, which I get0x04(one power of two different than0x08in your outcomes)
I decided to add this because I was packing MSB for no particular reason in the reference implementation, which of course leads to a different encoding. I thought it best to be thorough here. How does this sound?
LandHare bitstrings. Throughout this document, a bitstring is serialized to bytes least significant bit first:
bit$j$ of a bitstring is stored at bit position$j \bmod 8$ of byte$\lfloor j / 8 \rfloor$ , where bit position 0 is
the least significant bit of a byte, bytes are serialized in ascending order, and unused bits of the final byte are
set to0. For example, the bitstring11010010001is serialized as the two bytes0x4B 0x04.
SwiftSync is a protocol for clients to parallelize initial block download, based on the original writeup.