Skip to content

Commit 81a9b55

Browse files
authored
Wasm followup (#82)
* Wasm followup cleanup * Add tools in docker
1 parent b8c29da commit 81a9b55

16 files changed

Lines changed: 458 additions & 184 deletions

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
!src/
1313
!migration/
1414
!build.rs
15+
!tools/
1516

1617
# but still ignore these
1718
rust-lightning/.git
1819
rust-lightning/.github
1920
rust-lightning/.gitignore
21+
tools/wasm-proxy-gateway/target

bindings/wasm-sdk/ARCHITECTURE.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This document is the **canonical architecture reference** for the WASM-related s
55
- **WASM SDK crate**: `bindings/wasm-sdk` (browser-facing `wasm-bindgen` SDK)
66
- **WS↔TCP gateway + dev helpers**: `tools/wasm-proxy-gateway`
77
- **Browser E2E**: `e2e-specs` + `scripts/ci/wasm_regular_rln_e2e.sh`
8-
- **Shared contracts**: `src/sdk/contracts` (types + stable error strings + drift fixtures)
8+
- **Shared contracts**: the `sdk-contracts` crate (git dependency; types + stable error strings)
99

1010
## Components
1111

@@ -66,10 +66,10 @@ flowchart LR
6666
BrowserDemo -->|submitFundingTransaction*| BrowserWasm["Browser WASM (LDK)"]
6767
```
6868

69-
## Contracts and drift prevention
69+
## Contracts
7070

71-
- **Shared contract types + stable error strings** live in `src/sdk/contracts`.
72-
- **Golden JSON fixtures** are enforced by `cargo test -p sdk-contracts`.
71+
- **Shared contract types + stable error strings** live in the `sdk-contracts` crate,
72+
consumed as a git dependency (see `bindings/wasm-sdk/Cargo.toml`).
7373

7474
## How to run
7575

Lines changed: 35 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,72 @@
1-
# LN WASM Native Parity Spec
1+
# LN WASM Native Parity
22

33
## Purpose
44

5-
This document freezes the implementation scope and acceptance criteria for
6-
fully native LN behavior in browser WASM (Mutiny-style runtime model), while
7-
keeping existing RLN SDK API contracts stable.
8-
9-
This is the source of truth for:
10-
11-
- what "fully ported LN behavior" means,
12-
- which infra is still external,
13-
- and what tests must pass before declaring parity complete.
5+
This document describes how LN behavior runs natively in browser WASM
6+
(Mutiny-style runtime model) while keeping the existing RLN SDK API contracts
7+
stable. It covers what "native LN behavior" means here, which infra stays
8+
external, and which behaviors the test suite exercises.
149

1510
## Scope Boundary
1611

17-
### In scope (must be native in WASM)
12+
### Native in WASM
1813

19-
1. LN runtime state machine authority is local in WASM (no RLN runtime bridge
20-
service as LN decision-maker).
14+
1. The LN runtime state-machine authority is local in WASM (no RLN runtime
15+
bridge service acts as the LN decision-maker).
2116
2. Peer/session/channel/payment state transitions are event-driven from local
2217
LDK runtime components.
2318
3. Runtime persistence/recovery works across page reload and browser restart.
24-
4. Public wasm node/sdk APIs return deterministic contracts equivalent to
19+
4. Public wasm node/sdk APIs return deterministic contracts equivalent to the
2520
existing SDK semantics.
2621

27-
### Out of scope (external infra remains required)
22+
### External infra required
2823

2924
1. Relay/proxy service for browser websocket transport bridging.
3025
2. Bitcoin chain source/indexer (Esplora).
3126
3. RGB transport endpoint.
3227
4. Funding/signing providers (wallet signer integration for on-chain tx flows).
3328

34-
## Definition of Done (Parity)
35-
36-
Parity is complete only when all are true:
29+
## Parity Properties
3730

3831
1. LN payment and channel lifecycle transitions are driven by local runtime
3932
events, not manual status APIs.
40-
2. Runtime can recover channel/payment state after reload without corruption.
33+
2. The runtime recovers channel/payment state after reload without corruption.
4134
3. `open_channel`, `close_channel`, `create_ln_invoice`, `send_payment`,
42-
`keysend`, `invoice_status`, `list_payments`, `get_payment` match frozen
43-
contracts for:
44-
- input validation (IV),
45-
- state transitions (ST),
46-
- output shape (OS),
47-
- error contracts (EC).
35+
`keysend`, `invoice_status`, `list_payments`, and `get_payment` honor stable
36+
contracts for input validation (IV), state transitions (ST), output shape
37+
(OS), and error contracts (EC).
4838
4. Virtual channel logic is bound to real runtime state and safety checks.
49-
5. Browser integration tests (not only compile checks) are green in CI.
5039

51-
## Behavioral Contract Freeze
40+
## Behavioral Contracts
5241

5342
### Runtime authority
5443

55-
1. Local runtime owns truth for peers/channels/payments.
44+
1. The local runtime owns truth for peers/channels/payments.
5645
2. API read methods (`node_info`, `network_info`, list/get APIs) read from
57-
runtime state, not from local ad-hoc shadow state.
46+
runtime state, not from ad-hoc shadow state.
5847

5948
### Payments
6049

61-
1. `pending -> claimable/claiming/succeeded/failed/expired/cancelled` transitions
62-
must obey strict transition rules.
50+
1. `pending -> claimable/claiming/succeeded/failed/expired/cancelled`
51+
transitions obey strict transition rules.
6352
2. Terminal state regressions are rejected with deterministic errors.
6453
3. Swap/runtime observers and RGB-LN transfer observers receive the same final
6554
status.
6655

6756
### Channels
6857

69-
1. `open -> usable -> closing/closed` semantics remain deterministic.
70-
2. Reconnect must not duplicate live channels or peers.
71-
3. Channel close safety checks must be consistent across restart/recovery.
58+
1. `open -> usable -> closing/closed` semantics are deterministic.
59+
2. Reconnect does not duplicate live channels or peers.
60+
3. Channel close safety checks are consistent across restart/recovery.
7261

7362
### Recovery
7463

75-
1. Snapshot schema is versioned.
76-
2. Checkpoint protocol is crash-safe (pending+committed recovery semantics).
77-
3. Recreated node handle for same runtime key restores state without manual
78-
repair.
64+
1. The snapshot schema is versioned.
65+
2. The checkpoint protocol is crash-safe (pending+committed recovery semantics).
66+
3. A recreated node handle for the same runtime key restores state without
67+
manual repair.
7968

80-
## Acceptance Test Matrix (Must be Green)
69+
## Test Coverage
8170

8271
### A. Runtime lifecycle and recovery
8372

@@ -122,23 +111,12 @@ Parity is complete only when all are true:
122111
2. SDK facade forwarding parity.
123112
3. SDK node-handle forwarding parity.
124113

125-
## CI Gate Requirements
126-
127-
1. `cargo check --target wasm32-unknown-unknown` (wasm-sdk crate).
128-
2. `cargo test --target wasm32-unknown-unknown --no-run` (wasm-sdk crate).
129-
3. Browser wasm test execution job (wasm-bindgen test path) for contract tests.
130-
131-
The crate targets `wasm32` only (the `real-wasm-rgb` backend feature is on by default), so all
132-
compile checks use the wasm32 target.
133-
134-
Parity cannot be declared complete until all three gate groups are green on CI.
135-
136-
## Tracking Convention
114+
## Build and test commands
137115

138-
For every parity work item, include:
139-
140-
1. module/file ownership,
141-
2. contract impact (IV/ST/OS/EC),
142-
3. test id(s) added/updated,
143-
4. CI gate affected.
116+
The crate targets `wasm32` only (the `real-wasm-rgb` backend feature is on by
117+
default), so all compile checks use the wasm32 target:
144118

119+
1. `cargo check --target wasm32-unknown-unknown` (wasm-sdk crate) — run in CI.
120+
2. `cargo test --target wasm32-unknown-unknown --no-run` (wasm-sdk crate).
121+
3. Browser wasm test execution (`scripts/run-browser-tests.sh`, wasm-bindgen
122+
test path) for the contract tests — run locally.

bindings/wasm-sdk/README.md

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ See [ARCHITECTURE.md](ARCHITECTURE.md) for the consolidated WASM stack overview
1111
## Scope
1212

1313
- Target: browser and Node.js consumers via `wasm-bindgen` output.
14-
- Focus: SDK parity where feasible in WASM.
15-
- Current intentional gap: `issue_asset_uda` remains unsupported for now.
14+
- Focus: SDK parity in WASM.
15+
- `issue_asset_uda` is unsupported (no UDA primitive in `rgb-lib-wasm`).
1616

1717
For endpoint-level status, see [SDK_WASM_ENDPOINT_MATRIX.md](SDK_WASM_ENDPOINT_MATRIX.md).
1818

@@ -62,11 +62,11 @@ docker compose -f compose.wasm.yaml up -d
6262

6363
This brings up:
6464

65-
- RGB proxy: `127.0.0.1:3005` (host port mapped from compose `proxy`)
65+
- RGB proxy: `127.0.0.1:3000` (host port mapped from compose `proxy`)
6666
- WASM proxy gateway: `127.0.0.1:3001`
6767
- Esplora HTTP: `127.0.0.1:3002`
68-
- Electrum: `127.0.0.1:50011` (host port mapped from compose `electrs`)
69-
- Bitcoind RPC: `127.0.0.1:19443` (host port for `compose.wasm-infra.yaml` / `compose.wasm.yaml` bitcoind)
68+
- Electrum: `127.0.0.1:50001` (host port mapped from compose `electrs`)
69+
- Bitcoind RPC: `127.0.0.1:18443` (host port mapped from compose `bitcoind`)
7070

7171
Build WASM package for browser examples:
7272

@@ -111,18 +111,12 @@ model) and avoids REST coupling.
111111

112112
## CI
113113

114-
WASM checks are wired into CI in `.github/workflows/test.yaml`:
114+
WASM checks run in `.github/workflows/test.yaml`: the `feature-matrix` job's
115+
`wasm-without-vls` mode runs `cargo check --target wasm32-unknown-unknown` against
116+
`bindings/wasm-sdk/Cargo.toml`. The package `pkg/` artifact is built separately by
117+
`.github/workflows/wasm-artifacts.yaml` via `wasm-pack build`.
115118

116-
- `wasm-sdk` (wasm32 crate check + test-binary compile)
117-
- `wasm-sdk-wasm32` (target compatibility check)
118-
- `wasm-sdk-browser` (blocking headless browser run in Chrome)
119-
- `wasm-sdk-browser-diagnostic-firefox` (non-blocking diagnostic run in Firefox)
120-
121-
Both browser jobs pin:
122-
- `wasm-pack` to `0.13.1`
123-
- `wasm-bindgen-test-runner` to `0.2.117` (verified in CI after test bootstrap)
124-
125-
Local browser test command (same wrapper used by CI):
119+
Run the browser unit tests locally (not run in CI):
126120

127121
```sh
128122
WASM_BINDGEN_TEST_TIMEOUT=300 WASM_TEST_BROWSER=chrome ./bindings/wasm-sdk/scripts/run-browser-tests.sh

bindings/wasm-sdk/RGB_WASM_PROXY_TRANSPORT_SPEC.md

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
1-
# RGB WASM Proxy Transport Spec
1+
# RGB WASM Proxy Transport
22

33
## Purpose
44

5-
This document freezes the architecture boundary for porting RGB business logic
6-
to native wasm runtime while routing RGB network transport through a proxy
5+
This document describes the architecture boundary: RGB business logic runs in
6+
the native wasm runtime, while RGB network transport is routed through a proxy
77
service colocated with LN websocket proxying.
88

9-
This is the scope/contract baseline for the RGB-native migration track.
10-
119
## Scope Boundary
1210

13-
### In scope (must become wasm-native)
11+
### Native in the wasm runtime
1412

15-
1. RGB transfer orchestration and lifecycle state transitions in wasm runtime.
13+
1. RGB transfer orchestration and lifecycle state transitions.
1614
2. RGB runtime persistence and recovery in browser storage.
1715
3. Deterministic wasm API contracts for RGB operations and status surfaces.
1816
4. LN<->RGB status synchronization in wasm runtime observers.
1917

20-
### Out of scope (external infra still required)
18+
### External infra required
2119

2220
1. RGB network transport service itself (provided by proxy upstream).
2321
2. Bitcoin chain source/indexer (Esplora).
2422
3. Funding/signing provider integration for on-chain tx flows.
2523

26-
## Proxy Contract (Frozen)
24+
## Proxy Contract
2725

2826
Browser-facing routes (example):
2927

@@ -38,26 +36,20 @@ Transport contract requirements:
3836
4. Tenant isolation: requests for one session/node cannot access another session.
3937
5. Request size/time limits and rate limiting are enforced.
4038

41-
## Wasm Runtime Contract (Frozen)
39+
## Wasm Runtime Contract
4240

43-
1. Wasm runtime is authoritative for RGB transfer state machine.
44-
2. Proxy is transport-only; business decisions are not delegated to proxy.
41+
1. The wasm runtime is authoritative for the RGB transfer state machine.
42+
2. The proxy is transport-only; business decisions are not delegated to it.
4543
3. Runtime state persistence uses browser-backed storage with deterministic
4644
recovery semantics.
47-
4. Error contracts returned by wasm APIs remain deterministic and documented in
45+
4. Error contracts returned by wasm APIs are deterministic and documented in
4846
`ERROR_CONTRACT.md`.
4947

50-
## Deliverables
51-
52-
1. This boundary/spec document.
53-
2. README reference to this document.
54-
3. No behavior changes are required by this document.
55-
56-
## Exit Criteria
48+
## Responsibility split
5749

58-
1. Team agrees on responsibility split (wasm runtime vs proxy).
59-
2. No ambiguous ownership for transport, state, or auth/session logic.
60-
3. Follow-up implementation steps can proceed without redefining boundaries.
50+
The wasm runtime owns RGB transfer state, persistence, and auth/session logic;
51+
the proxy owns only transport. There is no shared ownership of transport, state,
52+
or auth/session logic across the boundary.
6153

6254
## RGB on the LN peer link (not the HTTP proxy)
6355

0 commit comments

Comments
 (0)