Skip to main content

RedStuff Encoding Example

This page continues from the RedStuff encoding algorithm overview with a concrete worked example.

Encoding​

Consider a Walrus instance with N=7=3f+1N = 7 = 3f + 1 shards. This means the number of primary source symbols is N−2f=3N - 2f = 3, and secondary N−f=5N - f = 5. A blob of size S=15⋅sS = 15 \cdot s can therefore be divided into 15 symbols of size ss, and arranged in the matrix as follows.

[s0,0s0,1s0,2s0,3s0,4s1,0s1,1s1,2s1,3s1,4s2,0s2,1s2,2s2,3s2,4]\left[ \begin{array}{ccccc} s_{0,0} & s_{0,1} & s_{0,2} & s_{0,3} & s_{0,4} \\ s_{1,0} & s_{1,1} & s_{1,2} & s_{1,3} & s_{1,4} \\ s_{2,0} & s_{2,1} & s_{2,2} & s_{2,3} & s_{2,4} \\ \end{array} \right]

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,js_{i,j} indicates source symbols, while ri,jr_{i,j} indicates repair symbols).

[s0,0s0,1s0,2s0,3s0,4s1,0s1,1s1,2s1,3s1,4s2,0s2,1s2,2s2,3s2,4r3,0r3,1r3,2r3,3r3,4r4,0r4,1r4,2r4,3r4,4r5,0r5,1r5,2r5,3r5,4r6,0r6,1r6,2r6,3r6,4]\left[ \begin{array}{c|c|c|c|c} s_{0,0} & s_{0,1} & s_{0,2} & s_{0,3} & s_{0,4} \\ s_{1,0} & s_{1,1} & s_{1,2} & s_{1,3} & s_{1,4} \\ s_{2,0} & s_{2,1} & s_{2,2} & s_{2,3} & s_{2,4} \\ \color{blue} r_{3,0} & \color{blue} r_{3,1} & \color{blue} r_{3,2} & \color{blue} r_{3,3} & \color{blue} r_{3,4} \\ \color{blue} r_{4,0} & \color{blue} r_{4,1} & \color{blue} r_{4,2} & \color{blue} r_{4,3} & \color{blue} r_{4,4} \\ \color{blue} r_{5,0} & \color{blue} r_{5,1} & \color{blue} r_{5,2} & \color{blue} r_{5,3} & \color{blue} r_{5,4} \\ \color{blue} r_{6,0} & \color{blue} r_{6,1} & \color{blue} r_{6,2} & \color{blue} r_{6,3} & \color{blue} r_{6,4} \\ \end{array} \right]

Each of the rows of this column expansion is a primary sliver. For example, [r5,0,r5,1,r5,2,r5,3,r5,4][r_{5,0}, r_{5,1}, r_{5,2}, r_{5,3}, r_{5,4}].

Similarly, the secondary encoding on the rows of the matrix produces the expanded rows.

[s0,0s0,1s0,2s0,3s0,4r0,5r0,6s1,0s1,1s1,2s1,3s1,4r1,5r1,6s2,0s2,1s2,2s2,3s2,4r2,5r2,6]\left[ \begin{array}{ccccccc} s_{0,0} & s_{0,1} & s_{0,2} & s_{0,3} & s_{0,4} & \color{blue} r_{0,5} & \color{blue} r_{0,6} \\ \hline s_{1,0} & s_{1,1} & s_{1,2} & s_{1,3} & s_{1,4} & \color{blue} r_{1,5} & \color{blue} r_{1,6} \\ \hline s_{2,0} & s_{2,1} & s_{2,2} & s_{2,3} & s_{2,4} & \color{blue} r_{2,5} & \color{blue} r_{2,6} \\ \end{array} \right]

Each of the columns of this row expansion is a secondary sliver. For example, [r0,6,r1,6,r2,6][r_{0,6}, r_{1,6}, r_{2,6}].

For simplicity, this example and the recovery example pair primary sliver ii with secondary sliver ii (as in the Walrus paper), and store sliver pair ii on shard ii. In the implementation, sliver pair ii holds primary sliver ii and secondary sliver N−1−iN-1-i, and the sliver-pair-to-shard mapping assigns sliver pairs to shards. 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. These symbols can be represented as the lower-right quadrant of what is called the fully expanded message matrix.

[s0,0s0,1s0,2s0,3s0,4r0,5r0,6s1,0s1,1s1,2s1,3s1,4r1,5r1,6s2,0s2,1s2,2s2,3s2,4r2,5r2,6r3,0r3,1r3,2r3,3r3,4r3,5r3,6r4,0r4,1r4,2r4,3r4,4r4,5r4,6r5,0r5,1r5,2r5,3r5,4r5,5r5,6r6,0r6,1r6,2r6,3r6,4r6,5r6,6]\left[ \begin{array}{ccccc|cc} s_{0,0} & s_{0,1} & s_{0,2} & s_{0,3} & s_{0,4} & r_{0,5} & r_{0,6} \\ s_{1,0} & s_{1,1} & s_{1,2} & s_{1,3} & s_{1,4} & r_{1,5} & r_{1,6} \\ s_{2,0} & s_{2,1} & s_{2,2} & s_{2,3} & s_{2,4} & r_{2,5} & r_{2,6} \\ \hline r_{3,0} & r_{3,1} & r_{3,2} & r_{3,3} & r_{3,4} & \color{blue} r_{3,5} & \color{blue} r_{3,6} \\ r_{4,0} & r_{4,1} & r_{4,2} & r_{4,3} & r_{4,4} & \color{blue} r_{4,5} & \color{blue} r_{4,6} \\ r_{5,0} & r_{5,1} & r_{5,2} & r_{5,3} & r_{5,4} & \color{blue} r_{5,5} & \color{blue} r_{5,6} \\ r_{6,0} & r_{6,1} & r_{6,2} & r_{6,3} & r_{6,4} & \color{blue} r_{6,5} & \color{blue} r_{6,6} \\ \end{array} \right]

These symbols do not need to be stored on any node because they can always be recomputed by expanding either a primary or secondary sliver. For example, r4,5r_{4,5} can be obtained by:

  • the secondary-encoding expansion of primary sliver 4: [r4,0,r4,1,r4,2,r4,3,r4,4,r4,5,r4,6][r_{4,0}, r_{4,1}, r_{4,2}, r_{4,3}, r_{4,4}, \color{blue} r_{4,5}, r_{4,6}], or
  • the primary-encoding expansion of secondary sliver 5: [r0,5,r1,5,r2,5,r3,5,r4,5,r5,5,r6,5][r_{0,5}, r_{1,5}, r_{2,5}, r_{3,5}, \color{blue} r_{4,5}, r_{5,5}, r_{6,5}].

For a worked example of sliver recovery after shard failure, see RedStuff recovery example. For properties, Walrus-specific parameters, blob size limits, and sliver authentication details, see RedStuff properties and parameters.

  • Encoding