|
1 | | -# LN WASM Native Parity Spec |
| 1 | +# LN WASM Native Parity |
2 | 2 |
|
3 | 3 | ## Purpose |
4 | 4 |
|
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. |
14 | 9 |
|
15 | 10 | ## Scope Boundary |
16 | 11 |
|
17 | | -### In scope (must be native in WASM) |
| 12 | +### Native in WASM |
18 | 13 |
|
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). |
21 | 16 | 2. Peer/session/channel/payment state transitions are event-driven from local |
22 | 17 | LDK runtime components. |
23 | 18 | 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 |
25 | 20 | existing SDK semantics. |
26 | 21 |
|
27 | | -### Out of scope (external infra remains required) |
| 22 | +### External infra required |
28 | 23 |
|
29 | 24 | 1. Relay/proxy service for browser websocket transport bridging. |
30 | 25 | 2. Bitcoin chain source/indexer (Esplora). |
31 | 26 | 3. RGB transport endpoint. |
32 | 27 | 4. Funding/signing providers (wallet signer integration for on-chain tx flows). |
33 | 28 |
|
34 | | -## Definition of Done (Parity) |
35 | | - |
36 | | -Parity is complete only when all are true: |
| 29 | +## Parity Properties |
37 | 30 |
|
38 | 31 | 1. LN payment and channel lifecycle transitions are driven by local runtime |
39 | 32 | 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. |
41 | 34 | 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). |
48 | 38 | 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. |
50 | 39 |
|
51 | | -## Behavioral Contract Freeze |
| 40 | +## Behavioral Contracts |
52 | 41 |
|
53 | 42 | ### Runtime authority |
54 | 43 |
|
55 | | -1. Local runtime owns truth for peers/channels/payments. |
| 44 | +1. The local runtime owns truth for peers/channels/payments. |
56 | 45 | 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. |
58 | 47 |
|
59 | 48 | ### Payments |
60 | 49 |
|
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. |
63 | 52 | 2. Terminal state regressions are rejected with deterministic errors. |
64 | 53 | 3. Swap/runtime observers and RGB-LN transfer observers receive the same final |
65 | 54 | status. |
66 | 55 |
|
67 | 56 | ### Channels |
68 | 57 |
|
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. |
72 | 61 |
|
73 | 62 | ### Recovery |
74 | 63 |
|
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. |
79 | 68 |
|
80 | | -## Acceptance Test Matrix (Must be Green) |
| 69 | +## Test Coverage |
81 | 70 |
|
82 | 71 | ### A. Runtime lifecycle and recovery |
83 | 72 |
|
@@ -122,23 +111,12 @@ Parity is complete only when all are true: |
122 | 111 | 2. SDK facade forwarding parity. |
123 | 112 | 3. SDK node-handle forwarding parity. |
124 | 113 |
|
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 |
137 | 115 |
|
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: |
144 | 118 |
|
| 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. |
0 commit comments