Priority-fill block relay: fewer orphans under 25 s blocks, no fork needed (ZECATHON Submission)

Hi all,

With NU7 moving Zcash to 25-second blocks on 5 November (ZIP 218), how fast a block crosses the network becomes a much bigger share of each block interval, and with it the orphan rate. I’ve been looking at one part of block relay nobody seems to have discussed yet: the order in which a node uploads a new block to the peers that ask for it. I’ve written it up as a discussion paper with a testbed and a live simulation, and submitted it to ZECATHON. I’d really value feedback, especially from the Zebra team.

The idea in one paragraph

Today a Zebra node uploads a new block to every peer that asks for it in parallel, as the requests arrive. Concurrent uploads share its bandwidth evenly through TCP, so every copy finishes late, at about the same moment, and nobody can pass the block on until then. Priority fill serves the peers most likely to relay the block onward first, ranked by the throughput the node has measured from them, at full speed, and fills any spare upload with the next peer in line. Peers that stall are demoted. It’s local to each node: no new messages, no consensus change, no hard or soft fork, no extra bytes.

What I measured

  • 100-node testbed built on Zebra’s own zebra-network code (real handshake, codec, peer set, inventory routing and gossip loop), emulated home and datacenter links, 2 MB blocks every 25 s: the estimated stale rate fell from 10.0% to 3.6%, and blocks reached other miners in a median 0.82 s instead of 2.67 s.
  • 1,000-node model with Poisson block arrivals, which counts orphans directly: 16.2% of blocks orphaned under today’s relay vs 6.0% with priority fill. Most orphans come from blocks found within seconds of each other: 64% of those were orphaned today vs 26% with priority fill.
  • Mining centralisation: a pool never orphans its own blocks, so orphans favour big pools. In the model, a 46% pool’s revenue edge over a 1% pool falls from 7.3% to 2.7%.

What it costs

  • It needs learned rankings: freshly started nodes recovered only about a quarter of the gain.
  • The slowest 10% of nodes don’t gain; home nodes rank low and wait in upload queues.
  • Rankings can be gamed. Ten slow-reading attackers delayed the slowest nodes by 0.8 s. A demotion rule (a stalled upload gives up its slot and its rank) cut that to 0.4 s: blunted, not removed.
  • It adds state and tuning to a security-critical path.

Things I want to be upfront about

  • The testbed’s priority-fill runs also announced relayed blocks to every peer rather than Zebra’s random third. For freshly started nodes this made no measurable difference, and the 1,000-node model keeps one-third announcements and still shows most of the gain. But steady state with one-third fanout hasn’t been tested on Zebra’s code.
  • Poisson block arrivals haven’t been run on Zebra’s code yet: my single-machine testbed ran out of memory when blocks overlapped. The Poisson results come from the model, which matches the testbed when run at 100 nodes.
  • The models assume full 2 MB blocks, equal-hashrate miners and no compact blocks, so absolute numbers run high (the model orphans 5.2% at 75 s, where mainnet sees about 0.4%). Read them as direction and rough size.

A separate, simpler finding

zebrad’s gossip loop waits PEER_GOSSIP_DELAY (7 s) between tip announcements, and the code comment says it was sized for 75-second blocks (as of commit 1e03ee75). With Poisson arrivals at a 25 s mean, about a quarter of blocks reach a relay while it’s still waiting. Removing the wait in the model cut orphans from 16.2% to 13.4% under today’s relay, and from 6.0% to 3.9% with priority fill. It may already be addressed in newer code, but it seems worth checking before NU7.

What it isn’t

This is not a proposal to merge anything. The Zebra changes sit behind an off-by-default testbed feature and the relay binary refuses to run off loopback. The aim is to ask whether upload order deserves a place in the relay discussion alongside compact blocks (PR #11938).

Questions I’d love input on

  1. Is there data on Zcash nodes’ real bandwidth and connectivity, or would a measurement study or testnet trial be the right next step?
  2. Is trading fairness for speed acceptable, or should home nodes get a guaranteed share of upload?
  3. Which mitigations against ranking attacks are worth their complexity (prefix caps, a random reserve slot, outbound preference)?
  4. Would this fit in Zebra as an opt-in setting, somewhere else, or not at all?
  5. Once NU7 is live, how should the measured stale rate feed into decisions like this?

Links

The analysis, code and drafting were done with help from Claude. I’m responsible for the content and happy to dig into any of it. This is based on an idea I had many years ago for Bitcoin and decided to look into it again for zcash.

3 Likes

Nice write-up. On your separate finding about the gossip wait: it’s still there on Zebra’s main branch today. PEER_GOSSIP_DELAY is 7 seconds in zebrad/src/components/sync.rs, and the comment above the sleep in sync/gossip.rs still talks about blocks arriving every 75 seconds.

The Zebra team already has it open as ZcashFoundation/zebra#11680 (“Committed blocks can wait up to 7 seconds before being gossiped”). It makes the same point you do, that about a quarter of blocks would hit the wait at 25-second spacing, and notes mempool gossip uses the same interval. Your model’s numbers (16.2% to 13.4% orphans with the wait removed) might be useful to add there, since the issue has no comments yet.

Also possibly relevant to your upload-order idea: #11670 is an open PR to relay a mined block before it’s committed locally, so it touches the same first-hop timing.

2 Likes

Thanks very much for pointing me to these. I’ll certainly chime in with a comment on #11680 to push for that to be fixed. It’s a particularly bad problem for miners as far as I can tell. I’ll have a look at Zakura too to see if the same problem exists there as well.

Do you happen to know the original thinking behind the 7s delay? Is this a leftover from Bitcoin?

1 Like

From the history, it doesn’t look like a Bitcoin leftover. The wait came in with zebra#6625 in May 2023, a security fix to rate-limit gossip and cut load on peers, mostly aimed at transaction gossip. It reused an existing 6-second syncer timeout (TIPS_RESPONSE_TIMEOUT) in both the transaction and block gossip loops, and the block loop’s comment reasoned that blocks arrive about every 75 seconds, so 6 seconds wouldn’t make much difference.

A week later zebra#6704 gave it its own name, PEER_GOSSIP_DELAY, and raised it to 7 seconds so it’s longer than that timeout. The comment still says 6 seconds, which suggests the block side wasn’t revisited after that.

Bitcoin Core does delay transaction announcements by a few random seconds for privacy, but it announces new blocks straight away, so there isn’t a Bitcoin precedent for holding blocks back.