Nitride.xyz
Shreds

Recovering and decoding: FEC, entries, transactions

Raw shreds become transactions in six steps: group, recover, order, deshred, deserialize and extract. This page walks through each one and points to the Agave crates that do it in production.

Start with parsed shreds: each datagram's slot, index, FEC set index, type and, for data shreds, the flags byte and entry bytes. Parsing the shred header gives the offsets. From there, six steps turn shreds into transactions. The byte layouts below match the Agave source as read on 2026-11-17, and this page is part of the Nitride.xyz docs.

Step 1: group by FEC set#

Put each shred in a bucket keyed by (slot, fec_set_index). Every shred of one erasure batch, data and coding alike, carries the same FEC set index: the index of the batch's first data shred. Agave calls this key ErasureSetId. In the current source each batch has 32 data shreds and 32 coding shreds, so a slot's batches start at data index 0, 32, 64 and so on. Background on how batches are built is in FEC sets and erasure coding.

Step 2: recover missing data shreds#

A batch can be rebuilt once any 32 of its 64 shreds are present. Agave uses the reed-solomon-erasure crate over GF(2^8), configured with 32 data shards and 32 parity shards. Each shred maps to one shard:

ShredShard numberShard bytes
Dataindex - fec_set_index (0 to 31)from byte 64 to the end of the body
Codingnum_data_shreds + position (32 to 63)from byte 89 to the end of the body

Both ranges are the same length: 987 bytes, or 923 for a resigned batch. The data shard covers the data shred's headers as well as its body, so recovery rebuilds the headers too. It does not cover the signature or the Merkle trailer. A rebuilt data shred takes the leader signature shared by the whole batch; Agave then rebuilds the Merkle tree and checks the recovered shreds against the root before trusting them.

In Agave 4.4.1, the only public entry point for recovery in solana-ledger (shred::filter::ShredRecoveryContext::recover) needs a validator Bank and a retransmit channel, so outside a validator call reed-solomon-erasure yourself with the shard layout above. If a batch stays below 32 shreds, its missing data is gone for your receiver: a raw UDP feed has no retransmission. Detecting gaps and duplicates shows how to count those batches.

Step 3: order and find complete runs#

Sort the slot's data shreds by index. Two flags in byte 85 mark the boundaries:

  • 0x40, DATA_COMPLETE_SHRED: the last shred of a run whose bytes deserialize on their own;
  • 0xC0, LAST_SHRED_IN_SLOT: the slot's last data shred. It sets the 0x40 bit as well.

A run starts at index 0, or just after the previous DATA_COMPLETE_SHRED, and ends at the next one. A run can span several FEC sets, so cut runs by these flags, after recovery, rather than by batch boundaries. You can decode a run as soon as every index in it is present, without waiting for the slot to finish.

Step 4: deshred the payload#

Concatenate the entry bytes of each shred in the run, in index order. A data shred's entry bytes are payload[88:size], where size is the u16 at bytes 86 to 87. Agave's Shredder::deshred does exactly this and refuses the run if the indices are not consecutive or the last shred lacks DATA_COMPLETE_SHRED.

Step 5: deserialize entries#

Each run's bytes start with a u64 count. When the count is above zero, the bytes are an entry batch laid out as bincode lays out a Vec<Entry>: the count, then each entry. An entry is:

FieldEncoding
num_hashesu64
hash32 bytes
transactionsu64 count, then each transaction

When the count is zero, the current source reads the run as a block marker, a newer kind of block component, rather than entries. A deshredded Alpenglow block is therefore a sequence of block components: a header marker, entry batches and a footer marker, not a bare list of entries, and its last entry batch ends with a single tick. Skip those unless you need them. Agave reads both forms with the wincode crate, which reads bincode's layout. What an entry is, and why it sits between shreds and transactions, is covered in Solana entries.

Step 6: extract transactions#

Transactions are packed back to back with no length prefix, so you must parse each one to find where the next begins. Three formats appear on mainnet:

  • Legacy: a compact-u16 signature count, the signatures (64 bytes each), then the message: a 3-byte header, account keys, a recent blockhash and instructions.
  • v0: the same, with a 0x80 byte before the message header and address table lookups after the instructions.
  • v1: the message comes first, starting with 0x81, and the signatures follow it.

The first signature is the transaction's ID. A block we fetched from public RPC on 2026-11-17 held all three formats.

A decoder in Python#

This covers steps 3 to 6 with the standard library. It assumes all shreds of a run are present (after recovery, if you need it) and does not verify signatures.

