Skip to content

Commit

Permalink
explain why the share reserve byte is zero
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-forbes committed Apr 18, 2022
1 parent 4161214 commit 8e54103
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions types/share_splitting.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ func (csw *ContiguousShareWriter) Write(rawData []byte) {
pendingCursor := len(rawData) + consts.NamespaceSize + consts.ShareReservedBytes
var reservedByte byte
if pendingCursor >= consts.ShareSize {
// the share reserve byte is zero when some contiguously written
// data takes up the entire share
reservedByte = byte(0)
} else {
reservedByte = byte(pendingCursor)
Expand Down Expand Up @@ -196,6 +198,10 @@ func (csw *ContiguousShareWriter) Export() NamespacedShares {
rawLastShare := lastShare.Data()

for i := 0; i < consts.ShareReservedBytes; i++ {
// here we force the last share reserved byte to be zero to avoid any
// confusion for light clients parsing these shares, as the rest of the
// data after transaction is padding. See
// https://github.com/celestiaorg/celestia-specs/blob/master/src/specs/data_structures.md#share
rawLastShare[consts.NamespaceSize+i] = byte(0)
}

Expand Down

0 comments on commit 8e54103

Please sign in to comment.