Nitride.xyz
Shreds

Parsing the shred header

Every datagram in the feed is one shred. This page gives the byte layout Agave uses today, a small parser you can test on your own machine, and how to pin the Agave crate for production.

Read the first 83 bytes of a datagram and you have the common header, which every shred carries. Byte 64 then tells you whether a data header or a coding header follows, and where the Merkle trailer starts. The layout below matches the Agave source on GitHub as read on 2026-11-17 (the master branch and release v4.4.1). It changes with the protocol, so check it against the release the cluster runs before you depend on a fixed offset. For background on what each field means, see the shred header, field by field. This page belongs to the Nitride.xyz docs.

All integers are little-endian.

The common header#

BytesFieldType
0 to 63Leader signature64 bytes
64Variantu8
65 to 72Slotu64
73 to 76Index within the slotu32
77 to 78Shred versionu16
79 to 82FEC set indexu32

The signature is the leader's signature over the Merkle root of the erasure batch, so every shred in one batch carries the same 64 bytes. Data and coding shreds count their index with separate counters that both restart at zero in each slot. A data shred and a coding shred of the same slot often share an index; only (slot, index, type) names one shred. The FEC set index is the index of the first data shred in the batch, and every shred of that batch, coding shreds included, carries the same value. The version is the cluster's shred version, which nodes use to drop shreds from another cluster.

What does the variant byte mean?#

The high four bits give the type. The low four bits give the number of entries in the Merkle proof.

High nibbleTypeByte with a 6-entry proof
0x6Coding, chained0x66
0x7Coding, chained, resigned0x76
0x9Data, chained0x96
0xBData, chained, resigned0xB6

Chained means the shred embeds the Merkle root of the previous erasure batch; the source notes that every variant in use is chained. Resigned means the shred reserves 64 bytes at its end for a retransmitter signature. Only the last erasure batch of a slot is resigned, and each node that forwards it down the Turbine tree signs it again, leaving the leader's signature as it was. Two copies of the same resigned shred can therefore differ in their last 64 bytes.

Batches are a fixed 32 data and 32 coding shreds, a 64-leaf tree, so the proof has 6 entries. Read the count from the low nibble anyway: the source still computes the layout from it while the fixed 32:32 rule is being enforced.

Older Agave releases also defined legacy shreds (0xA5 data, 0x5A coding) and unchained Merkle shreds (high nibble 0x4 for coding and 0x8 for data). The current source rejects those bytes as invalid variants. Log them instead of crashing, in case you replay an old capture.

Data shred header#

BytesFieldType
83 to 84parent_offset: slot minus the parent slotu16
85flagsu8
86 to 87size: headers plus entry bytesu16

The headers end at byte 88, and the entry bytes are payload[88:size]. size is an end offset, not a length, so it never falls below 88. A shred whose size is exactly 88 carries no entry data and pads a short batch.

The flags byte packs three things:

  • bits 0 to 5 (0x3F): the reference tick, capped at 63 (under Alpenglow it no longer measures time within the slot);
  • 0x40, DATA_COMPLETE_SHRED: the last shred of a run of entry data that deserializes on its own;
  • 0xC0, LAST_SHRED_IN_SLOT: the last data shred of the slot. Its value sets the 0x40 bit too, so test flags & 0xC0 == 0xC0.

Coding shred header#

BytesFieldType
83 to 84num_data_shredsu16
85 to 86num_coding_shredsu16
87 to 88position among the coding shreds of the batchu16

The headers end at byte 89. Both counts are 32 today. A coding shred's place in the erasure batch is num_data_shreds + position, because data shreds take the lower places. How recovery uses them is covered in recovering and decoding. For how the two kinds of shred relate, see data and coding shreds.

Where does the Merkle trailer start?#

After the body, each shred ends with a fixed trailer, counted back from the end of the payload:

PartSize
Chained Merkle root of the previous batch32 bytes
Merkle proof20 bytes per entry (120 with 6 entries)
Retransmitter signature, resigned variants only64 bytes

