Skip to content

Commit

Permalink
feat: Introduce --share-version CLI flag (#1603)
Browse files Browse the repository at this point in the history
## Overview

Introduce `--share-version` CLI flag 
-  #1041  

## Checklist

- [.] New and updated code has appropriate documentation
- [.] New and updated code has new and/or updated testing
- [.] Required CI checks are passing
- [] Visual proof for any user facing features like CLI or documentation
updates
- [.] Linked issues closed with keywords

---------

Co-authored-by: Rootul P <rootulp@gmail.com>
  • Loading branch information
amityadav0 and rootulp committed Apr 11, 2023
1 parent ab24a7b commit e905143
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 25 deletions.
12 changes: 6 additions & 6 deletions app/test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() {
val := s.network.Validators[0]
ns1 := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize))

mustNewBlob := func(ns appns.Namespace, data []byte) *blobtypes.Blob {
b, err := blobtypes.NewBlob(ns, data)
mustNewBlob := func(ns appns.Namespace, data []byte, shareVersion uint8) *blobtypes.Blob {
b, err := blobtypes.NewBlob(ns, data, shareVersion)
require.NoError(err)
return b
}
Expand All @@ -241,31 +241,31 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() {
tests := []test{
{
"small random typical",
mustNewBlob(ns1, tmrand.Bytes(3000)),
mustNewBlob(ns1, tmrand.Bytes(3000), appconsts.ShareVersionZero),
[]blobtypes.TxBuilderOption{
blobtypes.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(app.BondDenom, sdk.NewInt(1)))),
blobtypes.SetGasLimit(1_000_000_000),
},
},
{
"large random typical",
mustNewBlob(ns1, tmrand.Bytes(350000)),
mustNewBlob(ns1, tmrand.Bytes(350000), appconsts.ShareVersionZero),
[]types.TxBuilderOption{
blobtypes.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(app.BondDenom, sdk.NewInt(10)))),
blobtypes.SetGasLimit(1_000_000_000),
},
},
{
"medium random with memo",
mustNewBlob(ns1, tmrand.Bytes(100000)),
mustNewBlob(ns1, tmrand.Bytes(100000), appconsts.ShareVersionZero),
[]blobtypes.TxBuilderOption{
blobtypes.SetMemo("lol I could stick the rollup block here if I wanted to"),
blobtypes.SetGasLimit(1_000_000_000),
},
},
{
"medium random with timeout height",
mustNewBlob(ns1, tmrand.Bytes(100000)),
mustNewBlob(ns1, tmrand.Bytes(100000), appconsts.ShareVersionZero),
[]blobtypes.TxBuilderOption{
blobtypes.SetTimeoutHeight(1000),
blobtypes.SetGasLimit(1_000_000_000),
Expand Down
13 changes: 7 additions & 6 deletions testutil/blobfactory/payforblob_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"testing"

"github.com/celestiaorg/celestia-app/pkg/appconsts"
"github.com/celestiaorg/celestia-app/pkg/namespace"
appns "github.com/celestiaorg/celestia-app/pkg/namespace"
"github.com/celestiaorg/celestia-app/testutil/testfactory"
Expand All @@ -24,7 +25,7 @@ var defaultSigner = testfactory.RandomAddress().String()
func RandMsgPayForBlobsWithSigner(singer string, size, blobCount int) (*blobtypes.MsgPayForBlobs, []*tmproto.Blob) {
blobs := make([]*tmproto.Blob, blobCount)
for i := 0; i < blobCount; i++ {
blob, err := types.NewBlob(appns.RandomBlobNamespace(), tmrand.Bytes(size))
blob, err := types.NewBlob(appns.RandomBlobNamespace(), tmrand.Bytes(size), appconsts.ShareVersionZero)
if err != nil {
panic(err)
}
Expand All @@ -44,7 +45,7 @@ func RandMsgPayForBlobsWithSigner(singer string, size, blobCount int) (*blobtype
func RandBlobsWithNamespace(namespaces []appns.Namespace, sizes []int) []*tmproto.Blob {
blobs := make([]*tmproto.Blob, len(namespaces))
for i, ns := range namespaces {
blob, err := types.NewBlob(ns, tmrand.Bytes(sizes[i]))
blob, err := types.NewBlob(ns, tmrand.Bytes(sizes[i]), appconsts.ShareVersionZero)
if err != nil {
panic(err)
}
Expand All @@ -54,7 +55,7 @@ func RandBlobsWithNamespace(namespaces []appns.Namespace, sizes []int) []*tmprot
}

func RandMsgPayForBlobsWithNamespaceAndSigner(signer string, ns appns.Namespace, size int) (*blobtypes.MsgPayForBlobs, *tmproto.Blob) {
blob, err := types.NewBlob(ns, tmrand.Bytes(size))
blob, err := types.NewBlob(ns, tmrand.Bytes(size), appconsts.ShareVersionZero)
if err != nil {
panic(err)
}
Expand All @@ -69,7 +70,7 @@ func RandMsgPayForBlobsWithNamespaceAndSigner(signer string, ns appns.Namespace,
}

func RandMsgPayForBlobs(size int) (*blobtypes.MsgPayForBlobs, *tmproto.Blob) {
blob, err := types.NewBlob(namespace.RandomBlobNamespace(), tmrand.Bytes(size))
blob, err := types.NewBlob(namespace.RandomBlobNamespace(), tmrand.Bytes(size), appconsts.ShareVersionZero)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -300,7 +301,7 @@ func Repeat[T any](s T, count int) []T {
func ManyBlobs(t *testing.T, namespaces []appns.Namespace, sizes []int) []*tmproto.Blob {
blobs := make([]*tmproto.Blob, len(namespaces))
for i, ns := range namespaces {
blob, err := blobtypes.NewBlob(ns, tmrand.Bytes(sizes[i]))
blob, err := blobtypes.NewBlob(ns, tmrand.Bytes(sizes[i]), appconsts.ShareVersionZero)
require.NoError(t, err)
blobs[i] = blob
}
Expand All @@ -312,7 +313,7 @@ func NestedBlobs(t *testing.T, namespaces []appns.Namespace, sizes [][]int) [][]
counter := 0
for i, set := range sizes {
for _, size := range set {
blob, err := blobtypes.NewBlob(namespaces[counter], tmrand.Bytes(size))
blob, err := blobtypes.NewBlob(namespaces[counter], tmrand.Bytes(size), appconsts.ShareVersionZero)
require.NoError(t, err)
blobs[i] = append(blobs[i], blob)
counter++
Expand Down
2 changes: 1 addition & 1 deletion testutil/testnode/node_interaction_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (c *Context) PostData(account, broadcastMode string, ns appns.Namespace, bl
signer.SetAccountNumber(acc)
signer.SetSequence(seq)

blob, err := types.NewBlob(ns, blobData)
blob, err := types.NewBlob(ns, blobData, appconsts.ShareVersionZero)
if err != nil {
return nil, err
}
Expand Down
9 changes: 8 additions & 1 deletion x/blob/client/cli/payforblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import (
coretypes "github.com/tendermint/tendermint/types"
)

// FlagShareVersion allows the user to override the share version when
// submitting a PayForBlob.
const FlagShareVersion = "share-version"

func CmdPayForBlob() *cobra.Command {
cmd := &cobra.Command{
Use: "PayForBlobs [hexNamespaceID] [hexBlob]",
Expand All @@ -41,13 +45,15 @@ func CmdPayForBlob() *cobra.Command {
return fmt.Errorf("failure to create namespace: %w", err)
}

shareVersion, _ := cmd.Flags().GetUint8(FlagShareVersion)

rawblob, err := hex.DecodeString(args[1])
if err != nil {
return fmt.Errorf("failure to decode hex blob: %w", err)
}

// TODO: allow for more than one blob to be sumbmitted via the cli
blob, err := types.NewBlob(namespace, rawblob)
blob, err := types.NewBlob(namespace, rawblob, shareVersion)
if err != nil {
return err
}
Expand All @@ -57,6 +63,7 @@ func CmdPayForBlob() *cobra.Command {
}

flags.AddTxFlagsToCmd(cmd)
cmd.PersistentFlags().Uint8(FlagShareVersion, 0, "Specify the share version")

return cmd
}
Expand Down
3 changes: 2 additions & 1 deletion x/blob/client/cli/testrandblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"strconv"

"github.com/celestiaorg/celestia-app/pkg/appconsts"
appns "github.com/celestiaorg/celestia-app/pkg/namespace"
"github.com/celestiaorg/celestia-app/testutil/testfactory"
"github.com/celestiaorg/celestia-app/x/blob/types"
Expand Down Expand Up @@ -31,7 +32,7 @@ func CmdTestRandBlob() *cobra.Command {

ns := appns.RandomBlobNamespace()
coreBlob := testfactory.GenerateBlobsWithNamespace(1, size, ns)
blob, err := types.NewBlob(ns, coreBlob[0].Data)
blob, err := types.NewBlob(ns, coreBlob[0].Data, appconsts.ShareVersionZero)
if err != nil {
return fmt.Errorf("failure on generating random blob: %w", err)
}
Expand Down
16 changes: 16 additions & 0 deletions x/blob/client/testutil/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
appns "github.com/celestiaorg/celestia-app/pkg/namespace"
"github.com/celestiaorg/celestia-app/testutil/network"
"github.com/celestiaorg/celestia-app/testutil/testfactory"
"github.com/celestiaorg/celestia-app/x/blob/client/cli"
paycli "github.com/celestiaorg/celestia-app/x/blob/client/cli"
abci "github.com/tendermint/tendermint/abci/types"
)
Expand Down Expand Up @@ -87,6 +88,21 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() {
expectedCode: 0,
respType: &sdk.TxResponse{},
},
{
name: "unsupported share version",
args: []string{
hexNamespace,
hexBlob,
fmt.Sprintf("--from=%s", username),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(2))).String()),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=1", cli.FlagShareVersion),
},
expectErr: true,
expectedCode: 0,
respType: &sdk.TxResponse{},
},
}

for _, tc := range testCases {
Expand Down
5 changes: 2 additions & 3 deletions x/blob/types/blob_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package types
import (
"bytes"

"github.com/celestiaorg/celestia-app/pkg/appconsts"
appns "github.com/celestiaorg/celestia-app/pkg/namespace"
shares "github.com/celestiaorg/celestia-app/pkg/shares"
"github.com/cosmos/cosmos-sdk/client"
Expand All @@ -15,7 +14,7 @@ type Blob = tmproto.Blob

// NewBlob creates a new coretypes.Blob from the provided data after performing
// basic stateless checks over it.
func NewBlob(ns appns.Namespace, blob []byte) (*Blob, error) {
func NewBlob(ns appns.Namespace, blob []byte, shareVersion uint8) (*Blob, error) {
err := ns.ValidateBlobNamespace()
if err != nil {
return nil, err
Expand All @@ -28,7 +27,7 @@ func NewBlob(ns appns.Namespace, blob []byte) (*Blob, error) {
return &tmproto.Blob{
NamespaceId: ns.ID,
Data: blob,
ShareVersion: uint32(appconsts.DefaultShareVersion),
ShareVersion: uint32(shareVersion),
NamespaceVersion: uint32(ns.Version),
}, nil
}
Expand Down
9 changes: 5 additions & 4 deletions x/blob/types/blob_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/celestiaorg/celestia-app/app/encoding"
"github.com/celestiaorg/celestia-app/pkg/appconsts"
"github.com/celestiaorg/celestia-app/pkg/namespace"
appns "github.com/celestiaorg/celestia-app/pkg/namespace"
tmrand "github.com/tendermint/tendermint/libs/rand"
Expand All @@ -22,14 +23,14 @@ const (

func TestNewBlob(t *testing.T) {
rawBlob := []byte{1}
validBlob, err := NewBlob(namespace.RandomBlobNamespace(), rawBlob)
validBlob, err := NewBlob(namespace.RandomBlobNamespace(), rawBlob, appconsts.ShareVersionZero)
require.NoError(t, err)
require.Equal(t, validBlob.Data, rawBlob)

_, err = NewBlob(appns.TxNamespace, rawBlob)
_, err = NewBlob(appns.TxNamespace, rawBlob, appconsts.ShareVersionZero)
require.Error(t, err)

_, err = NewBlob(namespace.RandomBlobNamespace(), []byte{})
_, err = NewBlob(namespace.RandomBlobNamespace(), []byte{}, appconsts.ShareVersionZero)
require.Error(t, err)
}

Expand Down Expand Up @@ -105,7 +106,7 @@ func setupSigTest(t *testing.T) (string, sdk.Address, *KeyringSigner, encoding.C
}

func randMsgPayForBlobsWithNamespaceAndSigner(t *testing.T, signer string, ns appns.Namespace, size int) (*MsgPayForBlobs, *tmproto.Blob) {
blob, err := NewBlob(ns, tmrand.Bytes(size))
blob, err := NewBlob(ns, tmrand.Bytes(size), appconsts.ShareVersionZero)
require.NoError(t, err)
msg, err := NewMsgPayForBlobs(
signer,
Expand Down
6 changes: 3 additions & 3 deletions x/blob/types/test/blob_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestValidateBlobTx(t *testing.T) {
name: "invalid transaction, no pfb",
getTx: func() tmproto.BlobTx {
sendTx := blobfactory.GenerateManyRawSendTxs(encCfg.TxConfig, 1)
blob, err := types.NewBlob(namespace.RandomBlobNamespace(), rand.Bytes(100))
blob, err := types.NewBlob(namespace.RandomBlobNamespace(), rand.Bytes(100), appconsts.ShareVersionZero)
require.NoError(t, err)
return tmproto.BlobTx{
Tx: sendTx[0],
Expand All @@ -82,7 +82,7 @@ func TestValidateBlobTx(t *testing.T) {
getTx: func() tmproto.BlobTx {
rawBtx := validRawBtx()
btx, _ := coretypes.UnmarshalBlobTx(rawBtx)
blob, err := types.NewBlob(namespace.RandomBlobNamespace(), rand.Bytes(100))
blob, err := types.NewBlob(namespace.RandomBlobNamespace(), rand.Bytes(100), appconsts.ShareVersionZero)
require.NoError(t, err)
btx.Blobs = append(btx.Blobs, blob)
return btx
Expand All @@ -92,7 +92,7 @@ func TestValidateBlobTx(t *testing.T) {
{
name: "invalid share commitment",
getTx: func() tmproto.BlobTx {
blob, err := types.NewBlob(namespace.RandomBlobNamespace(), rand.Bytes(100))
blob, err := types.NewBlob(namespace.RandomBlobNamespace(), rand.Bytes(100), appconsts.ShareVersionZero)
require.NoError(t, err)
msg, err := types.NewMsgPayForBlobs(
signerAddr.String(),
Expand Down

0 comments on commit e905143

Please sign in to comment.