Skip to content

Commit

Permalink
feat!: max namespace version for parity namespace (#1627)
Browse files Browse the repository at this point in the history
Re-apply celestiaorg/celestia-app#1590 against
`main`
  • Loading branch information
rootulp authored Apr 17, 2023
1 parent 6d6e0af commit 0bdfa07
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 19 deletions.
6 changes: 3 additions & 3 deletions pkg/da/data_availability_header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestNilDataAvailabilityHeaderHashDoesntCrash(t *testing.T) {

func TestMinDataAvailabilityHeader(t *testing.T) {
dah := MinDataAvailabilityHeader()
expectedHash := []byte{0xad, 0x23, 0x6a, 0x2e, 0x4c, 0x5f, 0xca, 0x6c, 0xdb, 0xae, 0x5d, 0x5e, 0xdf, 0x79, 0xe8, 0x8e, 0x84, 0xc5, 0x2e, 0xed, 0x62, 0xeb, 0xd0, 0xb6, 0x5d, 0x18, 0xb2, 0x7c, 0x32, 0xa8, 0xbc, 0x58}
expectedHash := []byte{0xd3, 0x27, 0xf4, 0x4e, 0x52, 0x55, 0x21, 0xa6, 0x1b, 0x83, 0x65, 0x20, 0xd1, 0x96, 0xa2, 0xd2, 0x2c, 0x1d, 0x48, 0x67, 0xdb, 0xde, 0x3b, 0x1, 0xb, 0xfb, 0xa0, 0xef, 0x76, 0xed, 0x30, 0x27}
require.Equal(t, expectedHash, dah.hash)
require.NoError(t, dah.ValidateBasic())
}
Expand All @@ -42,13 +42,13 @@ func TestNewDataAvailabilityHeader(t *testing.T) {
tests := []test{
{
name: "typical",
expectedHash: []byte{0xeb, 0xfd, 0xb5, 0xc5, 0x52, 0x59, 0xd6, 0xe, 0x72, 0x6b, 0xde, 0x58, 0x7, 0x9a, 0x58, 0xd2, 0x18, 0x7b, 0xc9, 0x44, 0x7, 0x6e, 0xbe, 0x74, 0x47, 0x67, 0x45, 0xa3, 0xb7, 0x3a, 0x52, 0x47},
expectedHash: []byte{0x5b, 0x27, 0x3e, 0x3a, 0x5d, 0x9e, 0x90, 0x25, 0x58, 0x21, 0xb7, 0xe0, 0x4d, 0x4b, 0xaa, 0xde, 0x37, 0xa6, 0x6f, 0xcc, 0xd, 0x16, 0x6f, 0x9e, 0xe0, 0x7f, 0xbe, 0x8, 0xb4, 0x41, 0xc8, 0xa6},
squareSize: 2,
shares: generateShares(4),
},
{
name: "max square size",
expectedHash: []byte{0x48, 0x28, 0xa9, 0xef, 0x79, 0xc2, 0x12, 0x12, 0xc, 0x53, 0x83, 0x27, 0x55, 0x7d, 0x42, 0xdd, 0x64, 0x74, 0xad, 0x4e, 0x82, 0xcb, 0xa0, 0x43, 0xed, 0x14, 0x2, 0x54, 0x0, 0x3b, 0xf6, 0x11},
expectedHash: []byte{0xce, 0x5c, 0xf3, 0xc9, 0x15, 0xeb, 0xbf, 0xb0, 0x67, 0xe1, 0xa5, 0x97, 0x35, 0xf3, 0x25, 0x7b, 0x1c, 0x47, 0x74, 0x1f, 0xec, 0x6a, 0x33, 0x19, 0x7f, 0x8f, 0xc2, 0x4a, 0xe, 0xe2, 0xbe, 0x73},
squareSize: appconsts.DefaultMaxSquareSize,
shares: generateShares(appconsts.DefaultMaxSquareSize * appconsts.DefaultMaxSquareSize),
},
Expand Down
6 changes: 5 additions & 1 deletion pkg/namespace/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package namespace

import (
"bytes"
"math"

"github.com/celestiaorg/celestia-app/pkg/appconsts"
)
Expand Down Expand Up @@ -56,5 +57,8 @@ var (
TailPaddingNamespace = MustNewV0([]byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE})

// ParitySharesNamespace is the namespace reserved for erasure coded data.
ParitySharesNamespace = MustNewV0([]byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF})
ParitySharesNamespace = Namespace{
Version: math.MaxUint8,
ID: bytes.Repeat([]byte{0xFF}, NamespaceIDSize),
}
)
18 changes: 18 additions & 0 deletions pkg/namespace/random_namespace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package namespace

import tmrand "github.com/tendermint/tendermint/libs/rand"

func RandomNamespace() Namespace {
for {
id := RandomVerzionZeroID()
namespace, err := New(NamespaceVersionZero, id)
if err != nil {
continue
}
return namespace
}
}

func RandomVerzionZeroID() []byte {
return append(NamespaceVersionZeroPrefix, tmrand.Bytes(NamespaceVersionZeroIDSize)...)
}
6 changes: 5 additions & 1 deletion pkg/proof/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ func NewShareInclusionProof(
// get the extended rows containing the shares.
rows := make([][]shares.Share, endRow-startRow+1)
for i := startRow; i <= endRow; i++ {
rows[i-startRow] = shares.FromBytes(eds.Row(uint(i)))
shares, err := shares.FromBytes(eds.Row(uint(i)))
if err != nil {
return types.ShareProof{}, err
}
rows[i-startRow] = shares
}

var shareProofs []*tmproto.NMTProof //nolint:prealloc
Expand Down
2 changes: 1 addition & 1 deletion pkg/shares/compact_shares_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func Test_parseCompactSharesErrors(t *testing.T) {
shareWithUnsupportedShareVersionBytes := rawShares[0]
shareWithUnsupportedShareVersionBytes[appconsts.NamespaceSize] = byte(infoByte)

shareWithUnsupportedShareVersion, err := newShare(shareWithUnsupportedShareVersionBytes)
shareWithUnsupportedShareVersion, err := NewShare(shareWithUnsupportedShareVersionBytes)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/shares/parse_sparse_shares_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func Test_parseSparseSharesErrors(t *testing.T) {
rawShare = append(rawShare, namespace.ID{1, 1, 1, 1, 1, 1, 1, 1}...)
rawShare = append(rawShare, byte(infoByte))
rawShare = append(rawShare, bytes.Repeat([]byte{0}, appconsts.ShareSize-len(rawShare))...)
share, err := newShare(rawShare)
share, err := NewShare(rawShare)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/shares/share_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (b *Builder) AddData(rawData []byte) (rawDataLeftOver []byte) {
}

func (b *Builder) Build() (*Share, error) {
return newShare(b.rawShareData)
return NewShare(b.rawShareData)
}

// IsEmptyShare returns true if no data has been written to the share
Expand Down
15 changes: 9 additions & 6 deletions pkg/shares/shares.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (s *Share) InfoByte() (InfoByte, error) {
return ParseInfoByte(unparsed)
}

func newShare(data []byte) (*Share, error) {
func NewShare(data []byte) (*Share, error) {
if err := validateSize(data); err != nil {
return nil, err
}
Expand Down Expand Up @@ -200,10 +200,13 @@ func ToBytes(shares []Share) (bytes [][]byte) {
return bytes
}

func FromBytes(bytes [][]byte) (shares []Share) {
shares = make([]Share, len(bytes))
for i, b := range bytes {
shares[i] = Share{data: b}
func FromBytes(bytes [][]byte) (shares []Share, err error) {
for _, b := range bytes {
share, err := NewShare(b)
if err != nil {
return nil, err
}
shares = append(shares, *share)
}
return shares
return shares, nil
}
4 changes: 2 additions & 2 deletions specs/src/specs/consensus.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
| `INTERMEDIATE_STATE_ROOT_NAMESPACE` | `Namespace` | `0x000000000000000000000000000000000000000000000000000000000000000002` | Intermediate state roots, committed after every transaction. |
| `RESERVED_PADDING_NAMESPACE` | `Namespace` | `0x0000000000000000000000000000000000000000000000000000000000000000FF` | Padding after all reserved namespaces but before blobs. |
| `MAX_RESERVED_NAMESPACE` | `Namespace` | `0x0000000000000000000000000000000000000000000000000000000000000000FF` | Max reserved namespace is lexicographically the largest namespace that is reserved for protocol use. |
| `TAIL_PADDING_NAMESPACE` | `Namespace` | `0x00000000000000000000000000000000000000000000000000FFFFFFFFFFFFFFFE` | Tail padding for blobs: padding after all blobs to fill up the original data square. |
| `PARITY_SHARE_NAMESPACE` | `Namespace` | `0x00000000000000000000000000000000000000000000000000FFFFFFFFFFFFFFFF` | Parity shares: extended shares in the available data matrix. |
| `TAIL_PADDING_NAMESPACE` | `Namespace` | `0x00000000000000000000000000000000000000000000000000FFFFFFFFFFFFFFFE` | Tail padding for blobs: padding after all messages to fill up the original data square. |
| `PARITY_SHARE_NAMESPACE` | `Namespace` | `0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF` | Parity shares: extended shares in the available data matrix. |

### Rewards and Penalties

Expand Down
2 changes: 1 addition & 1 deletion x/blob/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ The blob module emits the following events:
celestia-app tx blob PayForBlobs <hex encoded namespace> <hex encoded data> [flags]
```

For submitting PFB transaction via a light client's rpc, see [celestia-node's documention](https://docs.celestia.org/developers/node-gateway-docs/#post-submit_pfd).
For submitting PFB transaction via a light client's rpc, see [celestia-node's documention](https://docs.celestia.org/developers/rpc-tutorial/#submitpayforblob-arguments).

While not directly supported, the steps in the [`SubmitPayForBlob`](https://github.com/celestiaorg/celestia-app/blob/a82110a281bf9ee95a9bf9f0492e5d091371ff0b/x/blob/payforblob.go) function can be reverse engineered to submit blobs programmatically.

Expand Down
1 change: 1 addition & 0 deletions x/blob/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ var (
ErrNoShareVersions = errors.Register(ModuleName, 11133, "no share versions provided")
ErrNoBlobSizes = errors.Register(ModuleName, 11134, "no blob sizes provided")
ErrNoShareCommitments = errors.Register(ModuleName, 11135, "no share commitments provided")
ErrInvalidNamespace = errors.Register(ModuleName, 11136, "invalid namespace")
)
3 changes: 2 additions & 1 deletion x/blob/types/payforblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
fmt "fmt"
math "math"

"cosmossdk.io/errors"
"github.com/celestiaorg/celestia-app/pkg/appconsts"
appns "github.com/celestiaorg/celestia-app/pkg/namespace"
appshares "github.com/celestiaorg/celestia-app/pkg/shares"
Expand Down Expand Up @@ -104,7 +105,7 @@ func (msg *MsgPayForBlobs) ValidateBasic() error {
for _, namespace := range msg.Namespaces {
ns, err := appns.From(namespace)
if err != nil {
return err
return errors.Wrap(ErrInvalidNamespace, err.Error())
}
err = ValidateBlobNamespaceID(ns)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion x/blob/types/payforblob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func TestValidateBasic(t *testing.T) {
{
name: "parity shares namespace id",
msg: paritySharesMsg,
wantErr: ErrParitySharesNamespace,
wantErr: ErrInvalidNamespace,
},
{
name: "tail padding namespace id",
Expand Down

0 comments on commit 0bdfa07

Please sign in to comment.