Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: refactor blob, namespace and shares into single package #2778

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions app/check_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/errors/insufficient_gas_price_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Question] Is there any plan on isolating test related functionalities to their own package as well?

require.NoError(t, err)

msg, err := blob.NewMsgPayForBlobs(signer.Address().String(), b)
Expand Down
4 changes: 2 additions & 2 deletions app/errors/nonce_mismatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/extend_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion app/prepare_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 2 additions & 3 deletions app/process_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion app/test/block_production_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
19 changes: 9 additions & 10 deletions app/test/check_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"}

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
},
Expand All @@ -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)
Expand Down
23 changes: 11 additions & 12 deletions app/test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
6 changes: 3 additions & 3 deletions app/test/max_total_blob_size_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand All @@ -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()
Expand Down
9 changes: 4 additions & 5 deletions app/test/prepare_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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),
)

Expand Down Expand Up @@ -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}},
),
)
Expand Down
4 changes: 2 additions & 2 deletions app/test/priority_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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),
)
Expand Down
Loading
Loading