Skip to content

feat(hyperliquid): one lossless gateway client for both data services - #698

Merged
abernatskiy merged 14 commits into
masterfrom
feat/hl-gateway-client
Dec 4, 2026
Merged

abernatskiy merged 14 commits into
masterfrom
feat/hl-gateway-client

Conversation

@abernatskiy

Copy link
Copy Markdown
Contributor

Stacked on #696.

The fills and replica-cmds data services each carried a copy of a gateway subscription reader. The copies had drifted apart:

  • the replica copy resumed from the last block consumed rather than the last buffered;
  • it numbered blocks by counting from the requested block;
  • both dropped the oldest buffered block when the consumer lagged.

This replaces both copies with one reader, GatewayStream, in a new package, @subsquid/hyperliquid-gateway-client. The archive ingests will move to it in a follow-up.

GatewayStream

  • Delivers every block exactly once and in order. Blocks are numbered by their own number (block_number for fills, height for replica).
    • A replay after a reopen is skipped.
    • A skipped block reopens the subscription at that block. It is never filled in.
  • Slow consumer: when it lags by blockBufferSize blocks, the subscription is closed instead of dropping blocks. It is reopened after the last buffered block once the consumer takes them. A slow consumer now costs a resubscribe, logged at warn level, not lost blocks.
  • Watchdogs: silence, and an optional block-age staleness check that tolerates catch-up. Both are taken over from the fills data service unchanged.
  • Failures: a failure before the stream's first block fails it, as today. Later ones reopen the subscription after retryDelay, up to an optional maxFailures in a row.
  • Optional to bound, abort signal, and onResubscribe(reason) hook.

Data services

  • Fills: same flags; the staleness watchdog is kept.
  • Replica:
    • blocks are numbered by height, so a replayed or skipped block can no longer be misnumbered;
    • the parent_round check stays, now with a message;
    • the head still comes from gateway_getBlockFills.
  • --gateway-block-queue-size: keeps its name. It is now the lag that triggers a resubscribe, and its default goes from 10 to 1000: with resubscribe semantics, 10 would resubscribe on every small hiccup.

Tests

  • Replica data service: tests of today's behaviour, committed first in a separate commit (it had none), then extended for numbering by height, skipped heights and a missing height.
  • Gateway client: 20 tests.
    • The fills staleness tests, ported.
    • Reopen after an error, an end, silence or a skip.
    • Replay skipped; maxFailures; failure before the first block; invalid notifications.
    • Lossless under a slow reader.
    • Following the head; abort.
  • Fills data service: head, contiguity, upper bound, gap, start past from, repeated block.

Local rush build and the tests of all three packages pass. A rush deploy of the replica data service picks up the new package.

🤖 Generated with Claude Code

abernatskiy and others added 3 commits December 4, 2026 03:30
… made-up empty blocks

A block missing from the gateway stream was filled in with an empty block timestamped 1970.
The stream can lose blocks when the consumer lags behind the subscription buffer, so such a
block is not known to be empty. A gap now fails the stream; the data service restarts it from
its head, and the new subscription delivers the block.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ehaviour

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
New @subsquid/hyperliquid-gateway-client: GatewayStream reads a hyperliquid-gateway-proxy
block subscription through rpc-client and delivers every block exactly once, in order.

- A consumer that lags by --gateway-block-queue-size blocks closes the subscription
  instead of dropping its oldest block; it is reopened after the last buffered block once
  the consumer takes them. The default threshold is now 1000.
- Blocks are numbered by their own number (fills block_number, replica height). A replay
  after a reopen is skipped; a skipped block reopens the subscription at it, never filled in.
- Silence and staleness watchdogs and failure handling as in the fills data service:
  a failure before the first block fails the stream, later ones reopen it.

The fills data service keeps the staleness watchdog. The replica data service no longer
numbers blocks by counting from the requested one, so a replayed or skipped block can no
longer be misnumbered; it keeps its parent_round check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
abernatskiy and others added 3 commits December 4, 2026 03:44
…s not fail the range

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…client

# Conflicts:
#	hyperliquid/hyperliquid-fills-data-service/src/data-source/data-source.ts
…e shared client

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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.

🟡 Changes recommended

The stream can emit blocks beyond the requested upper bound, continue buffering after cancellation, and remain frozen indefinitely when repeated notifications bypass staleness checks.

3 open issues
1 file not reviewed
  • common/config/rush/pnpm-lock.yaml: Generated file
What changed in this PR

Replaces duplicated Hyperliquid gateway readers with a shared lossless client, following up on #696’s gap-handling fix.

Changes:

  • Adds ordered streaming with replay filtering, bounded buffering, resubscription, watchdogs, and cancellation.
  • Migrates both data services, uses replica block heights, and raises the queue default to 1000.
  • Adds regression tests and updates package registration, dependencies, and release records.