A data shred's payload is 1,203 bytes and a coding shred's is 1,228 bytes. With 6 proof entries, a data shred holds at most 963 bytes of entry data, or 899 when resigned. The proof and the leader signature are what Merkle shreds explains in detail.

A parser in Python#

This parser uses only the standard library. It checks the variant and the size field and returns a dict. It does not verify the signature or the Merkle proof.

shred_header.py
1import struct
2
3SIG = 64 # leader signature, bytes 0 to 63
4DATA_HEADERS = 88 # signature + common header (19) + data header (5)
5CODE_HEADERS = 89 # signature + common header (19) + coding header (6)
6
7# high nibble of byte 64: (kind, resigned)
8VARIANTS = {0x60: ("code", False), 0x70: ("code", True),
9 0x90: ("data", False), 0xB0: ("data", True)}
10
11def parse_shred(buf):
12 if len(buf) < CODE_HEADERS:
13 raise ValueError(f"too short: {len(buf)} bytes")
14 variant = buf[64]
15 if variant & 0xF0 not in VARIANTS:
16 raise ValueError(f"unknown variant {variant:#04x}")
17 kind, resigned = VARIANTS[variant & 0xF0]
18 proof_entries = variant & 0x0F
19 slot, index, version, fec_set_index = struct.unpack_from("<QIHI", buf, 65)
20 shred = {"kind": kind, "resigned": resigned, "proof_entries": proof_entries,
21 "slot": slot, "index": index, "version": version,
22 "fec_set_index": fec_set_index}
23 # trailer: chained Merkle root (32), proof (20 per entry), retransmitter signature (64)
24 trailer = 32 + 20 * proof_entries + (64 if resigned else 0)
25 body_end = len(buf) - trailer
26 if kind == "data":
27 parent_offset, flags, size = struct.unpack_from("<HBH", buf, 83)
28 if not DATA_HEADERS <= size <= body_end:
29 raise ValueError(f"bad size field {size}")
30 shred.update(parent_slot=slot - parent_offset,
31 reference_tick=flags & 0x3F,
32 data_complete=bool(flags & 0x40),
33 last_in_slot=flags & 0xC0 == 0xC0,
34 data=bytes(buf[DATA_HEADERS:size]))
35 else:
36 num_data, num_coding, position = struct.unpack_from("<HHH", buf, 83)
37 if position >= num_coding:
38 raise ValueError(f"bad position {position}")
39 shred.update(num_data_shreds=num_data, num_coding_shreds=num_coding,
40 position=position)
41 return shred

Feed it from a socket on your port:

listen.py
1import socket
2from shred_header import parse_shred
3
4sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
5sock.bind(("0.0.0.0", 9000))
6while True:
7 pkt, _ = sock.recvfrom(1228)
8 try:
9 s = parse_shred(pkt)
10 except ValueError as err:
11 print("skipped:", err)
12 continue
13 print(s["slot"], s["kind"], s["index"], s["fec_set_index"])

We tested the parser on 127.0.0.1 with crafted 1,203-byte data shreds (0x96, and 0xB6 with LAST_SHRED_IN_SLOT), 1,228-byte coding shreds (0x66 and 0x76) and a legacy 0xA5 datagram. It returned the fields we wrote and rejected the legacy byte. A Rust version of the common-header part is on the Rust receiver page.

Use the Agave crate in production#

Fixed offsets are fine for counting and routing. For anything that must be correct across upgrades, such as signature checks, Merkle proofs or recovery, use the shred module of the solana-ledger crate from the Agave release the cluster runs. Shred::new_from_serialized_shred parses a payload, and the Shred type exposes slot(), index(), fec_set_index(), data_complete(), last_in_slot() and verify().

Pin the exact version, because the crate's API sits behind the agave-unstable-api feature and can change between releases:

Cargo.toml
[dependencies]
solana-ledger = { version = "=4.4.1", features = ["agave-unstable-api"] }

The = stops Cargo from moving to a newer release on its own. Commit Cargo.lock too. To choose the version, compare the version field that the getClusterNodes RPC method returns for validators, and bump the pin when the network upgrades. Recent releases need a recent Rust toolchain; Cargo names the minimum if yours is too old.

Sources#