Repository navigation
feat(wasm-sdk): let apps seed the contracts they already hold - #4745
Conversation
An app knows its contracts at build time, yet the browser SDK offered no way to hand them over: the cache filled only through fetches, so every load paid a contract round trip before its first document query. And the one query that could confirm a held contract is still current, getDataContractsLatestVersions, was exposed proved only, whose proof is the full multi-contract proof and costs as much as fetching the contracts. Add the two entry points the bundled-contract flow needs: - `addKnownContract(contract)` seeds the trusted-context cache (and, through it, the persisted store) with a contract the caller holds. Returns false without a trusted context. - `getDataContractsLatestVersionsUnproved(query)` answers versions from the unproved path rs-sdk already provides: the node's word, checked for freshness through the signed metadata, a few bytes per id. Versions only: `includeContracts` is refused, because contracts enter the cache through proved fetches alone. The trust model is bounded: a node overstating a version costs the caller one proved fetch; one understating it leaves the caller on its held contract, which the `$contractVersion` guard drops on the first document written under the newer version. evo-sdk exposes both as `contracts.addKnown` and `contracts.getLatestVersionsUnproved`, and the README shows the flow: seed the bundle, revalidate unproved off the critical path, fetch only what changed, proved. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
|
🕓 Queued for automated review — 10th in line, estimated start in ~50 min (commit 3eafd55)
|
…eeding The proved version proof is being made cheaper, so an unproved primitive would be a detour that also widened the trust surface. Apps seed the contracts they hold with `addKnownContract` and confirm them with the proved `getDataContractsLatestVersions` off the critical path, inheriting the cheaper proof when it lands. Co-Authored-By: Claude Fable 5.1 <[email protected]>
f6dc8ed
into
feat/wasm-sdk-persist-contracts
…n load (#399) * perf(sdk): bundle the deployed contracts and seed the SDK from them on load The app knows its contracts at build time, yet every load fetched all of them (one batched proved request, 0.7 to 1.3 s on moutai) before the first document query could run. Snapshot them instead. `npm run contracts:snapshot` writes the network's deployed contracts to `lib/contracts/bundled/<network>.json` (version + serialized bytes; one file per network, loaded on demand so a build ships only its own). On load the SDK service seeds the SDK with every bundled contract the deployment configures and fetches only the rest, then, off the critical path, asks the network unproved which bundled versions are stale and refetches those proved. Both SDK entry points (`contracts.addKnown`, `contracts.getLatestVersionsUnproved`, dashpay/platform#4745) land in a later evo-sdk than the pinned dev.10; until then the capability checks fall through to the existing preload, so this is inert today and switches on with the SDK bump. The snapshot script warms the devnet connection with one DPNS read before the first v6 contract fetch, the same protocol-version bootstrap the app does. Co-Authored-By: Claude Fable 5.1 <[email protected]> * refactor(sdk): revalidate bundled contracts through the proved versions check The proved versions proof is being made cheaper upstream, so the check no longer routes through an unproved variant. Versions only, off the critical path; the SDK bump that carries `contracts.getLatestVersions` switches it on. Co-Authored-By: Claude Fable 5.1 <[email protected]> --------- Co-authored-by: Quantum Explorer <[email protected]> Co-authored-by: Claude Fable 5.1 <[email protected]>
Issue being fixed or feature implemented
An app knows its contracts at build time, yet the browser SDK offers no way to hand them over: the trusted-context cache fills only through fetches, so every page load pays a contract round trip (0.7 to 1.3 s on Yappr against moutai) before its first document query. #4744 removes that on repeat visits by persisting fetched contracts; this PR removes it on first visits too, by letting the app seed a bundled snapshot.
Stacked on #4744, whose
$contractVersionstaleness guard also covers seeded contracts, and whose persistence they inherit. Retarget tov4.2-devonce it merges.What was done?
WasmSdk.addKnownContract(contract)seeds the trusted-context cache with a contract the caller holds (a bundled snapshot, a contract it just published). Throughcache_contractit is persisted like a fetched one. Returnsfalsewhen the SDK has no trusted context.contracts.addKnown(contract), and a README section showing the flow: seed the bundle, then confirm it off the critical path with the provedcontracts.getLatestVersions(feat(platform): add getDataContractsLatestVersions query for cheap contract staleness checks #4739) and refetch only what changed. As that proof gets cheaper the flow gets cheaper with it, with no API change.An unproved variant of the versions check was in an earlier revision of this PR and is gone: with the proved proof being slimmed down it would have been a detour that widened the trust surface for nothing.
How Has This Been Tested?
cargo test -p wasm-sdk --lib: 128 passed. New native test: seeding through the JS-facing entry point lands in the cache and the persisted store, and is a no-op without a trusted context.tests/functional/contracts.spec.ts:addKnownContractaccepts a fetched contract.cargo clippy -p wasm-sdk --lib --testsand--target wasm32-unknown-unknown: no findings in wasm-sdk.Breaking Changes
None. One new method on
WasmSdkand one on the evo-sdk contracts facade.Checklist:
For repository code-owners and collaborators only
🤖 Generated with Claude Code