decode.py
1import struct
2
3B58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
4
5def b58(raw):
6 n, out = int.from_bytes(raw, "big"), ""
7 while n:
8 n, r = divmod(n, 58)
9 out = B58[r] + out
10 return "1" * (len(raw) - len(raw.lstrip(b"\0"))) + out
11
12def deshred(data_shreds, start=0):
13 """data_shreds: {index: parsed data shred} for one slot. Yields each
14 completed payload, from `start` up to a shred flagged DATA_COMPLETE."""
15 chunk, i = [], start
16 while i in data_shreds:
17 shred = data_shreds[i]
18 chunk.append(shred["data"])
19 i += 1
20 if shred["data_complete"]:
21 yield b"".join(chunk)
22 chunk = []
23 if shred["last_in_slot"]:
24 return
25
26def cu16(b, p): # compact-u16 ("short_vec") length
27 v = 0
28 for k in range(3):
29 v |= (b[p + k] & 0x7F) << (7 * k)
30 if b[p + k] < 0x80:
31 return v, p + k + 1
32 raise ValueError("bad compact-u16")
33
34def skip_vec(b, p): # compact-u16 length, then that many bytes
35 n, p = cu16(b, p)
36 return p + n
37
38def read_transaction(b, p):
39 """Returns (end offset, first signature) of the transaction at p."""
40 if b[p] & 0x80: # v1: message first, signatures after it
41 if b[p] != 0x81:
42 raise ValueError(f"unknown transaction version {b[p]:#x}")
43 n_sigs, (mask,) = b[p + 1], struct.unpack_from("<I", b, p + 4)
44 n_ix, n_keys = b[p + 40], b[p + 41]
45 q = p + 42 + 32 * n_keys + 4 * bin(mask).count("1")
46 heads, q = q, q + 4 * n_ix
47 for k in range(n_ix): # header: program u8, accounts u8, data_len u16
48 _, n_acc, n_data = struct.unpack_from("<BBH", b, heads + 4 * k)
49 q += n_acc + n_data
50 return q + 64 * n_sigs, b[q:q + 64]
51 n_sigs, q = cu16(b, p) # legacy and v0: signatures first
52 first, q = b[q:q + 64], q + 64 * n_sigs
53 v0 = b[q] & 0x80
54 if v0 and b[q] != 0x80:
55 raise ValueError(f"unknown message version {b[q]:#x}")
56 q += 4 if v0 else 3 # version byte, then the 3-byte header
57 n_keys, q = cu16(b, q)
58 q += 32 * n_keys + 32 # account keys, recent blockhash
59 n_ix, q = cu16(b, q)
60 for _ in range(n_ix):
61 q = skip_vec(b, skip_vec(b, q + 1))
62 if v0: # address table lookups
63 n_lookups, q = cu16(b, q)
64 for _ in range(n_lookups):
65 q = skip_vec(b, skip_vec(b, q + 32))
66 return q, first
67
68def decode_entries(payload):
69 """One completed payload: u64 entry count, then the entries."""
70 (count,), p = struct.unpack_from("<Q", payload), 8
71 if count == 0:
72 return None # a block marker, not an entry batch
73 entries = []
74 for _ in range(count):
75 num_hashes, entry_hash, n_tx = struct.unpack_from("<Q32sQ", payload, p)
76 p += 48
77 txs = []
78 for _ in range(n_tx):
79 end, sig = read_transaction(payload, p)
80 txs.append((b58(sig), payload[p:end]))
81 p = end
82 entries.append((num_hashes, b58(entry_hash), txs))
83 return entries

deshred takes the dicts that the parser on the header page returns, keyed by index. It stops at the first missing index, so call it again from the next run's start once the hole is filled.

How we tested it: we took the 193 transactions of one mainnet block from public RPC (87 legacy, 54 v0 and 52 v1), packed them into entries and two entry batches, added a block marker, and cut the result into crafted data shreds. We sent those over a UDP socket on 127.0.0.1 in reverse order, then parsed, deshredded and decoded them. Every transaction's bytes and first signature matched what RPC returned for that block. That proves the decoder against real transaction bytes; the shreds themselves were crafted, and a real slot also fills the resigned last batch with smaller chunks.

The Agave crates#

For production, the practical route is Agave's own code, pinned to the release the cluster runs: solana-ledger for shreds (Shred, Shredder::deshred) and solana-entry for Entry and BlockComponent. Both put their API behind the agave-unstable-api feature, so pin an exact version.

Cargo.toml
1[dependencies]
2solana-ledger = { version = "=4.4.1", features = ["agave-unstable-api"] }
3solana-entry = { version = "=4.4.1", features = ["agave-unstable-api"] }
4wincode = "0.6"

The sketch below shows how the calls fit together. It is an outline, not a complete program: we did not compile it here, because version 4.4.1 needs a newer Rust toolchain than our test machine has.

outline.rs
1// Outline: one complete run of data shreds, sorted by index.
2use solana_entry::block_component::BlockComponent;
3use solana_ledger::shred::{Shred, Shredder};
4
5fn decode_run(run: &[Shred]) -> Result<(), Box<dyn std::error::Error>> {
6 let bytes = Shredder::deshred(run.iter().map(|s| s.payload()))?;
7 match wincode::deserialize::<BlockComponent>(&bytes)? {
8 BlockComponent::EntryBatch(entries) => {
9 for entry in entries {
10 for tx in entry.transactions {
11 println!("{}", tx.signatures[0]);
12 }
13 }
14 }
15 BlockComponent::BlockMarker(_) => {}
16 }
17 Ok(())
18}

For recovery, see step 2: Agave's public recovery entry point needs a validator Bank and a retransmit channel, so a standalone receiver calls reed-solomon-erasure directly.

Sources#