Skip to content

perf: defer heavy Dash SDK chunks to cut initial load time - #28

Merged
PastaPastaPasta merged 5 commits into
dashpay:mainfrom
thephez:perf/improve-load-time
Jun 4, 2026
Merged

PastaPastaPasta merged 5 commits into
dashpay:mainfrom
thephez:perf/improve-load-time

Conversation

@thephez

@thephez thephez commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Dynamically import @dashevo/evo-sdk, DAPI client, dashcore-lib, fee-estimator, DPNS, contract, and islock modules instead of bundling them into the initial chunk. An idle-time warmup (via requestIdleCallback / setTimeout fallback) primes them after first paint so user-initiated flows stay snappy, and the CAP widget is loaded on demand rather than from a blocking <script> tag in index.html.
  • Vite modulePreload.resolveDependencies now filters those heavy chunks out of the generated <link rel="modulepreload"> tags via a small shouldPreloadDashChunk helper, so the browser doesn't pre-fetch them on first paint.
  • Extract DPNS label utilities into src/platform/dpns-utils.ts with a dedicated Vitest suite, and split a reusable createCachedLoader out of loaders.ts (covered by tests for in-flight dedupe and post-failure retry).
  • Add scripts/check-build-artifacts.mjs (wired up as npm run test:build-artifacts and run in CI between Build and Test) that asserts the built index.html has no heavy modulepreload entries and that the entry chunk never statically imports a deferred module.
  • Minor CI/test housekeeping: npm test now runs once by default (vitest run) with test:watch for the watcher, and CI uses npm test directly instead of duplicating vitest flags.

Impact

Lighthouse on the same flow:

Metric Before After
Performance score 59 94
LCP 10.5 s 0.9 s
TTI 10.5 s 4.9 s
TBT 339 ms 172 ms
Total bytes 12.5 MB 5.3 MB
JS bootup 324 ms 116 ms

