Skip to content

fix(testnet): get InstantSend locks from the DAPI stream instead of trpc.digitalcash.dev - #53

Merged
PastaPastaPasta merged 15 commits into
mainfrom
feat/testnet-dapi-islock
Oct 24, 2026
Merged

PastaPastaPasta merged 15 commits into
mainfrom
feat/testnet-dapi-islock

Conversation

@PastaPastaPasta

@PastaPastaPasta PastaPastaPasta commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Why

The testnet V24 hard fork activated at block 1,578,000. trpc.digitalcash.dev, which the bridge polls for InstantSend locks and ChainLocks on testnet, is still on Dash Core v23 and stopped following the chain, so every testnet funding hangs after the asset lock is broadcast.

InstantSend locks do not need a central service. Any evonode delivers them over subscribeToTransactionsWithProofs, and the bridge already had that path for devnets. This PR moves testnet to it and removes the testnet dependency on trpc.digitalcash.dev. Mainnet is unchanged.

What changed (testnet)

  • IS locks from the DAPI bloom stream. TESTNET has explicit dapiAddresses and no rpcUrl. Default dapi-client discovery is broken on V24: the legacy @dashevo/dashcore-lib cannot parse CbTx v4 coinbases while syncing the masternode list, so the client never connects. Explicit addresses skip discovery.
  • Several nodes at once. The subscription opens streams on 3 distinct evonodes (one single-address client each), takes the first matching lock, cancels the rest, and replaces failed streams from the untried nodes (9 attempts max). The start height is raced across 3 nodes (8 s deadline). If every node fails before the subscription is established, subscribeForInstantSendLock throws before the asset lock is broadcast.
  • Evonode list. Fetched at startup from quorums.testnet.networks.dash.org/masternodes (ENABLED + version check, CORS-enabled), with a static 20-node fallback in src/config.ts.
  • Platform status via the EvoSDK. platform.getStatus() through @dashevo/dapi-client 3.1.0-dev.7 throws on every testnet node (state_sync is omitted and createFromProto reads it unconditionally), which made the network-health indicator say "degraded" and left the ChainLock fallback without a height source. Testnet now reads sdk.system.status() (src/platform/status.ts).
  • No SDK download for idle visitors. The EvoSDK (~7 MB gz) is not fetched for the health indicator. It starts connecting when a funding flow starts, so the indicator shows a real Platform reading before any funds are committed. Before that it is Core-only and says "Platform status: not read yet". After a connect, a failed Platform read shows degraded.
  • Health indicator fixes. It no longer disappears after Try Again / reset, tooltip numbers refresh while the verdict is unchanged, and a stale poll cannot write into another network's state.
  • Docs/comments updated; the app makes no request to any digitalcash.dev host on testnet (asserted in a new mock-mode e2e test).

Testing

  • tsc --noEmit, vitest run (720 tests), npm run build, and the mock-mode Playwright suite (53/53) pass.
  • Funded runs in headless Chromium against production builds of this branch on testnet V24, each creating identities verified with proofs, plus a top-up: lock 1.3 to 2.3 s after broadcast, zero requests to *.digitalcash.dev, healthy indicator with real Platform values at funding time.
  • Failure cases exercised live: nodes refusing or hanging (replacement works; the old 75 s start-height stall is gone), all lock streams refused (fails before broadcast, nothing broadcast, retry works), lock streams silent (broadcast then the ChainLock fallback completes), Platform/quorum endpoints blocked after connect (indicator degrades, then recovers).

Known limitations

  • First lock wins. The subscription takes the first matching lock from any node without checking it. Testnet evonodes are permissionless, so a hostile node could send a forged lock that beats the honest streams; Platform would reject the proof and the user would use the ChainLock fallback. Not addressed here.
  • The Platform SDK depends on quorums.testnet.networks.dash.org. If it is down, registration/top-up/send fail after broadcast (recoverable through the ChainLock fallback, but the asset lock stays unspent until retried). The health indicator shows degraded in that case once the SDK has started connecting.
  • A fast top-up can broadcast before the first Platform reading arrives (the SDK connect takes a few seconds); nothing is blocked.
  • Devnets with two or more dapiAddresses now use the multi-node path (side effect of the subscription change).
  • The height probe races 3 nodes. If all three are dead the subscription fails before broadcast ("3 nodes tried"); a retry works.
  • Mainnet still uses JSON-RPC at rpc.digitalcash.dev. It needs its own DAPI stream test and an evonode source before the mainnet V24 fork.
  • Supersedes fix: remove the bridge's dependency on Digital Cash RPC #37 for testnet (which proposed the same sdk.system.status() read but waits for a ChainLock instead of an InstantSend lock).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Testnet InstantSend lock subscriptions can use multiple available nodes, with fallback attempts when a node is unavailable.
    • Testnet network status now uses Platform status; mainnet and devnets retain their existing status sources.
    • Testnet DAPI endpoints can be discovered dynamically, with configured endpoints available as a fallback.
    • Network status tooltips update as fresh information arrives, including when Platform status has not yet been checked.
  • Improvements
    • Funding flows can warm up Platform access on testnet, helping status checks reflect connection issues and recovery.

