Skip to content
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

Feat/article/062 Binary Port #104

Merged
merged 4 commits into from
Aug 22, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions articles/062-binary-port.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Binary Port in Casper 2.0

Casper 2.0 introduces a significant upgrade to its node communication: the binary port. This new RPC interface replaces the traditional JSON-RPC with a binary protocol. The result is faster, more efficient communication between the nodes and the applications within the network.
sczembor marked this conversation as resolved.
Show resolved Hide resolved

## Advantages

The adoption of a binary RPC protocol brings several benefits to the Casper network:

* **Reduced Network Congestion**: The compact nature of binary encoding leads to smaller message sizes, decreasing bandwidth consumption and network strain. This is particularly valuable in scenarios with high transaction volumes or limited bandwidth. This is particulary important for communication between the nodes themselves.
melpadden marked this conversation as resolved.
Show resolved Hide resolved
melpadden marked this conversation as resolved.
Show resolved Hide resolved
* **Improved Node Responsiveness**: While the node still needs to process requests, binary data is often faster to handle than JSON. This can lead to quicker response times from the node, enhancing overall network performance
* **Scalability**: The efficiency gains from binary communication contribute to the network ability to scale and handle increased transaction loads without sacrificing performance.

melpadden marked this conversation as resolved.
Show resolved Hide resolved
## Binary RPC and the Sidecar

In Casper 2.0, the newly introduced Sidecar plays a crucial role. It acts as a bridge between external clients using JSON-RPC and the node's binary port. This setup ensures compatibility with existing tools while leveraging the performance benefits of the binary protocol.

The sidecar translates JSON-RPC requests into binary requests for the node and converts binary responses back into JSON for the client.
melpadden marked this conversation as resolved.
Show resolved Hide resolved
melpadden marked this conversation as resolved.
Show resolved Hide resolved

## Direct Binary Communication

Future Casper SDKs will allow clients to communicate directly with the node's binary port, bypassing the sidecar. This approach offers several potential advantages:

* **Enhanced Performance**: Eliminating the sidecar's translation step can further reduce latency and improve overall communication speed.
* **Simplified Architecture**: Direct communication reduces complexity, leading to a more streamlined and maintainable system.
* **Greater Control**: Developers gain more granular control over their interactions with the node, opening doors for optimization and customization.

## TODO: more info about how the nodes comunicate with each other?
melpadden marked this conversation as resolved.
Show resolved Hide resolved
sczembor marked this conversation as resolved.
Show resolved Hide resolved

## Example: Seding a Transaction
sczembor marked this conversation as resolved.
Show resolved Hide resolved

melpadden marked this conversation as resolved.
Show resolved Hide resolved
Lets illustrate the workflow of using the binary port with a simplified example of sending a native transfer transaction.

### Flow with Sidecar:

1. **Construct JSON Request:** The client constructs a JSON-RPC request containing the transaction details.
2. **Send to Sidecar:** The request is sent to the sidecar over HTTP.
3. **Sidecar to Node (Binary)**: The sidecar translates the JSON request into a binary request and sends it to the node's binary port.
4. **Node Processing:** The node processes the binary request, executes the transaction, and constructs a binary response.
5. **Back to Sidecar (Binary):** The binary response is sent back to the sidecar.
6. **Sidecar to Client (JSON):** The sidecar translates the binary response into a JSON response and sends it back to the client.

### Flow with Direct Binary Communication:

1. **Construct Binary Request:** The client directly constructs a binary request containing the transaction details using the appropriate SDK.
2. **Send to Node (Binary)**: The request is sent directly to the node's binary port over TCP.
3. **Node Processing:** The node processes the binary request, executes the transaction, and constructs a binary response.
4. **Back to Client (Binary):** The binary response is sent directly back to the client.

By enabling direct communication, the flow eliminates the translation steps, potentially leading to even faster and more efficient interactions.
melpadden marked this conversation as resolved.
Show resolved Hide resolved

## Summary

melpadden marked this conversation as resolved.
Show resolved Hide resolved
The introduction of the binary port in Casper 2.0, alongside the new sidecar, represents a significant step towards a more efficient, scalable, and developer-friendly Casper network. While the sidecar currently provides a bridge for JSON-RPC compatibility, the future holds the promise of even greater performance and control through direct binary communication