(Before run is prod bridge.thepasta.org; after run is local vite preview — environment isn't identical, but the byte-weight and main-thread numbers are environment-independent.)

Test plan

  • npm run build succeeds
  • npm test passes (loaders, vite-preload filter, DPNS utils, state)
  • npm run test:build-artifacts passes; manually verified it fails if either (a) the Vite modulePreload filter is removed or (b) a heavy SDK module is statically imported from the entry
  • Manual: create identity, top-up, contract publish, and ?contract= deep-link flows still work; warmup kicks in after first paint
  • Manual: network switch and custom devnet modal still re-initialize clients correctly

Summary by CodeRabbit

  • New Features

    • DPNS utilities: username validation, homograph-safe normalization, contested-name detection, and helper helpers for entries/status counts.
  • Bug Fixes

    • CAP widget no longer loaded at page head; now handled on-demand with retries and timeout handling.
  • Performance

    • Dash platform modules load lazily to improve initial startup.
    • Heavy Dash chunks excluded from automatic preload.
  • Chores

    • CI: added build artifact smoke check and new test scripts.
  • Tests

    • Added suites covering preload logic, loaders, DPNS utilities, CAP widget loading, and related flows.

thephez and others added 4 commits June 3, 2026 13:25
Dynamically import @dashevo/evo-sdk, dpns, contract, client, fee-estimator, and islock modules instead of eagerly bundling them with the main chunk, and load the CAP widget on demand rather than from a blocking script tag. An idle-time warmup primes these modules after first paint so user-initiated flows still feel instant, and the Vite modulePreload policy is adjusted to skip preload links for the heavy SDK chunks. DPNS label utilities are extracted to dpns-utils.ts with a Vitest suite, and the npm test script now runs once by default with test:watch reserved for the watcher.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Add a Vitest suite for the cached module loader and the Vite modulepreload filter to lock in the heavy-chunk exclusion contract, plus a check-build-artifacts.mjs script (wired up as the test:build-artifacts npm script) that asserts the built index.html and entry chunk never statically pull in the deferred Dash SDK chunks. Also covers getStepDescription so the user-facing key-generation copy can't silently drift.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Wire the lazy-Dash-chunk guard into CI between the Build and Test steps so a regression in modulepreload filtering or a static SDK import in the entry bundle fails the pipeline. Failure output now uses the GitHub Actions ::error annotation and a plain banner so the cause is visible from both the workflow summary and raw logs.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
The test script is already "vitest run", so passing --run --passWithNoTests through npm just duplicates the run flag and silently allows an empty suite. Letting npm test drive the invocation keeps CI honest if the suite ever disappears.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Jun 3, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR defers EvoSDK and other heavy module imports via cached dynamic loaders, schedules on-demand warmup on user intent, extracts DPNS utilities with tests, makes the CAP widget load-on-demand, and adds a Vite preload filter plus a CI smoke-check to prevent preloading heavy Dash chunks.

Changes

Lazy SDK Loading and Build Optimization

Layer / File(s) Summary
Build artifact preload filtering and smoke check
src/config/vite-preload.ts, src/config/vite-preload.test.ts, scripts/check-build-artifacts.mjs, .github/workflows/ci.yml, package.json, vite.config.ts
shouldPreloadDashChunk filters heavy Dash-related chunks from Vite modulepreload. A new build smoke check script validates that preloaded links and static entry imports avoid those patterns. CI now runs the check and the test scripts are adjusted.
SDK module lazy loading infrastructure
src/platform/sdkModule.ts, src/platform/loaders.ts, src/platform/loaders.test.ts
New createCachedLoader and loadSdkModule utilities enable deferred dynamic imports with singleton promise caching and retry-on-failure. Module loaders for platform, dpns, contract, client, fee estimator, and islock are exported, plus warmDashModules() to preload all in parallel.
CAP widget on-demand loading
index.html, src/api/faucet.ts, src/api/faucet.test.ts
Removed eager CAP widget script from HTML head. solveCap now calls loadCapWidget() to inject the CDN script on-demand, reusing existing script elements, caching the load operation, handling timeout/error, and tests cover failure/retry and timeout.
DPNS utilities extraction and refactoring
src/platform/dpns-utils.ts, src/platform/dpns-utils.test.ts, src/platform/dpns.ts, src/ui/components.ts, src/ui/state.ts, src/ui/state.test.ts
New dpns-utils module exports label validation, homograph-safe conversion, contested-username detection, and entry aggregation helpers with comprehensive tests. dpns.ts re-exports and delegates to these utilities, and downstream UI imports are updated to use the new module. Step description label updated to "Preparing Dash Platform...".
Platform SDK modules lazy loading
src/platform/client.ts, src/platform/contract.ts, src/platform/identity.ts
createPlatformSdk becomes async and loads EvoSDK on-demand. publishContract and identity functions (registerIdentity, topUpIdentity, updateIdentity, sendToPlatformAddress) load SDK classes via loadSdkModule() at runtime. toSdkProof is now async and resolves AssetLockProof/OutPoint dynamically.
Main.ts lazy loading and client initialization
src/main.ts
ensureClients() gates network client initialization behind a cached promise, deferring setup until needed. Dash module warmup is triggered by user interaction (pointerenter/focus/touchstart) on mode-entry buttons before their click handlers execute. Network polling is guarded to only run when clients exist. Bridge flows (top-up, send-to-address, identity create), recheck, chainlock fallback, and contract/DPNS registration dynamically load platform functions instead of using static imports. Contract deep-link hydration is now async and uses dynamic fee-estimator loading.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • dashpay/dash-bridge#15: Adds the send_to_address mode and new sendToPlatformAddress implementation that this PR integrates via dynamic lazy loading in bridge flows.
  • dashpay/dash-bridge#14: Refactors identity flows in src/platform/identity.ts with typed AssetLockProofData that this PR's async toSdkProof and dynamic SDK loading must coordinate with.
  • dashpay/dash-bridge#23: Also refactors Dash Platform EvoSDK connection in src/platform/client.ts and downstream flows, overlapping with the same client/contract/identity integration points affected by this PR's lazy loading changes.

"🐇 I waited for the hover, then fetched with a smile,
The heavy chunks hid — they won't slow the first mile.
CI checks the build while SDKs nap tight,
CAP wakes on demand and DPNS looks right.
Warmup on intent — everything loads just in time."

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main objective: deferring heavy Dash SDK chunks to improve initial load time, which is the core performance optimization across all changes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (2)
scripts/check-build-artifacts.mjs (1)

52-53: ⚡ Quick win

Consider refactoring the static import regex for maintainability.

The staticImportPattern is complex and attempts to match both bare imports (import "...") and named imports (import X from "..."). While functionally correct, the duplicated chunk-name list and complex alternation make it fragile. Consider extracting the chunk names to a shared constant or building the regex programmatically.

♻️ Proposed refactor to reduce duplication
+const heavyChunkNames = 'evo-sdk|dapi-client|dashcore-lib|dapi-subscription|islock';
+const heavyChunkPattern = new RegExp(`(?:${heavyChunkNames})`);
-const heavyChunkPattern = /(?:evo-sdk|dapi-client|dashcore-lib|dapi-subscription|islock)/;

 // ...later...

-const staticImportPattern =
-  /\bimport\s*(?:["'][^"']*(?:evo-sdk|dapi-client|dashcore-lib|dapi-subscription|islock)[^"']*["']|[\w*{}\s,]+from\s*["'][^"']*(?:evo-sdk|dapi-client|dashcore-lib|dapi-subscription|islock)[^"']*["'])/;
+const staticImportPattern = new RegExp(
+  `\\bimport\\s*(?:["'][^"']*(?:${heavyChunkNames})[^"']*["']|[\\w*{}\\s,]+from\\s*["'][^"']*(?:${heavyChunkNames})[^"']*["'])`
+);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/check-build-artifacts.mjs` around lines 52 - 53, The
staticImportPattern regex is fragile due to duplicated chunk-name lists and
complex alternation; extract the list of module chunk names (e.g., "evo-sdk",
"dapi-client", "dashcore-lib", "dapi-subscription", "islock") into a single
constant (e.g., CHUNK_NAMES or CHUNK_ALTERNATION) and programmatically build the
regex for staticImportPattern so both bare imports (import "x") and
named/import-from forms (import ... from "x") reuse that single source of truth;
update the code that defines staticImportPattern to construct the final RegExp
using the shared constant and verify it still matches both import variants.
src/platform/sdkModule.ts (1)

5-12: ⚡ Quick win

Consider using createCachedLoader to eliminate duplication.

The manual promise-caching and rejection-handling logic here duplicates the pattern already extracted in createCachedLoader (loaders.ts lines 1-12). Replacing this with:

export const loadSdkModule = createCachedLoader(() => import('`@dashevo/evo-sdk`'));

would reduce duplication and ensure both SDK and module loaders follow the same retry/cache semantics.

♻️ Proposed refactor
+import { createCachedLoader } from './loaders.js';
+
 export type SdkModule = typeof import('`@dashevo/evo-sdk`');

-let sdkModulePromise: Promise<SdkModule> | null = null;
-
-export function loadSdkModule(): Promise<SdkModule> {
-  if (!sdkModulePromise) {
-    sdkModulePromise = import('`@dashevo/evo-sdk`').catch((err) => {
-      sdkModulePromise = null;
-      throw err;
-    });
-  }
-  return sdkModulePromise;
-}
+export const loadSdkModule = createCachedLoader(() => import('`@dashevo/evo-sdk`'));
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/platform/sdkModule.ts` around lines 5 - 12, The loadSdkModule
implementation duplicates the manual promise-caching and rejection-handling
logic already provided by createCachedLoader; replace the current loadSdkModule
function with a cached loader by exporting loadSdkModule using
createCachedLoader(() => import('`@dashevo/evo-sdk`')), so the module uses the
shared retry/cache semantics and removes the custom sdkModulePromise handling in
loadSdkModule; ensure you remove the old function and any related
sdkModulePromise variable to avoid dead code.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/api/faucet.ts`:
- Around line 122-150: In loadCapWidget, the retry hang happens because a failed
<script data-cap-widget> element remains in the DOM and subsequent querySelector
finds it but its load/error events already fired; update the error handling for
both the existing script branch (the existing variable used in querySelector)
and the newly created script (the script variable) so that on 'error' you remove
the failing element from the DOM (existing.remove() or script.remove()), reset
capWidgetPromise = null, and then reject with the error; ensure the .catch
cleanup remains (or consolidate cleanup into the error handlers) so retries will
re-inject a fresh tag and the promise can settle.
- Around line 136-142: Pin the CDN URL and add a load timeout for the script
element to avoid indefinite waiting: replace the unpinned script.src string used
when creating the script element (`script.src`) with a pinned version (e.g.
'`@cap.js/widget`@<version>') and wrap the load/error handlers with a timeout (use
setTimeout to reject after N ms). In the script load flow (the code that calls
`document.createElement('script')`, `script.addEventListener('load', ...)`,
`script.addEventListener('error', ...)`, and the Promise resolve/reject), ensure
you clear the timeout on both load and error, remove listeners, and call reject
with a descriptive Error on timeout so `solveCap` (or the function that awaits
this promise) will fail fast instead of hanging.

In `@src/config/vite-preload.test.ts`:
- Around line 6-11: Add one assertion to the existing test that verifies the new
"islock" heavy chunk is filtered: call shouldPreloadDashChunk with a
representative islock asset filename (e.g., 'assets/islock-<hash>.js') and
expect false; this ensures the updated HEAVY_DASH_CHUNK_PATTERN change is
covered by the test.

In `@src/config/vite-preload.ts`:
- Line 1: HEAVY_DASH_CHUNK_PATTERN currently omits the "islock" identifier
causing a mismatch with the smoke check's heavyChunkPattern; update the regular
expression referenced as HEAVY_DASH_CHUNK_PATTERN so it includes "islock"
alongside the existing alternatives (e.g.,
evo-sdk|dapi-client|dashcore-lib|dapi-subscription) so Vite's modulePreload
filter will also treat islock as a heavy chunk and keep behavior consistent with
scripts/check-build-artifacts.mjs.

---

Nitpick comments:
In `@scripts/check-build-artifacts.mjs`:
- Around line 52-53: The staticImportPattern regex is fragile due to duplicated
chunk-name lists and complex alternation; extract the list of module chunk names
(e.g., "evo-sdk", "dapi-client", "dashcore-lib", "dapi-subscription", "islock")
into a single constant (e.g., CHUNK_NAMES or CHUNK_ALTERNATION) and
programmatically build the regex for staticImportPattern so both bare imports
(import "x") and named/import-from forms (import ... from "x") reuse that single
source of truth; update the code that defines staticImportPattern to construct
the final RegExp using the shared constant and verify it still matches both
import variants.

In `@src/platform/sdkModule.ts`:
- Around line 5-12: The loadSdkModule implementation duplicates the manual
promise-caching and rejection-handling logic already provided by
createCachedLoader; replace the current loadSdkModule function with a cached
loader by exporting loadSdkModule using createCachedLoader(() =>
import('`@dashevo/evo-sdk`')), so the module uses the shared retry/cache semantics
and removes the custom sdkModulePromise handling in loadSdkModule; ensure you
remove the old function and any related sdkModulePromise variable to avoid dead
code.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e5268a0f-cc58-422c-b548-d61afb33a211

📥 Commits

Reviewing files that changed from the base of the PR and between 3d255c9 and 9b83619.

📒 Files selected for processing (21)
  • .github/workflows/ci.yml
  • index.html
  • package.json
  • scripts/check-build-artifacts.mjs
  • src/api/faucet.ts
  • src/config/vite-preload.test.ts
  • src/config/vite-preload.ts
  • src/main.ts
  • src/platform/client.ts
  • src/platform/contract.ts
  • src/platform/dpns-utils.test.ts
  • src/platform/dpns-utils.ts
  • src/platform/dpns.ts
  • src/platform/identity.ts
  • src/platform/loaders.test.ts
  • src/platform/loaders.ts
  • src/platform/sdkModule.ts
  • src/ui/components.ts
  • src/ui/state.test.ts
  • src/ui/state.ts
  • vite.config.ts
💤 Files with no reviewable changes (1)
  • index.html

Comment thread src/api/faucet.ts Resolved
Comment thread src/api/faucet.ts Resolved
Comment thread src/config/vite-preload.test.ts Resolved
Comment thread src/config/vite-preload.ts Resolved
Pin the CAP widget CDN to a specific version, add a 30s load timeout, and remove the script tag on failure so a retry can inject a fresh one. Also exclude the islock chunk from preload alongside the other heavy Dash modules.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/api/faucet.test.ts (1)

76-109: 💤 Low value

Optional: cover the reuse-existing-script and "loaded without exposing Cap" branches.

The two tests exercise error→retry and timeout, but loadCapWidget has two untested branches that are easy to regress: reusing an already-present script[data-cap-widget] (the existing path), and the load event firing while Cap is still undefined (rejects with "CAP widget loaded without exposing Cap"). Since the fake document already tracks scripts and querySelector, adding these cases is low-cost and locks in the loader's idempotency/guard behavior.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/api/faucet.test.ts` around lines 76 - 109, Add two unit tests for
loadCapWidget/solveCap: one that simulates an existing <script data-cap-widget>
in the fake document (reuse-existing-script path) so calling solveCap or
loadCapWidget returns/uses the existing script rather than injecting another,
and assert no duplicate script is created and behavior is correct; and another
that simulates the <script> firing a 'load' event while the global Cap is still
undefined to exercise the "CAP widget loaded without exposing Cap" branch
(expect a rejection with that message and ensure the script is removed). Use the
existing helpers installFakeDocument, installCap, and reference
loadCapWidget/solveCap and the script[data-cap-widget] attribute to locate the
code paths to test.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/api/faucet.test.ts`:
- Around line 76-109: Add two unit tests for loadCapWidget/solveCap: one that
simulates an existing <script data-cap-widget> in the fake document
(reuse-existing-script path) so calling solveCap or loadCapWidget returns/uses
the existing script rather than injecting another, and assert no duplicate
script is created and behavior is correct; and another that simulates the
<script> firing a 'load' event while the global Cap is still undefined to
exercise the "CAP widget loaded without exposing Cap" branch (expect a rejection
with that message and ensure the script is removed). Use the existing helpers
installFakeDocument, installCap, and reference loadCapWidget/solveCap and the
script[data-cap-widget] attribute to locate the code paths to test.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d780cba1-2f35-4c1c-9408-6c8427a7f25f

📥 Commits

Reviewing files that changed from the base of the PR and between 9b83619 and 89ce89d.

📒 Files selected for processing (4)
  • src/api/faucet.test.ts
  • src/api/faucet.ts
  • src/config/vite-preload.test.ts
  • src/config/vite-preload.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/config/vite-preload.test.ts
  • src/config/vite-preload.ts
  • src/api/faucet.ts

@PastaPastaPasta
PastaPastaPasta merged commit 64ae4e2 into dashpay:main Jun 4, 2026
2 checks passed
PastaPastaPasta added a commit that referenced this pull request Oct 24, 2026
…rpc.digitalcash.dev (#53)

* feat(testnet): read InstantSend locks from the DAPI bloom stream

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 <[email protected]>

* feat(islock): subscribe on several evonodes at once and take the first 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 <[email protected]>

* refactor(islock): drop redundant node counters in multi-node subscribe

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 <[email protected]>

* fix(testnet): read Platform status through the EvoSDK

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 <[email protected]>

* feat(testnet): fetch the live evonode list at client init

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 <[email protected]>

* docs(testnet): align comments, docs and e2e with the DAPI stream model

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 <[email protected]>

* fix(testnet): harden client init, status routing and evonode parsing

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 <[email protected]>

* fix(islock): fail the subscription before broadcast when every node fails

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 <[email protected]>

* fix(islock): race the start height across nodes instead of one random 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 <[email protected]>

* fix(testnet): don't download the EvoSDK just for the health indicator

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 <[email protected]>

* fix(ui): keep the health indicator fresh and visible across resets

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 <[email protected]>

* feat(islock): log which node delivered the InstantSend lock

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 <[email protected]>

* fix(testnet): address review of the height race and health indicator

- 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 <[email protected]>

* feat(testnet): connect the EvoSDK when a funding flow starts

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 <[email protected]>

* fix(testnet): keep the degraded verdict stable and polls from racing

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 <[email protected]>

---------

Co-authored-by: Claude Sonnet 5.5 <[email protected]>
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