PastaPastaPasta and others added 15 commits October 23, 2026 18:13
trpc.digitalcash.dev is stuck on Core v23 and stops serving IS locks after
the testnet V24 fork (block 1,578,000), so the bridge hung waiting for the
lock. Testnet now uses the existing DAPI subscription path with an explicit
snapshot of healthy evonodes, which skips dapi-client's seed/SML discovery
(broken on V24 CbTx v4 coinbases).

- TESTNET: drop rpcUrl, add 15 explicit https://<ip>:1443 dapiAddresses
- dapi.ts: remove the implicit testnet JSON-RPC default so hasRpcUrl is
  false and no request goes to any digitalcash.dev host
- tests: pin testnet to the subscription path; JSON-RPC deadline tests now
  use mainnet

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…t lock

The bloom-filter IS lock stream used one dapi-client instance that picks a
random node per call. subscribeToTransactionsWithProofs returns before any
connection exists, so a dead node only surfaced ~12 s later as 'Response
closed without headers', after the asset-lock tx was already broadcast, with
no retry. A single live node can also silently drop a lock.

With two or more configured addresses, open streams on up to 3 distinct nodes
at once, each through its own one-address DAPIClient so nodes cannot repeat.
The first matching lock wins and the other streams and clients are torn down;
late locks and errors from losers are ignored. A stream that errors or ends is
replaced from the untried shuffled list (9 attempts max), and when every node
has failed the error names the nodes tried and the last cause. Timeout and
abort messages are unchanged.

The function returns after the first stream message or a 3 s readiness cap,
so the broadcast is not held up by slow nodes. disconnect() now also stops
in-flight subscriptions, since DAPIClient.disconnect() does not cancel
streams. Fewer than two distinct addresses keep the single-client path.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
attempts already indexes the next untried node and slots.size is the number
of live streams, so nextNode and running were duplicates.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Every testnet node omits the optional state_sync message from platform
getStatus, and @dashevo/dapi-client 3.1.0-dev.7 dereferences it
unconditionally, so the network-health indicator reported "degraded" and
the chain-lock fallback never got a height. Testnet now reads chain-locked
height, Platform block height and block time via sdk.system.status();
devnets and mainnet keep their existing paths.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Testnet certificates rotate in 2-6 days and nodes come and go, so the
static dapiAddresses snapshot goes stale. At client init, testnet now
fetches the quorum service /masternodes list (CORS-enabled for browsers;
5 s, one attempt), keeps ENABLED nodes with a successful version check and
dials them on :1443. The static list is the fallback when the fetch fails
and tops up the result when fewer than 3 nodes come back. The static list
is refreshed to a current 20-node snapshot with regeneration notes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Testnet no longer uses JSON-RPC, so fix the stale mainnet/testnet wording
in islock.ts, main.ts and the network-status tests, document the per-network
InstantSend source in CLAUDE.md, and add a mock-mode e2e test asserting that
testnet discovers evonodes from the quorum service and sends no request to
any digitalcash.dev host.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Review follow-ups:
- initClients no longer installs a stale islock service when the user
  switched networks while the evonode list was loading.
- evonode hosts that pass the character check but are not valid URLs
  (999.1.1.1) are dropped instead of making the DAPI client constructor
  throw for the whole list.
- Platform status routes on the network config type rather than its name,
  so an unknown name that falls back to the testnet config still uses the
  SDK path.
- connectPlatformSdk shares one in-flight connect between concurrent
  callers (status polls and write paths) instead of orphaning SDKs.
- Trim duplicated comments and redundant tests.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ails

The caller broadcasts the asset-lock tx as soon as subscribeForInstantSendLock
returns. When every node attempt had already failed inside the readiness
window or initial open loop, it used to return a handle whose wait() rejected
later, so funds were committed with no listener. It now rejects itself with
the same "N nodes tried, last error" message; main.ts's existing catch turns
that into the retryable ISLOCK error with nothing broadcast. Failures after
subscribe has returned still surface through wait().

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… pick

