Skip to content

Commit 5e4fe61

Browse files
committed
feat: add page about syncing and update config and peers API (#13)
* feat: add page about syncing and update config and peers API * chore: add more details about syncing * style: use less text in links * docs: describe new peer properties
1 parent 6ce3eea commit 5e4fe61

File tree

4 files changed

+76
-3
lines changed

4 files changed

+76
-3
lines changed

.vitepress/config.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export default defineConfig({
3939
{ text: 'Configuration', link: '/own-node/configuration' },
4040
{ text: 'Testnet', link: '/own-node/testnet' },
4141
{ text: 'Consensus', link: '/own-node/consensus' },
42+
{ text: 'Syncing', link: '/own-node/syncing' },
4243
],
4344
},
4445
{

api-endpoints/blockchain.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ GET /api/peers
3030
- `height` — current node's blockchain height
3131
- `updated` — Unix timestamp based in ms, when peer updated
3232
- `nonce` — unique Identifier for the peer. Random string.
33+
- `syncProtocol``"http"` if the node is subscribed to the peer using HTTP only. `"ws"` if the node is subscribed to the peer using WebSocket (which also allows receiving transactions via both WebSocket and HTTP).
34+
- `isBroadcastingViaSocket``true` if the node can send transactions to the peer over WebSocket.
3335

3436
Available parameters:
3537

@@ -62,7 +64,9 @@ GET /api/peers
6264
"height": 10146365,
6365
"clock": null,
6466
"updated": 1562424199553,
65-
"nonce": "jxXV6g0sHJhmDubq"
67+
"nonce": "jxXV6g0sHJhmDubq",
68+
"isBroadcastingViaSocket": false,
69+
"syncProtocol": "ws"
6670
},
6771
{
6872
"ip": "144.217.93.8",
@@ -74,7 +78,9 @@ GET /api/peers
7478
"height": 10146364,
7579
"clock": null,
7680
"updated": 1562424195742,
77-
"nonce": "YngSDjA5MeUNk2iZ"
81+
"nonce": "YngSDjA5MeUNk2iZ",
82+
"isBroadcastingViaSocket": false,
83+
"syncProtocol": "http"
7884
}
7985
]
8086
}
@@ -154,7 +160,9 @@ GET /api/peers/get
154160
"height": 38723235,
155161
"clock": null,
156162
"updated": 1713630137277,
157-
"nonce": "YWXG1LsX0QUw4tFD"
163+
"nonce": "YWXG1LsX0QUw4tFD",
164+
"isBroadcastingViaSocket": false,
165+
"syncProtocol": "ws"
158166
}
159167
}
160168
```

own-node/configuration.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,26 @@ Redis is used for caching. Required.
377377
- `enabled`: Enable or disable WebSocket client (e.g., `true`).
378378
- `portWS`: WebSocket client port (e.g., `36668`).
379379

380+
## WebSocket Node Configuration
381+
382+
- **WebSocket Node**
383+
384+
Configure WebSocket node-to-node connection for syncing with the `wsNode` object:
385+
386+
```json
387+
{
388+
"wsNode": {
389+
"enabled": true,
390+
"maxBroadcastConnections": 15,
391+
"maxReceiveConnections": 25
392+
}
393+
}
394+
```
395+
396+
- `enabled`: Enable or disable WebSocket node-to-node communication.
397+
- `maxBroadcastConnections`: Maximum number of outbound WebSocket connections used to broadcast data to other nodes.
398+
- `maxReceiveConnections`: Maximum number of inbound WebSocket connections to other nodes.
399+
380400
## Nethash Configuration
381401

382402
- **Nethash**

own-node/syncing.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Syncing
2+
3+
To maintain decentralization, a blockchain node must connect and synchronize with other nodes (peers) in the network.
4+
5+
You can define the initial list of peers in the configuration file using the [`peers`](./configuration.md#peer-configuration) field and check synchronization status using the [`/api/loader/status/sync`](../api-endpoints/blockchain.md#get-synchronization-status) endpoint.
6+
7+
:::info
8+
Make sure the peers are on the same network. You can verify this by checking the nethash using the [`/api/blocks/getNethash`](/api-endpoints/blockchain.md#get-blockchain-nethash) endpoint.
9+
:::
10+
11+
Once connected, the node will automatically discover more peers by querying the peers of its current connections. Discovered peers are saved in the local database, which helps speed up future deployments and restarts.
12+
13+
You can get the list of connected and discovered peers using the [`/api/peers`](/api-endpoints/blockchain.md#get-peers-list) endpoint.
14+
15+
## Socket connections
16+
17+
For faster transaction syncing between nodes, we recommend enabling [WebSocket Node connections](./configuration.md#websocket-node-configuration) in the configuration.
18+
19+
If you enable the WebSocket, a node will connect to another peer using both WebSocket and HTTP at the same time. It’s up to the broadcasting node to decide how to send transactions. By default, transactions are not sent twice to the same peer using both methods.
20+
21+
## Peer selection and rotation
22+
23+
To avoid centralization, the node randomly selects peers to broadcast transactions to. This is the same strategy used for HTTP broadcasting.
24+
25+
Every 30 minutes, the node replaces 20% of its current WebSocket connections with new ones. This rotation helps maintain a healthy and distributed peer network.
26+
27+
## Transaction broadcasting
28+
29+
When a node receives an unconfirmed transaction, it spreads it across the network by sending it to multiple randomly selected peers.
30+
31+
The method used for broadcasting depends on the type of connection:
32+
33+
- **WebSocket**: Transactions are sent instantly.
34+
- **HTTP (REST)**: Transactions are sent after a short delay, defined by the [`broadcastInterval`](./configuration.md#broadcast-configuration) configuration property.
35+
36+
If a peer is connected via WebSocket, it may still receive the same transaction via HTTP. This design ensures redundancy.
37+
38+
As a result, a node may receive the same unconfirmed transaction multiple times, from different peers, and through both REST and WebSocket. This helps ensure that transactions reliably reach their destination even if some connections fail.
39+
40+
## Backward compability
41+
42+
In earlier versions, nodes had a separate WebSocket server intended for transaction syncing, but it wasn't fully implemented and didn't receive transactions over WebSocket.
43+
44+
After recent changes, new nodes now support full transaction syncing over WebSocket. Even if many nodes on the network still run older software, the newer nodes can receive transactions instantly. Older nodes will continue relying on HTTP broadcasting as before.

0 commit comments

Comments
 (0)