File Description
rush.json Registers the shared client.
hyperliquid/​hyperliquid-replica-cmds-data-service/​src/​main.ts Updates queue default and help.
hyperliquid/​hyperliquid-replica-cmds-data-service/​src/​data-source/​setup.ts Configures height-based gateway streaming.
hyperliquid/​hyperliquid-replica-cmds-data-service/​src/​data-source/​gateway.ts Removes duplicated reader.
hyperliquid/​hyperliquid-replica-cmds-data-service/​src/​data-source/​data-source.ts Integrates shared streaming; preserves round checks.
hyperliquid/​hyperliquid-replica-cmds-data-service/​src/​data-source/​data-source.test.ts Adds replica regression coverage.
hyperliquid/​hyperliquid-replica-cmds-data-service/​package.json Adds client dependency and testing.
hyperliquid/​hyperliquid-gateway-client/​tsconfig.json Configures TypeScript compilation.
hyperliquid/​hyperliquid-gateway-client/​src/​stream.ts Implements shared subscription handling.
hyperliquid/​hyperliquid-gateway-client/​src/​stream.test.ts Tests recovery, buffering, and watchdogs.
hyperliquid/​hyperliquid-gateway-client/​src/​index.ts Exports the client API.
hyperliquid/​hyperliquid-gateway-client/​package.json Defines the new package.
hyperliquid/​hyperliquid-fills-data-service/​src/​main.ts Updates queue default and help.
hyperliquid/​hyperliquid-fills-data-service/​src/​data-source/​setup.ts Configures shared streaming and staleness checks.
hyperliquid/​hyperliquid-fills-data-service/​src/​data-source/​gateway.ts Removes duplicated reader.
hyperliquid/​hyperliquid-fills-data-service/​src/​data-source/​gateway.test.ts Removes tests ported to shared client.
hyperliquid/​hyperliquid-fills-data-service/​src/​data-source/​data-source.ts Delegates ordering and bounds to client.
hyperliquid/​hyperliquid-fills-data-service/​src/​data-source/​data-source.test.ts Updates integration regression tests.
hyperliquid/​hyperliquid-fills-data-service/​package.json Adds shared client dependency.
common/​config/​rush/​repo-state.json Updates shrinkwrap hash.
common/​config/​rush/​pnpm-lock.yaml Records dependency changes.
common/​changes/​@subsquid/​hyperliquid-replica-cmds-data-service/​hl-gateway-client_2026-12-04-00-00.json Records replica service changes.
common/​changes/​@subsquid/​hyperliquid-gateway-client/​hl-gateway-client_2026-12-04-00-00.json Records the new client.
common/​changes/​@subsquid/​hyperliquid-fills-data-service/​hl-gateway-client_2026-12-04-00-00.json Records fills service changes.

Review effort: Balanced

…ort while busy

- following the head with an end below it returns nothing instead of a block past the end
- replayed notifications count for the staleness watchdog, so a subscription stuck replaying
  an old block is reopened
- an abort closes the subscription at once, even while the reader is busy with a batch, and
  an already aborted signal opens none

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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.

🟡 Changes recommended

The overflow branch can create a replacement subscription after onResubscribe aborts the signal, allowing it to keep receiving despite cancellation.

1 open issue
3 resolved since last review
1 file not reviewed
  • common/config/rush/pnpm-lock.yaml: Generated file

Review effort: Balanced

abernatskiy and others added 3 commits December 4, 2026 04:04
…is checked

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…reopen after an abort

- the silence timer is reset only by a new block, so a subscription that keeps replaying
  blocks already delivered is reopened instead of holding the stream forever
- a subscription is never opened once the signal is aborted, including by an onResubscribe hook

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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.

🟡 Changes recommended

The replay-staleness test can pass despite a staleness regression because the silence watchdog fires first; its silence threshold should exceed the replay loop duration.

1 open issue
1 resolved since last review
1 file not reviewed
  • common/config/rush/pnpm-lock.yaml: Generated file

Review effort: Balanced

abernatskiy and others added 3 commits December 4, 2026 04:14
…e stale watchdog itself

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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.

🟢 Approval recommended

No active review issues are recorded for the shared GatewayStream migration.

No open issues 🎉

1 resolved since last review
1 file not reviewed
  • common/config/rush/pnpm-lock.yaml: Generated file

Review effort: Balanced

@abernatskiy
abernatskiy changed the base branch from fix/hl-fills-hotblocks-gap-error to master December 4, 2026 15:56
# Conflicts:
#	hyperliquid/hyperliquid-fills-data-service/src/data-source/data-source.test.ts
#	hyperliquid/hyperliquid-fills-data-service/src/data-source/data-source.ts
@abernatskiy
abernatskiy merged commit ba85429 into master Dec 4, 2026
2 checks passed
@abernatskiy
abernatskiy deleted the feat/hl-gateway-client branch December 4, 2026 16:14
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.

2 participants