Repository navigation
fix(wasm-sdk): preserve user-supplied addresses in withTrustedContext - #3912
QuantumExplorer merged 2 commits into
Conversation
WasmSdkBuilder.withAddresses([...]).withTrustedContext(ctx) used to silently overwrite the caller's explicit address list with whatever masternode addresses the trusted context discovered. That defeated the only knob users had to point the SDK at a specific node (testing, private deployments, a sticky single-node sandbox). Track an explicit has_user_addresses flag on the builder, set only by withAddresses(...). Preset constructors (mainnet/testnet/local/ newDevnet) leave it false so they continue to adopt the context's discovered addresses. All chain methods (withProofs, withSettings, withVersion, withContextProvider, withLogs, withTrustedContext itself) propagate the flag. Adds Rust unit tests covering the flag transitions and verifies via the built Sdk's address list that user-supplied addresses survive the trusted-context substitution while preset defaults are still replaced. A #[cfg(test)] helper builds a stub WasmTrustedContext with synthetic discovered addresses without touching the network. Fixes dashpay#3172
- Use struct functional-update syntax (..self) in the five chain methods that return a new WasmSdkBuilder, dropping per-call field copies for trusted_context and has_user_addresses. - Collapse the post-build address inspection in tests behind a sdk_addresses(&WasmSdk) helper. - Cover withLogs propagation in the chain-flag test so the commit's claim that every chain method preserves the flag is exercised. No behavior change; all 7 sdk::tests still pass.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds a ChangesWasmSdkBuilder address preservation fix
Sequence Diagram(s)sequenceDiagram
participant Caller
participant WasmSdkBuilder
participant WasmTrustedContext
Caller->>WasmSdkBuilder: withAddresses(['my-node:1443'], 'testnet')<br/>(has_user_addresses = true)
Caller->>WasmTrustedContext: prefetchTestnet() → discovered ~60 nodes
Caller->>WasmSdkBuilder: withTrustedContext(context)
WasmSdkBuilder->>WasmSdkBuilder: has_user_addresses == true → skip address replacement
WasmSdkBuilder->>WasmSdkBuilder: attach context provider only
WasmSdkBuilder-->>Caller: builder retains ['my-node:1443'] + trusted context
Caller->>WasmSdkBuilder: build()
WasmSdkBuilder-->>Caller: SDK connects to my-node:1443 with proof verification
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
|
✅ Review complete (commit 424834b) |
thepastaclaw
left a comment
There was a problem hiding this comment.
Code Review
Clean, surgical fix that adds a has_user_addresses provenance flag to WasmSdkBuilder so withTrustedContext no longer silently overwrites caller-supplied DAPI addresses. Verified the flag is correctly set (true only in new_with_addresses), propagated via ..self through every chain method (with_proofs, with_settings, with_version, with_context_provider, with_logs, with_trusted_context), and consulted at sdk.rs:320 to gate discovered-address substitution. Tests cover bug repro, preset-still-substitutes counterpart, empty discovered list, and flag propagation. No in-scope blocking, security, FFI, or correctness issues found.
GitHub does not allow PastaClaw to approve their own PR, so this clean review is posted as a COMMENT review rather than an APPROVE review.
No findings.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## v3.1-dev #3912 +/- ##
============================================
+ Coverage 71.20% 72.19% +0.99%
============================================
Files 20 21 +1
Lines 2837 2946 +109
============================================
+ Hits 2020 2127 +107
- Misses 817 819 +2
🚀 New features to boost your workflow:
|
Issue being fixed or feature implemented
Fixes #3172.
`WasmSdkBuilder.withAddresses([...]).withTrustedContext(ctx)` was silently overwriting the caller's explicit address list with whatever masternode addresses the trusted context had discovered. That defeated the only knob users had for pointing the WASM SDK at a specific node (testing, private deployments, a sticky single-node sandbox).
What was done?
Introduce a `has_user_addresses: bool` flag on `WasmSdkBuilder`:
Cleanups bundled in a follow-up refactor commit: chain-method returns use `..self` struct-update syntax instead of copying `trusted_context` / `has_user_addresses` by hand at every site.
How Has This Been Tested?
New Rust unit tests in `packages/wasm-sdk/src/sdk.rs` (7 added, all green; existing 15 still green):
A `#[cfg(test)] WasmTrustedContext::for_testing(discovered)` helper builds a real-but-unused inner provider against `http://127.0.0.1:22444\` (Regtest skips the HTTPS guard; `verify_domain_resolves` only does `to_socket_addrs` on the IP literal — no DNS, no network dial).
Validation run locally:
A wasm32 build was attempted but failed in the local toolchain on `secp256k1-sys` (clang missing wasm sysroot configuration) — unrelated to this change; the host `cargo check` over the same Rust source is clean.
Breaking Changes
None. The public `WasmSdkBuilder` JS surface is unchanged; the new field is `#[wasm_bindgen]`-invisible. Preset + trusted-context callers see the same address-substitution behavior as before; only the previously broken `withAddresses + withTrustedContext` path changes — and only to honor what the user asked for.
Checklist:
Summary by CodeRabbit
Bug Fixes
Tests