Repository navigation
Conversation
WithMessagePriority lets an application mark messages sent through Publish, locally originated or forwarded, to be queued ahead of the normal traffic already waiting for each peer, through the existing urgent path of the per-peer RPC queue. A prioritised publish is queued before the control and gossip it piggybacks, which stay in the normal queue. PublishBatch and all other sends are unchanged, and with the option unset nothing changes.
joxerx
pushed a commit
to joxerx/erigon
that referenced
this pull request
Nov 20, 2026
## Summary Caplin publishes up to 128 data column sidecars per block, each to the peers of its column subnet. Small, time-critical messages published or forwarded right after them (attestations, payload attestations, blocks, execution payload envelopes) wait behind several megabytes of columns in go-libp2p-pubsub's per-peer outbound queue. This PR uses a new GossipSub router option, `WithMessagePriority`, to put every message Caplin publishes or forwards, except data column and blob sidecars, in the queue's existing priority lane. - `cl/p2p/libp2p_setting.go`: `gossipMessageHasPriority` returns false for `data_column_sidecar_*` and `blob_sidecar_*` topics and true for every other topic. `pubsubOptions` passes it to `pubsub.WithMessagePriority`. - `go.mod`: the option is not released upstream yet (libp2p/go-libp2p-pubsub#741), so `github.com/libp2p/go-libp2p-pubsub` is replaced by `github.com/domiwei/go-libp2p-pubsub v0.0.0-20261119062000-9d96f54458a3`. That commit is upstream v0.17.0 plus a cherry-pick of the commit from that PR, nothing else. Its go.mod is the same as in v0.17.0 and the require stays at v0.17.0, so no other module version changes; go-libp2p is not bumped. Once upstream releases the option, the require can move to that release and the replace can go. - `.golangci.yml`: allows the new replace in `gomoddirectives`. Behaviour to note: - Priority changes the order, not the queue limit: prioritised messages still count towards the outbound queue limit (600 RPCs per peer), do not evict queued messages, and are dropped like any other message when the queue is full. - Messages in the priority lane keep FIFO order among themselves, so a large prioritised message (a block or an envelope) can still delay smaller ones queued after it. IDONTWANT already used this lane. Before this change it went out ahead of every queued gossip message; now it also waits behind prioritised messages queued before it. - `PublishBatch`, IWANT responses and heartbeat control traffic keep the queue they used before, as defined by the upstream option. The normal queue is sent only when the priority lane is empty, so on a link that cannot keep up with the prioritised traffic, sidecars, IWANT responses and heartbeat control traffic wait longer than before. ## Measurement E3 local devnet: Kurtosis, 8 beacon nodes (Lighthouse, Teku, Prysm, Nimbus, Lodestar, Grandine and two embedded Caplin nodes), 40 ms one-way delay per link, every node responsible for all 128 data columns. The two Caplin nodes ran side by side for 240 slots: A = main d273dec, B = the same build with an equivalent version of this change (the fork code vendored locally). Both had a local timing-log overlay. B − A, median of the paired per-slot differences with a 95% interval; the own-block rows compare different slots (unpaired, difference of the medians): | | A | B | B − A | |---|---|---|---| | payload attestation arrival at the other nodes, from slot start, per message | 1143 ms | 917 ms | −207 ms [−236, −151] | | payload attestation POST → arrival, per message | 415 ms | 201 ms | −185 ms [−231, −148] | | own block: VC block publication → first envelope at a calibrated reference node (unpaired, n 25 / 26) | 321 ms | 110 ms | −211 ms [−257, −184] | | own block: VC block publication → 128th column at Lighthouse (unpaired, n 23 / 24) | 714 ms | 713 ms | −1 ms [−45, +24] | Block → head, envelope → FULL head and attestation_data latency moved by less than 1 ms. CPU moved by −0.004 cores and peak memory by +0.02 GiB (medians of the paired 12 s samples). ## Tests - `TestGossipMessageHasPriority` checks the rule on full topic strings for the sidecar topics and for several other topic families. - `TestPubsubOptionsSendAttestationAheadOfQueuedColumns` builds a gossipsub router from `pubsubOptions` and connects it to a mocknet peer that does not read yet. It publishes four 1 KiB messages on a data column topic and then one on an attestation topic, and checks that the attestation-topic message is not sent last. It fails when the `WithMessagePriority` line is removed from `pubsubOptions`. - The queue behaviour of the option is tested in the fork (`gossipsub_priority_test.go`, the same tests as in libp2p/go-libp2p-pubsub#741). - `make lint`, `go test ./cl/p2p/...` and `go build ./cmd/erigon ./cmd/caplin` pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds a GossipSub router option that lets an application send some messages ahead of the normal traffic already queued for each peer. It addresses #210 ("Allow prioritization of traffic per topic") with a callback, so the application decides which messages are prioritised, by topic or by anything else in the message.
Motivation
Ethereum consensus clients publish bursts of large messages: when a block arrives, a node can publish up to 128 data column sidecars to every mesh peer at once. Small, time-critical messages published right after the burst (attestations, payload attestations) wait in the same per-peer FIFO queue behind several megabytes of columns.
We measured this in Erigon's consensus client (Caplin) on an 8-node local devnet (Kurtosis, 40 ms one-way delay per link, every node responsible for all 128 data columns), comparing two Caplin nodes side by side over 240 slots. With a local build of an earlier version of this option (applied to v0.17.0; it also sent the piggybacked control urgently), and Caplin prioritising every topic except data columns and blobs, the median arrival of our payload attestation messages at the other nodes improved by 144 ms (paired per-slot difference, 95% interval [-176, -112] ms). A simpler rule that marked every message below the IDONTWANT size threshold as urgent gave 160 ms. For comparison, each from its own paired run:
Other libp2p implementations already order outgoing traffic: nim-libp2p sends locally published messages before relayed ones, and rust-libp2p uses separate queues for subscription RPCs, control RPCs, and the remaining traffic (publish, forward, IHAVE, IWANT). This option keeps the policy in the application and leaves the default behaviour unchanged.
Changes
WithMessagePriority(func(*Message) bool) Option, a gossipsub router option likeWithFloodPublish.GossipSubRouter.Publishpasses the callback's result as the existingurgentflag ofsendRPC, so a prioritised message goes throughUrgentPushand is queued ahead of the normal traffic for each peer.Publishhandles both locally originated and forwarded messages.PublishBatchis unchanged and keeps the normal queue. Batch publishing is meant for bulk data, and extending priority throughRPCSchedulerwould require stable RPC or message identity, which the interface does not promise.sendRPCqueues the message before the control and gossip it piggybacks (for example a pending GRAFT or IHAVE), and keeps that control in the normal queue. Both lanes share the queue capacity, so the prioritised message is not the one dropped when a single slot is left; a dropped control RPC goes through the existing drop path. Control-only urgent RPCs, such as IDONTWANT, and all non-urgent sends keep their current order and lanes.Behaviour to note:
Tests
gossipsub_priority_test.gochecks the queue order directly, without timing, in a synctest bubble:GossipSubRouter.Publish, called on the event loop withReceivedFromset to the local host or to another peer, queues a prioritised message ahead of an earlier normal one (the tests call the router directly; they do not go through inbound validation);PublishBatchkeeps a selected message in the normal queue;go test ./...,go vet ./...and gofmt pass. Staticcheck reports only the pre-existing SA4006 finding.