Skip to content

newHeads: announce ws heads at heights a polled upstream reached first - #400

Closed
l0gun0v wants to merge 2 commits into
mainfrom
local-newheads-ws-race
Closed

l0gun0v wants to merge 2 commits into
mainfrom
local-newheads-ws-race

Conversation

@l0gun0v

@l0gun0v l0gun0v commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

The local newHeads source forwards ws heads at heights a polled upstream reached first. Workaround until deployed: drpcorg/private-config#1017.

Spec

  • Before: the source forwarded a chain head change only if the winning head carried a ws notification payload (RawData). When a polled upstream (or a head learnt from a response) reached a height first, the ws head of that height came with an unchanged chain head and was never sent. Hyperliquid (hl-node /evm polled every 200 ms, reth-hl over ws): drpc-warp US-East delivered ~3 of 60 heads per minute, other drpc regions 26-35.
  • After: the chain supervisor announces every ws head from an available upstream whose height is above the last announced one, whether or not it changed the chain head, and at most 128 blocks behind the chain head.
    • In order, each height once; a ws head that wins the chain head is announced immediately, as before.
    • An upstream reporting a lower chain head (reorg) lets that height be announced again; a chain head lowered by an upstream leaving is not re-announced.
  • The feed is a separate stream (ChainSupervisor.SubscribeNewHeads); the state stream (chain status for dproxy, logs source) does not change.
  • Metric: nodecore_new_heads_skipped_total{chain} - heights subscribers never got.

Changes

File Change
internal/upstreams/new_heads_feed.go announce rule + metric
internal/upstreams/chain_supervisor.go feed driven from updateHead, SubscribeNewHeads
internal/upstreams/interfaces.go SubscribeNewHeads on ChainSupervisor
internal/upstreams/flow/subengine/heads.go source forwards the feed; state stream only for NewHeadsCap loss
internal/upstreams/new_heads_feed_internal_test.go, chain_supervisor_test.go, flow/subengine/heads_test.go feed and wiring tests
internal/server/*_test.go, flow/sub_aggregation_internal_test.go test fakes implement SubscribeNewHeads
docs/nodecore/13-subscriptions.md, 08-prometheus-metrics.md behaviour and metric

The local newHeads source forwarded only chain head changes that carried a ws
notification payload. When a polled upstream reached a height first, the ws head
of the same height arrived with an unchanged chain head and was never sent. On
hyperliquid (hl-node /evm polled every 200ms, reth-hl over ws) drpc-warp US-East
delivered ~3 of 60 heads per minute.

- The chain supervisor keeps a newHeads feed: every ws head (RawData) from an
  available upstream above the last announced height, whether or not it changed
  the chain head, at most 128 blocks behind the chain head. When an upstream
  reports a lower chain head (reorg), that height can be announced again; a head
  lowered by an upstream leaving is not re-announced. Published on
  SubscribeNewHeads, apart from the state stream.
- The local newHeads source forwards that feed.
- Metric: new_heads_skipped_total - heights subscribers never got.
@l0gun0v
l0gun0v force-pushed the local-newheads-ws-race branch from ac75aff to ba1cb1f Compare October 4, 2026 12:26
@l0gun0v l0gun0v changed the title newHeads: announce heads the fork choice took from a polled upstream newHeads: announce ws heads at heights a polled upstream reached first Oct 4, 2026
@l0gun0v
l0gun0v marked this pull request as ready for review October 5, 2026 09:38
@l0gun0v l0gun0v closed this Oct 5, 2026
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.

1 participant