You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 03-Protocol-Overview.md
+47Lines changed: 47 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -131,6 +131,53 @@ This prevents the needlessly wasted bandwidth and potentially serious performanc
131
131
132
132
See `ChannelEndpointChanged` message in Common Protocol Messages for details about how extensions interact with dynamic channel reconfiguration in proxies.
133
133
134
+
## 3.4.1 Stratum V2 TLV Encoding Model
135
+
136
+
To ensure a consistent and extensible way of adding optional fields to existing messages, **Stratum V2 supports Type-Length-Value (TLV) encoding** for protocol extensions. This model allows for structured, backward-compatible extensions while ensuring that unknown fields can be safely ignored.
137
+
138
+
### TLV Structure
139
+
140
+
Each TLV-encoded field follows this format:
141
+
142
+
|**Field**|**Size**|**Description**|
143
+
|------------|---------|----------------|
144
+
|**Type**| 3 bytes (U16 + U8) | Identifies the TLV field. The first 2 bytes represent the `extension_type`, and the third byte represents the `field_type` within the extension context. |
145
+
|**Length**| 2 bytes (U16) | Indicates the size (in bytes) of the Value field. |
146
+
|**Value**|`N` bytes | The actual data of the extension field, of variable length. |
147
+
148
+
- The **Type** field consists of **3 bytes**, where:
149
+
- The **first 2 bytes** (`U16`) correspond to the negotiated `extension_type`, ensuring modular and self-contained extensions.
150
+
- The **third byte** (`U8`) specifies the `field_type` defined in the extension, allowing multiple fields to be added within the same message.
151
+
- The **Length** field defines the exact size of the **Value**, allowing efficient message parsing.
152
+
- If the **Length** is `0x0000`, the **Value** field is omitted.
153
+
- When multiple fields extend the same message type, their order **MUST** match the order defined in the extension.
154
+
155
+
### Usage Guidelines
156
+
157
+
-**TLV fields MUST be placed at the end of the message payload.** This ensures compatibility with existing Stratum V2 messages.
158
+
-**TLV fields MUST be ordered by `extension_type`.** Since all extensions are negotiated beforehand, the recipient MUST process TLV fields in order of `extension_type` and use their `Type` identifiers to correctly interpret them.
159
+
-**Order of TLV fields within the same extension MUST be respected.** If an extension defines multiple TLV fields to extend a single message, they **MUST** appear in the exact order specified by the extension’s documentation.
160
+
-**Length constraints MUST be respected.** Each extension must specify the valid length range for its TLV fields. If a TLV field exceeds the maximum length allowed by its specification, the recipient MUST reject the message.
161
+
162
+
### Example: Extending `SubmitSharesExtended`
163
+
164
+
If extension **0x0002** (Worker-Specific Hashrate Tracking) is negotiated, clients must append the following TLV field to `SubmitSharesExtended`:
A device processing `SubmitSharesExtended`**MUST scan for TLV fields** matching any negotiated extensions, allowing for future extensibility without breaking compatibility.
0 commit comments