-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add page about syncing and update config and peers API #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Syncing | ||
|
||
To maintain decentralization, a blockchain node must connect and synchronize with other nodes (peers) in the network. | ||
|
||
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. | ||
|
||
:::info | ||
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. | ||
::: | ||
|
||
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. | ||
|
||
You can get the list of connected and discovered peers using the [`/api/peers`](/api-endpoints/blockchain.md#get-peers-list) endpoint. | ||
|
||
## Socket connections | ||
|
||
For faster transaction syncing between nodes, we recommend enabling [WebSocket Node connections](./configuration.md#websocket-node-configuration) in the configuration. | ||
|
||
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. | ||
|
||
## Peer selection and rotation | ||
|
||
To avoid centralization, the node randomly selects peers to broadcast transactions to. This is the same strategy used for HTTP broadcasting. | ||
|
||
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. | ||
|
||
## Transaction broadcasting | ||
|
||
When a node receives an unconfirmed transaction, it spreads it across the network by sending it to multiple randomly selected peers. | ||
|
||
The method used for broadcasting depends on the type of connection: | ||
|
||
- **WebSocket**: Transactions are sent instantly. | ||
- **HTTP (REST)**: Transactions are sent after a short delay, defined by the [`broadcastInterval`](./configuration.md#broadcast-configuration) configuration property. | ||
|
||
If a peer is connected via WebSocket, it may still receive the same transaction via HTTP. This design ensures redundancy. | ||
|
||
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. | ||
|
||
## Backward compability | ||
|
||
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. | ||
|
||
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. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.