Skip to content

Commit

Permalink
feat!: stop forcing reserved byte to zero (#819)
Browse files Browse the repository at this point in the history
  • Loading branch information
rootulp authored Sep 30, 2022
1 parent bc2c544 commit c48311b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 33 deletions.
4 changes: 2 additions & 2 deletions pkg/shares/share_splitting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestSplitTxs(t *testing.T) {
append([]uint8{
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, // namespace id
0x0, // info byte
0x0, // reserved byte
0xb, // BUG: reserved byte should be zero
0xc, // continuation data of first transaction
}, bytes.Repeat([]byte{0x0}, 245)...), // padding
},
Expand All @@ -85,7 +85,7 @@ func TestSplitTxs(t *testing.T) {
append([]uint8{
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, // namespace id
0x0, // info byte
0x0, // reserved byte
0xd, // BUG: reserved byte should be zero
0xe, 0xe, 0xe, // continuation data of second transaction
}, bytes.Repeat([]byte{0x0}, 243)...), // padding
},
Expand Down
31 changes: 0 additions & 31 deletions pkg/shares/split_compact_shares.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,40 +145,9 @@ func (css *CompactShareSplitter) Export() NamespacedShares {

dataLengthVarint := css.dataLengthVarint(bytesOfPadding)
css.writeDataLengthVarintToFirstShare(dataLengthVarint)
css.forceLastShareReserveByteToZero()
return css.shares
}

// forceLastShareReserveByteToZero overwrites the reserve byte of the last share
// with zero. See https://github.com/celestiaorg/celestia-app/issues/779
func (css *CompactShareSplitter) forceLastShareReserveByteToZero() {
if len(css.shares) == 0 {
return
}
lastShare := css.shares[len(css.shares)-1]
rawLastShare := lastShare.Data()

for i := 0; i < appconsts.CompactShareReservedBytes; 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
if len(css.shares) == 1 {
// the reserved byte is after the namespace, info byte, and data length varint
rawLastShare[appconsts.NamespaceSize+appconsts.ShareInfoBytes+appconsts.FirstCompactShareDataLengthBytes+i] = byte(0)
} else {
// the reserved byte is after the namespace, info byte
rawLastShare[appconsts.NamespaceSize+appconsts.ShareInfoBytes+i] = byte(0)
}
}

newLastShare := NamespacedShare{
Share: rawLastShare,
ID: lastShare.NamespaceID(),
}
css.shares[len(css.shares)-1] = newLastShare
}

// dataLengthVarint returns a varint of the data length written to this compact
// share splitter.
func (css *CompactShareSplitter) dataLengthVarint(bytesOfPadding int) []byte {
Expand Down

0 comments on commit c48311b

Please sign in to comment.