-
Notifications
You must be signed in to change notification settings - Fork 0
goshard: add slave communication migration design #156
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
Open
iteyelmp
wants to merge
4
commits into
main
Choose a base branch
from
slave
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+251
−0
Open
Changes from 2 commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,219 @@ | ||
| # QuarkChain Slave Migration Design Document | ||
|
|
||
| ## 1. Migration Goal | ||
|
|
||
| Migrate the Slave component in QuarkChain cluster communication from Python to Go while maintaining byte-level protocol | ||
| compatibility with the Python Master. | ||
|
|
||
| The Python implementation remains the sole protocol specification. | ||
|
|
||
| The goal of this phase is to complete the migration of the communication infrastructure while keeping the existing | ||
| Python Master unchanged, providing a foundation for future business logic migration. | ||
|
|
||
| ## 2. Scope | ||
|
|
||
| This phase implements: | ||
|
|
||
| - Frame encoding and decoding | ||
| - Metadata / Opcode / Message definitions | ||
| - RpcConn (basic connection framework) | ||
| - MasterConn (Master-Slave communication) | ||
| - XshardConn (Slave-Slave communication) | ||
| - PeerConn (Peer virtual connection) | ||
| - Dispatcher (message routing) | ||
| - Slave Runtime (lifecycle management) | ||
| - Handler Registration (registration mechanism) | ||
| - Handler Dispatch (dispatch scheduling) | ||
|
|
||
| This phase does not implement business logic, such as: | ||
|
|
||
| - Shard Runtime | ||
| - StateDB | ||
| - TxPool | ||
| - Miner | ||
| - State Transition | ||
|
|
||
| ## 3. Current Status | ||
|
|
||
| | PR | Content | Status | | ||
| |-----|--------------------------------------------|-------------| | ||
| | PR1 | Wire Frame encoding/decoding | ✅ Completed | | ||
| | PR2 | Metadata and Opcode definitions | ✅ Completed | | ||
| | PR3 | Message definitions and protocol constants | Review | | ||
| | PR4 | RpcConn + XshardConn foundation | Review | | ||
| | PR5 | MasterConn, handler registration | Review | | ||
| | PR6 | PeerConn, Dispatcher, and peer routing | Planned | | ||
| | PR7 | Slave runtime and lifecycle management | Planned | | ||
|
|
||
| ## 4. Communication Flow | ||
|
|
||
| QuarkChain cluster communication consists of three communication paths: | ||
|
|
||
| - Master ↔ Slave | ||
| - Peer ↔ Slave (forwarded through Master) | ||
| - Slave ↔ Slave | ||
|
|
||
| ### 4.1 Master → Slave RPC | ||
|
|
||
| ``` | ||
| Master Slave (MasterConn) | ||
| │ │ | ||
| │──[TCP Frame]──────────────────►│ | ||
| │ 12B ClusterMetadata + │ | ||
| │ op + rpc_id + payload │ | ||
| │ │── cluster_peer_id == 0 | ||
| │ │── lookup MASTER_OP_RPC_MAP | ||
| │ │── dispatch handler | ||
| │◄──[TCP Frame]──────────────────│── return response | ||
| │ 12B ClusterMetadata + │ | ||
| │ op + rpc_id + payload │ | ||
| ``` | ||
|
|
||
| ### 4.2 Peer Virtual Connection Forwarding | ||
|
|
||
| ``` | ||
| External P2P Peer Master Slave (MasterConn) | ||
| │ │ │ | ||
| │──[P2P Frame]─────►│ │ | ||
| │ │── convert to ClusterMetadata | ||
| │ │──[Cluster Frame]─────►│ | ||
| │ │ │── cluster_peer_id ≠ 0 | ||
|
iteyelmp marked this conversation as resolved.
|
||
| │ │ │── route to PeerConn | ||
| │ │◄──[Cluster Frame]─────│── return response | ||
| │◄──[P2P Frame]─────│ │ | ||
| ``` | ||
|
|
||
| ### 4.3 Slave → Slave RPC | ||
|
|
||
| ``` | ||
| Slave A (XshardConn) Slave B (XshardConn) | ||
| │ │ | ||
| │──[TCP Frame]──────────────────►│ | ||
| │ 0B Metadata + │ | ||
| │ op + rpc_id + payload │ | ||
| │ │── lookup XSHARD_OP_RPC_MAP | ||
| │ │── dispatch handler | ||
| │◄──[TCP Frame]──────────────────│── return response | ||
| │ 0B Metadata + │ | ||
| │ op + rpc_id + payload │ | ||
| ``` | ||
|
|
||
| ## 5. Migration Plan | ||
|
|
||
| ``` | ||
| PR1-PR3 (Protocol foundation layer) | ||
| ↓ | ||
| PR4 (RpcConn / XshardConn) | ||
| ↓ | ||
| PR5 (MasterConn) | ||
| ↓ | ||
| PR6 (PeerConn / Dispatcher) | ||
| ↓ | ||
| PR7 (Slave Runtime) | ||
| ``` | ||
|
|
||
| ### PR4: RpcConn + XshardConn | ||
|
|
||
| Corresponding Python components: `Connection`, `SlaveConnection` | ||
|
|
||
| Main contents: | ||
|
|
||
| - RpcConn: connection framework (TCP read/write loops, RPC ID management, request/response matching) | ||
| - XshardConn: Slave-to-Slave TCP connections (0B Metadata) | ||
| - Xshard handler registration and Ping/Pong handshake | ||
|
|
||
| ### PR5: MasterConn | ||
|
|
||
| Corresponds to Python: `MasterConnection` | ||
|
|
||
| Main contents: | ||
|
|
||
| - Master-Slave TCP connection | ||
| - ClusterMetadata handling (12B) | ||
| - MasterConn lifecycle | ||
| - Master Handler registration and dispatch framework | ||
| - Stub implementations for Handlers depending on business components | ||
|
|
||
| ### PR6: PeerConn + Dispatcher | ||
|
|
||
| Corresponds to Python: `PeerShardConnection`, `VirtualConnection` | ||
|
|
||
| Main contents: | ||
|
|
||
| - Peer virtual connection + forwarding mechanism | ||
| - Dispatcher message routing | ||
| - Peer Handler registration and dispatch framework | ||
| - Stub implementations for Handlers depending on business components | ||
|
|
||
| ### PR7: Slave Runtime | ||
|
|
||
| Corresponds to Python: `SlaveServer` | ||
|
|
||
| Main contents: | ||
|
|
||
| - Slave lifecycle management + TCP listener | ||
| - Unified connection management (MasterConn / PeerConn / XshardConn) | ||
| - Dispatcher orchestration | ||
| - Wiring of all components | ||
|
|
||
| ## 6. Handler Implementation Strategy | ||
|
|
||
| Handlers are categorized by connection type: | ||
|
|
||
| - Xshard Handler → XshardConn | ||
| - Master Handler → MasterConn | ||
| - Peer Handler → PeerConn | ||
|
|
||
| This phase completes: | ||
|
|
||
| - Handler registration (Registration) | ||
| - Handler dispatch (Dispatch) | ||
| - RPC request/response flow | ||
|
|
||
| For Handlers depending on other components, such as: | ||
|
|
||
| - Shard Runtime | ||
| - StateDB | ||
| - TxPool | ||
| - Miner | ||
|
|
||
| Only Stub implementations are provided, without implementing actual business logic. | ||
|
|
||
| The goal of the Stubs is to ensure: | ||
|
|
||
| - Opcode can be recognized | ||
| - Messages can be parsed | ||
| - Handlers can be correctly dispatched | ||
| - RPC request/response flow is complete | ||
| - Protocol-compatible placeholder responses are returned | ||
|
|
||
| ## 7. Testing | ||
|
|
||
| The Python implementation is the protocol authority. | ||
|
|
||
| Testing is performed in two stages: | ||
|
|
||
| - PR1–PR6: Use Python-generated test vectors and lightweight Python protocol peers to validate serialization, RPC flows, | ||
| and connection lifecycles. These protocol peers are used solely for protocol compatibility testing and do not require | ||
| a full Python Master or business components. | ||
| - PR7: Run end-to-end interoperability tests using a real Python Master and the Go Slave implementation. | ||
|
|
||
| Testing focuses on: | ||
|
|
||
| - Frame and Metadata compatibility | ||
| - Message serialization compatibility | ||
| - RPC request/response flow | ||
| - Master-Slave communication | ||
| - Slave-Slave communication | ||
| - Peer communication | ||
|
|
||
| ## 8. Expected Result | ||
|
|
||
| After completing PR1-PR7: | ||
|
|
||
| - Complete the migration of the Slave communication framework | ||
| - Master-Slave, Slave-Slave, and Peer virtual connections are all ready | ||
| - All RPC Opcodes have completed registration and dispatch | ||
| - Business Handlers provide compatible Stub implementations | ||
|
|
||
| This phase only completes the communication layer infrastructure. Business logic will be implemented in later phases. | ||
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.