Skip to content

Commit 26431d7

Browse files
committed
Add some documentation on the exposed WASM API and WebRTC peer address format
1 parent 347635b commit 26431d7

File tree

3 files changed

+158
-9
lines changed

3 files changed

+158
-9
lines changed

node/web/src/lib.rs

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,57 @@ fn parse_bp_key(key: JsValue) -> Option<AccountSecretKey> {
7474
)
7575
}
7676

77+
/// Starts a Mina node in a WASM environment and returns an RPC interface.
78+
///
79+
/// This is the main entry point for running a Mina node from JavaScript/WASM.
80+
/// It spawns the node in a separate thread, sets up all necessary components,
81+
/// and returns an RPC sender that can be used to communicate with the running
82+
/// node.
83+
///
84+
/// # Arguments
85+
///
86+
/// * `block_producer` - Block producer configuration as a JavaScript value.
87+
/// Can be one of:
88+
/// - `null`/`undefined`: No block production
89+
/// - `string`: Plain text secret key
90+
/// - `[encrypted_key, password]`: Array with encrypted key and password
91+
/// * `seed_nodes_urls` - Optional list of URLs to fetch peer lists from.
92+
/// Each URL should return newline-separated peer addresses. This is similar
93+
/// to the `--peer-list-url` flag in the native node, but allows multiple URLs
94+
/// to be supplied.
95+
/// * `seed_nodes_addresses` - Optional list of peer addresses to connect to
96+
/// directly, in [WebRTC Multiaddr-ish format](https://o1-labs.github.io/mina-rust/docs/developers/webrtc#address-format-differences)
97+
/// This is directly comparable to the `--peers` flag in the native node.
98+
/// * `genesis_config_url` - Optional URL to fetch genesis configuration from.
99+
/// Genesis config must be in bin_prot format. If not provided, uses the default
100+
/// devnet configuration.
101+
///
102+
/// # Returns
103+
///
104+
/// An `RpcSender` that can be used to send RPC commands to the running node.
105+
///
106+
/// # Panics
107+
///
108+
/// Panics if:
109+
/// - Block producer key parsing fails
110+
/// - Node setup or build fails
111+
/// - Genesis configuration cannot be fetched
112+
///
113+
/// # Example
114+
///
115+
/// ```javascript
116+
/// const rpc = await run(
117+
/// null, // No block production
118+
/// ["https://bootnodes.minaprotocol.com/networks/devnet-webrtc.txt"],
119+
/// ["/PEER_ID/https/webrtc-peer-signaling.example.com/443"],
120+
/// null, // Use the default devnet configuration
121+
/// );
122+
/// ```
77123
#[wasm_bindgen]
78124
pub async fn run(
79125
block_producer: JsValue,
80126
seed_nodes_urls: Option<Vec<String>>,
81-
seed_nodes_fixed: Option<Vec<String>>,
127+
seed_nodes_addresses: Option<Vec<String>>,
82128
genesis_config_url: Option<String>,
83129
) -> RpcSender {
84130
let block_producer = parse_bp_key(block_producer);
@@ -89,7 +135,7 @@ pub async fn run(
89135
let mut node = setup_node(
90136
block_producer,
91137
seed_nodes_urls,
92-
seed_nodes_fixed,
138+
seed_nodes_addresses,
93139
genesis_config_url,
94140
)
95141
.await;
@@ -106,7 +152,7 @@ pub async fn run(
106152
async fn setup_node(
107153
block_producer: Option<AccountSecretKey>,
108154
seed_nodes_urls: Option<Vec<String>>,
109-
seed_nodes_fixed: Option<Vec<String>>,
155+
seed_nodes_addresses: Option<Vec<String>>,
110156
genesis_config_url: Option<String>,
111157
) -> mina_node_common::Node<NodeService> {
112158
let block_verifier_index = BlockVerifier::make().await;
@@ -127,7 +173,8 @@ async fn setup_node(
127173
.work_verifier_index(work_verifier_index.clone());
128174

129175
// TODO(binier): refactor
130-
let mut all_raw_peers = seed_nodes_fixed.unwrap_or_default();
176+
let mut all_raw_peers = seed_nodes_addresses.unwrap_or_default();
177+
131178
if let Some(seed_nodes_urls) = seed_nodes_urls {
132179
for seed_nodes_url in seed_nodes_urls {
133180
let peers = ::node::core::http::get_bytes(&seed_nodes_url).await;

website/docs/developers/webrtc.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,71 @@ The Web Node represents a significant advancement in blockchain accessibility,
181181
enabling truly decentralized participation without requiring users to install
182182
native applications or manage complex network configurations.
183183

184+
## Address Format Differences
185+
186+
The Mina Rust Node uses a custom Multiaddr-like format for WebRTC peer addresses
187+
that differs from normal Multiaddrs. These addresses are specifically designed
188+
to encode signaling server information rather than direct network addresses,
189+
reflecting the different connection model of WebRTC versus direct TCP/UDP
190+
connections.
191+
192+
The address parsing logic is implemented in
193+
[`p2p/src/connection/outgoing/mod.rs`](https://github.com/o1-labs/mina-rust/blob/develop/p2p/src/connection/outgoing/mod.rs)
194+
through the `FromStr` implementation for `P2pConnectionOutgoingInitOpts`. The
195+
parser distinguishes between libp2p addresses (starting with `/ip` or `/dns`)
196+
and WebRTC addresses (all other formats).
197+
198+
### WebRTC peer address format
199+
200+
WebRTC peer addresses follow this structure:
201+
202+
```
203+
/{peer_id}/{signaling_method}
204+
```
205+
206+
Where `{peer_id}` is the base58-encoded peer ID and `{signaling_method}`
207+
specifies how to reach the signaling server.
208+
209+
### Signaling method formats
210+
211+
The signaling method component can take several forms:
212+
213+
**HTTP signaling:**
214+
215+
```
216+
/http/{host}/{port}
217+
```
218+
219+
Example:
220+
`/12D3KooWRTzN7HfmjoUBHokyRZuKdyohVVSGqKBMF24ZC3tGK74R/http/localhost/8080`
221+
222+
**HTTPS signaling:**
223+
224+
```
225+
/https/{host}/{port}
226+
```
227+
228+
Example:
229+
`/12D3KooWRTzN7HfmjoUBHokyRZuKdyohVVSGqKBMF24ZC3tGK74R/https/signal.example.com/443`
230+
231+
**HTTPS proxy signaling:**
232+
233+
```
234+
/https_proxy/{cluster_id}/{host}/{port}
235+
```
236+
237+
Example:
238+
`/12D3KooWRTzN7HfmjoUBHokyRZuKdyohVVSGqKBMF24ZC3tGK74R/https_proxy/123/proxy.example.com/443`
239+
240+
**P2P relay signaling:**
241+
242+
```
243+
/p2p/{relay_peer_id}
244+
```
245+
246+
Example:
247+
`/12D3KooWRTzN7HfmjoUBHokyRZuKdyohVVSGqKBMF24ZC3tGK74R/p2p/12D3KooWABC...`
248+
184249
## Future Considerations
185250

186251
While the current OCaml implementation doesn't use WebRTC, the Rust

website/docs/node-operators/webnode/local-webnode-docker.md

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,45 @@ update the port accordingly.
5454
The Dockerized WebNode can be configured with additional environment variables
5555
to customize behavior.
5656

57-
| Environment Variable | Required? | Description |
58-
| :-------------------------- | :-------: | :--------------------------------------------------------------------- |
59-
| `MINA_FRONTEND_ENVIRONMENT` | Yes | Must be set to `webnode` to run the frontend in webnode mode |
60-
| `MINA_WEBNODE_SEED_URLS` | No | A comma-separated list of http(s) URLs to fetch initial P2P Seeds from |
61-
| `MINA_WEBNODE_BOOTNODES` | No | A comma-separated list of initial peers in WebRTC-Multiaddrish format |
57+
### `MINA_FRONTEND_ENVIRONMENT`
58+
59+
This is required to launch the frontend in general. To serve a webnode, it must
60+
be set to the value `webnode`.
61+
62+
Example:
63+
64+
```
65+
-e MINA_FRONTEND_ENVIRONMENT=webnode
66+
```
67+
68+
### `MINA_WEBNODE_SEED_URLS`
69+
70+
A comma-separated list of http(s) URLs to fetch initial P2P seeds from. This is
71+
similar to the `--peer-list-url` flag in the native node, but can take multiple
72+
comma-separated values to fetch peer lists from multiple sources. Each peer list
73+
file must contain peer addresses in
74+
[WebRTC-Multiaddrish format](../../developers/webrtc.md#address-format-differences),
75+
separated by a newline.
76+
77+
Example:
78+
79+
```
80+
-e MINA_WEBNODE_SEED_URLS=https://bootnodes.minaprotocol.com/networks/devnet-webrtc.txt
81+
-e MINA_WEBNODE_SEED_URLS=https://example.com/extra-peers.txt,https://bootnodes.minaprotocol.com/networks/devnet-webrtc.txt,
82+
```
83+
84+
### `MINA_WEBNODE_BOOTNODES`
85+
86+
A comma separated list of
87+
[WebRTC-Multiaddrish](../../developers/webrtc.md#address-format-differences)
88+
peer addresses, to attempt to connect to in conjunction to any downloaded from
89+
`MINA_WEBNODE_SEED_URLS`. This is akin to the `--peers` flag in the native node,
90+
but instead of specifying the flag multiple times, each peer is simply
91+
comma-separated
92+
93+
Example:
94+
95+
```
96+
-e MINA_WEBNODE_BOOTNODES=/peer_id1/https/signaling.example.com/443
97+
-e MINA_WEBNODE_BOOTNODES=/peer_id1/https/signaling.example.com/443,/peer_id2/p2p/peer_id1
98+
```

0 commit comments

Comments
 (0)