RedStuff encoding arranges a blob as a matrix of source symbols, expands the columns to produce primary slivers, and expands the rows to produce secondary slivers. The following example traces these steps for a Walrus instance with 7 shards and continues from the RedStuff encoding algorithm overview.
Arrange the source symbols of the blob in a matrix with N−2f rows and N−f columns.
Apply the primary encoding to each column. Each row of the expanded matrix is a primary sliver.
Apply the secondary encoding to each row. Each column of the expanded matrix is a secondary sliver.
Store one primary sliver and one secondary sliver, a sliver pair, on each shard.
Consider a Walrus instance with N=7=3f+1 shards, so f=2. This means the number of primary source symbols is N−2f=3, and secondary N−f=5. You can therefore divide a blob of size S=15⋅s into 15 symbols of size s and arrange them in the matrix as follows.
Then, the primary encoding acts on the columns of the matrix, expanding them such that each column is composed of 3 source symbols and 4 repair symbols (si,j indicates source symbols, while ri,j indicates repair symbols).
The secondary encoding adds 2 repair symbols to each row of 5 source symbols, so columns 5 and 6 are new and hold only repair symbols (ri,5 and ri,6).
Each of the columns of this row expansion is a secondary sliver, so a secondary sliver holds 3 symbols, one from each row. For example, [r0,6,r1,6,r2,6]. Expanding such a column with the primary encoding gives 3 source symbols and 4 repair symbols, that is, 7 symbols in total.
For simplicity, this example and the recovery example pair primary sliver i with secondary sliver i (as in the Walrus paper), and store sliver pair i on shard i. In the implementation, sliver pair i holds primary sliver i and secondary sliver N−1−i, and the sliver-pair-to-shard mapping assigns sliver pairs to shards. Each shard therefore stores exactly one sliver pair, that is, one primary sliver and one secondary sliver. Neither difference changes how encoding and recovery work.
Thanks to the linearity of Reed-Solomon codes, the expansion of:
the repair secondary slivers (columns 5 and 6) with the primary encoding, and
the repair primary slivers (rows 3, 4, 5, and 6) with the secondary encoding,
results in the same set of symbols, which is essential for recovery. You can represent these symbols as the lower-right quadrant of the fully expanded message matrix.
No node needs to store these symbols because you can always recompute them by expanding either a primary or secondary sliver. For example, you can obtain r4,5 from:
the secondary-encoding expansion of primary sliver 4: [r4,0,r4,1,r4,2,r4,3,r4,4,r4,5,r4,6], or
the primary-encoding expansion of secondary sliver 5, which extends its 3 symbols to 7: [r0,5,r1,5,r2,5,r3,5,r4,5,r5,5,r6,5].
Both the primary and the secondary encoding use Reed-Solomon codes. The current encoding type, RS2, is RedStuff with the Reed-Solomon erasure code, and its configuration holds the number of source symbols for both encodings. Walrus no longer supports the original RedStuff encoding, which used the RaptorQ erasure code. With Reed-Solomon codes, the number of symbols you need to recover a sliver is exactly the number of source symbols.