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: network/vpack/README.md
+33-32Lines changed: 33 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,9 +12,9 @@ Vote compression uses two layers:
12
12
13
13
1.**Stateless compression** (`StatelessEncoder`/`StatelessDecoder`): Removes msgpack formatting and field names, replacing them with a bitmask. This is always applied and has no memory overhead.
14
14
15
-
2.**Stateful compression (optional)** (`StatefulEncoder`/`StatefulDecoder`): Further compresses by replacing frequently repeated values with references to LRU tables and a sliding window. This layer requires per-connection state (configurable size, e.g., ~224KB per encoder/decoder pair for 1024-entry tables) and is optional. When used, it operates on the output of the stateless layer.
15
+
2.**Stateful compression (optional)** (`StatefulEncoder`/`StatefulDecoder`): Further compresses by replacing frequently repeated values with references to LRU tables and a sliding window. This layer requires per-connection state (configurable size, e.g., ~224KB per direction for 1024-entry tables) and is optional. When used, it operates on the output of the stateless layer.
16
16
17
-
Both layers use the same 2-byte header format, with byte 0 used by the stateless layer and byte 1 used by the stateful layer (zero when stateful compression is not used).
17
+
Both layers use the same 2-byte header format, with byte 0 used by the stateless layer, and byte 1 used by the stateful layer.
When stateful compression is used, byte 1 encodes which values have been replaced by references:
63
+
When stateful compression is used, byte 1 encodes which values have been replaced by references. When stateful compression is not used, byte 1 must be zero.
-**Round delta encoding**: Most votes reference the same round or adjacent rounds, so 2 bits can encode common cases.
74
+
-**Round delta encoding**: Most votes reference the same round as before, with some interleaving votes between the current and next round, as voters gradually observe consensus and move on to the next round. A 2-bit encoding specifies whether `r.rnd` is the same as the previous vote, or has increased or decreased by one, and can be omitted from the message for these cases. If `rndDelta` is `00`, the literal value appears in the message.
75
75
-**Proposal sliding window**: A 7-entry HPACK-style window tracks recent proposal values. In a typical round, all votes should be for the same proposal value, compressing previously-seen proposal values from ~96 bytes down to a 3-bit reference.
76
-
-**LRU tables**: Three 2-way set-associative hash tables cache recently seen values for `snd` (sender addresses), `pk` (public key + signature pairs), and `pk2` (second-tier key + signature pairs). Since some consensus participants (and their associated public keys) will appear more often than others based on the distribution of stake, a larger table can capture participant-related data and replace them with LRU references. For each participant, the `snd` field is re-used across all votes; the `pk` reference is re-used across all votes in the same round; and the `pk2` reference is re-used across all votes in a batch (typically thousands of rounds) under our hierarchical 3-tiered consensus signature scheme.
77
-
78
-
When stateful compression is not used, byte 1 must be zero.
76
+
-**LRU tables**: Three 2-way set-associative hash tables cache recently seen values for sender addresses, and two tiers of (public key, signature) pairs. Since some consensus participants vote in rounds more often than others, these tables record the most common field values re-used across votes by the same participant, and replace them with references:
77
+
- The `snd` table tracks participating addresses, which are re-used across all votes by a participant;
78
+
- the `pk` table tracks `sig.pk` and `sig.p1s` values, which are re-used across votes in the same round by a participant;
79
+
- and the `pk2` table tracks `sig.p2` and `sig.p2s` values, which are re-used across all votes in a batch by a participant (typically thousands of rounds), under Algorand's hierarchical consensus signature scheme.
79
80
80
81
---
81
82
82
83
## 3. Field serialization order
83
84
84
-
After the 2-byte header, the encoder emits values in the following order:
|`sig.p2s`| Signature over batch ID | 64 bytes | Required |
101
-
|`sig.s`| Signature over vote using `p`| 64 bytes | Required |
85
+
After the 2-byte header, the encoder emits values in the following order. If stateful compression is enabled, the "stateful encoding" column specifies how each field is additionally transformed or omitted.
86
+
87
+
| Field | Type | Encoded size | Presence flag | Stateful encoding |
0 commit comments