Skip to content

Event bus: build high-rate topics only for clients that subscribed to them #845

Open

Description

@MegaRedHand

Problem. EventBus::has_subscribers is receiver_count() > 0 (crates/blockchain/src/events.rs:644). Every producer gates on it, so a single SSE client turns on every topic's payload construction, whatever ?topics= it asked for: a validator client that only wants head, for example. The filtering happens afterwards, in the stream (crates/net/rpc/src/events.rs, !topics.contains(&ev.topic())).

For the two high-rate beacon topics that means:

Both go into the one ring all topics share (CHAIN_EVENT_CHANNEL_CAPACITY, 8192, events.rs:600). A client whose connection stalls lags after capacity / total rate, and loses the low-rate events it did ask for, which it learns only from the dropped N messages comment frame. The doc on CHAIN_EVENT_CHANNEL_CAPACITY already names this and calls a per-topic split "the escape hatch". The rates on a mainnet node are not measured; lean_-prefixed counters per topic emitted would measure them.

Why not in #757. 757 adds one producer and follows the bus's existing gate, as attestation already does. Per-topic interest changes the bus, the SSE handler and every producer's gate.

Fix. Either of two:

  • Count subscriptions per Topic. The SSE handler registers its topic set with a guard that decrements on drop, and EventBus::wants(Topic) replaces has_subscribers at each producer; the sink trait in ethlambda-network-api grows the same method.
  • Keep has_subscribers, but give single_attestation and attestation a ring of their own, so their rate cannot push low-rate events out of a slow client's window.

A test: a client subscribed to head alone causes no single_attestation to be built.

Also high-rate (from #748): the gloas payload_attestation_message and execution_payload_bid events are built per message too, so the same per-topic interest check should cover them.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions