Canonical: https://nitride.xyz/learn/fec-sets

# FEC sets and erasure coding

What a Solana FEC set is, how a leader cuts entry batches into 32:32 Reed-Solomon sets, and how a receiver recovers lost data shreds from them.

A Solana FEC set is a group of 32 data shreds and 32 coding shreds that the leader erasure-codes together with Reed-Solomon. All 64 share one slot and one FEC set index. Any 32 of them, in any mix, are enough to rebuild every missing data shred in the group without asking another node.

## What does forward error correction mean here?
Forward error correction (FEC) means the sender adds redundancy before anything is lost, so the receiver can fix losses on its own. The other way to handle loss is to ask for the missing packet again, which costs at least one more round trip. Solana uses both: FEC first, and the [repair protocol](https://nitride.xyz/learn/repair-protocol) only when FEC is not enough.

The code Agave uses is Reed-Solomon over bytes, set up with 32 data pieces and 32 parity pieces. The data pieces are the [data shreds](https://nitride.xyz/learn/data-and-coding-shreds), and the parity pieces are the coding shreds computed from them. Reed-Solomon has a useful property: with k data pieces, any k of the pieces, data or parity, determine the rest. At 32:32, half of a set can disappear and it is still whole.

That doubles what the leader sends, since every set is 64 packets for 32 packets of data. The trade is deliberate. Blocks travel over UDP across a network of validators, and a set that cannot be rebuilt stalls the reader until repair fills the gap.

## How does a leader cut a block into FEC sets?
The leader does not shred a whole block at once. It shreds batches of [entries](https://nitride.xyz/learn/entries) as it produces them. For each batch, current Agave code does this:

1. Serialize the batch into one byte string.
2. Split the bytes into chunks that fit a data shred, 32 chunks per set.
3. If the last set has fewer than 32 chunks of data, fill it with empty data shreds so it still has 32.
4. Mark the last data shred of the batch as batch complete, or as last in slot if the block ends there.
5. Compute the 32 coding shreds of each set with Reed-Solomon, build a Merkle tree over all 64 shreds, and sign the root.

Every shred in a set records `fec_set_index`, the index of the set's first data shred. Because each set now holds exactly 32 data shreds, the set indexes in a slot step by 32: 0, 32, 64 and on.

The sets of a slot are also linked. Each shred carries the Merkle root of the set before it, so a set cannot be signed until the previous one is done. SIMD-0313, now activated, made this chained form the only one validators accept. How the tree and signature are checked is covered in [Merkle shreds and shred signatures](https://nitride.xyz/learn/merkle-shreds).

## How does a receiver recover missing data shreds?
A receiver that wants transactions needs every data shred of a batch. Recovery runs per set:

- **Group.** Collect shreds by slot and `fec_set_index`. Ignore duplicates of a shred you already hold.
- **Count.** Once all 32 data shreds are present, nothing needs recovering. If some are missing but the set holds 32 or more distinct shreds, it can be rebuilt.
- **Order.** Put the 64 pieces in shard order. Data shreds take positions 0 to 31, by how far their index sits past `fec_set_index`. Coding shreds take positions 32 to 63, by the position field in their header.
- **Decode.** Run Reed-Solomon reconstruction, then rebuild the missing data shreds from the recovered bytes.
- **Check.** Recompute the Merkle root and compare it with the one the leader signed, so a bad piece cannot slip in.

With fewer than 32 distinct shreds, the set cannot be rebuilt. A validator then asks peers for the missing shreds by repair. A receiver on a raw shred feed has no peers to ask, so it sees a gap in that batch until its own logic gives up on it. The step-by-step version, with the decode of the recovered entries, is in [recovering and decoding shreds](https://nitride.xyz/docs/shreds/recover-and-decode).

## Why 32 coding shreds and not fewer?
Older Solana software allowed other ratios, such as fewer coding shreds than data shreds. The Agave Turbine page explains why more parity matters by modeling loss over the two hops a shred travels. In its example, with 15% packet loss per hop, a block coded 16:4 almost never arrives complete, 16:16 succeeds about 43% of the time, and 32:32 succeeds about 99% of the time.

Fixed set sizes also make validation simpler. SIMD-0317 notes that every current client already sends 32 data and 32 coding shreds, and proposes dropping sets of any other shape. With a fixed shape, a node knows a set's index range from any one of its shreds, and spotting a leader that signs two different versions of a set gets easier.

## Questions

### Is an FEC set the same as an entry batch?

No. A batch can span several sets, and current Agave code pads the last set so the batch ends where a set ends. One set never holds the end of one batch and the start of the next.

### How many FEC sets can a slot have?

When slots targeted 400 ms, Agave capped a slot at 32,768 data shreds, which is 1,024 sets. SIMD-0525, which brought the target down to 200 ms on mainnet in October 2026, scales that cap down with the slot time, so read the current value from the release you run.

### Does recovery need the coding shreds of other sets?

No. Each set decodes on its own, so a loss in one set never blocks recovery in another.
