Review this, is it accurate, are there errors:
I connected two Bitcoin Core nodes running on mainnet, one prefilling transactions to a node that only received CMPCTBLOCK announcements from its prefilling peer. Even though the intended effects of prefilling transactions are network-wide, and it would be nice to have some more complicated topologies and scenarios tested in e.g. Warnet, this basic setup can be used to validate some of the basic assumptions of the effects of prefilling:
- Does prefilling work to prevent failed block reconstructions that otherwise require
GETBLOCKTXN->BLOCKTXN roundtrips, irrespective of the cost of prefilling?
- Does prefilling result in a net reduction on block propagation times?
Latency and Bandwidth
Taking a simplified view, the latency for a receiver to hear an unsolicited message (the scenario we care about in block relay) consists of
transmission delay plus propagation delay:
Latency≈BandwidthData+∼21∗Round-trip time
Any time compact block reconstruction fails because the receiver was missing transactions, an additional round-trip-time (RTT) of requesting missing transactions and receiving them (GETBLOCKTXN->BLOCKTXN) must be paid in order to complete reconstruction. Where f is the probability for a block to fail reconstruction:
Latency≈BandwidthData+∼2
If we had perfect information about the transactions our peer will be missing, we should always send these along with the block announcements since we will pay basically the same transmission delay, minus the unnecessary round-trip. If we don't have perfect information, then the worst we can do is send transactions which our peer already knew about, while not sending them transactions they didn't know about, incurring the RTT anyways, plus the transmission time of the redundant data. Let's say we send p extra prefill bytes, with each byte having a probability n of being redundant and prefilling p bytes gets us a reconstruction failure probability of fp, then:
Latency≈BandwidthData+Bandwidth
Thus, in order in order for prefilling latency to be better than or equal to no-prefilling latency:
Bandwidth∗RTTp∗n≤f0
If latency while prefilling is less than or equal to latency without prefilling, where b is bandwidth, r is the RTT, d is the size of the CMPCTBLOCK without prefill, p is the size of the prefill, and fp is the reconstruction failure rate at a given prefill size :
bd+bpn
Subtracting the common terms bd and 21r from both sides:
bpn+fpr≤f
Subtracting fpr from both sides:
bpn≤f0r−f
Dividing both sides by r:
brpn≤f0−
If we plug in some example values, prefilling 10KiB with a bandwidth of 5 MiB/s and an RTT of 50ms (.050s) and use a worst case n of 1
5MiB/s∗0.050s10KiB∗1=0.0488
In this case, if prefilling improves reconstruction rates by at least 4.9% it is definitely better than not prefilling.
Takeaways
I don't think proving that the above formula is satisfied is necessary for a prefilling solution, what I think it's useful for is building an intuition of the problem, and setting theoretical boundaries on how effective prefilling needs to be to be worth it.
- Nodes are likelier to suffer rather than benefit from prefilling that have smaller Bandwidth∗RTT (See Bandwidth-delay product (BDP) connections: e.g. nodes with low bandwidth and low ping. And nodes that have connections with large BDP's are likelier to benefit, e.g. high-bandwidth, and high-latency ("Long Fat Networks" as described in RFC 7323)
- If the redundant broadcast probability n is zero, prefilling is always worth it.
TCP windows and the costs of prefilling.
But, the use of TCP in the Bitcoin P2P protocol complicates this, because a sender will not send data exceeding the TCP window size in a single round-trip. Instead, they will send up to the window size in data, wait for an ACK from the receiver, and then send up to window bytes after the data which was ACKed. That means that if we exceed a single TCP window, we will have to pay an additional RTT in propagation latency (and a little bit of transmission latency for the overhead). And for each additional window we overflow, we will pay another RTT:
TCP Latency≈BandwidthData+∼
Note ⌊a⌋ meaning std::floor(a)
Doing a similar dance as above, where p is the prefill size and fp is the probability of reconstruction failure at prefill size p, and n is the probability of a prefill byte being redundant:
Bandwidth∗RTTp∗n≤f
Overflowing current TCP window is always worse than doing nothing
The above formula establishes as a rule something which might have been intuited, that if the prefill causes us to exceed the current TCP window, then we will always do worse than if we hadn't prefilled, since:
- f0−fp≤1 since the smallest number f can be is 0, and the largest number can be is 1.
But, if we bound our prefill p so that we never increase the number of TCP windows used, i.e.: ⌊Window SizeData⌋−⌊ which, I believe is to do, we can use the exact same formula as above to decide whether or not prefilling is effective:
Bandwidth∗RTTp∗n≤f0
Complication: TCP Retransmission
So far, U have assumed perfectly reliable networks and this isn't always the case, packets do get lost. But, I believe the problem above I've described in relation to prefilling is very similar to the problem that the designers of TCP had in selecting a static window size, and later, dynamic window sizes through congestion control algorithms those described in RFC 5681 and RFC 9438. Instead of the probability that a block reconstruction will fail, they deal with the probability that a packet will not arrive, in both cases, the consequence is an additional round-trip, and a core question is whether the marginal value of potentially saving a round-trip by packing in more data, is worth the risk that retransmission will be necessary anyways (or re-routing around low-quality connection). There are many other considerations for TCP congestion control algorithms, but I argue that we can outsource this question to the operating system's congestion control implementation, and trust that the congestion window provided by the operating system for a connection is a message size that is unlikely to lose any packets.
Observation Setup
I connected a prefilling node to a prefill-receiving node, both with additional logging to measure things like TCP window sizes, and recorded measurements over 20 days1
Prefilling node
I ran one node with 0xB10C's prefilling branch(0xB10C/2025-03-prefill-compactblocks) with some additional logging (davidgumberg/06-18-2025-0xB10C-prefill-branch-with-logging)
In summary, the prefilling node, during compact block reconstruction, identifies as prefill candidates transactions that were in the block and not in its mempool. When sending CMPCTBLOCK's, it passes the prefill candidates in the PrefilledTransaction structure of the CMPCTBLOCK announcement, described in BIP-0152. Presently, PrefilledTransaction is only used by Bitcoin Core to prefill coinbase transactions.
Prefill-receiving node
I ran another node on a branch which will only ask for and listen to CMPCTBLOCK announcements from manually added peers (https://github.com/davidgumberg/bitcoin/commits/5-20-25-cmpct-manual-only/). I made a manual connection from this node to the prefilling node, this node doesn't do any prefilling, but like every Bitcoin Core node today, it will parse and use PrefilledTransaction's that it receives. No changes are required for nodes to enjoy the benefits/drawbacks of prefilling that their peers do, but I modified this node in order to measure the effects of receiving prefilled blocks in isolation.
Config