Skip to content

cl/p2p: send gossip messages ahead of queued sidecars - #26569

Merged
AskAlexSharov merged 1 commit into
mainfrom
kewei/caplin-gossip-message-priority
Nov 20, 2026
Merged

AskAlexSharov merged 1 commit into
mainfrom
kewei/caplin-gossip-message-priority

Conversation

@domiwei

@domiwei domiwei commented Nov 19, 2026

Copy link
Copy Markdown
Member

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 (Add WithMessagePriority router option 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 Add WithMessagePriority router option libp2p/go-libp2p-pubsub#741).
  • make lint, go test ./cl/p2p/... and go build ./cmd/erigon ./cmd/caplin pass.

Caplin publishes up to 128 data column sidecars per block to every mesh
peer, and small time-critical messages (attestations, payload
attestations, blocks, envelopes) wait behind them in the per-peer
outbound queue. Use the WithMessagePriority router option to put every
message except data column and blob sidecars in the priority lane.

The option is not released upstream yet (libp2p/go-libp2p-pubsub#741), so
go.mod replaces go-libp2p-pubsub with a fork that is v0.17.0 plus that
commit, and the lint config allows the replace.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Core queue scheduling depends on an unreleased pubsub fork absent from the snapshot, requiring human review of its pinned diff against v0.17.0 to verify queue bounds, synchronization, and priority semantics.

No open issues 🎉

What changed in this PR

This PR reduces Caplin gossip delays by prioritizing time-critical messages ahead of queued data column and blob sidecars in each peer’s outbound queue.

Changes:

  • Enables GossipSub message priority for all topics except data column and blob sidecars, without changing queue limits.
  • Pins a pubsub fork containing the unreleased priority option and permits the module replacement in lint configuration.
  • Adds topic-classification tests and a mock-network test checking that attestations overtake queued columns.
File Description
go.sum Replaces upstream pubsub checksums with the pinned fork’s checksums.
go.mod Adds the pubsub fork replacement.
cl/​p2p/​libp2p_setting.go Configures message priority and excludes sidecar topics.
cl/​p2p/​libp2p_setting_test.go Tests topic priorities and outbound message ordering.
.golangci.yml Allows the pubsub module replacement.

Review effort: Balanced

@domiwei

domiwei commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Re-ran the E3 devnet A/B with the exact commits of this PR (240 measured slots, both nodes with a local timing-log overlay):

  • A = main f10e686, the base of this PR.
  • B = 20c17c2, this PR, with go-libp2p-pubsub fetched through the replace.
A B B − A
payload attestation arrival at the other nodes, per message, from slot start 1135 ms 925 ms −202 ms [−249, −154]
payload attestation POST → arrival, per message 439 ms 222 ms −185 ms [−226, −142]
own block: VC block publication → first envelope at a calibrated reference node (unpaired, n 29 / 33) 251 ms 105 ms −147 ms [−172, −134]
own block: VC block publication → 128th column at Lighthouse (unpaired, n 16 / 15) 769 ms 769 ms +0.5 ms [−68, +39]
  • Block → head moved by +0.1 ms and envelope → FULL head by +2 ms (medians of the paired differences).
  • CPU moved by −0.004 cores and peak memory by −0.02 GiB.
  • Neither Caplin node logged errors or panics.
  • The p90 of the 128th-column row was 1085 ms for B and 848 ms for A in this run, the opposite of the earlier run (788 ms vs 949 ms). With about 15 samples per side, this is within the noise.
  • The connectivity checks, run at the start and again at the fork, found two reference nodes, Nimbus and Grandine, not directly connected to each other. Both Caplin nodes were connected to every node.

@AskAlexSharov
AskAlexSharov added this pull request to the merge queue Nov 20, 2026
Merged via the queue into main with commit 7b3cb39 Nov 20, 2026
102 checks passed
@AskAlexSharov
AskAlexSharov deleted the kewei/caplin-gossip-message-priority branch November 20, 2026 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants