From 52d08f8d9d5487897cd2d2c3c38333ef9c958949 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Fri, 27 Oct 2023 14:38:43 +0200 Subject: [PATCH 1/2] feat: refactor blob, namespace and shares into single package --- app/check_tx.go | 4 +- app/errors/insufficient_gas_price_test.go | 4 +- app/errors/nonce_mismatch_test.go | 4 +- app/extend_block.go | 2 +- app/prepare_proposal.go | 2 +- app/process_proposal.go | 5 +- app/test/block_production_test.go | 2 +- app/test/check_tx_test.go | 19 ++-- app/test/integration_test.go | 23 +++-- app/test/max_total_blob_size_test.go | 6 +- app/test/prepare_proposal_test.go | 9 +- app/test/priority_test.go | 4 +- app/test/process_proposal_test.go | 48 +++++----- app/validate_txs.go | 14 +-- pkg/appconsts/global_consts.go | 8 +- pkg/da/data_availability_header.go | 2 +- pkg/da/data_availability_header_test.go | 4 +- pkg/inclusion/nmt_caching_test.go | 6 +- pkg/inclusion/paths.go | 2 +- pkg/namespace/README.md | 3 - pkg/proof/proof.go | 14 ++- pkg/proof/proof_test.go | 35 ++++---- pkg/proof/querier.go | 19 ++-- pkg/shares/namespace.go | 49 ---------- pkg/square/builder.go | 16 ++-- pkg/square/builder_test.go | 48 +++++----- pkg/square/square.go | 16 ++-- pkg/square/square_fuzz_test.go | 2 +- pkg/square/square_test.go | 8 +- pkg/user/signer.go | 8 +- pkg/wrapper/nmt_wrapper.go | 2 +- pkg/wrapper/nmt_wrapper_test.go | 2 +- proto/celestia/core/v1/blob/blob.proto | 2 +- {pkg/shares => shares}/README.md | 0 {pkg/blob => shares}/blob.go | 20 ++--- {pkg/blob => shares}/blob.pb.go | 2 +- .../blob_share_commitment_rules.go | 0 .../blob_share_commitment_rules_test.go | 39 ++++---- shares/blob_test.go | 65 ++++++++++++++ {pkg/shares => shares}/compact_shares_test.go | 59 ++++++------ {pkg/namespace => shares}/consts.go | 53 ++++++++++- {pkg/shares => shares}/counter.go | 16 ++-- {pkg/shares => shares}/counter_test.go | 20 ++--- {pkg/shares => shares}/info_byte.go | 8 +- {pkg/shares => shares}/info_byte_test.go | 0 {pkg/namespace => shares}/namespace.go | 60 +++++++++++-- {pkg/namespace => shares}/namespace_test.go | 10 +-- {pkg/shares => shares}/padding.go | 17 ++-- {pkg/shares => shares}/padding_test.go | 18 ++-- {pkg/shares => shares}/parse.go | 10 +-- .../shares => shares}/parse_compact_shares.go | 0 {pkg/shares => shares}/parse_sparse_shares.go | 8 +- .../parse_sparse_shares_test.go | 35 ++++---- {pkg/shares => shares}/parse_test.go | 37 ++++---- {pkg/shares => shares}/powers_of_two.go | 0 {pkg/shares => shares}/powers_of_two_test.go | 0 {pkg/namespace => shares}/random_blob.go | 4 +- {pkg/namespace => shares}/random_namespace.go | 4 +- {pkg/shares => shares}/range.go | 0 {pkg/shares => shares}/reserved_bytes.go | 20 ++--- {pkg/shares => shares}/reserved_bytes_test.go | 0 {pkg/shares => shares}/share_builder.go | 49 +++++----- {pkg/shares => shares}/share_builder_test.go | 68 +++++++------- {pkg/shares => shares}/share_sequence.go | 17 ++-- {pkg/shares => shares}/share_sequence_test.go | 59 ++++++------ {pkg/shares => shares}/share_splitting.go | 33 +------ .../shares => shares}/share_splitting_test.go | 32 ++++--- {pkg/shares => shares}/shares.go | 33 ++++--- {pkg/shares => shares}/shares_test.go | 32 ++++--- {pkg/shares => shares}/sparse_shares_test.go | 17 ++-- .../shares => shares}/split_compact_shares.go | 12 ++- .../split_compact_shares_test.go | 58 ++++++------ {pkg/shares => shares}/split_sparse_shares.go | 6 +- .../split_sparse_shares_test.go | 21 ++--- shares/txs.go | 59 ++++++++++++ {pkg/shares => shares}/utils.go | 10 +-- {pkg/shares => shares}/utils_test.go | 3 +- test/txsim/blob.go | 12 +-- test/txsim/sequence.go | 4 +- test/util/blobfactory/payforblob_factory.go | 45 +++++----- test/util/direct_tx_gen.go | 4 +- test/util/malicious/app_test.go | 2 +- test/util/malicious/out_of_order_builder.go | 10 +-- test/util/malicious/out_of_order_prepare.go | 2 +- test/util/malicious/tree.go | 2 +- test/util/testfactory/blob.go | 19 ++-- test/util/testfactory/common.go | 4 +- test/util/testnode/full_node_test.go | 2 +- test/util/testnode/node_interaction_api.go | 10 +-- test/util/testnode/read.go | 4 +- x/blob/ante/ante_test.go | 2 +- x/blob/ante/max_total_blob_size_ante.go | 2 +- x/blob/ante/max_total_blob_size_ante_test.go | 2 +- x/blob/client/cli/payforblob.go | 27 +++--- x/blob/client/testutil/integration_test.go | 2 +- x/blob/types/blob_tx.go | 14 ++- x/blob/types/blob_tx_test.go | 89 +++++++++---------- x/blob/types/estimate_gas_test.go | 6 +- x/blob/types/params.go | 2 +- x/blob/types/payforblob.go | 42 +++++---- x/blob/types/payforblob_test.go | 86 +++++++++--------- x/upgrade/upgrade_test.go | 2 +- 102 files changed, 922 insertions(+), 880 deletions(-) delete mode 100644 pkg/namespace/README.md delete mode 100644 pkg/shares/namespace.go rename {pkg/shares => shares}/README.md (100%) rename {pkg/blob => shares}/blob.go (80%) rename {pkg/blob => shares}/blob.pb.go (99%) rename {pkg/shares => shares}/blob_share_commitment_rules.go (100%) rename {pkg/shares => shares}/blob_share_commitment_rules_test.go (86%) create mode 100644 shares/blob_test.go rename {pkg/shares => shares}/compact_shares_test.go (67%) rename {pkg/namespace => shares}/consts.go (58%) rename {pkg/shares => shares}/counter.go (79%) rename {pkg/shares => shares}/counter_test.go (64%) rename {pkg/shares => shares}/info_byte.go (83%) rename {pkg/shares => shares}/info_byte_test.go (100%) rename {pkg/namespace => shares}/namespace.go (76%) rename {pkg/namespace => shares}/namespace_test.go (96%) rename {pkg/shares => shares}/padding.go (70%) rename {pkg/shares => shares}/padding_test.go (75%) rename {pkg/shares => shares}/parse.go (86%) rename {pkg/shares => shares}/parse_compact_shares.go (100%) rename {pkg/shares => shares}/parse_sparse_shares.go (92%) rename {pkg/shares => shares}/parse_sparse_shares_test.go (71%) rename {pkg/shares => shares}/parse_test.go (80%) rename {pkg/shares => shares}/powers_of_two.go (100%) rename {pkg/shares => shares}/powers_of_two_test.go (100%) rename {pkg/namespace => shares}/random_blob.go (96%) rename {pkg/namespace => shares}/random_namespace.go (81%) rename {pkg/shares => shares}/range.go (100%) rename {pkg/shares => shares}/reserved_bytes.go (51%) rename {pkg/shares => shares}/reserved_bytes_test.go (100%) rename {pkg/shares => shares}/share_builder.go (77%) rename {pkg/shares => shares}/share_builder_test.go (65%) rename {pkg/shares => shares}/share_sequence.go (87%) rename {pkg/shares => shares}/share_sequence_test.go (69%) rename {pkg/shares => shares}/share_splitting.go (52%) rename {pkg/shares => shares}/share_splitting_test.go (93%) rename {pkg/shares => shares}/shares.go (86%) rename {pkg/shares => shares}/shares_test.go (82%) rename {pkg/shares => shares}/sparse_shares_test.go (70%) rename {pkg/shares => shares}/split_compact_shares.go (92%) rename {pkg/shares => shares}/split_compact_shares_test.go (76%) rename {pkg/shares => shares}/split_sparse_shares.go (91%) rename {pkg/shares => shares}/split_sparse_shares_test.go (55%) create mode 100644 shares/txs.go rename {pkg/shares => shares}/utils.go (88%) rename {pkg/shares => shares}/utils_test.go (92%) diff --git a/app/check_tx.go b/app/check_tx.go index 4f5438a7ce..db734c2561 100644 --- a/app/check_tx.go +++ b/app/check_tx.go @@ -3,7 +3,7 @@ package app import ( "fmt" - "github.com/celestiaorg/celestia-app/pkg/blob" + "github.com/celestiaorg/celestia-app/shares" blobtypes "github.com/celestiaorg/celestia-app/x/blob/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" abci "github.com/tendermint/tendermint/abci/types" @@ -15,7 +15,7 @@ import ( func (app *App) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx { tx := req.Tx // check if the transaction contains blobs - btx, isBlob := blob.UnmarshalBlobTx(tx) + btx, isBlob := shares.UnmarshalBlobTx(tx) if !isBlob { // reject transactions that can't be decoded diff --git a/app/errors/insufficient_gas_price_test.go b/app/errors/insufficient_gas_price_test.go index b599cbf938..10694aaa4f 100644 --- a/app/errors/insufficient_gas_price_test.go +++ b/app/errors/insufficient_gas_price_test.go @@ -9,8 +9,8 @@ import ( "github.com/celestiaorg/celestia-app/app/encoding" apperr "github.com/celestiaorg/celestia-app/app/errors" "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/namespace" "github.com/celestiaorg/celestia-app/pkg/user" + "github.com/celestiaorg/celestia-app/shares" testutil "github.com/celestiaorg/celestia-app/test/util" "github.com/celestiaorg/celestia-app/test/util/testfactory" blob "github.com/celestiaorg/celestia-app/x/blob/types" @@ -41,7 +41,7 @@ func TestInsufficientMinGasPriceIntegration(t *testing.T) { require.NoError(t, err) fee := sdk.NewCoins(sdk.NewCoin(app.BondDenom, sdk.NewInt(feeAmount))) - b, err := blob.NewBlob(namespace.RandomNamespace(), []byte("hello world"), 0) + b, err := blob.NewBlob(shares.RandomNamespace(), []byte("hello world"), 0) require.NoError(t, err) msg, err := blob.NewMsgPayForBlobs(signer.Address().String(), b) diff --git a/app/errors/nonce_mismatch_test.go b/app/errors/nonce_mismatch_test.go index b71cc57b12..6dc07f9e40 100644 --- a/app/errors/nonce_mismatch_test.go +++ b/app/errors/nonce_mismatch_test.go @@ -8,8 +8,8 @@ import ( "github.com/celestiaorg/celestia-app/app/encoding" apperr "github.com/celestiaorg/celestia-app/app/errors" "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/namespace" "github.com/celestiaorg/celestia-app/pkg/user" + "github.com/celestiaorg/celestia-app/shares" testutil "github.com/celestiaorg/celestia-app/test/util" "github.com/celestiaorg/celestia-app/test/util/testfactory" blob "github.com/celestiaorg/celestia-app/x/blob/types" @@ -35,7 +35,7 @@ func TestNonceMismatchIntegration(t *testing.T) { signer, err := user.NewSigner(kr, nil, addr, enc.TxConfig, testutil.ChainID, acc.GetAccountNumber(), 2) require.NoError(t, err) - b, err := blob.NewBlob(namespace.RandomNamespace(), []byte("hello world"), 0) + b, err := blob.NewBlob(shares.RandomNamespace(), []byte("hello world"), 0) require.NoError(t, err) msg, err := blob.NewMsgPayForBlobs(signer.Address().String(), b) diff --git a/app/extend_block.go b/app/extend_block.go index 39578b66c3..8b93407dd7 100644 --- a/app/extend_block.go +++ b/app/extend_block.go @@ -3,8 +3,8 @@ package app import ( "github.com/celestiaorg/celestia-app/pkg/appconsts" "github.com/celestiaorg/celestia-app/pkg/da" - "github.com/celestiaorg/celestia-app/pkg/shares" "github.com/celestiaorg/celestia-app/pkg/square" + "github.com/celestiaorg/celestia-app/shares" "github.com/celestiaorg/rsmt2d" coretypes "github.com/tendermint/tendermint/types" ) diff --git a/app/prepare_proposal.go b/app/prepare_proposal.go index 8929c31cd5..acdf5b6639 100644 --- a/app/prepare_proposal.go +++ b/app/prepare_proposal.go @@ -5,8 +5,8 @@ import ( "github.com/celestiaorg/celestia-app/app/ante" "github.com/celestiaorg/celestia-app/pkg/da" - "github.com/celestiaorg/celestia-app/pkg/shares" "github.com/celestiaorg/celestia-app/pkg/square" + "github.com/celestiaorg/celestia-app/shares" "github.com/celestiaorg/celestia-app/x/upgrade" "github.com/cosmos/cosmos-sdk/telemetry" abci "github.com/tendermint/tendermint/abci/types" diff --git a/app/process_proposal.go b/app/process_proposal.go index 9a09731871..fe01dc7a1f 100644 --- a/app/process_proposal.go +++ b/app/process_proposal.go @@ -6,10 +6,9 @@ import ( "time" "github.com/celestiaorg/celestia-app/app/ante" - "github.com/celestiaorg/celestia-app/pkg/blob" "github.com/celestiaorg/celestia-app/pkg/da" - "github.com/celestiaorg/celestia-app/pkg/shares" "github.com/celestiaorg/celestia-app/pkg/square" + "github.com/celestiaorg/celestia-app/shares" blobtypes "github.com/celestiaorg/celestia-app/x/blob/types" "github.com/celestiaorg/celestia-app/x/upgrade" "github.com/cosmos/cosmos-sdk/telemetry" @@ -52,7 +51,7 @@ func (app *App) ProcessProposal(req abci.RequestProcessProposal) (resp abci.Resp // blobTxs have no PFBs present for idx, rawTx := range req.BlockData.Txs { tx := rawTx - blobTx, isBlobTx := blob.UnmarshalBlobTx(rawTx) + blobTx, isBlobTx := shares.UnmarshalBlobTx(rawTx) if isBlobTx { tx = blobTx.Tx } diff --git a/app/test/block_production_test.go b/app/test/block_production_test.go index f8bfb5435a..dc2c681069 100644 --- a/app/test/block_production_test.go +++ b/app/test/block_production_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" + appns "github.com/celestiaorg/celestia-app/shares" "github.com/celestiaorg/celestia-app/test/util/testnode" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/stretchr/testify/suite" diff --git a/app/test/check_tx_test.go b/app/test/check_tx_test.go index 8842790114..2427b867d0 100644 --- a/app/test/check_tx_test.go +++ b/app/test/check_tx_test.go @@ -10,9 +10,8 @@ import ( "github.com/celestiaorg/celestia-app/app" "github.com/celestiaorg/celestia-app/app/encoding" - "github.com/celestiaorg/celestia-app/pkg/blob" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" "github.com/celestiaorg/celestia-app/pkg/user" + "github.com/celestiaorg/celestia-app/shares" testutil "github.com/celestiaorg/celestia-app/test/util" "github.com/celestiaorg/celestia-app/test/util/blobfactory" "github.com/celestiaorg/celestia-app/test/util/testfactory" @@ -27,7 +26,7 @@ import ( // assume that the rest of CheckTx is tested by the cosmos-sdk. func TestCheckTx(t *testing.T) { encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) - ns1 := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) + ns1 := shares.MustNewV0Namespace(bytes.Repeat([]byte{1}, shares.NamespaceVersionZeroIDSize)) accs := []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"} @@ -51,7 +50,7 @@ func TestCheckTx(t *testing.T) { signer := createSigner(t, kr, accs[0], encCfg.TxConfig, 1) btx := blobfactory.RandBlobTxsWithNamespacesAndSigner( signer, - []appns.Namespace{ns1}, + []shares.Namespace{ns1}, []int{100}, )[0] return btx @@ -65,7 +64,7 @@ func TestCheckTx(t *testing.T) { signer := createSigner(t, kr, accs[1], encCfg.TxConfig, 2) btx := blobfactory.RandBlobTxsWithNamespacesAndSigner( signer, - []appns.Namespace{ns1}, + []shares.Namespace{ns1}, []int{100}, )[0] return btx @@ -79,13 +78,13 @@ func TestCheckTx(t *testing.T) { signer := createSigner(t, kr, accs[2], encCfg.TxConfig, 3) btx := blobfactory.RandBlobTxsWithNamespacesAndSigner( signer, - []appns.Namespace{ns1}, + []shares.Namespace{ns1}, []int{100}, )[0] - dtx, _ := blob.UnmarshalBlobTx(btx) - dtx.Blobs[0].NamespaceId = appns.RandomBlobNamespace().ID - bbtx, err := blob.MarshalBlobTx(dtx.Tx, dtx.Blobs[0]) + dtx, _ := shares.UnmarshalBlobTx(btx) + dtx.Blobs[0].NamespaceId = shares.RandomBlobNamespace().ID + bbtx, err := shares.MarshalBlobTx(dtx.Tx, dtx.Blobs[0]) require.NoError(t, err) return bbtx }, @@ -98,7 +97,7 @@ func TestCheckTx(t *testing.T) { signer := createSigner(t, kr, accs[3], encCfg.TxConfig, 4) btx := blobfactory.RandBlobTxsWithNamespacesAndSigner( signer, - []appns.Namespace{ns1}, + []shares.Namespace{ns1}, []int{100}, )[0] dtx, _ := coretypes.UnmarshalBlobTx(btx) diff --git a/app/test/integration_test.go b/app/test/integration_test.go index 4a2e054e71..70de532c7c 100644 --- a/app/test/integration_test.go +++ b/app/test/integration_test.go @@ -23,11 +23,10 @@ import ( "github.com/celestiaorg/celestia-app/app" "github.com/celestiaorg/celestia-app/app/encoding" "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/blob" "github.com/celestiaorg/celestia-app/pkg/da" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" "github.com/celestiaorg/celestia-app/pkg/square" "github.com/celestiaorg/celestia-app/pkg/user" + "github.com/celestiaorg/celestia-app/shares" blobtypes "github.com/celestiaorg/celestia-app/x/blob/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -208,15 +207,15 @@ func (s *IntegrationTestSuite) TestMaxBlockSize() { func (s *IntegrationTestSuite) TestSubmitPayForBlob() { t := s.T() - ns1 := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) + ns1 := shares.MustNewV0Namespace(bytes.Repeat([]byte{1}, shares.NamespaceVersionZeroIDSize)) - mustNewBlob := func(ns appns.Namespace, data []byte, shareVersion uint8) *blob.Blob { - return blob.New(ns, data, shareVersion) + mustNewBlob := func(ns shares.Namespace, data []byte, shareVersion uint8) *shares.Blob { + return shares.NewBlob(ns, data, shareVersion) } type test struct { name string - blob *blob.Blob + blob *shares.Blob opts []user.TxOption } @@ -263,7 +262,7 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() { addr := testfactory.GetAddress(s.cctx.Keyring, s.accounts[141]) signer, err := user.SetupSigner(s.cctx.GoContext(), s.cctx.Keyring, s.cctx.GRPCClient, addr, s.ecfg) require.NoError(t, err) - res, err := signer.SubmitPayForBlob(context.TODO(), []*blob.Blob{tc.blob, tc.blob}, tc.opts...) + res, err := signer.SubmitPayForBlob(context.TODO(), []*shares.Blob{tc.blob, tc.blob}, tc.opts...) require.NoError(t, err) require.NotNil(t, res) require.Equal(t, abci.CodeTypeOK, res.Code, res.Logs) @@ -389,7 +388,7 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob_blobSizes() { type testCase struct { name string - blob *blob.Blob + blob *shares.Blob // txResponseCode is the expected tx response ABCI code. txResponseCode uint32 } @@ -425,7 +424,7 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob_blobSizes() { s.Run(tc.name, func() { subCtx, cancel := context.WithTimeout(s.cctx.GoContext(), 30*time.Second) defer cancel() - res, err := signer.SubmitPayForBlob(subCtx, []*blob.Blob{tc.blob}, user.SetGasLimit(1_000_000_000)) + res, err := signer.SubmitPayForBlob(subCtx, []*shares.Blob{tc.blob}, user.SetGasLimit(1_000_000_000)) if tc.txResponseCode == abci.CodeTypeOK { require.NoError(t, err) } else { @@ -437,8 +436,8 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob_blobSizes() { } } -func mustNewBlob(blobSize int) *blob.Blob { - ns1 := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) +func mustNewBlob(blobSize int) *shares.Blob { + ns1 := shares.MustNewV0Namespace(bytes.Repeat([]byte{1}, shares.NamespaceVersionZeroIDSize)) data := tmrand.Bytes(blobSize) - return blob.New(ns1, data, appconsts.ShareVersionZero) + return shares.NewBlob(ns1, data, appconsts.ShareVersionZero) } diff --git a/app/test/max_total_blob_size_test.go b/app/test/max_total_blob_size_test.go index 8c7875f2f9..d2188572bc 100644 --- a/app/test/max_total_blob_size_test.go +++ b/app/test/max_total_blob_size_test.go @@ -8,9 +8,9 @@ import ( "github.com/celestiaorg/celestia-app/app" "github.com/celestiaorg/celestia-app/app/encoding" "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/blob" "github.com/celestiaorg/celestia-app/pkg/square" "github.com/celestiaorg/celestia-app/pkg/user" + "github.com/celestiaorg/celestia-app/shares" "github.com/celestiaorg/celestia-app/test/util/testfactory" "github.com/celestiaorg/celestia-app/test/util/testnode" blobtypes "github.com/celestiaorg/celestia-app/x/blob/types" @@ -70,7 +70,7 @@ func (s *MaxTotalBlobSizeSuite) TestSubmitPayForBlob_blobSizes() { type testCase struct { name string - blob *blob.Blob + blob *shares.Blob // want is the expected tx response ABCI code. want uint32 } @@ -97,7 +97,7 @@ func (s *MaxTotalBlobSizeSuite) TestSubmitPayForBlob_blobSizes() { for _, tc := range testCases { s.Run(tc.name, func() { - blobTx, err := signer.CreatePayForBlob([]*blob.Blob{tc.blob}, user.SetGasLimit(1e9)) + blobTx, err := signer.CreatePayForBlob([]*shares.Blob{tc.blob}, user.SetGasLimit(1e9)) require.NoError(t, err) subCtx, cancel := context.WithTimeout(s.cctx.GoContext(), 30*time.Second) defer cancel() diff --git a/app/test/prepare_proposal_test.go b/app/test/prepare_proposal_test.go index 67b7134535..e43e1c811c 100644 --- a/app/test/prepare_proposal_test.go +++ b/app/test/prepare_proposal_test.go @@ -16,8 +16,7 @@ import ( "github.com/celestiaorg/celestia-app/app" "github.com/celestiaorg/celestia-app/app/encoding" "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/blob" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" + "github.com/celestiaorg/celestia-app/shares" testutil "github.com/celestiaorg/celestia-app/test/util" "github.com/celestiaorg/celestia-app/test/util/blobfactory" "github.com/celestiaorg/celestia-app/test/util/testfactory" @@ -37,8 +36,8 @@ func TestPrepareProposalPutsPFBsAtEnd(t *testing.T) { testutil.ChainID, accnts[:numBlobTxs], infos[:numBlobTxs], - testfactory.Repeat([]*blob.Blob{ - blob.New(appns.RandomBlobNamespace(), []byte{1}, appconsts.DefaultShareVersion), + testfactory.Repeat([]*shares.Blob{ + shares.NewBlob(shares.RandomBlobNamespace(), []byte{1}, appconsts.DefaultShareVersion), }, numBlobTxs), ) @@ -93,7 +92,7 @@ func TestPrepareProposalFiltering(t *testing.T) { infos[:3], blobfactory.NestedBlobs( t, - appns.RandomBlobNamespaces(tmrand.NewRand(), 3), + shares.RandomBlobNamespaces(tmrand.NewRand(), 3), [][]int{{100}, {1000}, {420}}, ), ) diff --git a/app/test/priority_test.go b/app/test/priority_test.go index 256c13eb0d..d5d7a494af 100644 --- a/app/test/priority_test.go +++ b/app/test/priority_test.go @@ -8,8 +8,8 @@ import ( "github.com/celestiaorg/celestia-app/app" "github.com/celestiaorg/celestia-app/app/encoding" - "github.com/celestiaorg/celestia-app/pkg/namespace" "github.com/celestiaorg/celestia-app/pkg/user" + "github.com/celestiaorg/celestia-app/shares" "github.com/celestiaorg/celestia-app/test/util/blobfactory" "github.com/celestiaorg/celestia-app/test/util/testfactory" "github.com/celestiaorg/celestia-app/test/util/testnode" @@ -79,7 +79,7 @@ func (s *PriorityTestSuite) TestPriorityByGasPrice() { btx, err := signer.CreatePayForBlob( blobfactory.ManyBlobs( s.rand, - []namespace.Namespace{namespace.RandomBlobNamespace()}, + []shares.Namespace{shares.RandomBlobNamespace()}, []int{100}), user.SetGasLimitAndFee(gasLimit, gasPrice), ) diff --git a/app/test/process_proposal_test.go b/app/test/process_proposal_test.go index 26ebeacc70..74432a4110 100644 --- a/app/test/process_proposal_test.go +++ b/app/test/process_proposal_test.go @@ -16,12 +16,10 @@ import ( "github.com/celestiaorg/celestia-app/app" "github.com/celestiaorg/celestia-app/app/encoding" "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/blob" "github.com/celestiaorg/celestia-app/pkg/da" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" - "github.com/celestiaorg/celestia-app/pkg/shares" "github.com/celestiaorg/celestia-app/pkg/square" "github.com/celestiaorg/celestia-app/pkg/user" + "github.com/celestiaorg/celestia-app/shares" testutil "github.com/celestiaorg/celestia-app/test/util" "github.com/celestiaorg/celestia-app/test/util/blobfactory" "github.com/celestiaorg/celestia-app/test/util/testfactory" @@ -42,7 +40,7 @@ func TestProcessProposal(t *testing.T) { t, enc, kr, testutil.ChainID, accounts[:4], infos[:4], blobfactory.NestedBlobs( t, - appns.RandomBlobNamespaces(tmrand.NewRand(), 4), + shares.RandomBlobNamespaces(tmrand.NewRand(), 4), [][]int{{100}, {1000}, {420}, {300}}, ), ) @@ -73,8 +71,8 @@ func TestProcessProposal(t *testing.T) { t, enc, kr, 1000, 1, false, testutil.ChainID, accounts[:1], 1, 3, false, )[0] - ns1 := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) - invalidNamespace, err := appns.New(appns.NamespaceVersionZero, bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) + ns1 := shares.MustNewV0Namespace(bytes.Repeat([]byte{1}, shares.NamespaceVersionZeroIDSize)) + invalidNamespace, err := shares.NewNamespace(shares.NamespaceVersionZero, bytes.Repeat([]byte{1}, shares.NamespaceVersionZeroIDSize)) // expect an error because the input is invalid: it doesn't contain the namespace version zero prefix. assert.Error(t, err) data := bytes.Repeat([]byte{1}, 13) @@ -113,8 +111,8 @@ func TestProcessProposal(t *testing.T) { name: "modified a blobTx", input: validData(), mutator: func(d *tmproto.Data) { - blobTx, _ := blob.UnmarshalBlobTx(blobTxs[0]) - blobTx.Blobs[0] = &blob.Blob{ + blobTx, _ := shares.UnmarshalBlobTx(blobTxs[0]) + blobTx.Blobs[0] = &shares.Blob{ NamespaceId: ns1.ID, Data: data, NamespaceVersion: uint32(ns1.Version), @@ -129,11 +127,11 @@ func TestProcessProposal(t *testing.T) { name: "invalid namespace TailPadding", input: validData(), mutator: func(d *tmproto.Data) { - blobTx, _ := blob.UnmarshalBlobTx(blobTxs[0]) - blobTx.Blobs[0] = &blob.Blob{ - NamespaceId: appns.TailPaddingNamespace.ID, + blobTx, _ := shares.UnmarshalBlobTx(blobTxs[0]) + blobTx.Blobs[0] = &shares.Blob{ + NamespaceId: shares.TailPaddingNamespace.ID, Data: data, - NamespaceVersion: uint32(appns.TailPaddingNamespace.Version), + NamespaceVersion: uint32(shares.TailPaddingNamespace.Version), ShareVersion: uint32(appconsts.ShareVersionZero), } blobTxBytes, _ := blobTx.Marshal() @@ -145,11 +143,11 @@ func TestProcessProposal(t *testing.T) { name: "invalid namespace TxNamespace", input: validData(), mutator: func(d *tmproto.Data) { - blobTx, _ := blob.UnmarshalBlobTx(blobTxs[0]) - blobTx.Blobs[0] = &blob.Blob{ - NamespaceId: appns.TxNamespace.ID, + blobTx, _ := shares.UnmarshalBlobTx(blobTxs[0]) + blobTx.Blobs[0] = &shares.Blob{ + NamespaceId: shares.TxNamespace.ID, Data: data, - NamespaceVersion: uint32(appns.TxNamespace.Version), + NamespaceVersion: uint32(shares.TxNamespace.Version), ShareVersion: uint32(appconsts.ShareVersionZero), } blobTxBytes, _ := blobTx.Marshal() @@ -161,11 +159,11 @@ func TestProcessProposal(t *testing.T) { name: "invalid namespace ParityShares", input: validData(), mutator: func(d *tmproto.Data) { - blobTx, _ := blob.UnmarshalBlobTx(blobTxs[0]) - blobTx.Blobs[0] = &blob.Blob{ - NamespaceId: appns.ParitySharesNamespace.ID, + blobTx, _ := shares.UnmarshalBlobTx(blobTxs[0]) + blobTx.Blobs[0] = &shares.Blob{ + NamespaceId: shares.ParitySharesNamespace.ID, Data: data, - NamespaceVersion: uint32(appns.ParitySharesNamespace.Version), + NamespaceVersion: uint32(shares.ParitySharesNamespace.Version), ShareVersion: uint32(appconsts.ShareVersionZero), } blobTxBytes, _ := blobTx.Marshal() @@ -177,8 +175,8 @@ func TestProcessProposal(t *testing.T) { name: "invalid blob namespace", input: validData(), mutator: func(d *tmproto.Data) { - blobTx, _ := blob.UnmarshalBlobTx(blobTxs[0]) - blobTx.Blobs[0] = &blob.Blob{ + blobTx, _ := shares.UnmarshalBlobTx(blobTxs[0]) + blobTx.Blobs[0] = &shares.Blob{ NamespaceId: invalidNamespace.ID, Data: data, ShareVersion: uint32(appconsts.ShareVersionZero), @@ -193,8 +191,8 @@ func TestProcessProposal(t *testing.T) { name: "pfb namespace version does not match blob", input: validData(), mutator: func(d *tmproto.Data) { - blobTx, _ := blob.UnmarshalBlobTx(blobTxs[0]) - blobTx.Blobs[0].NamespaceVersion = appns.NamespaceVersionMax + blobTx, _ := shares.UnmarshalBlobTx(blobTxs[0]) + blobTx.Blobs[0].NamespaceVersion = shares.NamespaceVersionMax blobTxBytes, _ := blobTx.Marshal() d.Txs[0] = blobTxBytes d.Hash = calculateNewDataHash(t, d.Txs) @@ -207,7 +205,7 @@ func TestProcessProposal(t *testing.T) { mutator: func(d *tmproto.Data) { index := 4 tx, b := blobfactory.IndexWrappedTxWithInvalidNamespace(t, tmrand.NewRand(), signer, uint32(index)) - blobTx, err := blob.MarshalBlobTx(tx, &b) + blobTx, err := shares.MarshalBlobTx(tx, &b) require.NoError(t, err) // Replace the data with new contents diff --git a/app/validate_txs.go b/app/validate_txs.go index 594f85de97..558d66d118 100644 --- a/app/validate_txs.go +++ b/app/validate_txs.go @@ -1,7 +1,7 @@ package app import ( - "github.com/celestiaorg/celestia-app/pkg/blob" + "github.com/celestiaorg/celestia-app/shares" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" @@ -11,11 +11,11 @@ import ( ) // separateTxs decodes raw tendermint txs into normal and blob txs. -func separateTxs(_ client.TxConfig, rawTxs [][]byte) ([][]byte, []blob.BlobTx) { +func separateTxs(_ client.TxConfig, rawTxs [][]byte) ([][]byte, []shares.BlobTx) { normalTxs := make([][]byte, 0, len(rawTxs)) - blobTxs := make([]blob.BlobTx, 0, len(rawTxs)) + blobTxs := make([]shares.BlobTx, 0, len(rawTxs)) for _, rawTx := range rawTxs { - bTx, isBlob := blob.UnmarshalBlobTx(rawTx) + bTx, isBlob := shares.UnmarshalBlobTx(rawTx) if isBlob { blobTxs = append(blobTxs, bTx) } else { @@ -69,7 +69,7 @@ func filterStdTxs(logger log.Logger, dec sdk.TxDecoder, ctx sdk.Context, handler // filterBlobTxs applies the provided antehandler to each transaction // and removes transactions that return an error. Panics are caught by the checkTxValidity // function used to apply the ante handler. -func filterBlobTxs(logger log.Logger, dec sdk.TxDecoder, ctx sdk.Context, handler sdk.AnteHandler, txs []blob.BlobTx) ([]blob.BlobTx, sdk.Context) { +func filterBlobTxs(logger log.Logger, dec sdk.TxDecoder, ctx sdk.Context, handler sdk.AnteHandler, txs []shares.BlobTx) ([]shares.BlobTx, sdk.Context) { n := 0 for _, tx := range txs { sdkTx, err := dec(tx.Tx) @@ -105,11 +105,11 @@ func msgTypes(sdkTx sdk.Tx) []string { return msgNames } -func encodeBlobTxs(blobTxs []blob.BlobTx) [][]byte { +func encodeBlobTxs(blobTxs []shares.BlobTx) [][]byte { txs := make([][]byte, len(blobTxs)) var err error for i, tx := range blobTxs { - txs[i], err = blob.MarshalBlobTx(tx.Tx, tx.Blobs...) + txs[i], err = shares.MarshalBlobTx(tx.Tx, tx.Blobs...) if err != nil { panic(err) } diff --git a/pkg/appconsts/global_consts.go b/pkg/appconsts/global_consts.go index 19c83eb2cf..7c07cc9ff1 100644 --- a/pkg/appconsts/global_consts.go +++ b/pkg/appconsts/global_consts.go @@ -3,7 +3,7 @@ package appconsts import ( "math" - ns "github.com/celestiaorg/celestia-app/pkg/namespace" + "github.com/celestiaorg/celestia-app/shares" "github.com/celestiaorg/rsmt2d" "github.com/tendermint/tendermint/pkg/consts" ) @@ -14,16 +14,16 @@ import ( // They can not change throughout the lifetime of a network. const ( // NamespaceVersionSize is the size of a namespace version in bytes. - NamespaceVersionSize = ns.NamespaceVersionSize + NamespaceVersionSize = shares.NamespaceVersionSize // NamespaceVersionMaxValue is the maximum value a namespace version can be. // This const must be updated if NamespaceVersionSize is changed. NamespaceVersionMaxValue = math.MaxUint8 // NamespaceIDSize is the size of a namespace ID in bytes. - NamespaceIDSize = ns.NamespaceIDSize + NamespaceIDSize = shares.NamespaceIDSize // NamespaceSize is the size of a namespace (version + ID) in bytes. - NamespaceSize = ns.NamespaceSize + NamespaceSize = shares.NamespaceSize // ShareSize is the size of a share in bytes. ShareSize = 512 diff --git a/pkg/da/data_availability_header.go b/pkg/da/data_availability_header.go index bff5b3cf27..37c78bce3e 100644 --- a/pkg/da/data_availability_header.go +++ b/pkg/da/data_availability_header.go @@ -10,10 +10,10 @@ import ( "github.com/tendermint/tendermint/types" "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/shares" "github.com/celestiaorg/celestia-app/pkg/square" "github.com/celestiaorg/celestia-app/pkg/wrapper" daproto "github.com/celestiaorg/celestia-app/proto/celestia/core/v1/da" + "github.com/celestiaorg/celestia-app/shares" ) var ( diff --git a/pkg/da/data_availability_header_test.go b/pkg/da/data_availability_header_test.go index 855a04e809..4bb5ed69a6 100644 --- a/pkg/da/data_availability_header_test.go +++ b/pkg/da/data_availability_header_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/celestiaorg/celestia-app/pkg/appconsts" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" + appns "github.com/celestiaorg/celestia-app/shares" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -245,7 +245,7 @@ func TestSquareSize(t *testing.T) { // generateShares generates count number of shares with a constant namespace and // share contents. func generateShares(count int) (shares [][]byte) { - ns1 := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) + ns1 := appns.MustNewV0Namespace(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) for i := 0; i < count; i++ { share := generateShare(ns1.Bytes()) diff --git a/pkg/inclusion/nmt_caching_test.go b/pkg/inclusion/nmt_caching_test.go index 5ba253de68..39eb290dfc 100644 --- a/pkg/inclusion/nmt_caching_test.go +++ b/pkg/inclusion/nmt_caching_test.go @@ -7,8 +7,8 @@ import ( "github.com/celestiaorg/celestia-app/pkg/appconsts" "github.com/celestiaorg/celestia-app/pkg/da" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" "github.com/celestiaorg/celestia-app/pkg/wrapper" + "github.com/celestiaorg/celestia-app/shares" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" "github.com/stretchr/testify/assert" @@ -21,7 +21,7 @@ func TestWalkCachedSubTreeRoot(t *testing.T) { strc := newSubTreeRootCacher() squareSize := uint64(8) tr := wrapper.NewErasuredNamespacedMerkleTree(squareSize, 0, nmt.NodeVisitor(strc.Visit)) - ns1 := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) + ns1 := shares.MustNewV0Namespace(bytes.Repeat([]byte{1}, shares.NamespaceVersionZeroIDSize)) data := append(ns1.Bytes(), []byte("data")...) for i := 0; i < 8; i++ { @@ -191,7 +191,7 @@ func chunkSlice(slice [][]byte, chunkSize int) [][][]byte { func generateRandNamespacedRawData(count int) (result [][]byte) { for i := 0; i < count; i++ { rawData := tmrand.Bytes(appconsts.ShareSize) - namespace := appns.RandomBlobNamespace().Bytes() + namespace := shares.RandomBlobNamespace().Bytes() copy(rawData, namespace) result = append(result, rawData) } diff --git a/pkg/inclusion/paths.go b/pkg/inclusion/paths.go index 0e787d63a8..2bd5b4fd9b 100644 --- a/pkg/inclusion/paths.go +++ b/pkg/inclusion/paths.go @@ -3,7 +3,7 @@ package inclusion import ( "math" - "github.com/celestiaorg/celestia-app/pkg/shares" + "github.com/celestiaorg/celestia-app/shares" ) type path struct { diff --git a/pkg/namespace/README.md b/pkg/namespace/README.md deleted file mode 100644 index cd94bbcac4..0000000000 --- a/pkg/namespace/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Namespace - -See the specs for [namespace](../../specs/src/specs/namespace.md). diff --git a/pkg/proof/proof.go b/pkg/proof/proof.go index 97ed33de52..40ffc4bdff 100644 --- a/pkg/proof/proof.go +++ b/pkg/proof/proof.go @@ -6,12 +6,10 @@ import ( "fmt" "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/blob" "github.com/celestiaorg/celestia-app/pkg/da" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" - "github.com/celestiaorg/celestia-app/pkg/shares" "github.com/celestiaorg/celestia-app/pkg/square" "github.com/celestiaorg/celestia-app/pkg/wrapper" + "github.com/celestiaorg/celestia-app/shares" "github.com/tendermint/tendermint/crypto/merkle" tmbytes "github.com/tendermint/tendermint/libs/bytes" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" @@ -44,12 +42,12 @@ func NewTxInclusionProof(txs [][]byte, txIndex, appVersion uint64) (types.ShareP return NewShareInclusionProof(dataSquare, namespace, shareRange) } -func getTxNamespace(tx []byte) (ns appns.Namespace) { - _, isBlobTx := blob.UnmarshalBlobTx(tx) +func getTxNamespace(tx []byte) (ns shares.Namespace) { + _, isBlobTx := shares.UnmarshalBlobTx(tx) if isBlobTx { - return appns.PayForBlobNamespace + return shares.PayForBlobNamespace } - return appns.TxNamespace + return shares.TxNamespace } // NewShareInclusionProof returns an NMT inclusion proof for a set of shares @@ -57,7 +55,7 @@ func getTxNamespace(tx []byte) (ns appns.Namespace) { // Expects the share range to be pre-validated. func NewShareInclusionProof( dataSquare square.Square, - namespace appns.Namespace, + namespace shares.Namespace, shareRange shares.Range, ) (types.ShareProof, error) { squareSize := dataSquare.Size() diff --git a/pkg/proof/proof_test.go b/pkg/proof/proof_test.go index c29fe0ccd4..49dfe920fc 100644 --- a/pkg/proof/proof_test.go +++ b/pkg/proof/proof_test.go @@ -15,8 +15,7 @@ import ( "github.com/celestiaorg/celestia-app/pkg/square" "github.com/celestiaorg/celestia-app/pkg/appconsts" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" - "github.com/celestiaorg/celestia-app/pkg/shares" + "github.com/celestiaorg/celestia-app/shares" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -93,13 +92,13 @@ func TestNewTxInclusionProof(t *testing.T) { } func TestNewShareInclusionProof(t *testing.T) { - ns1 := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) - ns2 := appns.MustNewV0(bytes.Repeat([]byte{2}, appns.NamespaceVersionZeroIDSize)) - ns3 := appns.MustNewV0(bytes.Repeat([]byte{3}, appns.NamespaceVersionZeroIDSize)) + ns1 := shares.MustNewV0Namespace(bytes.Repeat([]byte{1}, shares.NamespaceVersionZeroIDSize)) + ns2 := shares.MustNewV0Namespace(bytes.Repeat([]byte{2}, shares.NamespaceVersionZeroIDSize)) + ns3 := shares.MustNewV0Namespace(bytes.Repeat([]byte{3}, shares.NamespaceVersionZeroIDSize)) signer, err := testnode.NewOfflineSigner() require.NoError(t, err) - blobTxs := blobfactory.RandBlobTxsWithNamespacesAndSigner(signer, []appns.Namespace{ns1, ns2, ns3}, []int{500, 500, 500}) + blobTxs := blobfactory.RandBlobTxsWithNamespacesAndSigner(signer, []shares.Namespace{ns1, ns2, ns3}, []int{500, 500, 500}) txs := testfactory.GenerateRandomTxs(50, 500) txs = append(txs, blobTxs...) @@ -122,7 +121,7 @@ func TestNewShareInclusionProof(t *testing.T) { name string startingShare int endingShare int - namespaceID appns.Namespace + namespaceID shares.Namespace expectErr bool } tests := []test{ @@ -130,63 +129,63 @@ func TestNewShareInclusionProof(t *testing.T) { name: "negative starting share", startingShare: -1, endingShare: 99, - namespaceID: appns.TxNamespace, + namespaceID: shares.TxNamespace, expectErr: true, }, { name: "negative ending share", startingShare: 0, endingShare: -99, - namespaceID: appns.TxNamespace, + namespaceID: shares.TxNamespace, expectErr: true, }, { name: "ending share lower than starting share", startingShare: 1, endingShare: 0, - namespaceID: appns.TxNamespace, + namespaceID: shares.TxNamespace, expectErr: true, }, { name: "ending share higher than number of shares available in square size of 32", startingShare: 0, endingShare: 4097, - namespaceID: appns.TxNamespace, + namespaceID: shares.TxNamespace, expectErr: true, }, { name: "1 transaction share", startingShare: 0, endingShare: 1, - namespaceID: appns.TxNamespace, + namespaceID: shares.TxNamespace, expectErr: false, }, { name: "10 transaction shares", startingShare: 0, endingShare: 10, - namespaceID: appns.TxNamespace, + namespaceID: shares.TxNamespace, expectErr: false, }, { name: "53 transaction shares", startingShare: 0, endingShare: 53, - namespaceID: appns.TxNamespace, + namespaceID: shares.TxNamespace, expectErr: false, }, { name: "shares from different namespaces", startingShare: 48, endingShare: 55, - namespaceID: appns.TxNamespace, + namespaceID: shares.TxNamespace, expectErr: true, }, { name: "shares from PFB namespace", startingShare: 53, endingShare: 56, - namespaceID: appns.PayForBlobNamespace, + namespaceID: shares.PayForBlobNamespace, expectErr: false, }, { @@ -247,10 +246,10 @@ func TestAllSharesInclusionProof(t *testing.T) { actualNamespace, err := proof.ParseNamespace(dataSquare, 0, 256) require.NoError(t, err) - require.Equal(t, appns.TxNamespace, actualNamespace) + require.Equal(t, shares.TxNamespace, actualNamespace) proof, err := proof.NewShareInclusionProof( dataSquare, - appns.TxNamespace, + shares.TxNamespace, shares.NewRange(0, 256), ) require.NoError(t, err) diff --git a/pkg/proof/querier.go b/pkg/proof/querier.go index 9350a6139e..d2e6a0cf76 100644 --- a/pkg/proof/querier.go +++ b/pkg/proof/querier.go @@ -6,10 +6,9 @@ import ( "strconv" "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/shares" "github.com/celestiaorg/celestia-app/pkg/square" + "github.com/celestiaorg/celestia-app/shares" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" sdk "github.com/cosmos/cosmos-sdk/types" abci "github.com/tendermint/tendermint/abci/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" @@ -120,35 +119,35 @@ func QueryShareInclusionProof(_ sdk.Context, path []string, req abci.RequestQuer // ParseNamespace validates the share range, checks if it only contains one namespace and returns // that namespace ID. -func ParseNamespace(rawShares []shares.Share, startShare, endShare int) (appns.Namespace, error) { +func ParseNamespace(rawShares []shares.Share, startShare, endShare int) (shares.Namespace, error) { if startShare < 0 { - return appns.Namespace{}, fmt.Errorf("start share %d should be positive", startShare) + return shares.Namespace{}, fmt.Errorf("start share %d should be positive", startShare) } if endShare < 0 { - return appns.Namespace{}, fmt.Errorf("end share %d should be positive", endShare) + return shares.Namespace{}, fmt.Errorf("end share %d should be positive", endShare) } if endShare < startShare { - return appns.Namespace{}, fmt.Errorf("end share %d cannot be lower than starting share %d", endShare, startShare) + return shares.Namespace{}, fmt.Errorf("end share %d cannot be lower than starting share %d", endShare, startShare) } if endShare > len(rawShares) { - return appns.Namespace{}, fmt.Errorf("end share %d is higher than block shares %d", endShare, len(rawShares)) + return shares.Namespace{}, fmt.Errorf("end share %d is higher than block shares %d", endShare, len(rawShares)) } startShareNs, err := rawShares[startShare].Namespace() if err != nil { - return appns.Namespace{}, err + return shares.Namespace{}, err } for i, share := range rawShares[startShare:endShare] { ns, err := share.Namespace() if err != nil { - return appns.Namespace{}, err + return shares.Namespace{}, err } if !bytes.Equal(startShareNs.Bytes(), ns.Bytes()) { - return appns.Namespace{}, fmt.Errorf("shares range contain different namespaces at index %d: %v and %v ", i, startShareNs, ns) + return shares.Namespace{}, fmt.Errorf("shares range contain different namespaces at index %d: %v and %v ", i, startShareNs, ns) } } return startShareNs, nil diff --git a/pkg/shares/namespace.go b/pkg/shares/namespace.go deleted file mode 100644 index d5026c575c..0000000000 --- a/pkg/shares/namespace.go +++ /dev/null @@ -1,49 +0,0 @@ -package shares - -import ( - "fmt" - - "github.com/celestiaorg/celestia-app/pkg/namespace" -) - -// GetShareRangeForNamespace returns all shares that belong to a given -// namespace. It will return an empty range if the namespace could not be -// found. This assumes that the slice of shares are lexicographically -// sorted by namespace. Ranges here are always end exlusive. -func GetShareRangeForNamespace(shares []Share, ns namespace.Namespace) (Range, error) { - if len(shares) == 0 { - return EmptyRange(), nil - } - n0, err := shares[0].Namespace() - if err != nil { - return EmptyRange(), err - } - if ns.IsLessThan(n0) { - return EmptyRange(), nil - } - n1, err := shares[len(shares)-1].Namespace() - if err != nil { - return EmptyRange(), err - } - if ns.IsGreaterThan(n1) { - return EmptyRange(), nil - } - - start := -1 - for i, share := range shares { - shareNS, err := share.Namespace() - if err != nil { - return EmptyRange(), fmt.Errorf("failed to get namespace from share %d: %w", i, err) - } - if shareNS.IsGreaterThan(ns) && start != -1 { - return Range{start, i}, nil - } - if ns.Equals(shareNS) && start == -1 { - start = i - } - } - if start == -1 { - return EmptyRange(), nil - } - return Range{start, len(shares)}, nil -} diff --git a/pkg/square/builder.go b/pkg/square/builder.go index 02c912bb1b..bf10aef97e 100644 --- a/pkg/square/builder.go +++ b/pkg/square/builder.go @@ -7,9 +7,7 @@ import ( "sort" "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/blob" - "github.com/celestiaorg/celestia-app/pkg/namespace" - "github.com/celestiaorg/celestia-app/pkg/shares" + "github.com/celestiaorg/celestia-app/shares" "github.com/tendermint/tendermint/pkg/consts" coretypes "github.com/tendermint/tendermint/proto/tendermint/types" ) @@ -53,7 +51,7 @@ func NewBuilder(maxSquareSize int, appVersion uint64, txs ...[]byte) (*Builder, } seenFirstBlobTx := false for idx, tx := range txs { - blobTx, isBlobTx := blob.UnmarshalBlobTx(tx) + blobTx, isBlobTx := shares.UnmarshalBlobTx(tx) if isBlobTx { seenFirstBlobTx = true if !builder.AppendBlobTx(blobTx) { @@ -87,7 +85,7 @@ func (b *Builder) AppendTx(tx []byte) bool { // AppendBlobTx attempts to allocate the blob transaction to the square. It returns false if there is not // enough space in the square to fit the transaction. -func (b *Builder) AppendBlobTx(blobTx blob.BlobTx) bool { +func (b *Builder) AppendBlobTx(blobTx shares.BlobTx) bool { iw := &coretypes.IndexWrapper{ Tx: blobTx.Tx, TypeId: consts.ProtoIndexWrapperTypeID, @@ -135,7 +133,7 @@ func (b *Builder) Export() (Square, error) { }) // write all the regular transactions into compact shares - txWriter := shares.NewCompactShareSplitter(namespace.TxNamespace, appconsts.ShareVersionZero) + txWriter := shares.NewCompactShareSplitter(shares.TxNamespace, appconsts.ShareVersionZero) for _, tx := range b.Txs { if err := txWriter.WriteTx(tx); err != nil { return nil, fmt.Errorf("writing tx into compact shares: %w", err) @@ -181,7 +179,7 @@ func (b *Builder) Export() (Square, error) { // write all the pay for blob transactions into compact shares. We need to do this after allocating the blobs to their // appropriate shares as the starting index of each blob needs to be included in the PFB transaction - pfbWriter := shares.NewCompactShareSplitter(namespace.PayForBlobNamespace, appconsts.ShareVersionZero) + pfbWriter := shares.NewCompactShareSplitter(shares.PayForBlobNamespace, shares.ShareVersionZero) for _, iw := range b.Pfbs { iwBytes, err := iw.Marshal() if err != nil { @@ -363,14 +361,14 @@ func (b *Builder) IsEmpty() bool { } type Element struct { - Blob *blob.Blob + Blob *shares.Blob PfbIndex int BlobIndex int NumShares int MaxPadding int } -func newElement(blob *blob.Blob, pfbIndex, blobIndex, subtreeRootThreshold int) *Element { +func newElement(blob *shares.Blob, pfbIndex, blobIndex, subtreeRootThreshold int) *Element { numShares := shares.SparseSharesNeeded(uint32(len(blob.Data))) return &Element{ Blob: blob, diff --git a/pkg/square/builder_test.go b/pkg/square/builder_test.go index b83faefa77..637e647f6d 100644 --- a/pkg/square/builder_test.go +++ b/pkg/square/builder_test.go @@ -10,11 +10,9 @@ import ( "github.com/celestiaorg/celestia-app/app" "github.com/celestiaorg/celestia-app/app/encoding" "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/blob" - ns "github.com/celestiaorg/celestia-app/pkg/namespace" - "github.com/celestiaorg/celestia-app/pkg/shares" "github.com/celestiaorg/celestia-app/pkg/square" "github.com/celestiaorg/celestia-app/pkg/user" + "github.com/celestiaorg/celestia-app/shares" "github.com/celestiaorg/celestia-app/test/util/blobfactory" "github.com/celestiaorg/celestia-app/test/util/testfactory" "github.com/celestiaorg/celestia-app/test/util/testnode" @@ -154,7 +152,7 @@ func TestBuilderRejectsTransactions(t *testing.T) { } func TestBuilderRejectsBlobTransactions(t *testing.T) { - ns1 := ns.MustNewV0(bytes.Repeat([]byte{1}, ns.NamespaceVersionZeroIDSize)) + ns1 := shares.MustNewV0Namespace(bytes.Repeat([]byte{1}, shares.NamespaceVersionZeroIDSize)) testCases := []struct { blobSize []int added bool @@ -192,7 +190,7 @@ func TestBuilderRejectsBlobTransactions(t *testing.T) { require.NoError(t, err) txs := generateBlobTxsWithNamespaces(t, ns1.Repeat(len(tc.blobSize)), [][]int{tc.blobSize}) require.Len(t, txs, 1) - blobTx, isBlobTx := blob.UnmarshalBlobTx(txs[0]) + blobTx, isBlobTx := shares.UnmarshalBlobTx(txs[0]) require.True(t, isBlobTx) require.Equal(t, tc.added, builder.AppendBlobTx(blobTx)) }) @@ -228,7 +226,7 @@ func TestBuilderFindTxShareRange(t *testing.T) { var lastEnd int for idx, tx := range blockTxs { - blobTx, isBlobTx := blob.UnmarshalBlobTx(tx) + blobTx, isBlobTx := shares.UnmarshalBlobTx(tx) if isBlobTx { tx = blobTx.Tx } @@ -265,9 +263,9 @@ func rawData(shares []shares.Share) ([]byte, error) { // TestSquareBlobPositions ensures that the share commitment rules which dictate the padding // between blobs is followed as well as the ordering of blobs by namespace. func TestSquareBlobPostions(t *testing.T) { - ns1 := ns.MustNewV0(bytes.Repeat([]byte{1}, ns.NamespaceVersionZeroIDSize)) - ns2 := ns.MustNewV0(bytes.Repeat([]byte{2}, ns.NamespaceVersionZeroIDSize)) - ns3 := ns.MustNewV0(bytes.Repeat([]byte{3}, ns.NamespaceVersionZeroIDSize)) + ns1 := shares.MustNewV0Namespace(bytes.Repeat([]byte{1}, shares.NamespaceVersionZeroIDSize)) + ns2 := shares.MustNewV0Namespace(bytes.Repeat([]byte{2}, shares.NamespaceVersionZeroIDSize)) + ns3 := shares.MustNewV0Namespace(bytes.Repeat([]byte{3}, shares.NamespaceVersionZeroIDSize)) type test struct { squareSize int @@ -279,7 +277,7 @@ func TestSquareBlobPostions(t *testing.T) { squareSize: 4, blobTxs: generateBlobTxsWithNamespaces( t, - []ns.Namespace{ns1}, + []shares.Namespace{ns1}, [][]int{{1}}, ), expectedIndexes: [][]uint32{{1}}, @@ -288,7 +286,7 @@ func TestSquareBlobPostions(t *testing.T) { squareSize: 4, blobTxs: generateBlobTxsWithNamespaces( t, - []ns.Namespace{ns1, ns1}, + []shares.Namespace{ns1, ns1}, blobfactory.Repeat([]int{100}, 2), ), expectedIndexes: [][]uint32{{2}, {3}}, @@ -297,7 +295,7 @@ func TestSquareBlobPostions(t *testing.T) { squareSize: 4, blobTxs: generateBlobTxsWithNamespaces( t, - []ns.Namespace{ns1, ns1, ns1, ns1, ns1, ns1, ns1, ns1, ns1}, + []shares.Namespace{ns1, ns1, ns1, ns1, ns1, ns1, ns1, ns1, ns1}, blobfactory.Repeat([]int{100}, 9), ), expectedIndexes: [][]uint32{{7}, {8}, {9}, {10}, {11}, {12}, {13}, {14}, {15}}, @@ -306,7 +304,7 @@ func TestSquareBlobPostions(t *testing.T) { squareSize: 4, blobTxs: generateBlobTxsWithNamespaces( t, - []ns.Namespace{ns1, ns1, ns1}, + []shares.Namespace{ns1, ns1, ns1}, [][]int{{10000}, {10000}, {1000000}}, ), expectedIndexes: [][]uint32{}, @@ -315,7 +313,7 @@ func TestSquareBlobPostions(t *testing.T) { squareSize: 64, blobTxs: generateBlobTxsWithNamespaces( t, - []ns.Namespace{ns1, ns1, ns1}, + []shares.Namespace{ns1, ns1, ns1}, [][]int{{1000}, {10000}, {10000}}, ), expectedIndexes: [][]uint32{{3}, {6}, {27}}, @@ -324,7 +322,7 @@ func TestSquareBlobPostions(t *testing.T) { squareSize: 32, blobTxs: generateBlobTxsWithNamespaces( t, - []ns.Namespace{ns2, ns1, ns1}, + []shares.Namespace{ns2, ns1, ns1}, [][]int{{100}, {100}, {100}}, ), expectedIndexes: [][]uint32{{5}, {3}, {4}}, @@ -333,7 +331,7 @@ func TestSquareBlobPostions(t *testing.T) { squareSize: 16, blobTxs: generateBlobTxsWithNamespaces( t, - []ns.Namespace{ns1, ns2, ns1}, + []shares.Namespace{ns1, ns2, ns1}, [][]int{{100}, {900}, {900}}, // 1, 2, 2 shares respectively ), expectedIndexes: [][]uint32{{3}, {6}, {4}}, @@ -342,7 +340,7 @@ func TestSquareBlobPostions(t *testing.T) { squareSize: 4, blobTxs: generateBlobTxsWithNamespaces( t, - []ns.Namespace{ns1, ns3, ns3, ns2}, + []shares.Namespace{ns1, ns3, ns3, ns2}, [][]int{{100}, {1000, 1000}, {420}}, ), expectedIndexes: [][]uint32{{3}, {5, 8}, {4}}, @@ -352,7 +350,7 @@ func TestSquareBlobPostions(t *testing.T) { squareSize: 1, blobTxs: generateBlobTxsWithNamespaces( t, - []ns.Namespace{ns1, ns2, ns3}, + []shares.Namespace{ns1, ns2, ns3}, [][]int{{1000}, {1000}, {1000}}, ), expectedIndexes: [][]uint32{}, @@ -362,7 +360,7 @@ func TestSquareBlobPostions(t *testing.T) { squareSize: 4, blobTxs: generateBlobTxsWithNamespaces( t, - []ns.Namespace{ns3, ns2, ns1}, + []shares.Namespace{ns3, ns2, ns1}, [][]int{{2000}, {2000}, {5000}}, ), expectedIndexes: [][]uint32{{7}, {2}}, @@ -371,7 +369,7 @@ func TestSquareBlobPostions(t *testing.T) { squareSize: 4, blobTxs: generateBlobTxsWithNamespaces( t, - []ns.Namespace{ns3, ns3, ns2, ns1}, + []shares.Namespace{ns3, ns3, ns2, ns1}, [][]int{{1800, 1000}, {22000}, {1800}}, ), // should be ns1 and {ns3, ns3} as ns2 is too large @@ -381,7 +379,7 @@ func TestSquareBlobPostions(t *testing.T) { squareSize: 4, blobTxs: generateBlobTxsWithNamespaces( t, - []ns.Namespace{ns1, ns3, ns3, ns1, ns2, ns2}, + []shares.Namespace{ns1, ns3, ns3, ns1, ns2, ns2}, [][]int{{100}, {1400, 900, 200, 200}, {420}}, ), expectedIndexes: [][]uint32{{3}, {7, 10, 4, 5}, {6}}, @@ -390,7 +388,7 @@ func TestSquareBlobPostions(t *testing.T) { squareSize: 4, blobTxs: generateBlobTxsWithNamespaces( t, - []ns.Namespace{ns1, ns3, ns3, ns1, ns2, ns2}, + []shares.Namespace{ns1, ns3, ns3, ns1, ns2, ns2}, [][]int{{100}, {900, 1400, 200, 200}, {420}}, ), expectedIndexes: [][]uint32{{3}, {7, 9, 4, 5}, {6}}, @@ -399,7 +397,7 @@ func TestSquareBlobPostions(t *testing.T) { squareSize: 16, blobTxs: generateBlobTxsWithNamespaces( t, - []ns.Namespace{ns1, ns1}, + []shares.Namespace{ns1, ns1}, [][]int{{100}, {shares.AvailableBytesFromSparseShares(appconsts.DefaultSubtreeRootThreshold)}}, ), // There should be one share padding between the two blobs @@ -409,7 +407,7 @@ func TestSquareBlobPostions(t *testing.T) { squareSize: 16, blobTxs: generateBlobTxsWithNamespaces( t, - []ns.Namespace{ns1, ns1}, + []shares.Namespace{ns1, ns1}, [][]int{{100}, {shares.AvailableBytesFromSparseShares(appconsts.DefaultSubtreeRootThreshold) + 1}}, ), // There should be one share padding between the two blobs @@ -421,7 +419,7 @@ func TestSquareBlobPostions(t *testing.T) { builder, err := square.NewBuilder(tt.squareSize, appconsts.LatestVersion) require.NoError(t, err) for _, tx := range tt.blobTxs { - blobTx, isBlobTx := blob.UnmarshalBlobTx(tx) + blobTx, isBlobTx := shares.UnmarshalBlobTx(tx) require.True(t, isBlobTx) _ = builder.AppendBlobTx(blobTx) } diff --git a/pkg/square/square.go b/pkg/square/square.go index ccdba287dd..275095e8aa 100644 --- a/pkg/square/square.go +++ b/pkg/square/square.go @@ -6,9 +6,7 @@ import ( "math" "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/blob" - "github.com/celestiaorg/celestia-app/pkg/namespace" - "github.com/celestiaorg/celestia-app/pkg/shares" + "github.com/celestiaorg/celestia-app/shares" blobtypes "github.com/celestiaorg/celestia-app/x/blob/types" "github.com/cosmos/cosmos-sdk/types" core "github.com/tendermint/tendermint/types" @@ -27,7 +25,7 @@ func Build(txs [][]byte, appVersion uint64, maxSquareSize int) (Square, [][]byte normalTxs := make([][]byte, 0, len(txs)) blobTxs := make([][]byte, 0, len(txs)) for _, tx := range txs { - blobTx, isBlobTx := blob.UnmarshalBlobTx(tx) + blobTx, isBlobTx := shares.UnmarshalBlobTx(tx) if isBlobTx { if builder.AppendBlobTx(blobTx) { blobTxs = append(blobTxs, tx) @@ -69,7 +67,7 @@ func Deconstruct(s Square, decoder types.TxDecoder) (core.Txs, error) { // Work out which range of shares are non-pfb transactions // and which ones are pfb transactions - txShareRange, err := shares.GetShareRangeForNamespace(s, namespace.TxNamespace) + txShareRange, err := shares.GetShareRangeForNamespace(s, shares.TxNamespace) if err != nil { return nil, err } @@ -77,7 +75,7 @@ func Deconstruct(s Square, decoder types.TxDecoder) (core.Txs, error) { return nil, fmt.Errorf("expected txs to start at index 0, but got %d", txShareRange.Start) } - wpfbShareRange, err := shares.GetShareRangeForNamespace(s[txShareRange.End:], namespace.PayForBlobNamespace) + wpfbShareRange, err := shares.GetShareRangeForNamespace(s[txShareRange.End:], shares.PayForBlobNamespace) if err != nil { return nil, err } @@ -130,7 +128,7 @@ func Deconstruct(s Square, decoder types.TxDecoder) (core.Txs, error) { return nil, fmt.Errorf("expected PFB to have %d blob sizes, but got %d", len(wpfb.ShareIndexes), len(pfb.BlobSizes)) } - blobs := make([]*blob.Blob, len(wpfb.ShareIndexes)) + blobs := make([]*shares.Blob, len(wpfb.ShareIndexes)) for j, shareIndex := range wpfb.ShareIndexes { end := int(shareIndex) + shares.SparseSharesNeeded(pfb.BlobSizes[j]) parsedBlobs, err := shares.ParseBlobs(s[shareIndex:end]) @@ -144,7 +142,7 @@ func Deconstruct(s Square, decoder types.TxDecoder) (core.Txs, error) { blobs[j] = parsedBlobs[0] } - tx, err := blob.MarshalBlobTx(wpfb.Tx, blobs...) + tx, err := shares.MarshalBlobTx(wpfb.Tx, blobs...) if err != nil { return nil, err } @@ -214,7 +212,7 @@ func (s Square) Equals(other Square) bool { // WrappedPFBs returns the wrapped PFBs in a square func (s Square) WrappedPFBs() (core.Txs, error) { - wpfbShareRange, err := shares.GetShareRangeForNamespace(s, namespace.PayForBlobNamespace) + wpfbShareRange, err := shares.GetShareRangeForNamespace(s, shares.PayForBlobNamespace) if err != nil { return core.Txs{}, nil } diff --git a/pkg/square/square_fuzz_test.go b/pkg/square/square_fuzz_test.go index 4ff7fc4dae..4b6adbf3fa 100644 --- a/pkg/square/square_fuzz_test.go +++ b/pkg/square/square_fuzz_test.go @@ -8,8 +8,8 @@ import ( "github.com/celestiaorg/celestia-app/pkg/appconsts" "github.com/celestiaorg/celestia-app/pkg/da" "github.com/celestiaorg/celestia-app/pkg/inclusion" - "github.com/celestiaorg/celestia-app/pkg/shares" "github.com/celestiaorg/celestia-app/pkg/square" + "github.com/celestiaorg/celestia-app/shares" "github.com/celestiaorg/celestia-app/test/util/testnode" blob "github.com/celestiaorg/celestia-app/x/blob/types" "github.com/celestiaorg/rsmt2d" diff --git a/pkg/square/square_test.go b/pkg/square/square_test.go index 798955dc3f..8308e8e0d8 100644 --- a/pkg/square/square_test.go +++ b/pkg/square/square_test.go @@ -10,12 +10,10 @@ import ( "github.com/celestiaorg/celestia-app/app" "github.com/celestiaorg/celestia-app/app/encoding" "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/blob" "github.com/celestiaorg/celestia-app/pkg/da" "github.com/celestiaorg/celestia-app/pkg/inclusion" - ns "github.com/celestiaorg/celestia-app/pkg/namespace" - "github.com/celestiaorg/celestia-app/pkg/shares" "github.com/celestiaorg/celestia-app/pkg/square" + "github.com/celestiaorg/celestia-app/shares" "github.com/celestiaorg/celestia-app/test/util/blobfactory" "github.com/celestiaorg/celestia-app/test/util/testnode" blobtypes "github.com/celestiaorg/celestia-app/x/blob/types" @@ -119,7 +117,7 @@ func TestSquareTxShareRange(t *testing.T) { // len(blobSizes[i]) number of blobs per BlobTx. Note: not suitable for using in // prepare or process proposal, as the signatures will be invalid since this // does not query for relevant account numbers or sequences. -func generateBlobTxsWithNamespaces(t *testing.T, namespaces []ns.Namespace, blobSizes [][]int) [][]byte { +func generateBlobTxsWithNamespaces(t *testing.T, namespaces []shares.Namespace, blobSizes [][]int) [][]byte { encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) const acc = "signer" kr, _ := testnode.NewKeyring(acc) @@ -148,7 +146,7 @@ func TestSquareBlobShareRange_Flaky(t *testing.T) { require.NoError(t, err) for pfbIdx, tx := range txs { - blobTx, isBlobTx := blob.UnmarshalBlobTx(tx) + blobTx, isBlobTx := shares.UnmarshalBlobTx(tx) require.True(t, isBlobTx) for blobIdx := range blobTx.Blobs { shareRange, err := square.BlobShareRange(txs, pfbIdx, blobIdx, appconsts.LatestVersion) diff --git a/pkg/user/signer.go b/pkg/user/signer.go index a6cbd7a41e..01f7df20de 100644 --- a/pkg/user/signer.go +++ b/pkg/user/signer.go @@ -9,7 +9,7 @@ import ( "time" "github.com/celestiaorg/celestia-app/app/encoding" - "github.com/celestiaorg/celestia-app/pkg/blob" + "github.com/celestiaorg/celestia-app/shares" blobtypes "github.com/celestiaorg/celestia-app/x/blob/types" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" @@ -142,7 +142,7 @@ func (s *Signer) SubmitTx(ctx context.Context, msgs []sdktypes.Msg, opts ...TxOp // SubmitPayForBlob forms a transaction from the provided blobs, signs it, and submits it to the chain. // TxOptions may be provided to set the fee and gas limit. -func (s *Signer) SubmitPayForBlob(ctx context.Context, blobs []*blob.Blob, opts ...TxOption) (*sdktypes.TxResponse, error) { +func (s *Signer) SubmitPayForBlob(ctx context.Context, blobs []*shares.Blob, opts ...TxOption) (*sdktypes.TxResponse, error) { txBytes, err := s.CreatePayForBlob(blobs, opts...) if err != nil { return nil, err @@ -174,7 +174,7 @@ func (s *Signer) CreateTx(msgs []sdktypes.Msg, opts ...TxOption) ([]byte, error) return s.enc.TxEncoder()(txBuilder.GetTx()) } -func (s *Signer) CreatePayForBlob(blobs []*blob.Blob, opts ...TxOption) ([]byte, error) { +func (s *Signer) CreatePayForBlob(blobs []*shares.Blob, opts ...TxOption) ([]byte, error) { msg, err := blobtypes.NewMsgPayForBlobs(s.address.String(), blobs...) if err != nil { return nil, err @@ -185,7 +185,7 @@ func (s *Signer) CreatePayForBlob(blobs []*blob.Blob, opts ...TxOption) ([]byte, return nil, err } - return blob.MarshalBlobTx(txBytes, blobs...) + return shares.MarshalBlobTx(txBytes, blobs...) } // BroadcastTx submits the provided transaction bytes to the chain and returns the response. diff --git a/pkg/wrapper/nmt_wrapper.go b/pkg/wrapper/nmt_wrapper.go index bc63f84730..1f457be800 100644 --- a/pkg/wrapper/nmt_wrapper.go +++ b/pkg/wrapper/nmt_wrapper.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/celestiaorg/celestia-app/pkg/appconsts" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" + appns "github.com/celestiaorg/celestia-app/shares" "github.com/celestiaorg/nmt" "github.com/celestiaorg/nmt/namespace" "github.com/celestiaorg/rsmt2d" diff --git a/pkg/wrapper/nmt_wrapper_test.go b/pkg/wrapper/nmt_wrapper_test.go index 3ff73e796b..5ee9a039ef 100644 --- a/pkg/wrapper/nmt_wrapper_test.go +++ b/pkg/wrapper/nmt_wrapper_test.go @@ -7,8 +7,8 @@ import ( "testing" "github.com/celestiaorg/celestia-app/pkg/appconsts" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" "github.com/celestiaorg/celestia-app/pkg/wrapper" + appns "github.com/celestiaorg/celestia-app/shares" "github.com/celestiaorg/celestia-app/test/util/testfactory" "github.com/celestiaorg/nmt" nmtnamespace "github.com/celestiaorg/nmt/namespace" diff --git a/proto/celestia/core/v1/blob/blob.proto b/proto/celestia/core/v1/blob/blob.proto index 41e0620ab7..08b19a9383 100644 --- a/proto/celestia/core/v1/blob/blob.proto +++ b/proto/celestia/core/v1/blob/blob.proto @@ -1,7 +1,7 @@ syntax = "proto3"; package celestia.core.v1.blob; -option go_package = "github.com/celestiaorg/celestia-app/pkg/blob"; +option go_package = "github.com/celestiaorg/celestia-app/shares"; // Blob (named after binary large object) is a chunk of data submitted by a user // to be published to the Celestia blockchain. The data of a Blob is published diff --git a/pkg/shares/README.md b/shares/README.md similarity index 100% rename from pkg/shares/README.md rename to shares/README.md diff --git a/pkg/blob/blob.go b/shares/blob.go similarity index 80% rename from pkg/blob/blob.go rename to shares/blob.go index 40d3a16bf7..01686d456d 100644 --- a/pkg/blob/blob.go +++ b/shares/blob.go @@ -1,4 +1,4 @@ -package blob +package shares import ( "bytes" @@ -6,8 +6,6 @@ import ( fmt "fmt" math "math" "sort" - - "github.com/celestiaorg/celestia-app/pkg/namespace" ) // ProtoBlobTxTypeID is included in each encoded BlobTx to help prevent @@ -16,7 +14,7 @@ const ProtoBlobTxTypeID = "BLOB" // NewBlob creates a new coretypes.Blob from the provided data after performing // basic stateless checks over it. -func New(ns namespace.Namespace, blob []byte, shareVersion uint8) *Blob { +func NewBlob(ns Namespace, blob []byte, shareVersion uint8) *Blob { return &Blob{ NamespaceId: ns.ID, Data: blob, @@ -26,8 +24,8 @@ func New(ns namespace.Namespace, blob []byte, shareVersion uint8) *Blob { } // Namespace returns the namespace of the blob -func (b Blob) Namespace() namespace.Namespace { - return namespace.Namespace{ +func (b Blob) Namespace() Namespace { + return Namespace{ Version: uint8(b.NamespaceVersion), ID: b.NamespaceId, } @@ -38,13 +36,13 @@ func (b *Blob) Validate() error { if b == nil { return errors.New("nil blob") } - if len(b.NamespaceId) != namespace.NamespaceIDSize { - return fmt.Errorf("namespace id must be %d bytes", namespace.NamespaceIDSize) + if len(b.NamespaceId) != NamespaceIDSize { + return fmt.Errorf("namespace id must be %d bytes", NamespaceIDSize) } if b.ShareVersion > math.MaxUint8 { return errors.New("share version can not be greater than MaxShareVersion") } - if b.NamespaceVersion > namespace.NamespaceVersionMax { + if b.NamespaceVersion > NamespaceVersionMax { return errors.New("namespace version can not be greater than MaxNamespaceVersion") } if len(b.Data) == 0 { @@ -68,7 +66,7 @@ func UnmarshalBlobTx(tx []byte) (bTx BlobTx, isBlob bool) { return bTx, false } for _, b := range bTx.Blobs { - if len(b.NamespaceId) != namespace.NamespaceIDSize { + if len(b.NamespaceId) != NamespaceIDSize { return bTx, false } } @@ -89,7 +87,7 @@ func MarshalBlobTx(tx []byte, blobs ...*Blob) ([]byte, error) { return bTx.Marshal() } -func Sort(blobs []*Blob) { +func SortBlobs(blobs []*Blob) { sort.SliceStable(blobs, func(i, j int) bool { return bytes.Compare(blobs[i].Namespace().Bytes(), blobs[j].Namespace().Bytes()) < 0 }) diff --git a/pkg/blob/blob.pb.go b/shares/blob.pb.go similarity index 99% rename from pkg/blob/blob.pb.go rename to shares/blob.pb.go index 3bd6447adb..1549db775f 100644 --- a/pkg/blob/blob.pb.go +++ b/shares/blob.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. // source: celestia/core/v1/blob/blob.proto -package blob +package shares import ( fmt "fmt" diff --git a/pkg/shares/blob_share_commitment_rules.go b/shares/blob_share_commitment_rules.go similarity index 100% rename from pkg/shares/blob_share_commitment_rules.go rename to shares/blob_share_commitment_rules.go diff --git a/pkg/shares/blob_share_commitment_rules_test.go b/shares/blob_share_commitment_rules_test.go similarity index 86% rename from pkg/shares/blob_share_commitment_rules_test.go rename to shares/blob_share_commitment_rules_test.go index 466aade1cd..bb66292cfd 100644 --- a/pkg/shares/blob_share_commitment_rules_test.go +++ b/shares/blob_share_commitment_rules_test.go @@ -4,7 +4,6 @@ import ( "fmt" "testing" - "github.com/celestiaorg/celestia-app/pkg/appconsts" "github.com/stretchr/testify/assert" ) @@ -26,12 +25,12 @@ func TestBlobSharesUsedNonInteractiveDefaults(t *testing.T) { {0, 10, []int{10}, []uint32{0}}, {1, 20, []int{10, 10}, []uint32{1, 11}}, {0, 1000, []int{1000}, []uint32{0}}, - {0, appconsts.DefaultSquareSizeUpperBound + 1, []int{appconsts.DefaultSquareSizeUpperBound + 1}, []uint32{0}}, + {0, 129, []int{129}, []uint32{0}}, {1, 385, []int{128, 128, 128}, []uint32{2, 130, 258}}, {1024, 32, []int{32}, []uint32{1024}}, } for i, tt := range tests { - res, indexes := BlobSharesUsedNonInteractiveDefaults(tt.cursor, appconsts.DefaultSubtreeRootThreshold, tt.blobLens...) + res, indexes := BlobSharesUsedNonInteractiveDefaults(tt.cursor, 64, tt.blobLens...) test := fmt.Sprintf("test %d: cursor %d", i, tt.cursor) assert.Equal(t, tt.expected, res, test) assert.Equal(t, tt.indexes, indexes, test) @@ -138,7 +137,7 @@ func TestFitsInSquare(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - res, _ := FitsInSquare(tt.start, tt.size, appconsts.DefaultSubtreeRootThreshold, tt.blobs...) + res, _ := FitsInSquare(tt.start, tt.size, 64, tt.blobs...) assert.Equal(t, tt.fits, res) }) } @@ -231,28 +230,28 @@ func TestNextShareIndex(t *testing.T) { { name: "at threshold", cursor: 11, - blobLen: appconsts.DefaultSubtreeRootThreshold, - squareSize: RoundUpPowerOfTwo(appconsts.DefaultSubtreeRootThreshold), + blobLen: 64, + squareSize: RoundUpPowerOfTwo(64), expectedIndex: 11, }, { name: "one over the threshold", cursor: 64, - blobLen: appconsts.DefaultSubtreeRootThreshold + 1, + blobLen: 64 + 1, squareSize: 128, expectedIndex: 64, }, { name: "one under the threshold", cursor: 64, - blobLen: appconsts.DefaultSubtreeRootThreshold - 1, + blobLen: 64 - 1, squareSize: 128, expectedIndex: 64, }, { name: "one under the threshold small square size", cursor: 1, - blobLen: appconsts.DefaultSubtreeRootThreshold - 1, + blobLen: 64 - 1, squareSize: 16, expectedIndex: 1, }, @@ -287,7 +286,7 @@ func TestNextShareIndex(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - res := NextShareIndex(tt.cursor, tt.blobLen, appconsts.DefaultSubtreeRootThreshold) + res := NextShareIndex(tt.cursor, tt.blobLen, 64) assert.Equal(t, tt.expectedIndex, res) }) } @@ -422,45 +421,45 @@ func TestSubTreeWidth(t *testing.T) { want: 1, }, { - shareCount: appconsts.DefaultSubtreeRootThreshold, + shareCount: 64, want: 1, }, { - shareCount: appconsts.DefaultSubtreeRootThreshold + 1, + shareCount: 64 + 1, want: 2, }, { - shareCount: appconsts.DefaultSubtreeRootThreshold - 1, + shareCount: 64 - 1, want: 1, }, { - shareCount: appconsts.DefaultSubtreeRootThreshold * 2, + shareCount: 64 * 2, want: 2, }, { - shareCount: (appconsts.DefaultSubtreeRootThreshold * 2) + 1, + shareCount: (64 * 2) + 1, want: 4, }, { - shareCount: (appconsts.DefaultSubtreeRootThreshold * 3) - 1, + shareCount: (64 * 3) - 1, want: 4, }, { - shareCount: (appconsts.DefaultSubtreeRootThreshold * 4), + shareCount: (64 * 4), want: 4, }, { - shareCount: (appconsts.DefaultSubtreeRootThreshold * 5), + shareCount: (64 * 5), want: 8, }, { - shareCount: (appconsts.DefaultSubtreeRootThreshold * appconsts.DefaultSquareSizeUpperBound) - 1, + shareCount: (64 * 128) - 1, want: 128, }, } for i, tc := range testCases { t.Run(fmt.Sprintf("shareCount %d", tc.shareCount), func(t *testing.T) { - got := SubTreeWidth(tc.shareCount, appconsts.DefaultSubtreeRootThreshold) + got := SubTreeWidth(tc.shareCount, 64) assert.Equal(t, tc.want, got, i) }) } diff --git a/shares/blob_test.go b/shares/blob_test.go new file mode 100644 index 0000000000..5ebf9052f8 --- /dev/null +++ b/shares/blob_test.go @@ -0,0 +1,65 @@ +package shares + +import ( + "bytes" + + tmrand "github.com/tendermint/tendermint/libs/rand" + "github.com/tendermint/tendermint/types" +) + +func GenerateRandomlySizedBlobs(count, maxBlobSize int) []*Blob { + blobs := make([]*Blob, count) + for i := 0; i < count; i++ { + blobs[i] = GenerateRandomBlob(tmrand.Intn(maxBlobSize)) + if len(blobs[i].Data) == 0 { + i-- + } + } + + // this is just to let us use assert.Equal + if count == 0 { + blobs = nil + } + + SortBlobs(blobs) + return blobs +} + +// GenerateBlobsWithNamespace generates blobs with namespace ns. +func GenerateBlobsWithNamespace(count int, blobSize int, ns Namespace) []types.Blob { + blobs := make([]types.Blob, count) + for i := 0; i < count; i++ { + blobs[i] = types.Blob{ + NamespaceVersion: ns.Version, + NamespaceID: ns.ID, + Data: tmrand.Bytes(blobSize), + ShareVersion: ShareVersionZero, + } + } + + // this is just to let us use assert.Equal + if count == 0 { + blobs = nil + } + + return blobs +} + +func GenerateRandomBlob(dataSize int) *Blob { + ns := MustNewV0Namespace(bytes.Repeat([]byte{0x1}, NamespaceVersionZeroIDSize)) + return NewBlob(ns, tmrand.Bytes(dataSize), ShareVersionZero) +} + +// GenerateRandomBlobOfShareCount returns a blob that spans the given +// number of shares +func GenerateRandomBlobOfShareCount(count int) *Blob { + size := rawBlobSize(FirstSparseShareContentSize * count) + return GenerateRandomBlob(size) +} + +// rawBlobSize returns the raw blob size that can be used to construct a +// blob of totalSize bytes. This function is useful in tests to account for +// the delimiter length that is prefixed to a blob's data. +func rawBlobSize(totalSize int) int { + return totalSize - DelimLen(uint64(totalSize)) +} diff --git a/pkg/shares/compact_shares_test.go b/shares/compact_shares_test.go similarity index 67% rename from pkg/shares/compact_shares_test.go rename to shares/compact_shares_test.go index bb27cf1559..91b20979f8 100644 --- a/pkg/shares/compact_shares_test.go +++ b/shares/compact_shares_test.go @@ -6,9 +6,6 @@ import ( "testing" "time" - "github.com/celestiaorg/celestia-app/pkg/appconsts" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" - "github.com/celestiaorg/celestia-app/test/util/testfactory" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" coretypes "github.com/tendermint/tendermint/types" @@ -17,8 +14,8 @@ import ( func TestCompactShareSplitter(t *testing.T) { // note that this test is mainly for debugging purposes, the main round trip // tests occur in TestMerge and Test_processCompactShares - css := NewCompactShareSplitter(appns.TxNamespace, appconsts.ShareVersionZero) - txs := testfactory.GenerateRandomTxs(33, 200) + css := NewCompactShareSplitter(TxNamespace, ShareVersionZero) + txs := GenerateRandomTxs(33, 200) for _, tx := range txs { err := css.WriteTx(tx) require.NoError(t, err) @@ -26,7 +23,7 @@ func TestCompactShareSplitter(t *testing.T) { shares, err := css.Export() require.NoError(t, err) - rawResTxs, err := parseCompactShares(shares, appconsts.SupportedShareVersions) + rawResTxs, err := parseCompactShares(shares, SupportedShareVersions) resTxs := coretypes.ToTxs(rawResTxs) require.NoError(t, err) @@ -53,7 +50,7 @@ func Test_processCompactShares(t *testing.T) { // share, accounting for the tx length delimiter prepended to // each tx. Note that the length delimiter can be 1 to 10 bytes (varint) but // this test assumes it is 1 byte. - const exactTxShareSize = appconsts.FirstCompactShareContentSize - 1 + const exactTxShareSize = FirstCompactShareContentSize - 1 type test struct { name string @@ -64,10 +61,10 @@ func Test_processCompactShares(t *testing.T) { // each test is ran twice, once using txSize as an exact size, and again // using it as a cap for randomly sized txs tests := []test{ - {"single small tx", appconsts.ContinuationCompactShareContentSize / 8, 1}, - {"many small txs", appconsts.ContinuationCompactShareContentSize / 8, 10}, - {"single big tx", appconsts.ContinuationCompactShareContentSize * 4, 1}, - {"many big txs", appconsts.ContinuationCompactShareContentSize * 4, 10}, + {"single small tx", ContinuationCompactShareContentSize / 8, 1}, + {"many small txs", ContinuationCompactShareContentSize / 8, 10}, + {"single big tx", ContinuationCompactShareContentSize * 4, 1}, + {"many big txs", ContinuationCompactShareContentSize * 4, 10}, {"single exact size tx", exactTxShareSize, 1}, {"many exact size txs", exactTxShareSize, 100}, } @@ -77,12 +74,12 @@ func Test_processCompactShares(t *testing.T) { // run the tests with identically sized txs t.Run(fmt.Sprintf("%s idendically sized", tc.name), func(t *testing.T) { - txs := testfactory.GenerateRandomTxs(tc.txCount, tc.txSize) + txs := GenerateRandomTxs(tc.txCount, tc.txSize) shares, _, _, err := SplitTxs(txs) require.NoError(t, err) - parsedTxs, err := parseCompactShares(shares, appconsts.SupportedShareVersions) + parsedTxs, err := parseCompactShares(shares, SupportedShareVersions) if err != nil { t.Error(err) } @@ -95,11 +92,11 @@ func Test_processCompactShares(t *testing.T) { // run the same tests using randomly sized txs with caps of tc.txSize t.Run(fmt.Sprintf("%s randomly sized", tc.name), func(t *testing.T) { - txs := testfactory.GenerateRandomlySizedTxs(tc.txCount, tc.txSize) + txs := GenerateRandomlySizedTxs(tc.txCount, tc.txSize) txShares, _, _, err := SplitTxs(txs) require.NoError(t, err) - parsedTxs, err := parseCompactShares(txShares, appconsts.SupportedShareVersions) + parsedTxs, err := parseCompactShares(txShares, SupportedShareVersions) if err != nil { t.Error(err) } @@ -113,7 +110,7 @@ func Test_processCompactShares(t *testing.T) { } func TestAllSplit(t *testing.T) { - txs := testfactory.GenerateRandomlySizedTxs(1000, 150) + txs := GenerateRandomlySizedTxs(1000, 150) txShares, _, _, err := SplitTxs(txs) require.NoError(t, err) resTxs, err := ParseTxs(txShares) @@ -122,21 +119,21 @@ func TestAllSplit(t *testing.T) { } func TestParseRandomOutOfContextShares(t *testing.T) { - txs := testfactory.GenerateRandomlySizedTxs(1000, 150) + txs := GenerateRandomlySizedTxs(1000, 150) txShares, _, _, err := SplitTxs(txs) require.NoError(t, err) for i := 0; i < 1000; i++ { - start, length := testfactory.GetRandomSubSlice(len(txShares)) + start, length := GetRandomSubSlice(len(txShares)) randomRange := NewRange(start, start+length) resTxs, err := ParseTxs(txShares[randomRange.Start:randomRange.End]) require.NoError(t, err) - assert.True(t, testfactory.CheckSubArray(txs, resTxs)) + assert.True(t, CheckSubArray(txs, resTxs)) } } func TestParseOutOfContextSharesUsingShareRanges(t *testing.T) { - txs := testfactory.GenerateRandomlySizedTxs(1000, 150) + txs := GenerateRandomlySizedTxs(1000, 150) txShares, _, shareRanges, err := SplitTxs(txs) require.NoError(t, err) @@ -155,8 +152,8 @@ func TestParseOutOfContextSharesUsingShareRanges(t *testing.T) { } func TestCompactShareContainsInfoByte(t *testing.T) { - css := NewCompactShareSplitter(appns.TxNamespace, appconsts.ShareVersionZero) - txs := testfactory.GenerateRandomTxs(1, appconsts.ContinuationCompactShareContentSize/4) + css := NewCompactShareSplitter(TxNamespace, ShareVersionZero) + txs := GenerateRandomTxs(1, ContinuationCompactShareContentSize/4) for _, tx := range txs { err := css.WriteTx(tx) @@ -167,18 +164,18 @@ func TestCompactShareContainsInfoByte(t *testing.T) { require.NoError(t, err) assert.Condition(t, func() bool { return len(shares) == 1 }) - infoByte := shares[0].data[appconsts.NamespaceSize : appconsts.NamespaceSize+appconsts.ShareInfoBytes][0] + infoByte := shares[0].data[NamespaceSize : NamespaceSize+ShareInfoBytes][0] isSequenceStart := true - want, err := NewInfoByte(appconsts.ShareVersionZero, isSequenceStart) + want, err := NewInfoByte(ShareVersionZero, isSequenceStart) require.NoError(t, err) assert.Equal(t, byte(want), infoByte) } func TestContiguousCompactShareContainsInfoByte(t *testing.T) { - css := NewCompactShareSplitter(appns.TxNamespace, appconsts.ShareVersionZero) - txs := testfactory.GenerateRandomTxs(1, appconsts.ContinuationCompactShareContentSize*4) + css := NewCompactShareSplitter(TxNamespace, ShareVersionZero) + txs := GenerateRandomTxs(1, ContinuationCompactShareContentSize*4) for _, tx := range txs { err := css.WriteTx(tx) @@ -189,10 +186,10 @@ func TestContiguousCompactShareContainsInfoByte(t *testing.T) { require.NoError(t, err) assert.Condition(t, func() bool { return len(shares) > 1 }) - infoByte := shares[1].data[appconsts.NamespaceSize : appconsts.NamespaceSize+appconsts.ShareInfoBytes][0] + infoByte := shares[1].data[NamespaceSize : NamespaceSize+ShareInfoBytes][0] isSequenceStart := false - want, err := NewInfoByte(appconsts.ShareVersionZero, isSequenceStart) + want, err := NewInfoByte(ShareVersionZero, isSequenceStart) require.NoError(t, err) assert.Equal(t, byte(want), infoByte) @@ -204,7 +201,7 @@ func Test_parseCompactSharesErrors(t *testing.T) { shares []Share } - txs := testfactory.GenerateRandomTxs(2, appconsts.ContinuationCompactShareContentSize*4) + txs := GenerateRandomTxs(2, ContinuationCompactShareContentSize*4) txShares, _, _, err := SplitTxs(txs) require.NoError(t, err) rawShares := ToBytes(txShares) @@ -212,7 +209,7 @@ func Test_parseCompactSharesErrors(t *testing.T) { unsupportedShareVersion := 5 infoByte, _ := NewInfoByte(uint8(unsupportedShareVersion), true) shareWithUnsupportedShareVersionBytes := rawShares[0] - shareWithUnsupportedShareVersionBytes[appconsts.NamespaceSize] = byte(infoByte) + shareWithUnsupportedShareVersionBytes[NamespaceSize] = byte(infoByte) shareWithUnsupportedShareVersion, err := NewShare(shareWithUnsupportedShareVersionBytes) if err != nil { @@ -228,7 +225,7 @@ func Test_parseCompactSharesErrors(t *testing.T) { for _, tt := range testCases { t.Run(tt.name, func(t *testing.T) { - _, err := parseCompactShares(tt.shares, appconsts.SupportedShareVersions) + _, err := parseCompactShares(tt.shares, SupportedShareVersions) assert.Error(t, err) }) } diff --git a/pkg/namespace/consts.go b/shares/consts.go similarity index 58% rename from pkg/namespace/consts.go rename to shares/consts.go index 6da6e911c2..7d4ac1fbbc 100644 --- a/pkg/namespace/consts.go +++ b/shares/consts.go @@ -1,4 +1,4 @@ -package namespace +package shares import ( "bytes" @@ -6,6 +6,54 @@ import ( ) const ( + // ShareSize is the size of a share in bytes. + ShareSize = 512 + + // ShareInfoBytes is the number of bytes reserved for information. The info + // byte contains the share version and a sequence start idicator. + ShareInfoBytes = 1 + + // SequenceLenBytes is the number of bytes reserved for the sequence length + // that is present in the first share of a sequence. + SequenceLenBytes = 4 + + // ShareVersionZero is the first share version format. + ShareVersionZero = uint8(0) + + // DefaultShareVersion is the defacto share version. Use this if you are + // unsure of which version to use. + DefaultShareVersion = ShareVersionZero + + // CompactShareReservedBytes is the number of bytes reserved for the location of + // the first unit (transaction, ISR) in a compact share. + CompactShareReservedBytes = 4 + + // FirstCompactShareContentSize is the number of bytes usable for data in + // the first compact share of a sequence. + FirstCompactShareContentSize = ShareSize - NamespaceSize - ShareInfoBytes - SequenceLenBytes - CompactShareReservedBytes + + // ContinuationCompactShareContentSize is the number of bytes usable for + // data in a continuation compact share of a sequence. + ContinuationCompactShareContentSize = ShareSize - NamespaceSize - ShareInfoBytes - CompactShareReservedBytes + + // FirstSparseShareContentSize is the number of bytes usable for data in the + // first sparse share of a sequence. + FirstSparseShareContentSize = ShareSize - NamespaceSize - ShareInfoBytes - SequenceLenBytes + + // ContinuationSparseShareContentSize is the number of bytes usable for data + // in a continuation sparse share of a sequence. + ContinuationSparseShareContentSize = ShareSize - NamespaceSize - ShareInfoBytes + + // MinSquareSize is the smallest original square width. + MinSquareSize = 1 + + // MinshareCount is the minimum number of shares allowed in the original + // data square. + MinShareCount = MinSquareSize * MinSquareSize + + // MaxShareVersion is the maximum value a share version can be. + MaxShareVersion = 127 + // NamespaveVersionSize is the size of a namespace version in bytes. NamespaceVersionSize = 1 @@ -66,6 +114,9 @@ var ( // SupportedBlobNamespaceVersions is a list of namespace versions that can be specified by a user for blobs. SupportedBlobNamespaceVersions = []uint8{NamespaceVersionZero} + + // SupportedShareVersions is a list of supported share versions. + SupportedShareVersions = []uint8{ShareVersionZero} ) func primaryReservedNamespace(lastByte byte) Namespace { diff --git a/pkg/shares/counter.go b/shares/counter.go similarity index 79% rename from pkg/shares/counter.go rename to shares/counter.go index 027a2a0ed5..75fec10601 100644 --- a/pkg/shares/counter.go +++ b/shares/counter.go @@ -1,9 +1,5 @@ package shares -import ( - "github.com/celestiaorg/celestia-app/pkg/appconsts" -) - type CompactShareCounter struct { lastShares int lastRemainder int @@ -30,8 +26,8 @@ func (c *CompactShareCounter) Add(dataLen int) int { // if this is the first share, calculate how much is taken up by dataLen if c.shares == 0 { - if dataLen >= appconsts.FirstCompactShareContentSize-c.remainder { - dataLen -= (appconsts.FirstCompactShareContentSize - c.remainder) + if dataLen >= FirstCompactShareContentSize-c.remainder { + dataLen -= (FirstCompactShareContentSize - c.remainder) c.shares++ c.remainder = 0 } else { @@ -41,8 +37,8 @@ func (c *CompactShareCounter) Add(dataLen int) int { } // next, look to fill the remainder of the continuation share - if dataLen >= (appconsts.ContinuationCompactShareContentSize - c.remainder) { - dataLen -= (appconsts.ContinuationCompactShareContentSize - c.remainder) + if dataLen >= (ContinuationCompactShareContentSize - c.remainder) { + dataLen -= (ContinuationCompactShareContentSize - c.remainder) c.shares++ c.remainder = 0 } else { @@ -53,8 +49,8 @@ func (c *CompactShareCounter) Add(dataLen int) int { // finally, divide the remaining dataLen into the continuation shares and update // the remainder if dataLen > 0 { - c.shares += dataLen / appconsts.ContinuationCompactShareContentSize - c.remainder = dataLen % appconsts.ContinuationCompactShareContentSize + c.shares += dataLen / ContinuationCompactShareContentSize + c.remainder = dataLen % ContinuationCompactShareContentSize } // calculate the diff between before and after diff --git a/pkg/shares/counter_test.go b/shares/counter_test.go similarity index 64% rename from pkg/shares/counter_test.go rename to shares/counter_test.go index f64ba34963..a0eca0f79e 100644 --- a/pkg/shares/counter_test.go +++ b/shares/counter_test.go @@ -8,9 +8,7 @@ import ( "github.com/stretchr/testify/require" coretypes "github.com/tendermint/tendermint/types" - "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/namespace" - "github.com/celestiaorg/celestia-app/pkg/shares" + "github.com/celestiaorg/celestia-app/shares" ) func TestCounterMatchesCompactShareSplitter(t *testing.T) { @@ -19,11 +17,11 @@ func TestCounterMatchesCompactShareSplitter(t *testing.T) { }{ {txs: []coretypes.Tx{}}, {txs: []coretypes.Tx{newTx(120)}}, - {txs: []coretypes.Tx{newTx(appconsts.FirstCompactShareContentSize - 2)}}, - {txs: []coretypes.Tx{newTx(appconsts.FirstCompactShareContentSize - 1)}}, - {txs: []coretypes.Tx{newTx(appconsts.FirstCompactShareContentSize)}}, - {txs: []coretypes.Tx{newTx(appconsts.FirstCompactShareContentSize + 1)}}, - {txs: []coretypes.Tx{newTx(appconsts.FirstCompactShareContentSize), newTx(appconsts.ContinuationCompactShareContentSize - 4)}}, + {txs: []coretypes.Tx{newTx(shares.FirstCompactShareContentSize - 2)}}, + {txs: []coretypes.Tx{newTx(shares.FirstCompactShareContentSize - 1)}}, + {txs: []coretypes.Tx{newTx(shares.FirstCompactShareContentSize)}}, + {txs: []coretypes.Tx{newTx(shares.FirstCompactShareContentSize + 1)}}, + {txs: []coretypes.Tx{newTx(shares.FirstCompactShareContentSize), newTx(shares.ContinuationCompactShareContentSize - 4)}}, {txs: newTxs(1000, 100)}, {txs: newTxs(100, 1000)}, {txs: newTxs(8931, 77)}, @@ -31,7 +29,7 @@ func TestCounterMatchesCompactShareSplitter(t *testing.T) { for idx, tc := range testCases { t.Run(fmt.Sprintf("case%d", idx), func(t *testing.T) { - writer := shares.NewCompactShareSplitter(namespace.PayForBlobNamespace, appconsts.ShareVersionZero) + writer := shares.NewCompactShareSplitter(shares.PayForBlobNamespace, shares.ShareVersionZero) counter := shares.NewCompactShareCounter() sum := 0 @@ -49,7 +47,7 @@ func TestCounterMatchesCompactShareSplitter(t *testing.T) { }) } - writer := shares.NewCompactShareSplitter(namespace.PayForBlobNamespace, appconsts.ShareVersionZero) + writer := shares.NewCompactShareSplitter(shares.PayForBlobNamespace, shares.ShareVersionZero) counter := shares.NewCompactShareCounter() require.Equal(t, counter.Size(), 0) require.Equal(t, writer.Count(), counter.Size()) @@ -58,7 +56,7 @@ func TestCounterMatchesCompactShareSplitter(t *testing.T) { func TestCompactShareCounterRevert(t *testing.T) { counter := shares.NewCompactShareCounter() require.Equal(t, counter.Size(), 0) - counter.Add(appconsts.FirstCompactShareContentSize - 2) + counter.Add(shares.FirstCompactShareContentSize - 2) counter.Add(1) require.Equal(t, counter.Size(), 2) counter.Revert() diff --git a/pkg/shares/info_byte.go b/shares/info_byte.go similarity index 83% rename from pkg/shares/info_byte.go rename to shares/info_byte.go index 3d2e5e877e..50bf033641 100644 --- a/pkg/shares/info_byte.go +++ b/shares/info_byte.go @@ -2,8 +2,6 @@ package shares import ( "fmt" - - "github.com/celestiaorg/celestia-app/pkg/appconsts" ) // InfoByte is a byte with the following structure: the first 7 bits are @@ -13,8 +11,8 @@ import ( type InfoByte byte func NewInfoByte(version uint8, isSequenceStart bool) (InfoByte, error) { - if version > appconsts.MaxShareVersion { - return 0, fmt.Errorf("version %d must be less than or equal to %d", version, appconsts.MaxShareVersion) + if version > MaxShareVersion { + return 0, fmt.Errorf("version %d must be less than or equal to %d", version, MaxShareVersion) } prefix := version << 1 @@ -25,7 +23,7 @@ func NewInfoByte(version uint8, isSequenceStart bool) (InfoByte, error) { } // Version returns the version encoded in this InfoByte. Version is -// expected to be between 0 and appconsts.MaxShareVersion (inclusive). +// expected to be between 0 and MaxShareVersion (inclusive). func (i InfoByte) Version() uint8 { version := uint8(i) >> 1 return version diff --git a/pkg/shares/info_byte_test.go b/shares/info_byte_test.go similarity index 100% rename from pkg/shares/info_byte_test.go rename to shares/info_byte_test.go diff --git a/pkg/namespace/namespace.go b/shares/namespace.go similarity index 76% rename from pkg/namespace/namespace.go rename to shares/namespace.go index 3186d78509..f9e3889ea6 100644 --- a/pkg/namespace/namespace.go +++ b/shares/namespace.go @@ -1,4 +1,4 @@ -package namespace +package shares import ( "bytes" @@ -11,7 +11,7 @@ type Namespace struct { } // New returns a new namespace with the provided version and id. -func New(version uint8, id []byte) (Namespace, error) { +func NewNamespace(version uint8, id []byte) (Namespace, error) { err := validateVersionSupported(version) if err != nil { return Namespace{}, err @@ -30,8 +30,8 @@ func New(version uint8, id []byte) (Namespace, error) { // MustNew returns a new namespace with the provided version and id. It panics // if the provided version or id are not supported. -func MustNew(version uint8, id []byte) Namespace { - ns, err := New(version, id) +func MustNewNamespace(version uint8, id []byte) Namespace { + ns, err := NewNamespace(version, id) if err != nil { panic(err) } @@ -41,7 +41,7 @@ func MustNew(version uint8, id []byte) Namespace { // NewV0 returns a new namespace with version 0 and the provided subID. subID // must be <= 10 bytes. If subID is < 10 bytes, it will be left-padded with 0s // to fill 10 bytes. -func NewV0(subID []byte) (Namespace, error) { +func NewV0Namespace(subID []byte) (Namespace, error) { if lenSubID := len(subID); lenSubID > NamespaceVersionZeroIDSize { return Namespace{}, fmt.Errorf("subID must be <= %v, but it was %v bytes", NamespaceVersionZeroIDSize, lenSubID) } @@ -50,7 +50,7 @@ func NewV0(subID []byte) (Namespace, error) { id := make([]byte, NamespaceIDSize) copy(id[NamespaceVersionZeroPrefixSize:], subID) - ns, err := New(NamespaceVersionZero, id) + ns, err := NewNamespace(NamespaceVersionZero, id) if err != nil { return Namespace{}, err } @@ -60,8 +60,8 @@ func NewV0(subID []byte) (Namespace, error) { // MustNewV0 returns a new namespace with version 0 and the provided subID. This // function panics if the provided subID would result in an invalid namespace. -func MustNewV0(subID []byte) Namespace { - ns, err := NewV0(subID) +func MustNewV0Namespace(subID []byte) Namespace { + ns, err := NewV0Namespace(subID) if err != nil { panic(err) } @@ -75,7 +75,7 @@ func From(b []byte) (Namespace, error) { } rawVersion := b[0] rawNamespace := b[1:] - return New(rawVersion, rawNamespace) + return NewNamespace(rawVersion, rawNamespace) } // Bytes returns this namespace as a byte slice. @@ -189,3 +189,45 @@ func (n Namespace) deepCopy() Namespace { return copyNamespace } + +// GetShareRangeForNamespace returns all shares that belong to a given +// namespace. It will return an empty range if the namespace could not be +// found. This assumes that the slice of shares are lexicographically +// sorted by namespace. Ranges here are always end exlusive. +func GetShareRangeForNamespace(shares []Share, ns Namespace) (Range, error) { + if len(shares) == 0 { + return EmptyRange(), nil + } + n0, err := shares[0].Namespace() + if err != nil { + return EmptyRange(), err + } + if ns.IsLessThan(n0) { + return EmptyRange(), nil + } + n1, err := shares[len(shares)-1].Namespace() + if err != nil { + return EmptyRange(), err + } + if ns.IsGreaterThan(n1) { + return EmptyRange(), nil + } + + start := -1 + for i, share := range shares { + shareNS, err := share.Namespace() + if err != nil { + return EmptyRange(), fmt.Errorf("failed to get namespace from share %d: %w", i, err) + } + if shareNS.IsGreaterThan(ns) && start != -1 { + return Range{start, i}, nil + } + if ns.Equals(shareNS) && start == -1 { + start = i + } + } + if start == -1 { + return EmptyRange(), nil + } + return Range{start, len(shares)}, nil +} diff --git a/pkg/namespace/namespace_test.go b/shares/namespace_test.go similarity index 96% rename from pkg/namespace/namespace_test.go rename to shares/namespace_test.go index 57c125cc6c..a2d934c7b2 100644 --- a/pkg/namespace/namespace_test.go +++ b/shares/namespace_test.go @@ -1,4 +1,4 @@ -package namespace +package shares import ( "bytes" @@ -64,7 +64,7 @@ func TestNew(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - got, err := New(tc.version, tc.id) + got, err := NewNamespace(tc.version, tc.id) if tc.wantErr { assert.Error(t, err) return @@ -124,7 +124,7 @@ func TestNewV0(t *testing.T) { } for _, tc := range testCases { - got, err := NewV0(tc.subID) + got, err := NewV0Namespace(tc.subID) if tc.wantErr { assert.Error(t, err) return @@ -202,7 +202,7 @@ func TestFrom(t *testing.T) { } func TestBytes(t *testing.T) { - namespace, err := New(NamespaceVersionZero, validID) + namespace, err := NewNamespace(NamespaceVersionZero, validID) assert.NoError(t, err) want := append([]byte{NamespaceVersionZero}, validID...) @@ -248,7 +248,7 @@ func TestIsReserved(t *testing.T) { } testCases := []testCase{ { - ns: MustNewV0(bytes.Repeat([]byte{1}, NamespaceVersionZeroIDSize)), + ns: MustNewV0Namespace(bytes.Repeat([]byte{1}, NamespaceVersionZeroIDSize)), want: false, }, { diff --git a/pkg/shares/padding.go b/shares/padding.go similarity index 70% rename from pkg/shares/padding.go rename to shares/padding.go index b23d1dabc4..64ea3762d4 100644 --- a/pkg/shares/padding.go +++ b/shares/padding.go @@ -3,9 +3,6 @@ package shares import ( "bytes" "errors" - - "github.com/celestiaorg/celestia-app/pkg/appconsts" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" ) // NamespacePaddingShare returns a share that acts as padding. Namespace padding @@ -13,7 +10,7 @@ import ( // conforms to blob share commitment rules. The ns and shareVersion parameters // provided should be the namespace and shareVersion of the blob that precedes // this padding in the data square. -func NamespacePaddingShare(ns appns.Namespace, shareVersion uint8) (Share, error) { +func NamespacePaddingShare(ns Namespace, shareVersion uint8) (Share, error) { b, err := NewBuilder(ns, shareVersion, true) if err != nil { return Share{}, err @@ -21,7 +18,7 @@ func NamespacePaddingShare(ns appns.Namespace, shareVersion uint8) (Share, error if err := b.WriteSequenceLen(0); err != nil { return Share{}, err } - padding := bytes.Repeat([]byte{0}, appconsts.FirstSparseShareContentSize) + padding := bytes.Repeat([]byte{0}, FirstSparseShareContentSize) b.AddData(padding) share, err := b.Build() @@ -33,7 +30,7 @@ func NamespacePaddingShare(ns appns.Namespace, shareVersion uint8) (Share, error } // NamespacePaddingShares returns n namespace padding shares. -func NamespacePaddingShares(ns appns.Namespace, shareVersion uint8, n int) ([]Share, error) { +func NamespacePaddingShares(ns Namespace, shareVersion uint8, n int) ([]Share, error) { var err error if n < 0 { return nil, errors.New("n must be positive") @@ -53,7 +50,7 @@ func NamespacePaddingShares(ns appns.Namespace, shareVersion uint8, n int) ([]Sh // first blob can start at an index that conforms to non-interactive default // rules. func ReservedPaddingShare() Share { - share, err := NamespacePaddingShare(appns.PrimaryReservedPaddingNamespace, appconsts.ShareVersionZero) + share, err := NamespacePaddingShare(PrimaryReservedPaddingNamespace, ShareVersionZero) if err != nil { panic(err) } @@ -62,7 +59,7 @@ func ReservedPaddingShare() Share { // ReservedPaddingShare returns n reserved padding shares. func ReservedPaddingShares(n int) []Share { - shares, err := NamespacePaddingShares(appns.PrimaryReservedPaddingNamespace, appconsts.ShareVersionZero, n) + shares, err := NamespacePaddingShares(PrimaryReservedPaddingNamespace, ShareVersionZero, n) if err != nil { panic(err) } @@ -73,7 +70,7 @@ func ReservedPaddingShares(n int) []Share { // square size. Tail padding shares follow the last blob share in the data // square. func TailPaddingShare() Share { - share, err := NamespacePaddingShare(appns.TailPaddingNamespace, appconsts.ShareVersionZero) + share, err := NamespacePaddingShare(TailPaddingNamespace, ShareVersionZero) if err != nil { panic(err) } @@ -82,7 +79,7 @@ func TailPaddingShare() Share { // TailPaddingShares returns n tail padding shares. func TailPaddingShares(n int) []Share { - shares, err := NamespacePaddingShares(appns.TailPaddingNamespace, appconsts.ShareVersionZero, n) + shares, err := NamespacePaddingShares(TailPaddingNamespace, ShareVersionZero, n) if err != nil { panic(err) } diff --git a/pkg/shares/padding_test.go b/shares/padding_test.go similarity index 75% rename from pkg/shares/padding_test.go rename to shares/padding_test.go index e660288aae..f3e908c92e 100644 --- a/pkg/shares/padding_test.go +++ b/shares/padding_test.go @@ -4,13 +4,11 @@ import ( "bytes" "testing" - "github.com/celestiaorg/celestia-app/pkg/appconsts" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) -var ns1 = appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) +var ns1 = MustNewV0Namespace(bytes.Repeat([]byte{1}, NamespaceVersionZeroIDSize)) var nsOnePadding, _ = zeroPadIfNecessary( append( @@ -19,34 +17,34 @@ var nsOnePadding, _ = zeroPadIfNecessary( 1, // info byte 0, 0, 0, 0, // sequence len }..., - ), appconsts.ShareSize) + ), ShareSize) var reservedPadding, _ = zeroPadIfNecessary( append( - appns.PrimaryReservedPaddingNamespace.Bytes(), + PrimaryReservedPaddingNamespace.Bytes(), []byte{ 1, // info byte 0, 0, 0, 0, // sequence len }..., - ), appconsts.ShareSize) + ), ShareSize) var tailPadding, _ = zeroPadIfNecessary( append( - appns.TailPaddingNamespace.Bytes(), + TailPaddingNamespace.Bytes(), []byte{ 1, // info byte 0, 0, 0, 0, // sequence len }..., - ), appconsts.ShareSize) + ), ShareSize) func TestNamespacePaddingShare(t *testing.T) { - got, err := NamespacePaddingShare(ns1, appconsts.ShareVersionZero) + got, err := NamespacePaddingShare(ns1, ShareVersionZero) assert.NoError(t, err) assert.Equal(t, nsOnePadding, got.ToBytes()) } func TestNamespacePaddingShares(t *testing.T) { - shares, err := NamespacePaddingShares(ns1, appconsts.ShareVersionZero, 2) + shares, err := NamespacePaddingShares(ns1, ShareVersionZero, 2) assert.NoError(t, err) for _, share := range shares { assert.Equal(t, nsOnePadding, share.ToBytes()) diff --git a/pkg/shares/parse.go b/shares/parse.go similarity index 86% rename from pkg/shares/parse.go rename to shares/parse.go index fb74c82413..fc4951c836 100644 --- a/pkg/shares/parse.go +++ b/shares/parse.go @@ -4,15 +4,13 @@ import ( "bytes" "fmt" - "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/blob" coretypes "github.com/tendermint/tendermint/types" ) // ParseTxs collects all of the transactions from the shares provided func ParseTxs(shares []Share) (coretypes.Txs, error) { // parse the shares - rawTxs, err := parseCompactShares(shares, appconsts.SupportedShareVersions) + rawTxs, err := parseCompactShares(shares, SupportedShareVersions) if err != nil { return nil, err } @@ -27,10 +25,10 @@ func ParseTxs(shares []Share) (coretypes.Txs, error) { } // ParseBlobs collects all blobs from the shares provided -func ParseBlobs(shares []Share) ([]*blob.Blob, error) { - blobList, err := parseSparseShares(shares, appconsts.SupportedShareVersions) +func ParseBlobs(shares []Share) ([]*Blob, error) { + blobList, err := parseSparseShares(shares, SupportedShareVersions) if err != nil { - return []*blob.Blob{}, err + return []*Blob{}, err } return blobList, nil diff --git a/pkg/shares/parse_compact_shares.go b/shares/parse_compact_shares.go similarity index 100% rename from pkg/shares/parse_compact_shares.go rename to shares/parse_compact_shares.go diff --git a/pkg/shares/parse_sparse_shares.go b/shares/parse_sparse_shares.go similarity index 92% rename from pkg/shares/parse_sparse_shares.go rename to shares/parse_sparse_shares.go index 818ad8c65e..eb3d5ef1a7 100644 --- a/pkg/shares/parse_sparse_shares.go +++ b/shares/parse_sparse_shares.go @@ -3,19 +3,17 @@ package shares import ( "bytes" "fmt" - - "github.com/celestiaorg/celestia-app/pkg/blob" ) type sequence struct { - blob *blob.Blob + blob *Blob sequenceLen uint32 } // parseSparseShares iterates through rawShares and parses out individual // blobs. It returns an error if a rawShare contains a share version that // isn't present in supportedShareVersions. -func parseSparseShares(shares []Share, supportedShareVersions []uint8) (blobs []*blob.Blob, err error) { +func parseSparseShares(shares []Share, supportedShareVersions []uint8) (blobs []*Blob, err error) { if len(shares) == 0 { return nil, nil } @@ -56,7 +54,7 @@ func parseSparseShares(shares []Share, supportedShareVersions []uint8) (blobs [] if err != nil { return nil, err } - blob := blob.New(ns, data, version) + blob := NewBlob(ns, data, version) sequences = append(sequences, sequence{ blob: blob, sequenceLen: sequenceLen, diff --git a/pkg/shares/parse_sparse_shares_test.go b/shares/parse_sparse_shares_test.go similarity index 71% rename from pkg/shares/parse_sparse_shares_test.go rename to shares/parse_sparse_shares_test.go index f718f82762..a8c72070ad 100644 --- a/pkg/shares/parse_sparse_shares_test.go +++ b/shares/parse_sparse_shares_test.go @@ -5,9 +5,6 @@ import ( "fmt" "testing" - "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/blob" - "github.com/celestiaorg/celestia-app/test/util/testfactory" "github.com/celestiaorg/nmt/namespace" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -35,17 +32,17 @@ func Test_parseSparseShares(t *testing.T) { }, { name: "single big blob", - blobSize: appconsts.ContinuationSparseShareContentSize * 4, + blobSize: ContinuationSparseShareContentSize * 4, blobCount: 1, }, { name: "many big blobs", - blobSize: appconsts.ContinuationSparseShareContentSize * 4, + blobSize: ContinuationSparseShareContentSize * 4, blobCount: 10, }, { name: "single exact size blob", - blobSize: appconsts.FirstSparseShareContentSize, + blobSize: FirstSparseShareContentSize, blobCount: 1, }, } @@ -53,16 +50,16 @@ func Test_parseSparseShares(t *testing.T) { for _, tc := range tests { // run the tests with identically sized blobs t.Run(fmt.Sprintf("%s identically sized ", tc.name), func(t *testing.T) { - blobs := make([]*blob.Blob, tc.blobCount) + blobs := make([]*Blob, tc.blobCount) for i := 0; i < tc.blobCount; i++ { - blobs[i] = testfactory.GenerateRandomBlob(tc.blobSize) + blobs[i] = GenerateRandomBlob(tc.blobSize) } - blob.Sort(blobs) + SortBlobs(blobs) shares, err := SplitBlobs(blobs...) require.NoError(t, err) - parsedBlobs, err := parseSparseShares(shares, appconsts.SupportedShareVersions) + parsedBlobs, err := parseSparseShares(shares, SupportedShareVersions) if err != nil { t.Error(err) } @@ -76,10 +73,10 @@ func Test_parseSparseShares(t *testing.T) { // run the same tests using randomly sized blobs with caps of tc.blobSize t.Run(fmt.Sprintf("%s randomly sized", tc.name), func(t *testing.T) { - blobs := testfactory.GenerateRandomlySizedBlobs(tc.blobCount, tc.blobSize) + blobs := GenerateRandomlySizedBlobs(tc.blobCount, tc.blobSize) shares, err := SplitBlobs(blobs...) require.NoError(t, err) - parsedBlobs, err := parseSparseShares(shares, appconsts.SupportedShareVersions) + parsedBlobs, err := parseSparseShares(shares, SupportedShareVersions) if err != nil { t.Error(err) } @@ -105,7 +102,7 @@ func Test_parseSparseSharesErrors(t *testing.T) { rawShare := []byte{} 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))...) + rawShare = append(rawShare, bytes.Repeat([]byte{0}, ShareSize-len(rawShare))...) share, err := NewShare(rawShare) if err != nil { t.Fatal(err) @@ -120,7 +117,7 @@ func Test_parseSparseSharesErrors(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(*testing.T) { - _, err := parseSparseShares(tt.shares, appconsts.SupportedShareVersions) + _, err := parseSparseShares(tt.shares, SupportedShareVersions) assert.Error(t, err) }) } @@ -128,13 +125,13 @@ func Test_parseSparseSharesErrors(t *testing.T) { func Test_parseSparseSharesWithNamespacedPadding(t *testing.T) { sss := NewSparseShareSplitter() - randomSmallBlob := testfactory.GenerateRandomBlob(appconsts.ContinuationSparseShareContentSize / 2) - randomLargeBlob := testfactory.GenerateRandomBlob(appconsts.ContinuationSparseShareContentSize * 4) - blobs := []*blob.Blob{ + randomSmallBlob := GenerateRandomBlob(ContinuationSparseShareContentSize / 2) + randomLargeBlob := GenerateRandomBlob(ContinuationSparseShareContentSize * 4) + blobs := []*Blob{ randomSmallBlob, randomLargeBlob, } - blob.Sort(blobs) + SortBlobs(blobs) err := sss.Write(blobs[0]) require.NoError(t, err) @@ -149,7 +146,7 @@ func Test_parseSparseSharesWithNamespacedPadding(t *testing.T) { require.NoError(t, err) shares := sss.Export() - pblobs, err := parseSparseShares(shares, appconsts.SupportedShareVersions) + pblobs, err := parseSparseShares(shares, SupportedShareVersions) require.NoError(t, err) require.Equal(t, blobs, pblobs) } diff --git a/pkg/shares/parse_test.go b/shares/parse_test.go similarity index 80% rename from pkg/shares/parse_test.go rename to shares/parse_test.go index 45dd9a6092..2da5fed341 100644 --- a/pkg/shares/parse_test.go +++ b/shares/parse_test.go @@ -7,9 +7,6 @@ import ( "reflect" "testing" - "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/blob" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" tmrand "github.com/tendermint/tendermint/libs/rand" @@ -17,8 +14,8 @@ import ( ) func TestParseShares(t *testing.T) { - ns1 := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) - ns2 := appns.MustNewV0(bytes.Repeat([]byte{2}, appns.NamespaceVersionZeroIDSize)) + ns1 := MustNewV0Namespace(bytes.Repeat([]byte{1}, NamespaceVersionZeroIDSize)) + ns2 := MustNewV0Namespace(bytes.Repeat([]byte{2}, NamespaceVersionZeroIDSize)) txShares, _, _, err := SplitTxs(generateRandomTxs(2, 1000)) require.NoError(t, err) @@ -42,7 +39,7 @@ func TestParseShares(t *testing.T) { // because it takes more than one share to store a sequence of 1000 bytes tooLargeSequenceLen := generateRawShare(t, ns1, true, uint32(1000)) - ns1Padding, err := NamespacePaddingShare(ns1, appconsts.ShareVersionZero) + ns1Padding, err := NamespacePaddingShare(ns1, ShareVersionZero) require.NoError(t, err) type testCase struct { @@ -65,14 +62,14 @@ func TestParseShares(t *testing.T) { name: "one transaction share", shares: []Share{txShareStart}, ignorePadding: false, - want: []ShareSequence{{Namespace: appns.TxNamespace, Shares: []Share{txShareStart}}}, + want: []ShareSequence{{Namespace: TxNamespace, Shares: []Share{txShareStart}}}, expectErr: false, }, { name: "two transaction shares", shares: []Share{txShareStart, txShareContinuation}, ignorePadding: false, - want: []ShareSequence{{Namespace: appns.TxNamespace, Shares: []Share{txShareStart, txShareContinuation}}}, + want: []ShareSequence{{Namespace: TxNamespace, Shares: []Share{txShareStart, txShareContinuation}}}, expectErr: false, }, { @@ -104,7 +101,7 @@ func TestParseShares(t *testing.T) { shares: []Share{txShareStart, blobOneStart}, ignorePadding: false, want: []ShareSequence{ - {Namespace: appns.TxNamespace, Shares: []Share{txShareStart}}, + {Namespace: TxNamespace, Shares: []Share{txShareStart}}, {Namespace: ns1, Shares: []Share{blobOneStart}}, }, expectErr: false, @@ -114,7 +111,7 @@ func TestParseShares(t *testing.T) { shares: []Share{txShareStart, blobOneStart, blobTwoStart}, ignorePadding: false, want: []ShareSequence{ - {Namespace: appns.TxNamespace, Shares: []Share{txShareStart}}, + {Namespace: TxNamespace, Shares: []Share{txShareStart}}, {Namespace: ns1, Shares: []Share{blobOneStart}}, {Namespace: ns2, Shares: []Share{blobTwoStart}}, }, @@ -147,11 +144,11 @@ func TestParseShares(t *testing.T) { ignorePadding: false, want: []ShareSequence{ { - Namespace: appns.TailPaddingNamespace, + Namespace: TailPaddingNamespace, Shares: []Share{TailPaddingShare()}, }, { - Namespace: appns.TailPaddingNamespace, + Namespace: TailPaddingNamespace, Shares: []Share{TailPaddingShare()}, }, }, @@ -163,11 +160,11 @@ func TestParseShares(t *testing.T) { ignorePadding: false, want: []ShareSequence{ { - Namespace: appns.PrimaryReservedPaddingNamespace, + Namespace: PrimaryReservedPaddingNamespace, Shares: []Share{ReservedPaddingShare()}, }, { - Namespace: appns.PrimaryReservedPaddingNamespace, + Namespace: PrimaryReservedPaddingNamespace, Shares: []Share{ReservedPaddingShare()}, }, }, @@ -211,10 +208,10 @@ func TestParseShares(t *testing.T) { } } -func generateRawShare(t *testing.T, namespace appns.Namespace, isSequenceStart bool, sequenceLen uint32) (rawShare []byte) { - infoByte, _ := NewInfoByte(appconsts.ShareVersionZero, isSequenceStart) +func generateRawShare(t *testing.T, namespace Namespace, isSequenceStart bool, sequenceLen uint32) (rawShare []byte) { + infoByte, _ := NewInfoByte(ShareVersionZero, isSequenceStart) - sequenceLenBuf := make([]byte, appconsts.SequenceLenBytes) + sequenceLenBuf := make([]byte, SequenceLenBytes) binary.BigEndian.PutUint32(sequenceLenBuf, sequenceLen) rawShare = append(rawShare, namespace.Bytes()...) @@ -225,7 +222,7 @@ func generateRawShare(t *testing.T, namespace appns.Namespace, isSequenceStart b } func padWithRandomBytes(t *testing.T, partialShare []byte) (paddedShare []byte) { - paddedShare = make([]byte, appconsts.ShareSize) + paddedShare = make([]byte, ShareSize) copy(paddedShare, partialShare) _, err := rand.Read(paddedShare[len(partialShare):]) require.NoError(t, err) @@ -245,6 +242,6 @@ func generateRandomTxs(count, size int) types.Txs { return txs } -func generateRandomBlobWithNamespace(namespace appns.Namespace, size int) *blob.Blob { - return blob.New(namespace, tmrand.Bytes(size), appconsts.ShareVersionZero) +func generateRandomBlobWithNamespace(namespace Namespace, size int) *Blob { + return NewBlob(namespace, tmrand.Bytes(size), ShareVersionZero) } diff --git a/pkg/shares/powers_of_two.go b/shares/powers_of_two.go similarity index 100% rename from pkg/shares/powers_of_two.go rename to shares/powers_of_two.go diff --git a/pkg/shares/powers_of_two_test.go b/shares/powers_of_two_test.go similarity index 100% rename from pkg/shares/powers_of_two_test.go rename to shares/powers_of_two_test.go diff --git a/pkg/namespace/random_blob.go b/shares/random_blob.go similarity index 96% rename from pkg/namespace/random_blob.go rename to shares/random_blob.go index 156d8a574f..beed388d33 100644 --- a/pkg/namespace/random_blob.go +++ b/shares/random_blob.go @@ -1,4 +1,4 @@ -package namespace +package shares import ( tmrand "github.com/tendermint/tendermint/libs/rand" @@ -22,7 +22,7 @@ func RandomBlobNamespace() Namespace { func RandomBlobNamespaceWithPRG(prg *tmrand.Rand) Namespace { for { id := RandomBlobNamespaceIDWithPRG(prg) - namespace := MustNewV0(id) + namespace := MustNewV0Namespace(id) if isBlobNamespace(namespace) { return namespace } diff --git a/pkg/namespace/random_namespace.go b/shares/random_namespace.go similarity index 81% rename from pkg/namespace/random_namespace.go rename to shares/random_namespace.go index 79e52a6118..7947473e8a 100644 --- a/pkg/namespace/random_namespace.go +++ b/shares/random_namespace.go @@ -1,11 +1,11 @@ -package namespace +package shares import tmrand "github.com/tendermint/tendermint/libs/rand" func RandomNamespace() Namespace { for { id := RandomVerzionZeroID() - namespace, err := New(NamespaceVersionZero, id) + namespace, err := NewNamespace(NamespaceVersionZero, id) if err != nil { continue } diff --git a/pkg/shares/range.go b/shares/range.go similarity index 100% rename from pkg/shares/range.go rename to shares/range.go diff --git a/pkg/shares/reserved_bytes.go b/shares/reserved_bytes.go similarity index 51% rename from pkg/shares/reserved_bytes.go rename to shares/reserved_bytes.go index 7240e2551d..803e936069 100644 --- a/pkg/shares/reserved_bytes.go +++ b/shares/reserved_bytes.go @@ -3,31 +3,29 @@ package shares import ( "encoding/binary" "fmt" - - "github.com/celestiaorg/celestia-app/pkg/appconsts" ) // NewReservedBytes returns a byte slice of length -// appconsts.CompactShareReservedBytes that contains the byteIndex of the first +// CompactShareReservedBytes that contains the byteIndex of the first // unit that starts in a compact share. func NewReservedBytes(byteIndex uint32) ([]byte, error) { - if byteIndex >= appconsts.ShareSize { - return []byte{}, fmt.Errorf("byte index %d must be less than share size %d", byteIndex, appconsts.ShareSize) + if byteIndex >= ShareSize { + return []byte{}, fmt.Errorf("byte index %d must be less than share size %d", byteIndex, ShareSize) } - reservedBytes := make([]byte, appconsts.CompactShareReservedBytes) + reservedBytes := make([]byte, CompactShareReservedBytes) binary.BigEndian.PutUint32(reservedBytes, byteIndex) return reservedBytes, nil } // ParseReservedBytes parses a byte slice of length -// appconsts.CompactShareReservedBytes into a byteIndex. +// CompactShareReservedBytes into a byteIndex. func ParseReservedBytes(reservedBytes []byte) (uint32, error) { - if len(reservedBytes) != appconsts.CompactShareReservedBytes { - return 0, fmt.Errorf("reserved bytes must be of length %d", appconsts.CompactShareReservedBytes) + if len(reservedBytes) != CompactShareReservedBytes { + return 0, fmt.Errorf("reserved bytes must be of length %d", CompactShareReservedBytes) } byteIndex := binary.BigEndian.Uint32(reservedBytes) - if appconsts.ShareSize <= byteIndex { - return 0, fmt.Errorf("byteIndex must be less than share size %d", appconsts.ShareSize) + if ShareSize <= byteIndex { + return 0, fmt.Errorf("byteIndex must be less than share size %d", ShareSize) } return byteIndex, nil } diff --git a/pkg/shares/reserved_bytes_test.go b/shares/reserved_bytes_test.go similarity index 100% rename from pkg/shares/reserved_bytes_test.go rename to shares/reserved_bytes_test.go diff --git a/pkg/shares/share_builder.go b/shares/share_builder.go similarity index 77% rename from pkg/shares/share_builder.go rename to shares/share_builder.go index 0b5e3fa1fd..2f713f7084 100644 --- a/pkg/shares/share_builder.go +++ b/shares/share_builder.go @@ -3,13 +3,10 @@ package shares import ( "encoding/binary" "errors" - - "github.com/celestiaorg/celestia-app/pkg/appconsts" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" ) type Builder struct { - namespace appns.Namespace + namespace Namespace shareVersion uint8 isFirstShare bool isCompactShare bool @@ -18,12 +15,12 @@ type Builder struct { func NewEmptyBuilder() *Builder { return &Builder{ - rawShareData: make([]byte, 0, appconsts.ShareSize), + rawShareData: make([]byte, 0, ShareSize), } } // NewBuilder returns a new share builder. -func NewBuilder(ns appns.Namespace, shareVersion uint8, isFirstShare bool) (*Builder, error) { +func NewBuilder(ns Namespace, shareVersion uint8, isFirstShare bool) (*Builder, error) { b := Builder{ namespace: ns, shareVersion: shareVersion, @@ -45,7 +42,7 @@ func (b *Builder) init() error { } func (b *Builder) AvailableBytes() int { - return appconsts.ShareSize - len(b.rawShareData) + return ShareSize - len(b.rawShareData) } func (b *Builder) ImportRawShare(rawBytes []byte) *Builder { @@ -55,7 +52,7 @@ func (b *Builder) ImportRawShare(rawBytes []byte) *Builder { func (b *Builder) AddData(rawData []byte) (rawDataLeftOver []byte) { // find the len left in the pending share - pendingLeft := appconsts.ShareSize - len(b.rawShareData) + pendingLeft := ShareSize - len(b.rawShareData) // if we can simply add the tx to the share without creating a new // pending share, do so and return @@ -80,25 +77,25 @@ func (b *Builder) Build() (*Share, error) { // IsEmptyShare returns true if no data has been written to the share func (b *Builder) IsEmptyShare() bool { - expectedLen := appconsts.NamespaceSize + appconsts.ShareInfoBytes + expectedLen := NamespaceSize + ShareInfoBytes if b.isCompactShare { - expectedLen += appconsts.CompactShareReservedBytes + expectedLen += CompactShareReservedBytes } if b.isFirstShare { - expectedLen += appconsts.SequenceLenBytes + expectedLen += SequenceLenBytes } return len(b.rawShareData) == expectedLen } func (b *Builder) ZeroPadIfNecessary() (bytesOfPadding int) { - b.rawShareData, bytesOfPadding = zeroPadIfNecessary(b.rawShareData, appconsts.ShareSize) + b.rawShareData, bytesOfPadding = zeroPadIfNecessary(b.rawShareData, ShareSize) return bytesOfPadding } // isEmptyReservedBytes returns true if the reserved bytes are empty. func (b *Builder) isEmptyReservedBytes() (bool, error) { indexOfReservedBytes := b.indexOfReservedBytes() - reservedBytes, err := ParseReservedBytes(b.rawShareData[indexOfReservedBytes : indexOfReservedBytes+appconsts.CompactShareReservedBytes]) + reservedBytes, err := ParseReservedBytes(b.rawShareData[indexOfReservedBytes : indexOfReservedBytes+CompactShareReservedBytes]) if err != nil { return false, err } @@ -109,16 +106,16 @@ func (b *Builder) isEmptyReservedBytes() (bool, error) { func (b *Builder) indexOfReservedBytes() int { if b.isFirstShare { // if the share is the first share, the reserved bytes follow the namespace, info byte, and sequence length - return appconsts.NamespaceSize + appconsts.ShareInfoBytes + appconsts.SequenceLenBytes + return NamespaceSize + ShareInfoBytes + SequenceLenBytes } // if the share is not the first share, the reserved bytes follow the namespace and info byte - return appconsts.NamespaceSize + appconsts.ShareInfoBytes + return NamespaceSize + ShareInfoBytes } // indexOfInfoBytes returns the index of the InfoBytes. func (b *Builder) indexOfInfoBytes() int { // the info byte is immediately after the namespace - return appconsts.NamespaceSize + return NamespaceSize } // MaybeWriteReservedBytes will be a no-op if the reserved bytes @@ -145,7 +142,7 @@ func (b *Builder) MaybeWriteReservedBytes() error { indexOfReservedBytes := b.indexOfReservedBytes() // overwrite the reserved bytes of the pending share - for i := 0; i < appconsts.CompactShareReservedBytes; i++ { + for i := 0; i < CompactShareReservedBytes; i++ { b.rawShareData[indexOfReservedBytes+i] = reservedBytes[i] } return nil @@ -159,11 +156,11 @@ func (b *Builder) WriteSequenceLen(sequenceLen uint32) error { if !b.isFirstShare { return errors.New("not the first share") } - sequenceLenBuf := make([]byte, appconsts.SequenceLenBytes) + sequenceLenBuf := make([]byte, SequenceLenBytes) binary.BigEndian.PutUint32(sequenceLenBuf, sequenceLen) - for i := 0; i < appconsts.SequenceLenBytes; i++ { - b.rawShareData[appconsts.NamespaceSize+appconsts.ShareInfoBytes+i] = sequenceLenBuf[i] + for i := 0; i < SequenceLenBytes; i++ { + b.rawShareData[NamespaceSize+ShareInfoBytes+i] = sequenceLenBuf[i] } return nil @@ -179,13 +176,13 @@ func (b *Builder) FlipSequenceStart() { } func (b *Builder) prepareCompactShare() error { - shareData := make([]byte, 0, appconsts.ShareSize) + shareData := make([]byte, 0, ShareSize) infoByte, err := NewInfoByte(b.shareVersion, b.isFirstShare) if err != nil { return err } - placeholderSequenceLen := make([]byte, appconsts.SequenceLenBytes) - placeholderReservedBytes := make([]byte, appconsts.CompactShareReservedBytes) + placeholderSequenceLen := make([]byte, SequenceLenBytes) + placeholderReservedBytes := make([]byte, CompactShareReservedBytes) shareData = append(shareData, b.namespace.Bytes()...) shareData = append(shareData, byte(infoByte)) @@ -202,12 +199,12 @@ func (b *Builder) prepareCompactShare() error { } func (b *Builder) prepareSparseShare() error { - shareData := make([]byte, 0, appconsts.ShareSize) + shareData := make([]byte, 0, ShareSize) infoByte, err := NewInfoByte(b.shareVersion, b.isFirstShare) if err != nil { return err } - placeholderSequenceLen := make([]byte, appconsts.SequenceLenBytes) + placeholderSequenceLen := make([]byte, SequenceLenBytes) shareData = append(shareData, b.namespace.Bytes()...) shareData = append(shareData, byte(infoByte)) @@ -220,6 +217,6 @@ func (b *Builder) prepareSparseShare() error { return nil } -func isCompactShare(ns appns.Namespace) bool { +func isCompactShare(ns Namespace) bool { return ns.IsTx() || ns.IsPayForBlob() } diff --git a/pkg/shares/share_builder_test.go b/shares/share_builder_test.go similarity index 65% rename from pkg/shares/share_builder_test.go rename to shares/share_builder_test.go index 779bacdf4c..7317e9f424 100644 --- a/pkg/shares/share_builder_test.go +++ b/shares/share_builder_test.go @@ -5,8 +5,6 @@ import ( "fmt" "testing" - "github.com/celestiaorg/celestia-app/pkg/appconsts" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -18,54 +16,54 @@ func TestShareBuilderIsEmptyShare(t *testing.T) { data []byte // input data want bool } - ns1 := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) + ns1 := MustNewV0Namespace(bytes.Repeat([]byte{1}, NamespaceVersionZeroIDSize)) testCases := []testCase{ { name: "first compact share empty", - builder: mustNewBuilder(t, appns.TxNamespace, appconsts.ShareVersionZero, true), + builder: mustNewBuilder(t, TxNamespace, ShareVersionZero, true), data: nil, want: true, }, { name: "first compact share not empty", - builder: mustNewBuilder(t, appns.TxNamespace, appconsts.ShareVersionZero, true), + builder: mustNewBuilder(t, TxNamespace, ShareVersionZero, true), data: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, want: false, }, { name: "first sparse share empty", - builder: mustNewBuilder(t, ns1, appconsts.ShareVersionZero, true), + builder: mustNewBuilder(t, ns1, ShareVersionZero, true), data: nil, want: true, }, { name: "first sparse share not empty", - builder: mustNewBuilder(t, ns1, appconsts.ShareVersionZero, true), + builder: mustNewBuilder(t, ns1, ShareVersionZero, true), data: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, want: false, }, { name: "continues compact share empty", - builder: mustNewBuilder(t, appns.TxNamespace, appconsts.ShareVersionZero, false), + builder: mustNewBuilder(t, TxNamespace, ShareVersionZero, false), data: nil, want: true, }, { name: "continues compact share not empty", - builder: mustNewBuilder(t, appns.TxNamespace, appconsts.ShareVersionZero, false), + builder: mustNewBuilder(t, TxNamespace, ShareVersionZero, false), data: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, want: false, }, { name: "continues sparse share not empty", - builder: mustNewBuilder(t, ns1, appconsts.ShareVersionZero, false), + builder: mustNewBuilder(t, ns1, ShareVersionZero, false), data: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, want: false, }, { name: "continues sparse share empty", - builder: mustNewBuilder(t, ns1, appconsts.ShareVersionZero, false), + builder: mustNewBuilder(t, ns1, ShareVersionZero, false), data: nil, want: true, }, @@ -86,7 +84,7 @@ func TestShareBuilderWriteSequenceLen(t *testing.T) { wantLen uint32 wantErr bool } - ns1 := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) + ns1 := MustNewV0Namespace(bytes.Repeat([]byte{1}, NamespaceVersionZeroIDSize)) testCases := []testCase{ { @@ -109,7 +107,7 @@ func TestShareBuilderWriteSequenceLen(t *testing.T) { }, { name: "compact share", - builder: mustNewBuilder(t, appns.TxNamespace, 1, true), + builder: mustNewBuilder(t, TxNamespace, 1, true), wantLen: 10, wantErr: false, }, @@ -153,61 +151,61 @@ func TestShareBuilderAddData(t *testing.T) { data []byte // input data want []byte } - ns1 := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) + ns1 := MustNewV0Namespace(bytes.Repeat([]byte{1}, NamespaceVersionZeroIDSize)) testCases := []testCase{ { name: "small share", - builder: mustNewBuilder(t, ns1, appconsts.ShareVersionZero, true), + builder: mustNewBuilder(t, ns1, ShareVersionZero, true), data: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, want: nil, }, { name: "exact fit first compact share", - builder: mustNewBuilder(t, appns.TxNamespace, appconsts.ShareVersionZero, true), - data: bytes.Repeat([]byte{1}, appconsts.ShareSize-appconsts.NamespaceSize-appconsts.ShareInfoBytes-appconsts.CompactShareReservedBytes-appconsts.SequenceLenBytes), + builder: mustNewBuilder(t, TxNamespace, ShareVersionZero, true), + data: bytes.Repeat([]byte{1}, ShareSize-NamespaceSize-ShareInfoBytes-CompactShareReservedBytes-SequenceLenBytes), want: nil, }, { name: "exact fit first sparse share", - builder: mustNewBuilder(t, ns1, appconsts.ShareVersionZero, true), - data: bytes.Repeat([]byte{1}, appconsts.ShareSize-appconsts.NamespaceSize-appconsts.SequenceLenBytes-1 /*1 = info byte*/), + builder: mustNewBuilder(t, ns1, ShareVersionZero, true), + data: bytes.Repeat([]byte{1}, ShareSize-NamespaceSize-SequenceLenBytes-1 /*1 = info byte*/), want: nil, }, { name: "exact fit continues compact share", - builder: mustNewBuilder(t, appns.TxNamespace, appconsts.ShareVersionZero, false), - data: bytes.Repeat([]byte{1}, appconsts.ShareSize-appconsts.NamespaceSize-appconsts.CompactShareReservedBytes-1 /*1 = info byte*/), + builder: mustNewBuilder(t, TxNamespace, ShareVersionZero, false), + data: bytes.Repeat([]byte{1}, ShareSize-NamespaceSize-CompactShareReservedBytes-1 /*1 = info byte*/), want: nil, }, { name: "exact fit continues sparse share", - builder: mustNewBuilder(t, ns1, appconsts.ShareVersionZero, false), - data: bytes.Repeat([]byte{1}, appconsts.ShareSize-appconsts.NamespaceSize-1 /*1 = info byte*/), + builder: mustNewBuilder(t, ns1, ShareVersionZero, false), + data: bytes.Repeat([]byte{1}, ShareSize-NamespaceSize-1 /*1 = info byte*/), want: nil, }, { name: "oversize first compact share", - builder: mustNewBuilder(t, appns.TxNamespace, appconsts.ShareVersionZero, true), - data: bytes.Repeat([]byte{1}, 1 /*1 extra byte*/ +appconsts.ShareSize-appconsts.NamespaceSize-appconsts.CompactShareReservedBytes-appconsts.SequenceLenBytes-1 /*1 = info byte*/), + builder: mustNewBuilder(t, TxNamespace, ShareVersionZero, true), + data: bytes.Repeat([]byte{1}, 1 /*1 extra byte*/ +ShareSize-NamespaceSize-CompactShareReservedBytes-SequenceLenBytes-1 /*1 = info byte*/), want: []byte{1}, }, { name: "oversize first sparse share", - builder: mustNewBuilder(t, ns1, appconsts.ShareVersionZero, true), - data: bytes.Repeat([]byte{1}, 1 /*1 extra byte*/ +appconsts.ShareSize-appconsts.NamespaceSize-appconsts.SequenceLenBytes-1 /*1 = info byte*/), + builder: mustNewBuilder(t, ns1, ShareVersionZero, true), + data: bytes.Repeat([]byte{1}, 1 /*1 extra byte*/ +ShareSize-NamespaceSize-SequenceLenBytes-1 /*1 = info byte*/), want: []byte{1}, }, { name: "oversize continues compact share", - builder: mustNewBuilder(t, appns.TxNamespace, appconsts.ShareVersionZero, false), - data: bytes.Repeat([]byte{1}, 1 /*1 extra byte*/ +appconsts.ShareSize-appconsts.NamespaceSize-appconsts.CompactShareReservedBytes-1 /*1 = info byte*/), + builder: mustNewBuilder(t, TxNamespace, ShareVersionZero, false), + data: bytes.Repeat([]byte{1}, 1 /*1 extra byte*/ +ShareSize-NamespaceSize-CompactShareReservedBytes-1 /*1 = info byte*/), want: []byte{1}, }, { name: "oversize continues sparse share", - builder: mustNewBuilder(t, ns1, appconsts.ShareVersionZero, false), - data: bytes.Repeat([]byte{1}, 1 /*1 extra byte*/ +appconsts.ShareSize-appconsts.NamespaceSize-1 /*1 = info byte*/), + builder: mustNewBuilder(t, ns1, ShareVersionZero, false), + data: bytes.Repeat([]byte{1}, 1 /*1 extra byte*/ +ShareSize-NamespaceSize-1 /*1 = info byte*/), want: []byte{1}, }, } @@ -227,7 +225,7 @@ func TestShareBuilderImportRawData(t *testing.T) { want []byte wantErr bool } - ns1 := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) + ns1 := MustNewV0Namespace(bytes.Repeat([]byte{1}, NamespaceVersionZeroIDSize)) firstSparseShare := append(ns1.Bytes(), []byte{ 1, // info byte @@ -240,14 +238,14 @@ func TestShareBuilderImportRawData(t *testing.T) { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // data }...) - firstCompactShare := append(appns.TxNamespace.Bytes(), []byte{ + firstCompactShare := append(TxNamespace.Bytes(), []byte{ 1, // info byte 0, 0, 0, 10, // sequence len 0, 0, 0, 15, // reserved bytes 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // data }...) - continuationCompactShare := append(appns.TxNamespace.Bytes(), []byte{ + continuationCompactShare := append(TxNamespace.Bytes(), []byte{ 0, // info byte 0, 0, 0, 0, // reserved bytes 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // data @@ -313,7 +311,7 @@ func TestShareBuilderImportRawData(t *testing.T) { } // mustNewBuilder returns a new builder with the given parameters. It fails the test if an error is encountered. -func mustNewBuilder(t *testing.T, ns appns.Namespace, shareVersion uint8, isFirstShare bool) *Builder { +func mustNewBuilder(t *testing.T, ns Namespace, shareVersion uint8, isFirstShare bool) *Builder { b, err := NewBuilder(ns, shareVersion, isFirstShare) require.NoError(t, err) return b diff --git a/pkg/shares/share_sequence.go b/shares/share_sequence.go similarity index 87% rename from pkg/shares/share_sequence.go rename to shares/share_sequence.go index 939f807ed4..bd08f78fe5 100644 --- a/pkg/shares/share_sequence.go +++ b/shares/share_sequence.go @@ -2,16 +2,13 @@ package shares import ( "fmt" - - "github.com/celestiaorg/celestia-app/pkg/appconsts" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" ) // ShareSequence represents a contiguous sequence of shares that are part of the // same namespace and blob. For compact shares, one share sequence exists per // reserved namespace. For sparse shares, one share sequence exists per blob. type ShareSequence struct { - Namespace appns.Namespace + Namespace Namespace Shares []Share } @@ -108,14 +105,14 @@ func CompactSharesNeeded(sequenceLen int) (sharesNeeded int) { return 0 } - if sequenceLen < appconsts.FirstCompactShareContentSize { + if sequenceLen < FirstCompactShareContentSize { return 1 } - bytesAvailable := appconsts.FirstCompactShareContentSize + bytesAvailable := FirstCompactShareContentSize sharesNeeded++ for bytesAvailable < sequenceLen { - bytesAvailable += appconsts.ContinuationCompactShareContentSize + bytesAvailable += ContinuationCompactShareContentSize sharesNeeded++ } return sharesNeeded @@ -128,14 +125,14 @@ func SparseSharesNeeded(sequenceLen uint32) (sharesNeeded int) { return 0 } - if sequenceLen < appconsts.FirstSparseShareContentSize { + if sequenceLen < FirstSparseShareContentSize { return 1 } - bytesAvailable := appconsts.FirstSparseShareContentSize + bytesAvailable := FirstSparseShareContentSize sharesNeeded++ for uint32(bytesAvailable) < sequenceLen { - bytesAvailable += appconsts.ContinuationSparseShareContentSize + bytesAvailable += ContinuationSparseShareContentSize sharesNeeded++ } return sharesNeeded diff --git a/pkg/shares/share_sequence_test.go b/shares/share_sequence_test.go similarity index 69% rename from pkg/shares/share_sequence_test.go rename to shares/share_sequence_test.go index 82a781e765..a7920f2b33 100644 --- a/pkg/shares/share_sequence_test.go +++ b/shares/share_sequence_test.go @@ -5,9 +5,6 @@ import ( "encoding/binary" "testing" - "github.com/celestiaorg/celestia-app/pkg/appconsts" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" - "github.com/celestiaorg/celestia-app/test/util/testfactory" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -19,13 +16,13 @@ func TestShareSequenceRawData(t *testing.T) { want []byte wantErr bool } - blobNamespace := appns.RandomBlobNamespace() + blobNamespace := RandomBlobNamespace() testCases := []testCase{ { name: "empty share sequence", shareSequence: ShareSequence{ - Namespace: appns.TxNamespace, + Namespace: TxNamespace, Shares: []Share{}, }, want: []byte{}, @@ -34,7 +31,7 @@ func TestShareSequenceRawData(t *testing.T) { { name: "one empty share", shareSequence: ShareSequence{ - Namespace: appns.TxNamespace, + Namespace: TxNamespace, Shares: []Share{ shareWithData(blobNamespace, true, 0, []byte{}), }, @@ -45,7 +42,7 @@ func TestShareSequenceRawData(t *testing.T) { { name: "one share with one byte", shareSequence: ShareSequence{ - Namespace: appns.TxNamespace, + Namespace: TxNamespace, Shares: []Share{ shareWithData(blobNamespace, true, 1, []byte{0x0f}), }, @@ -56,13 +53,13 @@ func TestShareSequenceRawData(t *testing.T) { { name: "removes padding from last share", shareSequence: ShareSequence{ - Namespace: appns.TxNamespace, + Namespace: TxNamespace, Shares: []Share{ - shareWithData(blobNamespace, true, appconsts.FirstSparseShareContentSize+1, bytes.Repeat([]byte{0xf}, appconsts.FirstSparseShareContentSize)), + shareWithData(blobNamespace, true, FirstSparseShareContentSize+1, bytes.Repeat([]byte{0xf}, FirstSparseShareContentSize)), shareWithData(blobNamespace, false, 0, []byte{0x0f}), }, }, - want: bytes.Repeat([]byte{0xf}, appconsts.FirstSparseShareContentSize+1), + want: bytes.Repeat([]byte{0xf}, FirstSparseShareContentSize+1), wantErr: false, }, } @@ -88,10 +85,10 @@ func TestCompactSharesNeeded(t *testing.T) { {0, 0}, {1, 1}, {2, 1}, - {appconsts.FirstCompactShareContentSize, 1}, - {appconsts.FirstCompactShareContentSize + 1, 2}, - {appconsts.FirstCompactShareContentSize + appconsts.ContinuationCompactShareContentSize, 2}, - {appconsts.FirstCompactShareContentSize + appconsts.ContinuationCompactShareContentSize*100, 101}, + {FirstCompactShareContentSize, 1}, + {FirstCompactShareContentSize + 1, 2}, + {FirstCompactShareContentSize + ContinuationCompactShareContentSize, 2}, + {FirstCompactShareContentSize + ContinuationCompactShareContentSize*100, 101}, } for _, tc := range testCases { got := CompactSharesNeeded(tc.sequenceLen) @@ -108,11 +105,11 @@ func TestSparseSharesNeeded(t *testing.T) { {0, 0}, {1, 1}, {2, 1}, - {appconsts.FirstSparseShareContentSize, 1}, - {appconsts.FirstSparseShareContentSize + 1, 2}, - {appconsts.FirstSparseShareContentSize + appconsts.ContinuationSparseShareContentSize, 2}, - {appconsts.FirstSparseShareContentSize + appconsts.ContinuationCompactShareContentSize*2, 3}, - {appconsts.FirstSparseShareContentSize + appconsts.ContinuationCompactShareContentSize*99, 100}, + {FirstSparseShareContentSize, 1}, + {FirstSparseShareContentSize + 1, 2}, + {FirstSparseShareContentSize + ContinuationSparseShareContentSize, 2}, + {FirstSparseShareContentSize + ContinuationCompactShareContentSize*2, 3}, + {FirstSparseShareContentSize + ContinuationCompactShareContentSize*99, 100}, {1000, 3}, {10000, 21}, {100000, 208}, @@ -123,13 +120,13 @@ func TestSparseSharesNeeded(t *testing.T) { } } -func shareWithData(namespace appns.Namespace, isSequenceStart bool, sequenceLen uint32, data []byte) (rawShare Share) { - infoByte, _ := NewInfoByte(appconsts.ShareVersionZero, isSequenceStart) - rawShareBytes := make([]byte, 0, appconsts.ShareSize) +func shareWithData(namespace Namespace, isSequenceStart bool, sequenceLen uint32, data []byte) (rawShare Share) { + infoByte, _ := NewInfoByte(ShareVersionZero, isSequenceStart) + rawShareBytes := make([]byte, 0, ShareSize) rawShareBytes = append(rawShareBytes, namespace.Bytes()...) rawShareBytes = append(rawShareBytes, byte(infoByte)) if isSequenceStart { - sequenceLenBuf := make([]byte, appconsts.SequenceLenBytes) + sequenceLenBuf := make([]byte, SequenceLenBytes) binary.BigEndian.PutUint32(sequenceLenBuf, sequenceLen) rawShareBytes = append(rawShareBytes, sequenceLenBuf...) } @@ -146,12 +143,12 @@ func Test_validSequenceLen(t *testing.T) { } tailPadding := ShareSequence{ - Namespace: appns.TailPaddingNamespace, + Namespace: TailPaddingNamespace, Shares: []Share{TailPaddingShare()}, } - ns1 := appns.MustNewV0(bytes.Repeat([]byte{0x1}, appns.NamespaceVersionZeroIDSize)) - share, err := NamespacePaddingShare(ns1, appconsts.ShareVersionZero) + ns1 := MustNewV0Namespace(bytes.Repeat([]byte{0x1}, NamespaceVersionZeroIDSize)) + share, err := NamespacePaddingShare(ns1, ShareVersionZero) require.NoError(t, err) namespacePadding := ShareSequence{ Namespace: ns1, @@ -159,7 +156,7 @@ func Test_validSequenceLen(t *testing.T) { } reservedPadding := ShareSequence{ - Namespace: appns.PrimaryReservedPaddingNamespace, + Namespace: PrimaryReservedPaddingNamespace, Shares: []Share{ReservedPaddingShare()}, } @@ -216,8 +213,8 @@ func Test_validSequenceLen(t *testing.T) { } func generateValidShareSequence(t *testing.T) ShareSequence { - css := NewCompactShareSplitter(appns.TxNamespace, appconsts.ShareVersionZero) - txs := testfactory.GenerateRandomTxs(5, 200) + css := NewCompactShareSplitter(TxNamespace, ShareVersionZero) + txs := GenerateRandomTxs(5, 200) for _, tx := range txs { err := css.WriteTx(tx) require.NoError(t, err) @@ -226,7 +223,7 @@ func generateValidShareSequence(t *testing.T) ShareSequence { require.NoError(t, err) return ShareSequence{ - Namespace: appns.TxNamespace, + Namespace: TxNamespace, Shares: shares, } } @@ -238,7 +235,7 @@ func FuzzValidSequenceLen(f *testing.F) { t.Skip() } - ns, err := appns.From(rawNamespace) + ns, err := From(rawNamespace) if err != nil { t.Skip() } diff --git a/pkg/shares/share_splitting.go b/shares/share_splitting.go similarity index 52% rename from pkg/shares/share_splitting.go rename to shares/share_splitting.go index 70aba928cf..178c5661fd 100644 --- a/pkg/shares/share_splitting.go +++ b/shares/share_splitting.go @@ -3,9 +3,6 @@ package shares import ( "errors" - "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/blob" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" coretypes "github.com/tendermint/tendermint/types" "golang.org/x/exp/maps" ) @@ -19,33 +16,9 @@ var ( ) ) -// ExtractShareIndexes iterates over the transactions and extracts the share -// indexes from wrapped transactions. It returns nil if the transactions are -// from an old block that did not have share indexes in the wrapped txs. -func ExtractShareIndexes(txs coretypes.Txs) []uint32 { - var shareIndexes []uint32 - for _, rawTx := range txs { - if indexWrappedTxs, isIndexWrapped := coretypes.UnmarshalIndexWrapper(rawTx); isIndexWrapped { - // Since share index == 0 is invalid, it indicates that we are - // attempting to extract share indexes from txs that do not have any - // due to them being old. here we return nil to indicate that we are - // attempting to extract indexes from a block that doesn't support - // it. It checks for 0 because if there is a message in the block, - // then there must also be a tx, which will take up at least one - // share. - if len(indexWrappedTxs.ShareIndexes) == 0 { - return nil - } - shareIndexes = append(shareIndexes, indexWrappedTxs.ShareIndexes...) - } - } - - return shareIndexes -} - func SplitTxs(txs coretypes.Txs) (txShares []Share, pfbShares []Share, shareRanges map[coretypes.TxKey]Range, err error) { - txWriter := NewCompactShareSplitter(appns.TxNamespace, appconsts.ShareVersionZero) - pfbTxWriter := NewCompactShareSplitter(appns.PayForBlobNamespace, appconsts.ShareVersionZero) + txWriter := NewCompactShareSplitter(TxNamespace, ShareVersionZero) + pfbTxWriter := NewCompactShareSplitter(PayForBlobNamespace, ShareVersionZero) for _, tx := range txs { if _, isIndexWrapper := coretypes.UnmarshalIndexWrapper(tx); isIndexWrapper { @@ -74,7 +47,7 @@ func SplitTxs(txs coretypes.Txs) (txShares []Share, pfbShares []Share, shareRang } // SplitBlobs splits the provided blobs into shares. -func SplitBlobs(blobs ...*blob.Blob) ([]Share, error) { +func SplitBlobs(blobs ...*Blob) ([]Share, error) { writer := NewSparseShareSplitter() for _, blob := range blobs { if err := writer.Write(blob); err != nil { diff --git a/pkg/shares/share_splitting_test.go b/shares/share_splitting_test.go similarity index 93% rename from pkg/shares/share_splitting_test.go rename to shares/share_splitting_test.go index 950e3a91c4..89d0a8c3ef 100644 --- a/pkg/shares/share_splitting_test.go +++ b/shares/share_splitting_test.go @@ -5,8 +5,6 @@ import ( "reflect" "testing" - "github.com/celestiaorg/celestia-app/pkg/appconsts" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" coretypes "github.com/tendermint/tendermint/types" @@ -34,7 +32,7 @@ func TestSplitTxs_forTxShares(t *testing.T) { want: []Share{ padShare(Share{ data: append( - appns.TxNamespace.Bytes(), + TxNamespace.Bytes(), []byte{ 0x1, // info byte 0x0, 0x0, 0x0, 0x2, // 1 byte (unit) + 1 byte (unit length) = 2 bytes sequence length @@ -53,7 +51,7 @@ func TestSplitTxs_forTxShares(t *testing.T) { want: []Share{ padShare(Share{ data: append( - appns.TxNamespace.Bytes(), + TxNamespace.Bytes(), []byte{ 0x1, // info byte 0x0, 0x0, 0x0, 0x4, // 2 bytes (first transaction) + 2 bytes (second transaction) = 4 bytes sequence length @@ -74,7 +72,7 @@ func TestSplitTxs_forTxShares(t *testing.T) { want: []Share{ fillShare(Share{ data: append( - appns.TxNamespace.Bytes(), + TxNamespace.Bytes(), []byte{ 0x1, // info byte 0x0, 0x0, 0x2, 0x2, // 512 (unit) + 2 (unit length) = 514 sequence length @@ -88,7 +86,7 @@ func TestSplitTxs_forTxShares(t *testing.T) { padShare(Share{ data: append( append( - appns.TxNamespace.Bytes(), + TxNamespace.Bytes(), []byte{ 0x0, // info byte 0x0, 0x0, 0x0, 0x0, // reserved bytes @@ -106,7 +104,7 @@ func TestSplitTxs_forTxShares(t *testing.T) { want: []Share{ fillShare(Share{ data: append( - appns.TxNamespace.Bytes(), + TxNamespace.Bytes(), []byte{ 0x1, // info byte 0x0, 0x0, 0x2, 0x4, // 2 bytes (first transaction) + 514 bytes (second transaction) = 516 bytes sequence length @@ -122,7 +120,7 @@ func TestSplitTxs_forTxShares(t *testing.T) { padShare(Share{ data: append( append( - appns.TxNamespace.Bytes(), + TxNamespace.Bytes(), []byte{ 0x0, // info byte 0x0, 0x0, 0x0, 0x0, // reserved bytes @@ -140,7 +138,7 @@ func TestSplitTxs_forTxShares(t *testing.T) { want: []Share{ fillShare(Share{ data: append( - appns.TxNamespace.Bytes(), + TxNamespace.Bytes(), []byte{ 0x1, // info byte 0x0, 0x0, 0x2, 0x4, // 514 bytes (first transaction) + 2 bytes (second transaction) = 516 bytes sequence length @@ -153,7 +151,7 @@ func TestSplitTxs_forTxShares(t *testing.T) { ), padShare(Share{ data: append( - appns.TxNamespace.Bytes(), + TxNamespace.Bytes(), []byte{ 0x0, // info byte 0x0, 0x0, 0x0, 0x4a, // reserved bytes @@ -192,7 +190,7 @@ func TestSplitTxs(t *testing.T) { smallTx := coretypes.Tx{0xa} // spans one share smallTxShares := []Share{ padShare(Share{ - data: append(appns.TxNamespace.Bytes(), + data: append(TxNamespace.Bytes(), []byte{ 0x1, // info byte 0x0, 0x0, 0x0, 0x2, // 1 byte (unit) + 1 byte (unit length) = 2 bytes sequence length @@ -210,7 +208,7 @@ func TestSplitTxs(t *testing.T) { pfbTxShares := []Share{ padShare(Share{ data: append( - appns.PayForBlobNamespace.Bytes(), + PayForBlobNamespace.Bytes(), []uint8{ 0x1, // info byte 0x0, 0x0, 0x0, 13, // 1 byte (unit) + 1 byte (unit length) = 2 bytes sequence length @@ -223,10 +221,10 @@ func TestSplitTxs(t *testing.T) { ), } - largeTx := coretypes.Tx(bytes.Repeat([]byte{0xc}, appconsts.ShareSize)) // spans two shares + largeTx := coretypes.Tx(bytes.Repeat([]byte{0xc}, ShareSize)) // spans two shares largeTxShares := []Share{ fillShare(Share{ - data: append(appns.TxNamespace.Bytes(), + data: append(TxNamespace.Bytes(), []uint8{ 0x1, // info byte 0x0, 0x0, 0x2, 0x2, // 512 (unit) + 2 (unit length) = 514 sequence length @@ -239,7 +237,7 @@ func TestSplitTxs(t *testing.T) { padShare(Share{ data: append( append( - appns.TxNamespace.Bytes(), + TxNamespace.Bytes(), []uint8{ 0x0, // info byte 0x0, 0x0, 0x0, 0x0, // reserved bytes @@ -315,9 +313,9 @@ func padShare(share Share) (paddedShare Share) { } // fillShare returns a share filled with filler so that the share length -// is equal to appconsts.ShareSize. +// is equal to ShareSize. func fillShare(share Share, filler byte) (paddedShare Share) { - return Share{data: append(share.data, bytes.Repeat([]byte{filler}, appconsts.ShareSize-len(share.data))...)} + return Share{data: append(share.data, bytes.Repeat([]byte{filler}, ShareSize-len(share.data))...)} } func Test_mergeMaps(t *testing.T) { diff --git a/pkg/shares/shares.go b/shares/shares.go similarity index 86% rename from pkg/shares/shares.go rename to shares/shares.go index 93711cc639..5055ef1228 100644 --- a/pkg/shares/shares.go +++ b/shares/shares.go @@ -4,9 +4,6 @@ import ( "bytes" "encoding/binary" "fmt" - - "github.com/celestiaorg/celestia-app/pkg/appconsts" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" ) // Share contains the raw share data (including namespace ID). @@ -14,19 +11,19 @@ type Share struct { data []byte } -func (s *Share) Namespace() (appns.Namespace, error) { - if len(s.data) < appns.NamespaceSize { +func (s *Share) Namespace() (Namespace, error) { + if len(s.data) < NamespaceSize { panic(fmt.Sprintf("share %s is too short to contain a namespace", s)) } - return appns.From(s.data[:appns.NamespaceSize]) + return From(s.data[:NamespaceSize]) } func (s *Share) InfoByte() (InfoByte, error) { - if len(s.data) < appns.NamespaceSize+appconsts.ShareInfoBytes { + if len(s.data) < NamespaceSize+ShareInfoBytes { return 0, fmt.Errorf("share %s is too short to contain an info byte", s) } // the info byte is the first byte after the namespace - unparsed := s.data[appns.NamespaceSize] + unparsed := s.data[NamespaceSize] return ParseInfoByte(unparsed) } @@ -42,8 +39,8 @@ func (s *Share) Validate() error { } func validateSize(data []byte) error { - if len(data) != appconsts.ShareSize { - return fmt.Errorf("share data must be %d bytes, got %d", appconsts.ShareSize, len(data)) + if len(data) != ShareSize { + return fmt.Errorf("share data must be %d bytes, got %d", ShareSize, len(data)) } return nil } @@ -102,8 +99,8 @@ func (s *Share) SequenceLen() (sequenceLen uint32, err error) { return 0, nil } - start := appconsts.NamespaceSize + appconsts.ShareInfoBytes - end := start + appconsts.SequenceLenBytes + start := NamespaceSize + ShareInfoBytes + end := start + SequenceLenBytes if len(s.data) < end { return 0, fmt.Errorf("share %s with length %d is too short to contain a sequence length", s, len(s.data)) @@ -181,12 +178,12 @@ func (s *Share) rawDataStartIndex() int { panic(err) } - index := appconsts.NamespaceSize + appconsts.ShareInfoBytes + index := NamespaceSize + ShareInfoBytes if isStart { - index += appconsts.SequenceLenBytes + index += SequenceLenBytes } if isCompact { - index += appconsts.CompactShareReservedBytes + index += CompactShareReservedBytes } return index } @@ -221,13 +218,13 @@ func (s *Share) rawDataStartIndexUsingReserved() (int, error) { return 0, err } - index := appconsts.NamespaceSize + appconsts.ShareInfoBytes + index := NamespaceSize + ShareInfoBytes if isStart { - index += appconsts.SequenceLenBytes + index += SequenceLenBytes } if isCompact { - reservedBytes, err := ParseReservedBytes(s.data[index : index+appconsts.CompactShareReservedBytes]) + reservedBytes, err := ParseReservedBytes(s.data[index : index+CompactShareReservedBytes]) if err != nil { return 0, err } diff --git a/pkg/shares/shares_test.go b/shares/shares_test.go similarity index 82% rename from pkg/shares/shares_test.go rename to shares/shares_test.go index cc7ee1bb19..bc8f2c0948 100644 --- a/pkg/shares/shares_test.go +++ b/shares/shares_test.go @@ -4,8 +4,6 @@ import ( "bytes" "testing" - "github.com/celestiaorg/celestia-app/pkg/appconsts" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -17,7 +15,7 @@ func TestSequenceLen(t *testing.T) { wantLen uint32 wantErr bool } - sparseNamespaceID := bytes.Repeat([]byte{1}, appconsts.NamespaceSize) + sparseNamespaceID := bytes.Repeat([]byte{1}, NamespaceSize) firstShare := append(sparseNamespaceID, []byte{ 1, // info byte @@ -33,13 +31,13 @@ func TestSequenceLen(t *testing.T) { []byte{ 0, // info byte }...) - compactShare := append(appns.TxNamespace.Bytes(), + compactShare := append(TxNamespace.Bytes(), []byte{ 1, // info byte 0, 0, 0, 10, // sequence len }...) - noInfoByte := appns.TxNamespace.Bytes() - noSequenceLen := append(appns.TxNamespace.Bytes(), + noInfoByte := TxNamespace.Bytes() + noSequenceLen := append(TxNamespace.Bytes(), []byte{ 1, // info byte }...) @@ -104,7 +102,7 @@ func TestRawData(t *testing.T) { want []byte wantErr bool } - sparseNamespaceID := appns.MustNewV0(bytes.Repeat([]byte{0x1}, appns.NamespaceVersionZeroIDSize)) + sparseNamespaceID := MustNewV0Namespace(bytes.Repeat([]byte{0x1}, NamespaceVersionZeroIDSize)) firstSparseShare := append( sparseNamespaceID.Bytes(), []byte{ @@ -118,24 +116,24 @@ func TestRawData(t *testing.T) { 0, // info byte 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // data }...) - firstCompactShare := append(appns.TxNamespace.Bytes(), + firstCompactShare := append(TxNamespace.Bytes(), []byte{ 1, // info byte 0, 0, 0, 10, // sequence len 0, 0, 0, 15, // reserved bytes 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // data }...) - continuationCompactShare := append(appns.TxNamespace.Bytes(), + continuationCompactShare := append(TxNamespace.Bytes(), []byte{ 0, // info byte 0, 0, 0, 0, // reserved bytes 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // data }...) - noSequenceLen := append(appns.TxNamespace.Bytes(), + noSequenceLen := append(TxNamespace.Bytes(), []byte{ 1, // info byte }...) - notEnoughSequenceLenBytes := append(appns.TxNamespace.Bytes(), + notEnoughSequenceLenBytes := append(TxNamespace.Bytes(), []byte{ 1, // info byte 0, 0, 10, // sequence len @@ -192,10 +190,10 @@ func TestIsCompactShare(t *testing.T) { want bool } - ns1 := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) - txShare, _ := zeroPadIfNecessary(appns.TxNamespace.Bytes(), appconsts.ShareSize) - pfbTxShare, _ := zeroPadIfNecessary(appns.PayForBlobNamespace.Bytes(), appconsts.ShareSize) - blobShare, _ := zeroPadIfNecessary(ns1.Bytes(), appconsts.ShareSize) + ns1 := MustNewV0Namespace(bytes.Repeat([]byte{1}, NamespaceVersionZeroIDSize)) + txShare, _ := zeroPadIfNecessary(TxNamespace.Bytes(), ShareSize) + pfbTxShare, _ := zeroPadIfNecessary(PayForBlobNamespace.Bytes(), ShareSize) + blobShare, _ := zeroPadIfNecessary(ns1.Bytes(), ShareSize) testCases := []testCase{ { @@ -239,9 +237,9 @@ func TestIsPadding(t *testing.T) { 0xff, // data }..., ), - appconsts.ShareSize) + ShareSize) - nsPadding, err := NamespacePaddingShare(ns1, appconsts.ShareVersionZero) + nsPadding, err := NamespacePaddingShare(ns1, ShareVersionZero) require.NoError(t, err) testCases := []testCase{ diff --git a/pkg/shares/sparse_shares_test.go b/shares/sparse_shares_test.go similarity index 70% rename from pkg/shares/sparse_shares_test.go rename to shares/sparse_shares_test.go index 8da8a82129..b703eb8fc6 100644 --- a/pkg/shares/sparse_shares_test.go +++ b/shares/sparse_shares_test.go @@ -3,20 +3,17 @@ package shares import ( "testing" - "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/blob" - "github.com/celestiaorg/celestia-app/test/util/testfactory" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestSparseShareContainsInfoByte(t *testing.T) { - blob := testfactory.GenerateRandomBlobOfShareCount(4) + blob := GenerateRandomBlobOfShareCount(4) - sequenceStartInfoByte, err := NewInfoByte(appconsts.ShareVersionZero, true) + sequenceStartInfoByte, err := NewInfoByte(ShareVersionZero, true) require.NoError(t, err) - sequenceContinuationInfoByte, err := NewInfoByte(appconsts.ShareVersionZero, false) + sequenceContinuationInfoByte, err := NewInfoByte(ShareVersionZero, false) require.NoError(t, err) type testCase struct { @@ -53,23 +50,23 @@ func TestSparseShareContainsInfoByte(t *testing.T) { func TestSparseShareSplitterCount(t *testing.T) { type testCase struct { name string - blob *blob.Blob + blob *Blob expected int } testCases := []testCase{ { name: "one share", - blob: testfactory.GenerateRandomBlobOfShareCount(1), + blob: GenerateRandomBlobOfShareCount(1), expected: 1, }, { name: "two shares", - blob: testfactory.GenerateRandomBlobOfShareCount(2), + blob: GenerateRandomBlobOfShareCount(2), expected: 2, }, { name: "ten shares", - blob: testfactory.GenerateRandomBlobOfShareCount(10), + blob: GenerateRandomBlobOfShareCount(10), expected: 10, }, } diff --git a/pkg/shares/split_compact_shares.go b/shares/split_compact_shares.go similarity index 92% rename from pkg/shares/split_compact_shares.go rename to shares/split_compact_shares.go index 727fa57b06..de6d678bcf 100644 --- a/pkg/shares/split_compact_shares.go +++ b/shares/split_compact_shares.go @@ -4,8 +4,6 @@ import ( "encoding/binary" "fmt" - "github.com/celestiaorg/celestia-app/pkg/appconsts" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" coretypes "github.com/tendermint/tendermint/types" ) @@ -16,7 +14,7 @@ type CompactShareSplitter struct { shares []Share // pendingShare Share shareBuilder *Builder - namespace appns.Namespace + namespace Namespace done bool shareVersion uint8 // shareRanges is a map from a transaction key to the range of shares it @@ -28,7 +26,7 @@ type CompactShareSplitter struct { // NewCompactShareSplitter returns a CompactShareSplitter using the provided // namespace and shareVersion. -func NewCompactShareSplitter(ns appns.Namespace, shareVersion uint8) *CompactShareSplitter { +func NewCompactShareSplitter(ns Namespace, shareVersion uint8) *CompactShareSplitter { sb, err := NewBuilder(ns, shareVersion, true) if err != nil { panic(err) @@ -193,12 +191,12 @@ func (css *CompactShareSplitter) sequenceLen(bytesOfPadding int) uint32 { return 0 } if len(css.shares) == 1 { - return uint32(appconsts.FirstCompactShareContentSize) - uint32(bytesOfPadding) + return uint32(FirstCompactShareContentSize) - uint32(bytesOfPadding) } continuationSharesCount := len(css.shares) - 1 - continuationSharesSequenceLen := continuationSharesCount * appconsts.ContinuationCompactShareContentSize - return uint32(appconsts.FirstCompactShareContentSize + continuationSharesSequenceLen - bytesOfPadding) + continuationSharesSequenceLen := continuationSharesCount * ContinuationCompactShareContentSize + return uint32(FirstCompactShareContentSize + continuationSharesSequenceLen - bytesOfPadding) } // isEmpty returns whether this compact share splitter is empty. diff --git a/pkg/shares/split_compact_shares_test.go b/shares/split_compact_shares_test.go similarity index 76% rename from pkg/shares/split_compact_shares_test.go rename to shares/split_compact_shares_test.go index ca4bd7a05f..82b92dc7d3 100644 --- a/pkg/shares/split_compact_shares_test.go +++ b/shares/split_compact_shares_test.go @@ -4,8 +4,6 @@ import ( "bytes" "testing" - "github.com/celestiaorg/celestia-app/pkg/appconsts" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" coretypes "github.com/tendermint/tendermint/types" @@ -21,13 +19,13 @@ func TestCount(t *testing.T) { {transactions: []coretypes.Tx{[]byte{0}}, wantShareCount: 1}, {transactions: []coretypes.Tx{bytes.Repeat([]byte{1}, 100)}, wantShareCount: 1}, // Test with 1 byte over 1 share - {transactions: []coretypes.Tx{bytes.Repeat([]byte{1}, RawTxSize(appconsts.FirstCompactShareContentSize+1))}, wantShareCount: 2}, + {transactions: []coretypes.Tx{bytes.Repeat([]byte{1}, RawTxSize(FirstCompactShareContentSize+1))}, wantShareCount: 2}, {transactions: []coretypes.Tx{generateTx(1)}, wantShareCount: 1}, {transactions: []coretypes.Tx{generateTx(2)}, wantShareCount: 2}, {transactions: []coretypes.Tx{generateTx(20)}, wantShareCount: 20}, } for _, tc := range testCases { - css := NewCompactShareSplitter(appns.TxNamespace, appconsts.ShareVersionZero) + css := NewCompactShareSplitter(TxNamespace, ShareVersionZero) for _, transaction := range tc.transactions { err := css.WriteTx(transaction) require.NoError(t, err) @@ -38,7 +36,7 @@ func TestCount(t *testing.T) { } } - css := NewCompactShareSplitter(appns.TxNamespace, appconsts.ShareVersionZero) + css := NewCompactShareSplitter(TxNamespace, ShareVersionZero) assert.Equal(t, 0, css.Count()) } @@ -49,9 +47,9 @@ func generateTx(numShares int) coretypes.Tx { return coretypes.Tx{} } if numShares == 1 { - return bytes.Repeat([]byte{1}, RawTxSize(appconsts.FirstCompactShareContentSize)) + return bytes.Repeat([]byte{1}, RawTxSize(FirstCompactShareContentSize)) } - return bytes.Repeat([]byte{2}, RawTxSize(appconsts.FirstCompactShareContentSize+(numShares-1)*appconsts.ContinuationCompactShareContentSize)) + return bytes.Repeat([]byte{2}, RawTxSize(FirstCompactShareContentSize+(numShares-1)*ContinuationCompactShareContentSize)) } func TestExport_write(t *testing.T) { @@ -63,7 +61,7 @@ func TestExport_write(t *testing.T) { oneShare, _ := zeroPadIfNecessary( append( - appns.TxNamespace.Bytes(), + TxNamespace.Bytes(), []byte{ 0x1, // info byte 0x0, 0x0, 0x0, 0x1, // sequence len @@ -71,10 +69,10 @@ func TestExport_write(t *testing.T) { 0xf, // data }..., ), - appconsts.ShareSize) + ShareSize) firstShare := fillShare(Share{data: append( - appns.TxNamespace.Bytes(), + TxNamespace.Bytes(), []byte{ 0x1, // info byte 0x0, 0x0, 0x2, 0x0, // sequence len @@ -84,15 +82,15 @@ func TestExport_write(t *testing.T) { continuationShare, _ := zeroPadIfNecessary( append( - appns.TxNamespace.Bytes(), + TxNamespace.Bytes(), append( []byte{ 0x0, // info byte 0x0, 0x0, 0x0, 0x0, // reserved bytes - }, bytes.Repeat([]byte{0xf}, appconsts.NamespaceSize+appconsts.ShareInfoBytes+appconsts.SequenceLenBytes+appconsts.CompactShareReservedBytes)..., // data + }, bytes.Repeat([]byte{0xf}, NamespaceSize+ShareInfoBytes+SequenceLenBytes+CompactShareReservedBytes)..., // data )..., ), - appconsts.ShareSize) + ShareSize) testCases := []testCase{ { @@ -118,7 +116,7 @@ func TestExport_write(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - css := NewCompactShareSplitter(appns.TxNamespace, appconsts.ShareVersionZero) + css := NewCompactShareSplitter(TxNamespace, ShareVersionZero) for _, bytes := range tc.writeBytes { err := css.write(bytes) require.NoError(t, err) @@ -160,26 +158,26 @@ func TestWriteAndExportIdempotence(t *testing.T) { { name: "two txs that occupy exactly two shares", txs: []coretypes.Tx{ - bytes.Repeat([]byte{0xf}, RawTxSize(appconsts.FirstCompactShareContentSize)), - bytes.Repeat([]byte{0xf}, RawTxSize(appconsts.ContinuationCompactShareContentSize)), + bytes.Repeat([]byte{0xf}, RawTxSize(FirstCompactShareContentSize)), + bytes.Repeat([]byte{0xf}, RawTxSize(ContinuationCompactShareContentSize)), }, wantLen: 2, }, { name: "three txs that occupy exactly three shares", txs: []coretypes.Tx{ - bytes.Repeat([]byte{0xf}, RawTxSize(appconsts.FirstCompactShareContentSize)), - bytes.Repeat([]byte{0xf}, RawTxSize(appconsts.ContinuationCompactShareContentSize)), - bytes.Repeat([]byte{0xf}, RawTxSize(appconsts.ContinuationCompactShareContentSize)), + bytes.Repeat([]byte{0xf}, RawTxSize(FirstCompactShareContentSize)), + bytes.Repeat([]byte{0xf}, RawTxSize(ContinuationCompactShareContentSize)), + bytes.Repeat([]byte{0xf}, RawTxSize(ContinuationCompactShareContentSize)), }, wantLen: 3, }, { name: "four txs that occupy three full shares and one partial share", txs: []coretypes.Tx{ - bytes.Repeat([]byte{0xf}, RawTxSize(appconsts.FirstCompactShareContentSize)), - bytes.Repeat([]byte{0xf}, RawTxSize(appconsts.ContinuationCompactShareContentSize)), - bytes.Repeat([]byte{0xf}, RawTxSize(appconsts.ContinuationCompactShareContentSize)), + bytes.Repeat([]byte{0xf}, RawTxSize(FirstCompactShareContentSize)), + bytes.Repeat([]byte{0xf}, RawTxSize(ContinuationCompactShareContentSize)), + bytes.Repeat([]byte{0xf}, RawTxSize(ContinuationCompactShareContentSize)), []byte{0xf}, }, wantLen: 4, @@ -187,7 +185,7 @@ func TestWriteAndExportIdempotence(t *testing.T) { } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - css := NewCompactShareSplitter(appns.TxNamespace, appconsts.ShareVersionZero) + css := NewCompactShareSplitter(TxNamespace, ShareVersionZero) for _, tx := range tc.txs { err := css.WriteTx(tx) @@ -213,8 +211,8 @@ func TestExport(t *testing.T) { txOne := coretypes.Tx{0x1} txTwo := coretypes.Tx(bytes.Repeat([]byte{2}, 600)) txThree := coretypes.Tx(bytes.Repeat([]byte{3}, 1000)) - exactlyOneShare := coretypes.Tx(bytes.Repeat([]byte{4}, RawTxSize(appconsts.FirstCompactShareContentSize))) - exactlyTwoShares := coretypes.Tx(bytes.Repeat([]byte{5}, RawTxSize(appconsts.FirstCompactShareContentSize+appconsts.ContinuationCompactShareContentSize))) + exactlyOneShare := coretypes.Tx(bytes.Repeat([]byte{4}, RawTxSize(FirstCompactShareContentSize))) + exactlyTwoShares := coretypes.Tx(bytes.Repeat([]byte{5}, RawTxSize(FirstCompactShareContentSize+ContinuationCompactShareContentSize))) testCases := []testCase{ { @@ -319,7 +317,7 @@ func TestExport(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - css := NewCompactShareSplitter(appns.TxNamespace, appconsts.ShareVersionZero) + css := NewCompactShareSplitter(TxNamespace, ShareVersionZero) for _, tx := range tc.txs { err := css.WriteTx(tx) @@ -333,12 +331,12 @@ func TestExport(t *testing.T) { } func TestWriteAfterExport(t *testing.T) { - a := bytes.Repeat([]byte{0xf}, RawTxSize(appconsts.FirstCompactShareContentSize)) - b := bytes.Repeat([]byte{0xf}, RawTxSize(appconsts.ContinuationCompactShareContentSize*2)) - c := bytes.Repeat([]byte{0xf}, RawTxSize(appconsts.ContinuationCompactShareContentSize)) + a := bytes.Repeat([]byte{0xf}, RawTxSize(FirstCompactShareContentSize)) + b := bytes.Repeat([]byte{0xf}, RawTxSize(ContinuationCompactShareContentSize*2)) + c := bytes.Repeat([]byte{0xf}, RawTxSize(ContinuationCompactShareContentSize)) d := []byte{0xf} - css := NewCompactShareSplitter(appns.TxNamespace, appconsts.ShareVersionZero) + css := NewCompactShareSplitter(TxNamespace, ShareVersionZero) shares, err := css.Export() require.NoError(t, err) assert.Equal(t, 0, len(shares)) diff --git a/pkg/shares/split_sparse_shares.go b/shares/split_sparse_shares.go similarity index 91% rename from pkg/shares/split_sparse_shares.go rename to shares/split_sparse_shares.go index 2e48eaf0ab..0175944db1 100644 --- a/pkg/shares/split_sparse_shares.go +++ b/shares/split_sparse_shares.go @@ -4,8 +4,6 @@ import ( "errors" "fmt" - "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/blob" "golang.org/x/exp/slices" ) @@ -22,12 +20,12 @@ func NewSparseShareSplitter() *SparseShareSplitter { // Write writes the provided blob to this sparse share splitter. It returns an // error or nil if no error is encountered. -func (sss *SparseShareSplitter) Write(blob *blob.Blob) error { +func (sss *SparseShareSplitter) Write(blob *Blob) error { if err := blob.Validate(); err != nil { return err } - if !slices.Contains(appconsts.SupportedShareVersions, uint8(blob.ShareVersion)) { + if !slices.Contains(SupportedShareVersions, uint8(blob.ShareVersion)) { return fmt.Errorf("unsupported share version: %d", blob.ShareVersion) } diff --git a/pkg/shares/split_sparse_shares_test.go b/shares/split_sparse_shares_test.go similarity index 55% rename from pkg/shares/split_sparse_shares_test.go rename to shares/split_sparse_shares_test.go index 90509218f0..edc2e29dfa 100644 --- a/pkg/shares/split_sparse_shares_test.go +++ b/shares/split_sparse_shares_test.go @@ -4,20 +4,17 @@ import ( "bytes" "testing" - "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/blob" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" "github.com/stretchr/testify/assert" ) // TestSparseShareSplitter tests that the spare share splitter can split blobs // with different namespaces. func TestSparseShareSplitter(t *testing.T) { - ns1 := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) - ns2 := appns.MustNewV0(bytes.Repeat([]byte{2}, appns.NamespaceVersionZeroIDSize)) + ns1 := MustNewV0Namespace(bytes.Repeat([]byte{1}, NamespaceVersionZeroIDSize)) + ns2 := MustNewV0Namespace(bytes.Repeat([]byte{2}, NamespaceVersionZeroIDSize)) - blob1 := blob.New(ns1, []byte("data1"), appconsts.ShareVersionZero) - blob2 := blob.New(ns2, []byte("data2"), appconsts.ShareVersionZero) + blob1 := NewBlob(ns1, []byte("data1"), ShareVersionZero) + blob2 := NewBlob(ns2, []byte("data2"), ShareVersionZero) sss := NewSparseShareSplitter() err := sss.Write(blob1) @@ -31,8 +28,8 @@ func TestSparseShareSplitter(t *testing.T) { } func TestWriteNamespacePaddingShares(t *testing.T) { - ns1 := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) - blob1 := newBlob(ns1, appconsts.ShareVersionZero) + ns1 := MustNewV0Namespace(bytes.Repeat([]byte{1}, NamespaceVersionZeroIDSize)) + blob1 := newBlob(ns1, ShareVersionZero) sss := NewSparseShareSplitter() @@ -53,9 +50,9 @@ func TestWriteNamespacePaddingShares(t *testing.T) { // verify that the padding share has the same share version as blob1 info, err := got[1].InfoByte() assert.NoError(t, err) - assert.Equal(t, info.Version(), appconsts.ShareVersionZero) + assert.Equal(t, info.Version(), ShareVersionZero) } -func newBlob(ns appns.Namespace, shareVersion uint8) *blob.Blob { - return blob.New(ns, []byte("data"), shareVersion) +func newBlob(ns Namespace, shareVersion uint8) *Blob { + return NewBlob(ns, []byte("data"), shareVersion) } diff --git a/shares/txs.go b/shares/txs.go new file mode 100644 index 0000000000..f5cba1d4bc --- /dev/null +++ b/shares/txs.go @@ -0,0 +1,59 @@ +package shares + +import ( + "bytes" + crand "crypto/rand" + "math/rand" + + "github.com/tendermint/tendermint/types" +) + +func GenerateRandomlySizedTxs(count, maxSize int) types.Txs { + txs := make(types.Txs, count) + for i := 0; i < count; i++ { + size := rand.Intn(maxSize) + if size == 0 { + size = 1 + } + txs[i] = GenerateRandomTxs(1, size)[0] + } + return txs +} + +func GenerateRandomTxs(count, size int) types.Txs { + txs := make(types.Txs, count) + for i := 0; i < count; i++ { + tx := make([]byte, size) + _, err := crand.Read(tx) + if err != nil { + panic(err) + } + txs[i] = tx + } + return txs +} + +// GetRandomSubSlice returns two integers representing a randomly sized range in the interval [0, size] +func GetRandomSubSlice(size int) (start int, length int) { + length = rand.Intn(size + 1) + start = rand.Intn(size - length + 1) + return start, length +} + +// CheckSubArray returns whether subTxList is a subarray of txList +func CheckSubArray(txList []types.Tx, subTxList []types.Tx) bool { + for i := 0; i <= len(txList)-len(subTxList); i++ { + j := 0 + for j = 0; j < len(subTxList); j++ { + tx := txList[i+j] + subTx := subTxList[j] + if !bytes.Equal([]byte(tx), []byte(subTx)) { + break + } + } + if j == len(subTxList) { + return true + } + } + return false +} diff --git a/pkg/shares/utils.go b/shares/utils.go similarity index 88% rename from pkg/shares/utils.go rename to shares/utils.go index 4487568356..7a3eb53a32 100644 --- a/pkg/shares/utils.go +++ b/shares/utils.go @@ -3,8 +3,6 @@ package shares import ( "bytes" "encoding/binary" - - "github.com/celestiaorg/celestia-app/pkg/appconsts" ) // DelimLen calculates the length of the delimiter for a given unit size @@ -77,9 +75,9 @@ func AvailableBytesFromCompactShares(n int) int { return 0 } if n == 1 { - return appconsts.FirstCompactShareContentSize + return FirstCompactShareContentSize } - return (n-1)*appconsts.ContinuationCompactShareContentSize + appconsts.FirstCompactShareContentSize + return (n-1)*ContinuationCompactShareContentSize + FirstCompactShareContentSize } // AvailableBytesFromSparseShares returns the maximum amount of bytes that could fit in `n` sparse shares @@ -88,7 +86,7 @@ func AvailableBytesFromSparseShares(n int) int { return 0 } if n == 1 { - return appconsts.FirstSparseShareContentSize + return FirstSparseShareContentSize } - return (n-1)*appconsts.ContinuationSparseShareContentSize + appconsts.FirstSparseShareContentSize + return (n-1)*ContinuationSparseShareContentSize + FirstSparseShareContentSize } diff --git a/pkg/shares/utils_test.go b/shares/utils_test.go similarity index 92% rename from pkg/shares/utils_test.go rename to shares/utils_test.go index cf743dbece..f25b217e12 100644 --- a/pkg/shares/utils_test.go +++ b/shares/utils_test.go @@ -4,7 +4,6 @@ import ( "reflect" "testing" - "github.com/celestiaorg/celestia-app/test/util/testfactory" "github.com/stretchr/testify/assert" ) @@ -39,7 +38,7 @@ func Test_zeroPadIfNecessary(t *testing.T) { func TestParseDelimiter(t *testing.T) { for i := uint64(0); i < 100; i++ { - tx := testfactory.GenerateRandomTxs(1, int(i))[0] + tx := GenerateRandomTxs(1, int(i))[0] input, err := MarshalDelimitedTx(tx) if err != nil { panic(err) diff --git a/test/txsim/blob.go b/test/txsim/blob.go index e42cfe635c..ae99c63fc7 100644 --- a/test/txsim/blob.go +++ b/test/txsim/blob.go @@ -5,7 +5,7 @@ import ( "fmt" "math/rand" - ns "github.com/celestiaorg/celestia-app/pkg/namespace" + "github.com/celestiaorg/celestia-app/shares" "github.com/celestiaorg/celestia-app/test/util/blobfactory" blob "github.com/celestiaorg/celestia-app/x/blob/types" "github.com/cosmos/cosmos-sdk/types" @@ -20,7 +20,7 @@ const fundsForGas int = 1e9 // 1000 TIA // BlobSequence defines a pattern whereby a single user repeatedly sends a pay for blob // message roughly every height. The PFB may consist of several blobs type BlobSequence struct { - namespace ns.Namespace + namespace shares.Namespace sizes Range blobsPerPFB Range @@ -37,7 +37,7 @@ func NewBlobSequence(sizes, blobsPerPFB Range) *BlobSequence { // WithNamespace provides the option of fixing a predefined namespace for // all blobs. -func (s *BlobSequence) WithNamespace(namespace ns.Namespace) *BlobSequence { +func (s *BlobSequence) WithNamespace(namespace shares.Namespace) *BlobSequence { s.namespace = namespace return s } @@ -66,18 +66,18 @@ func (s *BlobSequence) Init(_ context.Context, _ grpc.ClientConn, allocateAccoun func (s *BlobSequence) Next(_ context.Context, _ grpc.ClientConn, rand *rand.Rand) (Operation, error) { numBlobs := s.blobsPerPFB.Rand(rand) sizes := make([]int, numBlobs) - namespaces := make([]ns.Namespace, numBlobs) + namespaces := make([]shares.Namespace, numBlobs) for i := range sizes { if s.namespace.ID != nil { namespaces[i] = s.namespace } else { // generate a random namespace for the blob - namespace := make([]byte, ns.NamespaceVersionZeroIDSize) + namespace := make([]byte, shares.NamespaceVersionZeroIDSize) _, err := rand.Read(namespace) if err != nil { return Operation{}, fmt.Errorf("generating random namespace: %w", err) } - namespaces[i] = ns.MustNewV0(namespace) + namespaces[i] = shares.MustNewV0Namespace(namespace) } sizes[i] = s.sizes.Rand(rand) } diff --git a/test/txsim/sequence.go b/test/txsim/sequence.go index d0d8088a62..a2f9670b06 100644 --- a/test/txsim/sequence.go +++ b/test/txsim/sequence.go @@ -5,7 +5,7 @@ import ( "errors" "math/rand" - "github.com/celestiaorg/celestia-app/pkg/blob" + "github.com/celestiaorg/celestia-app/shares" "github.com/cosmos/cosmos-sdk/types" "github.com/gogo/protobuf/grpc" ) @@ -35,7 +35,7 @@ type Sequence interface { // The gas limit and price can also be set. If left at 0, the DefaultGasLimit will be used. type Operation struct { Msgs []types.Msg - Blobs []*blob.Blob + Blobs []*shares.Blob Delay uint64 GasLimit uint64 GasPrice float64 diff --git a/test/util/blobfactory/payforblob_factory.go b/test/util/blobfactory/payforblob_factory.go index 40211d87bb..cdf8404068 100644 --- a/test/util/blobfactory/payforblob_factory.go +++ b/test/util/blobfactory/payforblob_factory.go @@ -7,9 +7,8 @@ import ( "github.com/celestiaorg/celestia-app/app/encoding" "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/blob" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" "github.com/celestiaorg/celestia-app/pkg/user" + "github.com/celestiaorg/celestia-app/shares" "github.com/celestiaorg/celestia-app/test/util/testfactory" blobtypes "github.com/celestiaorg/celestia-app/x/blob/types" "github.com/cosmos/cosmos-sdk/client" @@ -28,10 +27,10 @@ var ( TestMaxBlobCount = 5 ) -func RandMsgPayForBlobsWithSigner(rand *tmrand.Rand, signer string, size, blobCount int) (*blobtypes.MsgPayForBlobs, []*blob.Blob) { - blobs := make([]*blob.Blob, blobCount) +func RandMsgPayForBlobsWithSigner(rand *tmrand.Rand, signer string, size, blobCount int) (*blobtypes.MsgPayForBlobs, []*shares.Blob) { + blobs := make([]*shares.Blob, blobCount) for i := 0; i < blobCount; i++ { - blob, err := blobtypes.NewBlob(appns.RandomBlobNamespaceWithPRG(rand), tmrand.Bytes(size), appconsts.ShareVersionZero) + blob, err := blobtypes.NewBlob(shares.RandomBlobNamespaceWithPRG(rand), tmrand.Bytes(size), appconsts.ShareVersionZero) if err != nil { panic(err) } @@ -45,15 +44,15 @@ func RandMsgPayForBlobsWithSigner(rand *tmrand.Rand, signer string, size, blobCo return msg, blobs } -func RandBlobsWithNamespace(namespaces []appns.Namespace, sizes []int) []*blob.Blob { - blobs := make([]*blob.Blob, len(namespaces)) +func RandBlobsWithNamespace(namespaces []shares.Namespace, sizes []int) []*shares.Blob { + blobs := make([]*shares.Blob, len(namespaces)) for i, ns := range namespaces { - blobs[i] = blob.New(ns, tmrand.Bytes(sizes[i]), appconsts.ShareVersionZero) + blobs[i] = shares.NewBlob(ns, tmrand.Bytes(sizes[i]), appconsts.ShareVersionZero) } return blobs } -func RandMsgPayForBlobsWithNamespaceAndSigner(signer string, ns appns.Namespace, size int) (*blobtypes.MsgPayForBlobs, *blob.Blob) { +func RandMsgPayForBlobsWithNamespaceAndSigner(signer string, ns shares.Namespace, size int) (*blobtypes.MsgPayForBlobs, *shares.Blob) { blob, err := blobtypes.NewBlob(ns, tmrand.Bytes(size), appconsts.ShareVersionZero) if err != nil { panic(err) @@ -68,8 +67,8 @@ func RandMsgPayForBlobsWithNamespaceAndSigner(signer string, ns appns.Namespace, return msg, blob } -func RandMsgPayForBlobs(rand *tmrand.Rand, size int) (*blobtypes.MsgPayForBlobs, *blob.Blob) { - blob := blob.New(appns.RandomBlobNamespaceWithPRG(rand), tmrand.Bytes(size), appconsts.ShareVersionZero) +func RandMsgPayForBlobs(rand *tmrand.Rand, size int) (*blobtypes.MsgPayForBlobs, *shares.Blob) { + blob := shares.NewBlob(shares.RandomBlobNamespaceWithPRG(rand), tmrand.Bytes(size), appconsts.ShareVersionZero) msg, err := blobtypes.NewMsgPayForBlobs( testfactory.TestAccAddr, blob, @@ -178,8 +177,8 @@ func RandBlobTxs(signer *user.Signer, rand *tmrand.Rand, count, blobsPerTx, size return txs } -func ManyRandBlobs(rand *tmrand.Rand, sizes ...int) []*blob.Blob { - return ManyBlobs(rand, appns.RandomBlobNamespaces(rand, len(sizes)), sizes) +func ManyRandBlobs(rand *tmrand.Rand, sizes ...int) []*shares.Blob { + return ManyBlobs(rand, shares.RandomBlobNamespaces(rand, len(sizes)), sizes) } func Repeat[T any](s T, count int) []T { @@ -190,16 +189,16 @@ func Repeat[T any](s T, count int) []T { return ss } -func ManyBlobs(rand *tmrand.Rand, namespaces []appns.Namespace, sizes []int) []*blob.Blob { - blobs := make([]*blob.Blob, len(namespaces)) +func ManyBlobs(rand *tmrand.Rand, namespaces []shares.Namespace, sizes []int) []*shares.Blob { + blobs := make([]*shares.Blob, len(namespaces)) for i, ns := range namespaces { - blobs[i] = blob.New(ns, rand.Bytes(sizes[i]), appconsts.ShareVersionZero) + blobs[i] = shares.NewBlob(ns, rand.Bytes(sizes[i]), appconsts.ShareVersionZero) } return blobs } -func NestedBlobs(t *testing.T, namespaces []appns.Namespace, sizes [][]int) [][]*blob.Blob { - blobs := make([][]*blob.Blob, len(sizes)) +func NestedBlobs(t *testing.T, namespaces []shares.Namespace, sizes [][]int) [][]*shares.Blob { + blobs := make([][]*shares.Blob, len(sizes)) counter := 0 for i, set := range sizes { for _, size := range set { @@ -219,7 +218,7 @@ func ManyMultiBlobTx( chainid string, accounts []string, accInfos []AccountInfo, - blobs [][]*blob.Blob, + blobs [][]*shares.Blob, ) [][]byte { t.Helper() txs := make([][]byte, len(accounts)) @@ -241,7 +240,7 @@ func IndexWrappedTxWithInvalidNamespace( rand *tmrand.Rand, signer *user.Signer, index uint32, -) (coretypes.Tx, blob.Blob) { +) (coretypes.Tx, shares.Blob) { t.Helper() addr := signer.Address() blob := ManyRandBlobs(rand, 100)[0] @@ -260,7 +259,7 @@ func IndexWrappedTxWithInvalidNamespace( func RandBlobTxsWithNamespacesAndSigner( signer *user.Signer, - namespaces []appns.Namespace, + namespaces []shares.Namespace, sizes []int, ) []coretypes.Tx { addr := signer.Address() @@ -268,7 +267,7 @@ func RandBlobTxsWithNamespacesAndSigner( for i := 0; i < len(namespaces); i++ { // TODO: this can be refactored as the signer only needs the blobs and can construct the PFB itself _, b := RandMsgPayForBlobsWithNamespaceAndSigner(addr.String(), namespaces[i], sizes[i]) - cTx, err := signer.CreatePayForBlob([]*blob.Blob{b}, DefaultTxOpts()...) + cTx, err := signer.CreatePayForBlob([]*shares.Blob{b}, DefaultTxOpts()...) if err != nil { panic(err) } @@ -286,7 +285,7 @@ func ComplexBlobTxWithOtherMsgs(t *testing.T, rand *tmrand.Rand, signer *user.Si rawTx, err := signer.CreateTx(msgs, DefaultTxOpts()...) require.NoError(t, err) - btx, err := blob.MarshalBlobTx(rawTx, blobs...) + btx, err := shares.MarshalBlobTx(rawTx, blobs...) require.NoError(t, err) return btx } diff --git a/test/util/direct_tx_gen.go b/test/util/direct_tx_gen.go index b00615e263..617601ca3a 100644 --- a/test/util/direct_tx_gen.go +++ b/test/util/direct_tx_gen.go @@ -7,8 +7,8 @@ import ( tmrand "github.com/tendermint/tendermint/libs/rand" "github.com/celestiaorg/celestia-app/app" - "github.com/celestiaorg/celestia-app/pkg/blob" "github.com/celestiaorg/celestia-app/pkg/user" + "github.com/celestiaorg/celestia-app/shares" "github.com/celestiaorg/celestia-app/test/util/blobfactory" "github.com/celestiaorg/celestia-app/test/util/testfactory" "github.com/cosmos/cosmos-sdk/client" @@ -142,7 +142,7 @@ func RandBlobTxsWithManualSequence( tx, err = cfg.TxEncoder()(builder.GetTx()) require.NoError(t, err) } - cTx, err := blob.MarshalBlobTx(tx, blobs...) + cTx, err := shares.MarshalBlobTx(tx, blobs...) if err != nil { panic(err) } diff --git a/test/util/malicious/app_test.go b/test/util/malicious/app_test.go index 269d43b07a..5599a126f0 100644 --- a/test/util/malicious/app_test.go +++ b/test/util/malicious/app_test.go @@ -5,9 +5,9 @@ import ( "github.com/celestiaorg/celestia-app/pkg/appconsts" "github.com/celestiaorg/celestia-app/pkg/da" - "github.com/celestiaorg/celestia-app/pkg/shares" "github.com/celestiaorg/celestia-app/pkg/square" "github.com/celestiaorg/celestia-app/pkg/wrapper" + "github.com/celestiaorg/celestia-app/shares" "github.com/celestiaorg/celestia-app/test/util/blobfactory" "github.com/celestiaorg/celestia-app/test/util/testfactory" "github.com/celestiaorg/celestia-app/test/util/testnode" diff --git a/test/util/malicious/out_of_order_builder.go b/test/util/malicious/out_of_order_builder.go index 0fb22988f0..a529bbb1a4 100644 --- a/test/util/malicious/out_of_order_builder.go +++ b/test/util/malicious/out_of_order_builder.go @@ -6,10 +6,8 @@ import ( "sort" "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/blob" - "github.com/celestiaorg/celestia-app/pkg/namespace" - "github.com/celestiaorg/celestia-app/pkg/shares" "github.com/celestiaorg/celestia-app/pkg/square" + "github.com/celestiaorg/celestia-app/shares" ) type ExportFn func(builder *square.Builder) (square.Square, error) @@ -27,7 +25,7 @@ func Build(txs [][]byte, appVersion uint64, maxSquareSize int, efn ExportFn) (sq normalTxs := make([][]byte, 0, len(txs)) blobTxs := make([][]byte, 0, len(txs)) for _, tx := range txs { - blobTx, isBlobTx := blob.UnmarshalBlobTx(tx) + blobTx, isBlobTx := shares.UnmarshalBlobTx(tx) if isBlobTx { if builder.AppendBlobTx(blobTx) { blobTxs = append(blobTxs, tx) @@ -87,7 +85,7 @@ func OutOfOrderExport(b *square.Builder) (square.Square, error) { } // write all the regular transactions into compact shares - txWriter := shares.NewCompactShareSplitter(namespace.TxNamespace, appconsts.ShareVersionZero) + txWriter := shares.NewCompactShareSplitter(shares.TxNamespace, appconsts.ShareVersionZero) for _, tx := range b.Txs { if err := txWriter.WriteTx(tx); err != nil { return nil, fmt.Errorf("writing tx into compact shares: %w", err) @@ -133,7 +131,7 @@ func OutOfOrderExport(b *square.Builder) (square.Square, error) { // write all the pay for blob transactions into compact shares. We need to do this after allocating the blobs to their // appropriate shares as the starting index of each blob needs to be included in the PFB transaction - pfbWriter := shares.NewCompactShareSplitter(namespace.PayForBlobNamespace, appconsts.ShareVersionZero) + pfbWriter := shares.NewCompactShareSplitter(shares.PayForBlobNamespace, appconsts.ShareVersionZero) for _, iw := range b.Pfbs { iwBytes, err := iw.Marshal() if err != nil { diff --git a/test/util/malicious/out_of_order_prepare.go b/test/util/malicious/out_of_order_prepare.go index ebc23bc31b..e48bc69fc5 100644 --- a/test/util/malicious/out_of_order_prepare.go +++ b/test/util/malicious/out_of_order_prepare.go @@ -4,7 +4,7 @@ import ( "github.com/celestiaorg/celestia-app/app" "github.com/celestiaorg/celestia-app/app/ante" "github.com/celestiaorg/celestia-app/pkg/da" - "github.com/celestiaorg/celestia-app/pkg/shares" + "github.com/celestiaorg/celestia-app/shares" abci "github.com/tendermint/tendermint/abci/types" core "github.com/tendermint/tendermint/proto/tendermint/types" ) diff --git a/test/util/malicious/tree.go b/test/util/malicious/tree.go index c31fe64966..0b31c043ed 100644 --- a/test/util/malicious/tree.go +++ b/test/util/malicious/tree.go @@ -4,9 +4,9 @@ import ( "fmt" "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/shares" "github.com/celestiaorg/celestia-app/pkg/square" "github.com/celestiaorg/celestia-app/pkg/wrapper" + "github.com/celestiaorg/celestia-app/shares" "github.com/celestiaorg/nmt" "github.com/celestiaorg/nmt/namespace" "github.com/celestiaorg/rsmt2d" diff --git a/test/util/testfactory/blob.go b/test/util/testfactory/blob.go index 63396c40f4..d5c7542809 100644 --- a/test/util/testfactory/blob.go +++ b/test/util/testfactory/blob.go @@ -5,14 +5,13 @@ import ( "encoding/binary" "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/blob" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" + "github.com/celestiaorg/celestia-app/shares" tmrand "github.com/tendermint/tendermint/libs/rand" "github.com/tendermint/tendermint/types" ) -func GenerateRandomlySizedBlobs(count, maxBlobSize int) []*blob.Blob { - blobs := make([]*blob.Blob, count) +func GenerateRandomlySizedBlobs(count, maxBlobSize int) []*shares.Blob { + blobs := make([]*shares.Blob, count) for i := 0; i < count; i++ { blobs[i] = GenerateRandomBlob(tmrand.Intn(maxBlobSize)) if len(blobs[i].Data) == 0 { @@ -25,12 +24,12 @@ func GenerateRandomlySizedBlobs(count, maxBlobSize int) []*blob.Blob { blobs = nil } - blob.Sort(blobs) + shares.SortBlobs(blobs) return blobs } // GenerateBlobsWithNamespace generates blobs with namespace ns. -func GenerateBlobsWithNamespace(count int, blobSize int, ns appns.Namespace) []types.Blob { +func GenerateBlobsWithNamespace(count int, blobSize int, ns shares.Namespace) []types.Blob { blobs := make([]types.Blob, count) for i := 0; i < count; i++ { blobs[i] = types.Blob{ @@ -49,14 +48,14 @@ func GenerateBlobsWithNamespace(count int, blobSize int, ns appns.Namespace) []t return blobs } -func GenerateRandomBlob(dataSize int) *blob.Blob { - ns := appns.MustNewV0(bytes.Repeat([]byte{0x1}, appns.NamespaceVersionZeroIDSize)) - return blob.New(ns, tmrand.Bytes(dataSize), appconsts.ShareVersionZero) +func GenerateRandomBlob(dataSize int) *shares.Blob { + ns := shares.MustNewV0Namespace(bytes.Repeat([]byte{0x1}, shares.NamespaceVersionZeroIDSize)) + return shares.NewBlob(ns, tmrand.Bytes(dataSize), appconsts.ShareVersionZero) } // GenerateRandomBlobOfShareCount returns a blob that spans the given // number of shares -func GenerateRandomBlobOfShareCount(count int) *blob.Blob { +func GenerateRandomBlobOfShareCount(count int) *shares.Blob { size := rawBlobSize(appconsts.FirstSparseShareContentSize * count) return GenerateRandomBlob(size) } diff --git a/test/util/testfactory/common.go b/test/util/testfactory/common.go index f33f6fcfa9..ae4c2d27ff 100644 --- a/test/util/testfactory/common.go +++ b/test/util/testfactory/common.go @@ -5,7 +5,7 @@ import ( "sort" "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/namespace" + "github.com/celestiaorg/celestia-app/shares" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" @@ -36,7 +36,7 @@ func Repeat[T any](s T, count int) []T { func GenerateRandNamespacedRawData(count int) (result [][]byte) { for i := 0; i < count; i++ { rawData := tmrand.Bytes(appconsts.ShareSize) - namespace := namespace.RandomBlobNamespace().Bytes() + namespace := shares.RandomBlobNamespace().Bytes() copy(rawData, namespace) result = append(result, rawData) } diff --git a/test/util/testnode/full_node_test.go b/test/util/testnode/full_node_test.go index a2e9dca5d8..ddb6e46028 100644 --- a/test/util/testnode/full_node_test.go +++ b/test/util/testnode/full_node_test.go @@ -9,7 +9,7 @@ import ( "github.com/celestiaorg/celestia-app/app" "github.com/celestiaorg/celestia-app/app/encoding" "github.com/celestiaorg/celestia-app/pkg/appconsts" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" + appns "github.com/celestiaorg/celestia-app/shares" "github.com/celestiaorg/celestia-app/test/util/genesis" blobtypes "github.com/celestiaorg/celestia-app/x/blob/types" "github.com/cosmos/cosmos-sdk/client/flags" diff --git a/test/util/testnode/node_interaction_api.go b/test/util/testnode/node_interaction_api.go index cf8e2e3bbb..3558fe29df 100644 --- a/test/util/testnode/node_interaction_api.go +++ b/test/util/testnode/node_interaction_api.go @@ -10,10 +10,8 @@ import ( "github.com/celestiaorg/celestia-app/app" "github.com/celestiaorg/celestia-app/app/encoding" "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/blob" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" - "github.com/celestiaorg/celestia-app/pkg/shares" "github.com/celestiaorg/celestia-app/pkg/user" + "github.com/celestiaorg/celestia-app/shares" "github.com/celestiaorg/celestia-app/test/util/blobfactory" "github.com/celestiaorg/celestia-app/x/blob/types" "github.com/cosmos/cosmos-sdk/client" @@ -215,7 +213,7 @@ func (c *Context) WaitForTx(hashHexStr string, blocks int) (*rpctypes.ResultTx, // PostData will create and submit PFB transaction containing the namespace and // blobData. This function blocks until the PFB has been included in a block and // returns an error if the transaction is invalid or is rejected by the mempool. -func (c *Context) PostData(account, broadcastMode string, ns appns.Namespace, blobData []byte) (*sdk.TxResponse, error) { +func (c *Context) PostData(account, broadcastMode string, ns shares.Namespace, blobData []byte) (*sdk.TxResponse, error) { rec, err := c.Keyring.Key(account) if err != nil { return nil, err @@ -245,7 +243,7 @@ func (c *Context) PostData(account, broadcastMode string, ns appns.Namespace, bl gas := types.DefaultEstimateGas([]uint32{uint32(len(blobData))}) opts := blobfactory.FeeTxOpts(gas) - blobTx, err := signer.CreatePayForBlob([]*blob.Blob{b}, opts...) + blobTx, err := signer.CreatePayForBlob([]*shares.Blob{b}, opts...) if err != nil { return nil, err } @@ -291,7 +289,7 @@ func (c *Context) FillBlock(squareSize int, accounts []string, broadcastMode str // we use a formula to guarantee that the tx is the exact size needed to force a specific square size. blobSize := shares.AvailableBytesFromSparseShares(shareCount) - return c.PostData(accounts[0], broadcastMode, appns.RandomBlobNamespace(), tmrand.Bytes(blobSize)) + return c.PostData(accounts[0], broadcastMode, shares.RandomBlobNamespace(), tmrand.Bytes(blobSize)) } // HeightForTimestamp returns the block height for the first block after a diff --git a/test/util/testnode/read.go b/test/util/testnode/read.go index af95a90904..8f6a4da815 100644 --- a/test/util/testnode/read.go +++ b/test/util/testnode/read.go @@ -6,7 +6,7 @@ import ( "github.com/celestiaorg/celestia-app/app" "github.com/celestiaorg/celestia-app/app/encoding" - "github.com/celestiaorg/celestia-app/pkg/blob" + "github.com/celestiaorg/celestia-app/shares" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/tendermint/tendermint/rpc/client/http" "github.com/tendermint/tendermint/types" @@ -60,7 +60,7 @@ func DecodeBlockData(data types.Data) ([]sdk.Msg, error) { decoder := encCfg.TxConfig.TxDecoder() msgs := make([]sdk.Msg, 0) for _, txBytes := range data.Txs { - blobTx, isBlobTx := blob.UnmarshalBlobTx(txBytes) + blobTx, isBlobTx := shares.UnmarshalBlobTx(txBytes) if isBlobTx { txBytes = blobTx.Tx } diff --git a/x/blob/ante/ante_test.go b/x/blob/ante/ante_test.go index 80acc877f2..d6a956e616 100644 --- a/x/blob/ante/ante_test.go +++ b/x/blob/ante/ante_test.go @@ -6,7 +6,7 @@ import ( "github.com/celestiaorg/celestia-app/app" "github.com/celestiaorg/celestia-app/app/encoding" "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/shares" + "github.com/celestiaorg/celestia-app/shares" ante "github.com/celestiaorg/celestia-app/x/blob/ante" blob "github.com/celestiaorg/celestia-app/x/blob/types" sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/x/blob/ante/max_total_blob_size_ante.go b/x/blob/ante/max_total_blob_size_ante.go index 7d7c0f4a7c..a58b06f2bb 100644 --- a/x/blob/ante/max_total_blob_size_ante.go +++ b/x/blob/ante/max_total_blob_size_ante.go @@ -2,7 +2,7 @@ package ante import ( "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/shares" + "github.com/celestiaorg/celestia-app/shares" blobtypes "github.com/celestiaorg/celestia-app/x/blob/types" "cosmossdk.io/errors" diff --git a/x/blob/ante/max_total_blob_size_ante_test.go b/x/blob/ante/max_total_blob_size_ante_test.go index 8e76ca455d..c13a7652f5 100644 --- a/x/blob/ante/max_total_blob_size_ante_test.go +++ b/x/blob/ante/max_total_blob_size_ante_test.go @@ -5,7 +5,7 @@ import ( "github.com/celestiaorg/celestia-app/app" "github.com/celestiaorg/celestia-app/app/encoding" - "github.com/celestiaorg/celestia-app/pkg/shares" + "github.com/celestiaorg/celestia-app/shares" ante "github.com/celestiaorg/celestia-app/x/blob/ante" blob "github.com/celestiaorg/celestia-app/x/blob/types" sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/x/blob/client/cli/payforblob.go b/x/blob/client/cli/payforblob.go index 52ebff4cf6..a0ed4d0e54 100644 --- a/x/blob/client/cli/payforblob.go +++ b/x/blob/client/cli/payforblob.go @@ -10,8 +10,7 @@ import ( "github.com/spf13/cobra" - "github.com/celestiaorg/celestia-app/pkg/blob" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" + "github.com/celestiaorg/celestia-app/shares" "github.com/celestiaorg/celestia-app/x/blob/types" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -22,11 +21,11 @@ import ( const ( // FlagShareVersion allows the user to override the share version when - // submitting a PayForBlob. + // submitting a PayForShares. FlagShareVersion = "share-version" // FlagNamespaceVersion allows the user to override the namespace version when - // submitting a PayForBlob. + // submitting a PayForShares. FlagNamespaceVersion = "namespace-version" ) @@ -91,24 +90,24 @@ func CmdPayForBlob() *cobra.Command { return cmd } -func getNamespace(namespaceID []byte, namespaceVersion uint8) (appns.Namespace, error) { +func getNamespace(namespaceID []byte, namespaceVersion uint8) (shares.Namespace, error) { switch namespaceVersion { - case appns.NamespaceVersionZero: - if len(namespaceID) != appns.NamespaceVersionZeroIDSize { - return appns.Namespace{}, fmt.Errorf("the user specifiable portion of the namespace ID must be %d bytes for namespace version 0", appns.NamespaceVersionZeroIDSize) + case shares.NamespaceVersionZero: + if len(namespaceID) != shares.NamespaceVersionZeroIDSize { + return shares.Namespace{}, fmt.Errorf("the user specifiable portion of the namespace ID must be %d bytes for namespace version 0", shares.NamespaceVersionZeroIDSize) } - id := make([]byte, 0, appns.NamespaceIDSize) - id = append(id, appns.NamespaceVersionZeroPrefix...) + id := make([]byte, 0, shares.NamespaceIDSize) + id = append(id, shares.NamespaceVersionZeroPrefix...) id = append(id, namespaceID...) - return appns.New(namespaceVersion, id) + return shares.NewNamespace(namespaceVersion, id) default: - return appns.Namespace{}, fmt.Errorf("namespace version %d is not supported", namespaceVersion) + return shares.Namespace{}, fmt.Errorf("namespace version %d is not supported", namespaceVersion) } } // broadcastPFB creates the new PFB message type that will later be broadcast to tendermint nodes // this private func is used in CmdPayForBlob -func broadcastPFB(cmd *cobra.Command, b *blob.Blob) error { +func broadcastPFB(cmd *cobra.Command, b *shares.Blob) error { clientCtx, err := client.GetClientTxContext(cmd) if err != nil { return err @@ -131,7 +130,7 @@ func broadcastPFB(cmd *cobra.Command, b *blob.Blob) error { return err } - blobTx, err := blob.MarshalBlobTx(txBytes, b) + blobTx, err := shares.MarshalBlobTx(txBytes, b) if err != nil { return err } diff --git a/x/blob/client/testutil/integration_test.go b/x/blob/client/testutil/integration_test.go index 0674189940..1e3ee0192f 100644 --- a/x/blob/client/testutil/integration_test.go +++ b/x/blob/client/testutil/integration_test.go @@ -18,7 +18,7 @@ import ( "github.com/celestiaorg/celestia-app/x/blob/types" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" + appns "github.com/celestiaorg/celestia-app/shares" "github.com/celestiaorg/celestia-app/test/util/network" "github.com/celestiaorg/celestia-app/test/util/testnode" paycli "github.com/celestiaorg/celestia-app/x/blob/client/cli" diff --git a/x/blob/types/blob_tx.go b/x/blob/types/blob_tx.go index 1ebf9b15fc..5820f4b4f8 100644 --- a/x/blob/types/blob_tx.go +++ b/x/blob/types/blob_tx.go @@ -3,16 +3,14 @@ package types import ( "bytes" - "github.com/celestiaorg/celestia-app/pkg/blob" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" - shares "github.com/celestiaorg/celestia-app/pkg/shares" + "github.com/celestiaorg/celestia-app/shares" "github.com/cosmos/cosmos-sdk/client" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" ) // NewBlob creates a new coretypes.Blob from the provided data after performing // basic stateless checks over it. -func NewBlob(ns appns.Namespace, data []byte, shareVersion uint8) (*blob.Blob, error) { +func NewBlob(ns shares.Namespace, data []byte, shareVersion uint8) (*shares.Blob, error) { err := ValidateBlobNamespace(ns) if err != nil { return nil, err @@ -22,7 +20,7 @@ func NewBlob(ns appns.Namespace, data []byte, shareVersion uint8) (*blob.Blob, e return nil, ErrZeroBlobSize } - return &blob.Blob{ + return &shares.Blob{ NamespaceId: ns.ID, Data: data, ShareVersion: uint32(shareVersion), @@ -32,7 +30,7 @@ func NewBlob(ns appns.Namespace, data []byte, shareVersion uint8) (*blob.Blob, e // ValidateBlobTx performs stateless checks on the BlobTx to ensure that the // blobs attached to the transaction are valid. -func ValidateBlobTx(txcfg client.TxEncodingConfig, bTx blob.BlobTx) error { +func ValidateBlobTx(txcfg client.TxEncodingConfig, bTx shares.BlobTx) error { sdkTx, err := txcfg.TxDecoder()(bTx.Tx) if err != nil { return err @@ -70,14 +68,14 @@ func ValidateBlobTx(txcfg client.TxEncodingConfig, bTx blob.BlobTx) error { } for i, ns := range msgPFB.Namespaces { - msgPFBNamespace, err := appns.From(ns) + msgPFBNamespace, err := shares.From(ns) if err != nil { return err } // this not only checks that the pfb namespaces match the ones in the blobs // but that the namespace version and namespace id are valid - blobNamespace, err := appns.New(uint8(bTx.Blobs[i].NamespaceVersion), bTx.Blobs[i].NamespaceId) + blobNamespace, err := shares.NewNamespace(uint8(bTx.Blobs[i].NamespaceVersion), bTx.Blobs[i].NamespaceId) if err != nil { return err } diff --git a/x/blob/types/blob_tx_test.go b/x/blob/types/blob_tx_test.go index de43cbf53f..709f57738e 100644 --- a/x/blob/types/blob_tx_test.go +++ b/x/blob/types/blob_tx_test.go @@ -7,8 +7,7 @@ import ( "github.com/celestiaorg/celestia-app/app" "github.com/celestiaorg/celestia-app/app/encoding" "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/blob" - "github.com/celestiaorg/celestia-app/pkg/namespace" + "github.com/celestiaorg/celestia-app/shares" "github.com/celestiaorg/celestia-app/test/util/blobfactory" "github.com/celestiaorg/celestia-app/test/util/testnode" "github.com/celestiaorg/celestia-app/x/blob/types" @@ -21,14 +20,14 @@ import ( func TestNewBlob(t *testing.T) { rawBlob := []byte{1} - validBlob, err := types.NewBlob(namespace.RandomBlobNamespace(), rawBlob, appconsts.ShareVersionZero) + validBlob, err := types.NewBlob(shares.RandomBlobNamespace(), rawBlob, appconsts.ShareVersionZero) require.NoError(t, err) require.Equal(t, validBlob.Data, rawBlob) - _, err = types.NewBlob(namespace.TxNamespace, rawBlob, appconsts.ShareVersionZero) + _, err = types.NewBlob(shares.TxNamespace, rawBlob, appconsts.ShareVersionZero) require.Error(t, err) - _, err = types.NewBlob(namespace.RandomBlobNamespace(), []byte{}, appconsts.ShareVersionZero) + _, err = types.NewBlob(shares.RandomBlobNamespace(), []byte{}, appconsts.ShareVersionZero) require.Error(t, err) } @@ -36,19 +35,19 @@ func TestValidateBlobTx(t *testing.T) { encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) signer, err := testnode.NewOfflineSigner() require.NoError(t, err) - ns1 := namespace.MustNewV0(bytes.Repeat([]byte{0x01}, namespace.NamespaceVersionZeroIDSize)) + ns1 := shares.MustNewV0Namespace(bytes.Repeat([]byte{0x01}, shares.NamespaceVersionZeroIDSize)) addr := signer.Address() type test struct { name string - getTx func() blob.BlobTx + getTx func() shares.BlobTx expectedErr error } validRawBtx := func() []byte { btx := blobfactory.RandBlobTxsWithNamespacesAndSigner( signer, - []namespace.Namespace{ns1}, + []shares.Namespace{ns1}, []int{10}, )[0] return btx @@ -57,42 +56,42 @@ func TestValidateBlobTx(t *testing.T) { tests := []test{ { name: "normal transaction", - getTx: func() blob.BlobTx { + getTx: func() shares.BlobTx { rawBtx := validRawBtx() - btx, _ := blob.UnmarshalBlobTx(rawBtx) + btx, _ := shares.UnmarshalBlobTx(rawBtx) return btx }, expectedErr: nil, }, { name: "invalid transaction, mismatched namespace", - getTx: func() blob.BlobTx { + getTx: func() shares.BlobTx { rawBtx := validRawBtx() - btx, _ := blob.UnmarshalBlobTx(rawBtx) - btx.Blobs[0].NamespaceId = namespace.RandomBlobNamespace().ID + btx, _ := shares.UnmarshalBlobTx(rawBtx) + btx.Blobs[0].NamespaceId = shares.RandomBlobNamespace().ID return btx }, expectedErr: types.ErrNamespaceMismatch, }, { name: "invalid transaction, no pfb", - getTx: func() blob.BlobTx { + getTx: func() shares.BlobTx { sendTx := blobfactory.GenerateManyRawSendTxs(signer, 1) - b, err := types.NewBlob(namespace.RandomBlobNamespace(), tmrand.Bytes(100), appconsts.ShareVersionZero) + b, err := types.NewBlob(shares.RandomBlobNamespace(), tmrand.Bytes(100), appconsts.ShareVersionZero) require.NoError(t, err) - return blob.BlobTx{ + return shares.BlobTx{ Tx: sendTx[0], - Blobs: []*blob.Blob{b}, + Blobs: []*shares.Blob{b}, } }, expectedErr: types.ErrNoPFB, }, { name: "mismatched number of pfbs and blobs", - getTx: func() blob.BlobTx { + getTx: func() shares.BlobTx { rawBtx := validRawBtx() - btx, _ := blob.UnmarshalBlobTx(rawBtx) - blob, err := types.NewBlob(namespace.RandomBlobNamespace(), tmrand.Bytes(100), appconsts.ShareVersionZero) + btx, _ := shares.UnmarshalBlobTx(rawBtx) + blob, err := types.NewBlob(shares.RandomBlobNamespace(), tmrand.Bytes(100), appconsts.ShareVersionZero) require.NoError(t, err) btx.Blobs = append(btx.Blobs, blob) return btx @@ -101,8 +100,8 @@ func TestValidateBlobTx(t *testing.T) { }, { name: "invalid share commitment", - getTx: func() blob.BlobTx { - b, err := types.NewBlob(namespace.RandomBlobNamespace(), tmrand.Bytes(100), appconsts.ShareVersionZero) + getTx: func() shares.BlobTx { + b, err := types.NewBlob(shares.RandomBlobNamespace(), tmrand.Bytes(100), appconsts.ShareVersionZero) require.NoError(t, err) msg, err := types.NewMsgPayForBlobs( addr.String(), @@ -111,9 +110,9 @@ func TestValidateBlobTx(t *testing.T) { require.NoError(t, err) badCommit, err := types.CreateCommitment( - &blob.Blob{ - NamespaceVersion: uint32(namespace.RandomBlobNamespace().Version), - NamespaceId: namespace.RandomBlobNamespace().ID, + &shares.Blob{ + NamespaceVersion: uint32(shares.RandomBlobNamespace().Version), + NamespaceId: shares.RandomBlobNamespace().ID, Data: tmrand.Bytes(99), ShareVersion: uint32(appconsts.ShareVersionZero), }) @@ -124,9 +123,9 @@ func TestValidateBlobTx(t *testing.T) { rawTx, err := signer.CreateTx([]sdk.Msg{msg}) require.NoError(t, err) - btx := blob.BlobTx{ + btx := shares.BlobTx{ Tx: rawTx, - Blobs: []*blob.Blob{b}, + Blobs: []*shares.Blob{b}, } return btx }, @@ -134,7 +133,7 @@ func TestValidateBlobTx(t *testing.T) { }, { name: "complex transaction with one send and one pfb", - getTx: func() blob.BlobTx { + getTx: func() shares.BlobTx { signerAddr := signer.Address() sendMsg := banktypes.NewMsgSend(signerAddr, signerAddr, sdk.NewCoins(sdk.NewCoin(app.BondDenom, sdk.NewInt(10)))) @@ -144,7 +143,7 @@ func TestValidateBlobTx(t *testing.T) { signer, sendMsg, ) - btx, isBlob := blob.UnmarshalBlobTx(tx) + btx, isBlob := shares.UnmarshalBlobTx(tx) require.True(t, isBlob) return btx }, @@ -152,9 +151,9 @@ func TestValidateBlobTx(t *testing.T) { }, { name: "only send tx", - getTx: func() blob.BlobTx { + getTx: func() shares.BlobTx { sendtx := blobfactory.GenerateManyRawSendTxs(signer, 1)[0] - return blob.BlobTx{ + return shares.BlobTx{ Tx: sendtx, } }, @@ -162,14 +161,14 @@ func TestValidateBlobTx(t *testing.T) { }, { name: "normal transaction with two blobs w/ different namespaces", - getTx: func() blob.BlobTx { + getTx: func() shares.BlobTx { rawBtx, err := signer.CreatePayForBlob( blobfactory.RandBlobsWithNamespace( - []namespace.Namespace{namespace.RandomBlobNamespace(), namespace.RandomBlobNamespace()}, + []shares.Namespace{shares.RandomBlobNamespace(), shares.RandomBlobNamespace()}, []int{100, 100}), ) require.NoError(t, err) - btx, isBlobTx := blob.UnmarshalBlobTx(rawBtx) + btx, isBlobTx := shares.UnmarshalBlobTx(rawBtx) require.True(t, isBlobTx) return btx }, @@ -177,14 +176,14 @@ func TestValidateBlobTx(t *testing.T) { }, { name: "normal transaction with two large blobs w/ different namespaces", - getTx: func() blob.BlobTx { + getTx: func() shares.BlobTx { rawBtx, err := signer.CreatePayForBlob( blobfactory.RandBlobsWithNamespace( - []namespace.Namespace{namespace.RandomBlobNamespace(), namespace.RandomBlobNamespace()}, + []shares.Namespace{shares.RandomBlobNamespace(), shares.RandomBlobNamespace()}, []int{100000, 1000000}), ) require.NoError(t, err) - btx, isBlobTx := blob.UnmarshalBlobTx(rawBtx) + btx, isBlobTx := shares.UnmarshalBlobTx(rawBtx) require.True(t, isBlobTx) return btx }, @@ -192,15 +191,15 @@ func TestValidateBlobTx(t *testing.T) { }, { name: "normal transaction with two blobs w/ same namespace", - getTx: func() blob.BlobTx { - ns := namespace.RandomBlobNamespace() + getTx: func() shares.BlobTx { + ns := shares.RandomBlobNamespace() rawBtx, err := signer.CreatePayForBlob( blobfactory.RandBlobsWithNamespace( - []namespace.Namespace{ns, ns}, + []shares.Namespace{ns, ns}, []int{100, 100}), ) require.NoError(t, err) - btx, isBlobTx := blob.UnmarshalBlobTx(rawBtx) + btx, isBlobTx := shares.UnmarshalBlobTx(rawBtx) require.True(t, isBlobTx) return btx }, @@ -208,11 +207,11 @@ func TestValidateBlobTx(t *testing.T) { }, { name: "normal transaction with one hundred blobs of the same namespace", - getTx: func() blob.BlobTx { + getTx: func() shares.BlobTx { count := 100 - ns := namespace.RandomBlobNamespace() + ns := shares.RandomBlobNamespace() sizes := make([]int, count) - namespaces := make([]namespace.Namespace, count) + namespaces := make([]shares.Namespace, count) for i := 0; i < count; i++ { sizes[i] = 100 namespaces[i] = ns @@ -223,7 +222,7 @@ func TestValidateBlobTx(t *testing.T) { sizes, )) require.NoError(t, err) - btx, isBlobTx := blob.UnmarshalBlobTx(rawBtx) + btx, isBlobTx := shares.UnmarshalBlobTx(rawBtx) require.True(t, isBlobTx) return btx }, diff --git a/x/blob/types/estimate_gas_test.go b/x/blob/types/estimate_gas_test.go index b0ed06b034..4d4fc87607 100644 --- a/x/blob/types/estimate_gas_test.go +++ b/x/blob/types/estimate_gas_test.go @@ -7,8 +7,8 @@ import ( "cosmossdk.io/math" "github.com/celestiaorg/celestia-app/app" "github.com/celestiaorg/celestia-app/app/encoding" - "github.com/celestiaorg/celestia-app/pkg/blob" "github.com/celestiaorg/celestia-app/pkg/user" + "github.com/celestiaorg/celestia-app/shares" testutil "github.com/celestiaorg/celestia-app/test/util" "github.com/celestiaorg/celestia-app/test/util/blobfactory" "github.com/celestiaorg/celestia-app/test/util/testfactory" @@ -47,7 +47,7 @@ func TestPFBGasEstimation(t *testing.T) { fee := sdk.NewCoins(sdk.NewCoin(app.BondDenom, math.NewInt(int64(gas)))) tx, err := signer.CreatePayForBlob(blobs, user.SetGasLimit(gas), user.SetFeeAmount(fee)) require.NoError(t, err) - blobTx, ok := blob.UnmarshalBlobTx(tx) + blobTx, ok := shares.UnmarshalBlobTx(tx) require.True(t, ok) resp := testApp.DeliverTx(abci.RequestDeliverTx{ Tx: blobTx.Tx, @@ -92,7 +92,7 @@ func FuzzPFBGasEstimation(f *testing.F) { fee := sdk.NewCoins(sdk.NewCoin(app.BondDenom, math.NewInt(int64(gas)))) tx, err := signer.CreatePayForBlob(blobs, user.SetGasLimit(gas), user.SetFeeAmount(fee)) require.NoError(t, err) - blobTx, ok := blob.UnmarshalBlobTx(tx) + blobTx, ok := shares.UnmarshalBlobTx(tx) require.True(t, ok) resp := testApp.DeliverTx(abci.RequestDeliverTx{ Tx: blobTx.Tx, diff --git a/x/blob/types/params.go b/x/blob/types/params.go index 253dea139d..ff329c092c 100644 --- a/x/blob/types/params.go +++ b/x/blob/types/params.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/shares" + "github.com/celestiaorg/celestia-app/shares" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "gopkg.in/yaml.v2" ) diff --git a/x/blob/types/payforblob.go b/x/blob/types/payforblob.go index 44727da70b..3a6091e38c 100644 --- a/x/blob/types/payforblob.go +++ b/x/blob/types/payforblob.go @@ -7,9 +7,7 @@ import ( "cosmossdk.io/errors" "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/blob" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" - appshares "github.com/celestiaorg/celestia-app/pkg/shares" + "github.com/celestiaorg/celestia-app/shares" "github.com/celestiaorg/nmt" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" @@ -46,7 +44,7 @@ const ( // See: https://github.com/cosmos/cosmos-sdk/blob/v0.46.15/docs/building-modules/messages-and-queries.md#legacy-amino-legacymsgs var _ legacytx.LegacyMsg = &MsgPayForBlobs{} -func NewMsgPayForBlobs(signer string, blobs ...*blob.Blob) (*MsgPayForBlobs, error) { +func NewMsgPayForBlobs(signer string, blobs ...*shares.Blob) (*MsgPayForBlobs, error) { err := ValidateBlobs(blobs...) if err != nil { return nil, err @@ -57,9 +55,9 @@ func NewMsgPayForBlobs(signer string, blobs ...*blob.Blob) (*MsgPayForBlobs, err } namespaceVersions, namespaceIds, sizes, shareVersions := ExtractBlobComponents(blobs) - namespaces := []appns.Namespace{} + namespaces := []shares.Namespace{} for i := range namespaceVersions { - namespace, err := appns.New(uint8(namespaceVersions[i]), namespaceIds[i]) + namespace, err := shares.NewNamespace(uint8(namespaceVersions[i]), namespaceIds[i]) if err != nil { return nil, err } @@ -77,7 +75,7 @@ func NewMsgPayForBlobs(signer string, blobs ...*blob.Blob) (*MsgPayForBlobs, err return msg, msg.ValidateBasic() } -func namespacesToBytes(namespaces []appns.Namespace) (result [][]byte) { +func namespacesToBytes(namespaces []shares.Namespace) (result [][]byte) { for _, namespace := range namespaces { result = append(result, namespace.Bytes()) } @@ -119,7 +117,7 @@ func (msg *MsgPayForBlobs) ValidateBasic() error { } for _, namespace := range msg.Namespaces { - ns, err := appns.From(namespace) + ns, err := shares.From(namespace) if err != nil { return errors.Wrap(ErrInvalidNamespace, err.Error()) } @@ -159,7 +157,7 @@ func (msg *MsgPayForBlobs) Gas(gasPerByte uint32) uint64 { func GasToConsume(blobSizes []uint32, gasPerByte uint32) uint64 { var totalSharesUsed uint64 for _, size := range blobSizes { - totalSharesUsed += uint64(appshares.SparseSharesNeeded(size)) + totalSharesUsed += uint64(shares.SparseSharesNeeded(size)) } return totalSharesUsed * appconsts.ShareSize * uint64(gasPerByte) @@ -182,12 +180,12 @@ func DefaultEstimateGas(blobSizes []uint32) uint64 { // ValidateBlobNamespace returns an error if the provided namespace is an // invalid user-specifiable blob namespace (e.g. reserved, parity shares, or // tail padding). -func ValidateBlobNamespace(ns appns.Namespace) error { +func ValidateBlobNamespace(ns shares.Namespace) error { if ns.IsReserved() { return ErrReservedNamespace } - if !slices.Contains(appns.SupportedBlobNamespaceVersions, ns.Version) { + if !slices.Contains(shares.SupportedBlobNamespaceVersions, ns.Version) { return ErrInvalidNamespaceVersion } @@ -214,13 +212,13 @@ func (msg *MsgPayForBlobs) GetSigners() []sdk.AccAddress { // // [data square layout rationale]: ../../specs/src/specs/data_square_layout.md // [blob share commitment rules]: ../../specs/src/specs/data_square_layout.md#blob-share-commitment-rules -func CreateCommitment(blob *blob.Blob) ([]byte, error) { +func CreateCommitment(blob *shares.Blob) ([]byte, error) { if err := blob.Validate(); err != nil { return nil, err } namespace := blob.Namespace() - shares, err := appshares.SplitBlobs(blob) + s, err := shares.SplitBlobs(blob) if err != nil { return nil, err } @@ -229,15 +227,15 @@ func CreateCommitment(blob *blob.Blob) ([]byte, error) { // determined by the number of roots required to create a share commitment // over that blob. The size of the tree is only increased if the number of // subtree roots surpasses a constant threshold. - subTreeWidth := appshares.SubTreeWidth(len(shares), appconsts.DefaultSubtreeRootThreshold) - treeSizes, err := MerkleMountainRangeSizes(uint64(len(shares)), uint64(subTreeWidth)) + subTreeWidth := shares.SubTreeWidth(len(s), appconsts.DefaultSubtreeRootThreshold) + treeSizes, err := MerkleMountainRangeSizes(uint64(len(s)), uint64(subTreeWidth)) if err != nil { return nil, err } leafSets := make([][][]byte, len(treeSizes)) cursor := uint64(0) for i, treeSize := range treeSizes { - leafSets[i] = appshares.ToBytes(shares[cursor : cursor+treeSize]) + leafSets[i] = shares.ToBytes(s[cursor : cursor+treeSize]) cursor = cursor + treeSize } @@ -245,7 +243,7 @@ func CreateCommitment(blob *blob.Blob) ([]byte, error) { subTreeRoots := make([][]byte, len(leafSets)) for i, set := range leafSets { // create the nmt todo(evan) use nmt wrapper - tree := nmt.New(sha256.New(), nmt.NamespaceIDSize(appns.NamespaceSize), nmt.IgnoreMaxNamespace(true)) + tree := nmt.New(sha256.New(), nmt.NamespaceIDSize(shares.NamespaceSize), nmt.IgnoreMaxNamespace(true)) for _, leaf := range set { // the namespace must be added again here even though it is already // included in the leaf to ensure that the hash will match that of @@ -272,7 +270,7 @@ func CreateCommitment(blob *blob.Blob) ([]byte, error) { return merkle.HashFromByteSlices(subTreeRoots), nil } -func CreateCommitments(blobs []*blob.Blob) ([][]byte, error) { +func CreateCommitments(blobs []*shares.Blob) ([][]byte, error) { commitments := make([][]byte, len(blobs)) for i, blob := range blobs { commitment, err := CreateCommitment(blob) @@ -285,7 +283,7 @@ func CreateCommitments(blobs []*blob.Blob) ([][]byte, error) { } // ValidateBlobs performs basic checks over the components of one or more PFBs. -func ValidateBlobs(blobs ...*blob.Blob) error { +func ValidateBlobs(blobs ...*shares.Blob) error { if len(blobs) == 0 { return ErrNoBlobs } @@ -294,7 +292,7 @@ func ValidateBlobs(blobs ...*blob.Blob) error { if blob.NamespaceVersion > appconsts.NamespaceVersionMaxValue { return fmt.Errorf("namespace version %d is too large", blob.NamespaceVersion) } - ns, err := appns.New(uint8(blob.NamespaceVersion), blob.NamespaceId) + ns, err := shares.NewNamespace(uint8(blob.NamespaceVersion), blob.NamespaceId) if err != nil { return err } @@ -317,7 +315,7 @@ func ValidateBlobs(blobs ...*blob.Blob) error { // ExtractBlobComponents separates and returns the components of a slice of // blobs. -func ExtractBlobComponents(pblobs []*blob.Blob) (namespaceVersions []uint32, namespaceIds [][]byte, sizes []uint32, shareVersions []uint32) { +func ExtractBlobComponents(pblobs []*shares.Blob) (namespaceVersions []uint32, namespaceIds [][]byte, sizes []uint32, shareVersions []uint32) { namespaceVersions = make([]uint32, len(pblobs)) namespaceIds = make([][]byte, len(pblobs)) sizes = make([]uint32, len(pblobs)) @@ -348,7 +346,7 @@ func MerkleMountainRangeSizes(totalSize, maxTreeSize uint64) ([]uint64, error) { treeSizes = append(treeSizes, maxTreeSize) totalSize = totalSize - maxTreeSize case totalSize < maxTreeSize: - treeSize, err := appshares.RoundDownPowerOfTwo(totalSize) + treeSize, err := shares.RoundDownPowerOfTwo(totalSize) if err != nil { return treeSizes, err } diff --git a/x/blob/types/payforblob_test.go b/x/blob/types/payforblob_test.go index a367ead573..5ecada1df3 100644 --- a/x/blob/types/payforblob_test.go +++ b/x/blob/types/payforblob_test.go @@ -6,9 +6,7 @@ import ( sdkerrors "cosmossdk.io/errors" "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/blob" - appns "github.com/celestiaorg/celestia-app/pkg/namespace" - shares "github.com/celestiaorg/celestia-app/pkg/shares" + "github.com/celestiaorg/celestia-app/shares" "github.com/celestiaorg/celestia-app/test/util/testfactory" "github.com/celestiaorg/celestia-app/test/util/testnode" "github.com/celestiaorg/celestia-app/x/blob/types" @@ -68,11 +66,11 @@ func Test_MerkleMountainRangeHeights(t *testing.T) { // the commitment is calculated. If this is the case, the expected commitment // bytes will need to be updated. func TestCreateCommitment(t *testing.T) { - ns1 := appns.MustNewV0(bytes.Repeat([]byte{0x1}, appns.NamespaceVersionZeroIDSize)) + ns1 := shares.MustNewV0Namespace(bytes.Repeat([]byte{0x1}, shares.NamespaceVersionZeroIDSize)) type test struct { name string - namespace appns.Namespace + namespace shares.Namespace blob []byte expected []byte expectErr bool @@ -96,7 +94,7 @@ func TestCreateCommitment(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - blob := &blob.Blob{ + blob := &shares.Blob{ NamespaceId: tt.namespace.ID, Data: tt.blob, ShareVersion: uint32(tt.shareVersion), @@ -128,23 +126,23 @@ func TestValidateBasic(t *testing.T) { // MsgPayForBlobs that uses parity shares namespace paritySharesMsg := validMsgPayForBlobs(t) - paritySharesMsg.Namespaces[0] = appns.ParitySharesNamespace.Bytes() + paritySharesMsg.Namespaces[0] = shares.ParitySharesNamespace.Bytes() // MsgPayForBlobs that uses tail padding namespace tailPaddingMsg := validMsgPayForBlobs(t) - tailPaddingMsg.Namespaces[0] = appns.TailPaddingNamespace.Bytes() + tailPaddingMsg.Namespaces[0] = shares.TailPaddingNamespace.Bytes() // MsgPayForBlobs that uses transaction namespace txNamespaceMsg := validMsgPayForBlobs(t) - txNamespaceMsg.Namespaces[0] = appns.TxNamespace.Bytes() + txNamespaceMsg.Namespaces[0] = shares.TxNamespace.Bytes() // MsgPayForBlobs that uses intermediateStateRoots namespace intermediateStateRootsNamespaceMsg := validMsgPayForBlobs(t) - intermediateStateRootsNamespaceMsg.Namespaces[0] = appns.IntermediateStateRootsNamespace.Bytes() + intermediateStateRootsNamespaceMsg.Namespaces[0] = shares.IntermediateStateRootsNamespace.Bytes() // MsgPayForBlobs that uses the max primary reserved namespace maxReservedNamespaceMsg := validMsgPayForBlobs(t) - maxReservedNamespaceMsg.Namespaces[0] = appns.MaxPrimaryReservedNamespace.Bytes() + maxReservedNamespaceMsg.Namespaces[0] = shares.MaxPrimaryReservedNamespace.Bytes() // MsgPayForBlobs that has an empty share commitment emptyShareCommitment := validMsgPayForBlobs(t) @@ -262,13 +260,13 @@ func totalBlobSize(size int) int { func validMsgPayForBlobs(t *testing.T) *types.MsgPayForBlobs { signer, err := testnode.NewOfflineSigner() require.NoError(t, err) - ns1 := append(appns.NamespaceVersionZeroPrefix, bytes.Repeat([]byte{0x01}, appns.NamespaceVersionZeroIDSize)...) + ns1 := append(shares.NamespaceVersionZeroPrefix, bytes.Repeat([]byte{0x01}, shares.NamespaceVersionZeroIDSize)...) data := bytes.Repeat([]byte{2}, totalBlobSize(appconsts.ContinuationSparseShareContentSize*12)) - pblob := &blob.Blob{ + pblob := &shares.Blob{ Data: data, NamespaceId: ns1, - NamespaceVersion: uint32(appns.NamespaceVersionZero), + NamespaceVersion: uint32(shares.NamespaceVersionZero), ShareVersion: uint32(appconsts.ShareVersionZero), } @@ -282,25 +280,25 @@ func validMsgPayForBlobs(t *testing.T) *types.MsgPayForBlobs { func invalidNamespaceVersionMsgPayForBlobs(t *testing.T) *types.MsgPayForBlobs { signer, err := testnode.NewOfflineSigner() require.NoError(t, err) - ns1 := append(appns.NamespaceVersionZeroPrefix, bytes.Repeat([]byte{0x01}, appns.NamespaceVersionZeroIDSize)...) + ns1 := append(shares.NamespaceVersionZeroPrefix, bytes.Repeat([]byte{0x01}, shares.NamespaceVersionZeroIDSize)...) data := bytes.Repeat([]byte{2}, totalBlobSize(appconsts.ContinuationSparseShareContentSize*12)) - pblob := &blob.Blob{ + pblob := &shares.Blob{ Data: data, NamespaceId: ns1, NamespaceVersion: uint32(255), ShareVersion: uint32(appconsts.ShareVersionZero), } - blobs := []*blob.Blob{pblob} + blobs := []*shares.Blob{pblob} commitments, err := types.CreateCommitments(blobs) require.NoError(t, err) namespaceVersions, namespaceIds, sizes, shareVersions := types.ExtractBlobComponents(blobs) - namespaces := []appns.Namespace{} + namespaces := []shares.Namespace{} for i := range namespaceVersions { - namespace, err := appns.New(uint8(namespaceVersions[i]), namespaceIds[i]) + namespace, err := shares.NewNamespace(uint8(namespaceVersions[i]), namespaceIds[i]) require.NoError(t, err) namespaces = append(namespaces, namespace) } @@ -326,17 +324,17 @@ func TestNewMsgPayForBlobs(t *testing.T) { type testCase struct { name string signer string - blobs []*blob.Blob + blobs []*shares.Blob expectedErr bool } - ns1 := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) - ns2 := appns.MustNewV0(bytes.Repeat([]byte{2}, appns.NamespaceVersionZeroIDSize)) + ns1 := shares.MustNewV0Namespace(bytes.Repeat([]byte{1}, shares.NamespaceVersionZeroIDSize)) + ns2 := shares.MustNewV0Namespace(bytes.Repeat([]byte{2}, shares.NamespaceVersionZeroIDSize)) testCases := []testCase{ { name: "valid msg PFB with small blob", signer: testfactory.TestAccAddr, - blobs: []*blob.Blob{ + blobs: []*shares.Blob{ { NamespaceVersion: uint32(ns1.Version), NamespaceId: ns1.ID, @@ -349,7 +347,7 @@ func TestNewMsgPayForBlobs(t *testing.T) { { name: "valid msg PFB with large blob", signer: testfactory.TestAccAddr, - blobs: []*blob.Blob{ + blobs: []*shares.Blob{ { NamespaceVersion: uint32(ns1.Version), NamespaceId: ns1.ID, @@ -362,7 +360,7 @@ func TestNewMsgPayForBlobs(t *testing.T) { { name: "valid msg PFB with two blobs", signer: testfactory.TestAccAddr, - blobs: []*blob.Blob{ + blobs: []*shares.Blob{ { NamespaceVersion: uint32(ns1.Version), NamespaceId: ns1.ID, @@ -380,7 +378,7 @@ func TestNewMsgPayForBlobs(t *testing.T) { { name: "unsupported share version returns an error", signer: testfactory.TestAccAddr, - blobs: []*blob.Blob{ + blobs: []*shares.Blob{ { NamespaceVersion: uint32(ns1.Version), NamespaceId: ns1.ID, @@ -393,10 +391,10 @@ func TestNewMsgPayForBlobs(t *testing.T) { { name: "msg PFB with tx namespace returns an error", signer: testfactory.TestAccAddr, - blobs: []*blob.Blob{ + blobs: []*shares.Blob{ { - NamespaceVersion: uint32(appns.TxNamespace.Version), - NamespaceId: appns.TxNamespace.ID, + NamespaceVersion: uint32(shares.TxNamespace.Version), + NamespaceId: shares.TxNamespace.ID, Data: tmrand.Bytes(1000000), ShareVersion: uint32(appconsts.ShareVersionZero), }, @@ -406,7 +404,7 @@ func TestNewMsgPayForBlobs(t *testing.T) { { name: "msg PFB with invalid signer returns an error", signer: testfactory.TestAccAddr[:10], - blobs: []*blob.Blob{ + blobs: []*shares.Blob{ { NamespaceVersion: uint32(ns1.Version), NamespaceId: ns1.ID, @@ -427,7 +425,7 @@ func TestNewMsgPayForBlobs(t *testing.T) { for i, blob := range tc.blobs { assert.Equal(t, uint32(len(blob.Data)), msgPFB.BlobSizes[i]) - ns, err := appns.From(msgPFB.Namespaces[i]) + ns, err := shares.From(msgPFB.Namespaces[i]) assert.NoError(t, err) assert.Equal(t, ns.ID, blob.NamespaceId) assert.Equal(t, uint32(ns.Version), blob.NamespaceVersion) @@ -443,48 +441,48 @@ func TestNewMsgPayForBlobs(t *testing.T) { func TestValidateBlobs(t *testing.T) { type test struct { name string - blob *blob.Blob + blob *shares.Blob expectError bool } tests := []test{ { name: "valid blob", - blob: &blob.Blob{ + blob: &shares.Blob{ Data: []byte{1}, - NamespaceId: appns.RandomBlobNamespace().ID, + NamespaceId: shares.RandomBlobNamespace().ID, ShareVersion: uint32(appconsts.DefaultShareVersion), - NamespaceVersion: uint32(appns.NamespaceVersionZero), + NamespaceVersion: uint32(shares.NamespaceVersionZero), }, expectError: false, }, { name: "invalid share version", - blob: &blob.Blob{ + blob: &shares.Blob{ Data: []byte{1}, - NamespaceId: appns.RandomBlobNamespace().ID, + NamespaceId: shares.RandomBlobNamespace().ID, ShareVersion: uint32(10000), - NamespaceVersion: uint32(appns.NamespaceVersionZero), + NamespaceVersion: uint32(shares.NamespaceVersionZero), }, expectError: true, }, { name: "empty blob", - blob: &blob.Blob{ + blob: &shares.Blob{ Data: []byte{}, - NamespaceId: appns.RandomBlobNamespace().ID, + NamespaceId: shares.RandomBlobNamespace().ID, ShareVersion: uint32(appconsts.DefaultShareVersion), - NamespaceVersion: uint32(appns.NamespaceVersionZero), + NamespaceVersion: uint32(shares.NamespaceVersionZero), }, expectError: true, }, { name: "invalid namespace", - blob: &blob.Blob{ + blob: &shares.Blob{ Data: []byte{1}, - NamespaceId: appns.TxNamespace.ID, + NamespaceId: shares.TxNamespace.ID, ShareVersion: uint32(appconsts.DefaultShareVersion), - NamespaceVersion: uint32(appns.NamespaceVersionZero), + NamespaceVersion: uint32(shares.NamespaceVersionZero), }, expectError: true, }, diff --git a/x/upgrade/upgrade_test.go b/x/upgrade/upgrade_test.go index 2921d472e5..37b30f5b0e 100644 --- a/x/upgrade/upgrade_test.go +++ b/x/upgrade/upgrade_test.go @@ -9,9 +9,9 @@ import ( "github.com/celestiaorg/celestia-app/app/encoding" "github.com/celestiaorg/celestia-app/pkg/appconsts" "github.com/celestiaorg/celestia-app/pkg/da" - "github.com/celestiaorg/celestia-app/pkg/shares" "github.com/celestiaorg/celestia-app/pkg/square" "github.com/celestiaorg/celestia-app/pkg/user" + "github.com/celestiaorg/celestia-app/shares" "github.com/celestiaorg/celestia-app/test/util" "github.com/celestiaorg/celestia-app/test/util/testfactory" "github.com/celestiaorg/celestia-app/x/upgrade" From 8937ff83c8257a247bb2eea73d8e0eb134324583 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Fri, 27 Oct 2023 17:51:49 +0200 Subject: [PATCH 2/2] generate protos and update README's --- README.md | 2 +- shares/blob.pb.go | 39 ++++++++++++++++++------------------ specs/src/specs/namespace.md | 2 +- specs/src/specs/shares.md | 2 +- 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 8d0d17792b..5e7960c492 100644 --- a/README.md +++ b/README.md @@ -175,7 +175,7 @@ make goreleaser-build Package-specific READMEs aim to explain implementation details for developers that are contributing to these packages. The [specs](https://celestiaorg.github.io/celestia-app/) aim to explain the protocol as a whole for developers building on top of Celestia. -- [pkg/shares](./pkg/shares/README.md) +- [shares](./shares/README.md) - [pkg/wrapper](./pkg/wrapper/README.md) - [x/blob](./x/blob/README.md) - [x/blobstream](./x/blobstream/README.md) diff --git a/shares/blob.pb.go b/shares/blob.pb.go index 1549db775f..2411397a18 100644 --- a/shares/blob.pb.go +++ b/shares/blob.pb.go @@ -165,26 +165,25 @@ func init() { func init() { proto.RegisterFile("celestia/core/v1/blob/blob.proto", fileDescriptor_c6da8a12c2dbf976) } var fileDescriptor_c6da8a12c2dbf976 = []byte{ - // 289 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x48, 0x4e, 0xcd, 0x49, - 0x2d, 0x2e, 0xc9, 0x4c, 0xd4, 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x2f, 0x33, 0xd4, 0x4f, 0xca, 0xc9, - 0x4f, 0x02, 0x13, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0xa2, 0x30, 0x15, 0x7a, 0x20, 0x15, - 0x7a, 0x65, 0x86, 0x7a, 0x20, 0x49, 0xa5, 0x7e, 0x46, 0x2e, 0x16, 0xa7, 0x9c, 0xfc, 0x24, 0x21, - 0x45, 0x2e, 0x9e, 0xbc, 0xc4, 0xdc, 0xd4, 0xe2, 0x82, 0xc4, 0xe4, 0xd4, 0xf8, 0xcc, 0x14, 0x09, - 0x46, 0x05, 0x46, 0x0d, 0x9e, 0x20, 0x6e, 0xb8, 0x98, 0x67, 0x8a, 0x90, 0x10, 0x17, 0x4b, 0x4a, - 0x62, 0x49, 0xa2, 0x04, 0x13, 0x58, 0x0a, 0xcc, 0x16, 0x52, 0xe6, 0xe2, 0x2d, 0xce, 0x48, 0x2c, - 0x4a, 0x8d, 0x2f, 0x4b, 0x2d, 0x2a, 0xce, 0xcc, 0xcf, 0x93, 0x60, 0x56, 0x60, 0xd4, 0xe0, 0x0d, - 0xe2, 0x01, 0x0b, 0x86, 0x41, 0xc4, 0x84, 0xb4, 0xb9, 0x04, 0x11, 0x66, 0xc3, 0x14, 0xb2, 0x80, - 0x15, 0x0a, 0xc0, 0x25, 0xa0, 0x8a, 0x95, 0x52, 0xb8, 0xd8, 0x40, 0x0e, 0x0a, 0xa9, 0x10, 0xe2, - 0xe3, 0x62, 0x2a, 0xa9, 0x80, 0x3a, 0x84, 0xa9, 0xa4, 0x42, 0xc8, 0x90, 0x8b, 0x15, 0xe4, 0xe6, - 0x62, 0x09, 0x26, 0x05, 0x66, 0x0d, 0x6e, 0x23, 0x69, 0x3d, 0xac, 0x5e, 0xd2, 0x03, 0xe9, 0x0e, - 0x82, 0xa8, 0x14, 0x12, 0xe7, 0x62, 0x2f, 0xa9, 0x2c, 0x00, 0x7b, 0x08, 0xe4, 0x30, 0xce, 0x20, - 0x36, 0x10, 0xd7, 0x33, 0xc5, 0xc9, 0xed, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, - 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, - 0xa2, 0x74, 0xd2, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, 0xf5, 0x61, 0x16, 0xe4, - 0x17, 0xa5, 0xc3, 0xd9, 0xba, 0x89, 0x05, 0x05, 0xfa, 0x05, 0xd9, 0xe9, 0xe0, 0xc0, 0x4d, 0x62, - 0x03, 0x87, 0xae, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x06, 0x11, 0x3d, 0x47, 0x81, 0x01, 0x00, - 0x00, + // 286 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x90, 0xc1, 0x4a, 0xc3, 0x30, + 0x1c, 0xc6, 0x97, 0xae, 0x56, 0xfc, 0xaf, 0x13, 0x0d, 0x88, 0x05, 0x21, 0xd4, 0x79, 0x29, 0x8a, + 0x29, 0xd5, 0x37, 0x18, 0x5e, 0x76, 0x2d, 0xe2, 0xc1, 0xcb, 0x48, 0xdb, 0xb0, 0x15, 0xba, 0xa5, + 0x34, 0xb1, 0xd4, 0xa7, 0xd0, 0xc7, 0xf2, 0xb8, 0xa3, 0x47, 0x69, 0x5f, 0x44, 0x92, 0xad, 0xf5, + 0xe2, 0x25, 0xfc, 0xf3, 0x7d, 0xbf, 0x24, 0xdf, 0x17, 0xf0, 0x53, 0x5e, 0x70, 0xa9, 0x72, 0x16, + 0xa6, 0xa2, 0xe2, 0x61, 0x1d, 0x85, 0x49, 0x21, 0x12, 0xb3, 0xd0, 0xb2, 0x12, 0x4a, 0xe0, 0x8b, + 0x9e, 0xa0, 0x9a, 0xa0, 0x75, 0x44, 0xb5, 0x39, 0xfb, 0x40, 0x60, 0xcf, 0x0b, 0x91, 0xe0, 0x6b, + 0x70, 0xb7, 0x6c, 0xc3, 0x65, 0xc9, 0x52, 0xbe, 0xcc, 0x33, 0x0f, 0xf9, 0x28, 0x70, 0xe3, 0xc9, + 0xa0, 0x2d, 0x32, 0x8c, 0xc1, 0xce, 0x98, 0x62, 0x9e, 0x65, 0x2c, 0x33, 0xe3, 0x1b, 0x98, 0xca, + 0x35, 0xab, 0xf8, 0xb2, 0xe6, 0x95, 0xcc, 0xc5, 0xd6, 0x1b, 0xfb, 0x28, 0x98, 0xc6, 0xae, 0x11, + 0x5f, 0xf6, 0x1a, 0xbe, 0x83, 0xf3, 0xbf, 0xbb, 0x7b, 0xd0, 0x36, 0xe0, 0xd9, 0x60, 0x1c, 0xe0, + 0x59, 0x06, 0x8e, 0x0e, 0xf4, 0xdc, 0xe0, 0x53, 0xb0, 0x54, 0x73, 0x08, 0x62, 0xa9, 0x06, 0x47, + 0x70, 0xa4, 0x33, 0x4b, 0xcf, 0xf2, 0xc7, 0xc1, 0xe4, 0xe1, 0x8a, 0xfe, 0x5b, 0x89, 0xea, 0xd3, + 0xf1, 0x9e, 0xc4, 0x97, 0x70, 0xac, 0xde, 0x4b, 0x53, 0x48, 0x07, 0x3b, 0x89, 0x1d, 0xbd, 0x5d, + 0x64, 0xf3, 0xa7, 0xaf, 0x96, 0xa0, 0x5d, 0x4b, 0xd0, 0x4f, 0x4b, 0xd0, 0x67, 0x47, 0x46, 0xbb, + 0x8e, 0x8c, 0xbe, 0x3b, 0x32, 0x7a, 0xbd, 0x5d, 0xe5, 0x6a, 0xfd, 0x96, 0xd0, 0x54, 0x6c, 0xc2, + 0xfe, 0x01, 0x51, 0xad, 0x86, 0xf9, 0x9e, 0x95, 0x65, 0x68, 0xea, 0xc9, 0xc4, 0x31, 0x7f, 0xfb, + 0xf8, 0x1b, 0x00, 0x00, 0xff, 0xff, 0xff, 0x46, 0x58, 0x19, 0x7f, 0x01, 0x00, 0x00, } func (m *Blob) Marshal() (dAtA []byte, err error) { diff --git a/specs/src/specs/namespace.md b/specs/src/specs/namespace.md index 871e204fc5..9da6e3c7cf 100644 --- a/specs/src/specs/namespace.md +++ b/specs/src/specs/namespace.md @@ -89,7 +89,7 @@ Applications MUST refrain from using the [reserved namespaces](#reserved-namespa ## Implementation -See [pkg/namespace](../../../pkg/namespace). +See [shares](../../../shares). ## Protobuf Definition diff --git a/specs/src/specs/shares.md b/specs/src/specs/shares.md index cfa57e2f25..00749b3c30 100644 --- a/specs/src/specs/shares.md +++ b/specs/src/specs/shares.md @@ -112,7 +112,7 @@ Share splitting is the process of converting a blob into a share sequence. The p ## Implementation -See [pkg/shares](../../../pkg/shares). +See [shares](../../../shares). ## References