The one-off getBestBlockHeight before opening streams went through the
shared random-pick client. When it picked an unreachable node the browser's
TCP connect hung ~75 s before failover, with nothing broadcast meanwhile
(measured: 75 s from subscribe to broadcast in the funded browser test).

The multi-node path now asks the first three nodes of the shuffled list at
once, each through the single-address client its stream will reuse, with an
8 s per-request deadline. The first valid height wins; it fails only when
all of them fail or time out, with the usual "N nodes tried, last error"
message and the probe clients disconnected, before anything is broadcast.
Caller aborts also stop the wait. The single-node path is unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Since a057e84 the testnet health poll read Platform status through
sdk.system.status(), which loads and connects the whole EvoSDK (~7 MB gz)
on every testnet page load. Testnet is the default network, so that undid
the load-time work from PR #28.

What loads when now:
- Page load (idle warmup): the JS modules and the IslockService, the
  evonode list fetch, and the Core height poll via Insight. The EvoSDK
  chunk and wasm are NOT requested.
- Health polls (every 30 s) call IslockService.peekPlatformStatus(). On
  testnet that resolves undefined while no SDK is connected, without
  touching the loader. The verdict then rests on Core alone: healthy with
  only the Core height in the tooltip, no reasons, never "degraded"; if
  Insight also fails it is "unknown" ("Could not reach Insight").
- The SDK is loaded by the flows that need it (creating an identity,
  top-up, DPNS, ...). The first poll after connectPlatformSdk has cached a
  connected SDK reads Platform status through it and shows chain-lock lag
  and block age as before. A failure of that real read still degrades.
- The chain-lock fallback keeps using the loading getPlatformStatus path,
  since the user is mid-flow and needs the height.
- Devnets are unchanged: dapi-client needs no SDK. Mainnet is unchanged
  (JSON-RPC).

The mock-mode e2e test now also asserts no evo-sdk request on page load;
it fails if the poll uses the loading path.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Two bugs, both from the poller skipping any result whose verdict matched the
previous one:
- A flow reset (Try Again, Contract -> Back) builds a fresh state without
  networkStatus, and the poller then skipped the unchanged verdict, so the
  indicator stayed hidden until it changed (75+ s observed).
- The tooltip numbers (heights, block age) never refreshed while the verdict
  was unchanged (stuck over 8 polls).

Poll results are now always written to the state. A full re-render still
happens only when the verdict or its reasons change, which is all the label
and banner show; otherwise only the tooltip is patched in place, so focus
isn't disturbed every 30 s. updateState re-attaches the last known status of
the same network to any state that lacks one, and a poll that finds the
state without a status renders it. Logic lives in ui/network-status-sync.ts
so it can be tested.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Log "[islock-sub] IS lock for <txid> from <host>:<port> after <ms> ms since
subscribe" on the winning stream (node address and elapsed time only), so a
slow or failing lock can be traced to a node.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- The indicator says so when Platform was not read yet (tooltip line
  "Platform status: not read yet", NetworkStatus.platformChecked), so the
  Core-only "healthy" is not mistaken for a Platform check.
- A poll result for a network the user already left is ignored, and
  switching networks clears the old network's status instead of showing it
  under the new badge.
- Re-render decisions compare with the verdict actually on screen rather
  than with the previous poll.
- The height probes use retries 0 and a gRPC deadline, so no hidden
  background retries outlive the 8 s deadline.
- disconnect() (network switch) now also stops a pending height race, so no
  streams open on the network being left.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The health poll no longer downloads the SDK on page load (35eddc7), which
left testnet showing a Core-only "healthy" until registration, i.e. after the
asset lock was broadcast. Now, on testnet only, create / top-up /
send-to-address start connecting the EvoSDK as soon as their clients are
ready (before the deposit address is shown and before any funds can be
committed) via warmPlatformSdkForFunding in the existing loaders, and poll
the network status right after the connect settles. Registration needs the
SDK anyway, so funding users download nothing extra; idle visitors still
never do. Nothing blocks funding; mainnet and devnets are untouched.

Indicator behaviour:
- Before any funding flow, and while the first connect is in flight: Core
  only, tooltip "Platform status: not read yet", not degraded.
