Skip to content

feat(hyperliquid): the archive ingests read the gateway through the shared client - #699

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

abernatskiy merged 27 commits into
masterfrom
feat/hl-ingests-gateway-client

Conversation

@abernatskiy

Copy link
Copy Markdown
Contributor

Stacked on #698. It also merges in #697 (rpc-client raw text), so until #697 lands, this diff includes it.

This moves the gateway rescues of hyperliquid-fills-ingest and hyperliquid-replica-cmds-ingest (#693/#694) onto @subsquid/hyperliquid-gateway-client. The subscription readers in the repo are then down to one.

Changes

  • @subsquid/hyperliquid-gateway-client: a raw option. Each block then also carries its result text exactly as received, through rpc-client's opt-in raw subscriptions (feat(rpc-client): opt-in raw text of subscription results #697). A notification without its text fails the subscription; the value is never re-serialised.
  • @subsquid/hyperliquid-archive-recovery:
    • GatewayRangeStream and its hand-rolled extractResult are replaced by RawGateway. It is a thin bounded reader: the shared stream with raw: true, maxFailures 5 and a 120 s silence timeout.
    • The direct ws dependency goes away; ws is now a test-only dependency.
  • Both ingests: use RawGateway. The rescue logic, validation and storage are unchanged.

Behaviour changes

  • Slow rescue: a rescue that is slow to take blocks (uploading a unit) now costs a resubscribe instead of a paused socket. Nothing is lost.
  • Failure before the first block: a subscription that fails before its first block fails the rescue at once, instead of being retried there. The recovery then retries the range after its retry delay, as for any failed rescue.

Tests

  • RawGateway against a WebSocket fake gateway: raw text byte for byte, with odd spacing and an unsafe integer; reopen after a lost connection; following the head; a rejected subscription.
  • The GatewayRangeStream behaviours not covered here moved to the gateway client's tests in feat(hyperliquid): one lossless gateway client for both data services #698.
  • The ingests' fallback suites (27 and 31 tests) pass unchanged, apart from fake gateways that now answer unsubscribe calls and give each subscription its own id.

🤖 Generated with Claude Code

abernatskiy and others added 6 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>
A subscription with `raw: true` gets each notification's `result` also as the exact text
received, so a caller can store it byte for byte. The WebSocket transport passes the frame
text, taken before fixUnsafeIntegers rewrites it, along with single notifications; a small
string-aware scanner finds params.result in any key order and copies the slice so it does
not keep the frame alive. Batch frames carry no text; a raw subscription gets an error for
a notification in one. Subscriptions without `raw` are unchanged.

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>
…hared client

GatewayRangeStream, a direct ws client with its own extraction of the result text, is
replaced by RawGateway: a bounded reader over @subsquid/hyperliquid-gateway-client with
`raw: true`, which takes each result's exact text from rpc-client. A slow rescue now costs
a resubscribe instead of a paused socket; maxFailures and the silence timeout carry over.

One change of behaviour: a subscription that fails before its first block fails the rescue
at once; the recovery retries the range after its retry delay, as for any failed rescue.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
abernatskiy and others added 5 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

When the gateway is unreachable, timed-out or aborted recovery streams leave subscription calls queued because closing the handle cannot cancel them before an ID arrives. The shared client keeps reconnecting during cooldown, so repeated failed rescues accumulate pending subscriptions. Separately, the default 1,000-block buffer retains full parsed blocks alongside raw JSON even though RawGateway discards the parsed values, unnecessarily increasing memory use while uploads delay consumption.

2 open issues
What changed in this PR

Moves both Hyperliquid archive ingests onto the shared gateway client, consolidating subscription handling while preserving raw block text.

Changes:

  • Adds opt-in raw notification text to RPC subscriptions and gateway streams.
  • Replaces GatewayRangeStream with RawGateway for archive rescues.
  • Updates integration tests, dependencies, and release notes.
File Description
util/​rpc-client/​src/​transport/​ws.ts Preserves original notification frame text.
util/​rpc-client/​src/​subscriptions.ts Adds raw subscription delivery.
util/​rpc-client/​src/​raw.ts Extracts exact result text.
util/​rpc-client/​src/​raw.test.ts Tests extraction and raw subscriptions.
util/​rpc-client/​src/​client.ts Forwards text to notification listeners.
hyperliquid/​hyperliquid-replica-cmds-ingest/​src/​ingest.ts Configures RawGateway.
hyperliquid/​hyperliquid-replica-cmds-ingest/​src/​fallback.ts Updates the rescue gateway type.
hyperliquid/​hyperliquid-replica-cmds-ingest/​src/​fallback.test.ts Adapts gateway fixtures.
hyperliquid/​hyperliquid-gateway-client/​src/​stream.ts Adds raw block text support.
hyperliquid/​hyperliquid-gateway-client/​src/​stream.test.ts Tests raw delivery and missing text.
hyperliquid/​hyperliquid-fills-ingest/​src/​ingest.ts Configures RawGateway.
hyperliquid/​hyperliquid-fills-ingest/​src/​fallback.ts Updates the rescue gateway type.
hyperliquid/​hyperliquid-fills-ingest/​src/​fallback.test.ts Adapts gateway fixtures.
hyperliquid/​hyperliquid-archive-recovery/​src/​gateway.ts Replaces the standalone subscription reader.
hyperliquid/​hyperliquid-archive-recovery/​src/​gateway.test.ts Tests shared-client integration.
hyperliquid/​hyperliquid-archive-recovery/​package.json Adds shared clients; makes ws test-only.
common/​changes/​@subsquid/​rpc-client/​feat-rpc-client-raw-notifications_2026-12-04-00-00.json Records raw subscription support.
common/​changes/​@subsquid/​hyperliquid-replica-cmds-ingest/​hl-ingests-gateway-client_2026-12-04-00-00.json Records replica ingest migration.
common/​changes/​@subsquid/​hyperliquid-gateway-client/​hl-ingests-gateway-client_2026-12-04-00-00.json Records raw block support.
common/​changes/​@subsquid/​hyperliquid-fills-ingest/​hl-ingests-gateway-client_2026-12-04-00-00.json Records fills ingest migration.
common/​changes/​@subsquid/​hyperliquid-archive-recovery/​hl-ingests-gateway-client_2026-12-04-00-00.json Records the reader replacement.

Review effort: Balanced

abernatskiy and others added 3 commits December 4, 2026 03:53
…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>
…ient

# Conflicts:
#	hyperliquid/hyperliquid-gateway-client/src/stream.ts
…ep only number and raw text

Each RawGateway stream opens its own connection and closes it when the stream ends, so a
subscribe call still pending on an unreachable gateway does not outlive a failed rescue.
The stream's value is now the block number, so buffered blocks hold only their raw text.

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

When the gateway repeatedly replays blocks below the expected height, those replays reset the silence timer without advancing recovery, and no progress watchdog is enabled. The rescue can therefore wait indefinitely, occupying Recovery’s single job and preventing retries and other rescues.

1 open issue
2 resolved since last review

Review effort: Balanced

abernatskiy and others added 4 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 package README still tells users to use GatewayRangeStream and describes socket pausing, but the code now exports RawGateway and resubscribes slow readers instead. The documented API and recovery behavior therefore no longer match the implementation.

1 open issue
1 resolved since last review

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>

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 actionable issues were found in the reviewed changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@abernatskiy
abernatskiy changed the base branch from feat/hl-gateway-client to master December 4, 2026 16:05
…eway-client

# Conflicts:
#	hyperliquid/hyperliquid-gateway-client/README.md
#	hyperliquid/hyperliquid-gateway-client/src/stream.test.ts
#	hyperliquid/hyperliquid-gateway-client/src/stream.ts
@abernatskiy
abernatskiy merged commit 8270bed into master Dec 4, 2026
2 checks passed
@abernatskiy
abernatskiy deleted the feat/hl-ingests-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