- Once a connect has been attempted (connected, failed, or evicted after a
  connection error), the poll always reads Platform through the SDK, so a
  failing read is "degraded" and no longer reverts to the Core-only healthy
  when withConnectedPlatformSdk evicts the SDK. The next poll reconnects
  (module already loaded); success shows healthy again. This replaces
  hasConnectedPlatformSdk with isPlatformSdkSettled (attempted and not
  currently connecting).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Review follow-ups to the funding-flow SDK warmup:
- A reconnect in flight after an outage no longer reads as "not read yet"
  (which flipped the badge between degraded and healthy every poll): only
  the very first connect is shown that way, and only for a 60 s grace
  period, so a hung first connect cannot read as healthy forever. Later
  reads join the pending connect and are bounded by their own 20 s timeout.
  isPlatformSdkSettled becomes isPlatformSdkReadable.
- The status poll no longer passes maxAttempts 1 to the shared connect, so a
  write path that joins a poll-started connect keeps its normal retries.
- Overlapping polls (the extra one after the SDK connects) apply in order; a
  slower older poll cannot overwrite a newer result.
- The funding warmup is skipped in e2e mock mode, and the extra poll only
  runs when a connect was actually attempted (testnet), not on mainnet or
  devnets.
- Note: the warmup starts when a funding flow starts, which can be before
  the 7 MB download finishes; until it connects the indicator shows the
  Core-only "Platform status: not read yet".

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

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Caution

Review failed

The pull request is closed.

📝 Walkthrough

The pull request changes testnet InstantSend lock routing to use discovered DAPI endpoints and multi-node subscriptions. It adds testnet Platform SDK status reads, updates network-status polling and display behavior, and adds supporting tests and documentation.

Changes: Testnet routing and status

Layer / File(s) Summary
Testnet DAPI address resolution
src/api/evonodes.ts, src/api/evonodes.test.ts, src/config.ts, src/api/dapi.ts, src/main.ts, e2e/deterministic.spec.ts, CLAUDE.md
Testnet DAPI addresses are resolved from quorum-service data, with configured addresses used as fallback. Client initialization passes the resolved addresses to IslockService. The deterministic E2E test checks that mock testnet startup makes no requests to digitalcash.dev or SDK/WASM assets.
Multi-node InstantSend lock subscriptions
src/api/dapi-subscription.ts, src/api/dapi-subscription-multi.test.ts, src/api/islock.ts, src/api/islock.test.ts, src/api/request-deadlines.test.ts
Subscriptions with at least two addresses probe nodes for block height and attempt lock streams across nodes. The single-client path remains for fewer than two addresses. Tests cover routing, failures, readiness, cancellation, and cleanup.
Platform SDK status reads
src/platform/client.ts, src/platform/client.test.ts, src/platform/loaders.ts, src/platform/status.ts, src/platform/status*.test.ts, src/api/dapi-subscription.ts, src/api/islock.ts, src/api/platform-status-routing.test.ts
Testnet Platform status reads use the SDK when it is readable. The SDK connection is shared per network, status values are validated, and status reads have a 20-second timeout. Other network types use the DAPI client for Platform status.
Network status polling and display
src/types.ts, src/api/network-status.ts, src/api/network-status.test.ts, src/ui/components.ts, src/ui/components.network-status.test.ts, src/ui/index.ts, src/ui/network-status-sync.ts, src/ui/network-status-sync.test.ts, src/main.ts
Network status distinguishes an unread Platform source from an unreachable source. Poll results are synchronized with application state, and tooltip details can refresh without replacing the indicator. Funding flows can start testnet SDK warm-up.

Priority: ⚪ Not assessed

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant App
  participant AddressResolver
  participant QuorumService
  participant IslockService
  participant DAPISubscriptionClient
  participant DAPINode
  App->>AddressResolver: Resolve testnet DAPI addresses
  AddressResolver->>QuorumService: Fetch quorum masternodes
  QuorumService-->>AddressResolver: Return masternode data
  AddressResolver-->>App: Return live and fallback addresses
  App->>IslockService: Initialize with resolved addresses
  IslockService->>DAPISubscriptionClient: Start lock subscription
  DAPISubscriptionClient->>DAPINode: Probe height and open lock stream
  DAPINode-->>DAPISubscriptionClient: Return matching lock message
  DAPISubscriptionClient-->>IslockService: Resolve lock wait
Loading
Merge Risk: 🔵 Low · up to 79457

Funding may require a restart when the first three selected nodes fail, despite other healthy nodes being available. The issue is recoverable, but the height-probe fallback should be fixed before merge if practical.

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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