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

chore!: migrate to new square version #3742

Merged
merged 8 commits into from
Aug 7, 2024
Merged
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
7 changes: 5 additions & 2 deletions app/check_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/celestiaorg/celestia-app/v3/pkg/appconsts"
blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types"
"github.com/celestiaorg/go-square/blob"
blobtx "github.com/celestiaorg/go-square/v2/tx"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
abci "github.com/tendermint/tendermint/abci/types"
)
Expand All @@ -16,7 +16,10 @@ 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, err := blobtx.UnmarshalBlobTx(tx)
if isBlob && err != nil {
return sdkerrors.ResponseCheckTxWithEvents(err, 0, 0, []abci.Event{}, false)
}

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 @@ -13,7 +13,7 @@ import (
testutil "github.com/celestiaorg/celestia-app/v3/test/util"
"github.com/celestiaorg/celestia-app/v3/test/util/testfactory"
blob "github.com/celestiaorg/celestia-app/v3/x/blob/types"
"github.com/celestiaorg/go-square/namespace"
"github.com/celestiaorg/go-square/v2/share"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
Expand All @@ -40,7 +40,7 @@ func TestInsufficientMinGasPriceIntegration(t *testing.T) {
signer, err := user.NewSigner(kr, enc.TxConfig, testutil.ChainID, appconsts.LatestVersion, user.NewAccount(account, acc.GetAccountNumber(), acc.GetSequence()))
require.NoError(t, err)

b, err := blob.NewBlob(namespace.RandomNamespace(), []byte("hello world"), 0)
b, err := blob.NewBlob(share.RandomNamespace(), []byte("hello world"), 0)
require.NoError(t, err)

msg, err := blob.NewMsgPayForBlobs(signer.Account(account).Address().String(), appconsts.LatestVersion, 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 @@ -12,7 +12,7 @@ import (
testutil "github.com/celestiaorg/celestia-app/v3/test/util"
"github.com/celestiaorg/celestia-app/v3/test/util/testfactory"
blob "github.com/celestiaorg/celestia-app/v3/x/blob/types"
"github.com/celestiaorg/go-square/namespace"
"github.com/celestiaorg/go-square/v2/share"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/stretchr/testify/require"
Expand All @@ -35,7 +35,7 @@ func TestNonceMismatchIntegration(t *testing.T) {
signer, err := user.NewSigner(kr, enc.TxConfig, testutil.ChainID, appconsts.LatestVersion, user.NewAccount(account, acc.GetAccountNumber(), acc.GetSequence()+1))
require.NoError(t, err)

b, err := blob.NewBlob(namespace.RandomNamespace(), []byte("hello world"), 0)
b, err := blob.NewBlob(share.RandomNamespace(), []byte("hello world"), 0)
require.NoError(t, err)

msg, err := blob.NewMsgPayForBlobs(signer.Account(account).Address().String(), appconsts.LatestVersion, b)
Expand Down
6 changes: 3 additions & 3 deletions 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/v3/pkg/appconsts"
"github.com/celestiaorg/celestia-app/v3/pkg/da"
"github.com/celestiaorg/go-square/shares"
"github.com/celestiaorg/go-square/square"
square "github.com/celestiaorg/go-square/v2"
"github.com/celestiaorg/go-square/v2/share"
"github.com/celestiaorg/rsmt2d"
coretypes "github.com/tendermint/tendermint/types"
)
Expand All @@ -22,7 +22,7 @@ func ExtendBlock(data coretypes.Data, appVersion uint64) (*rsmt2d.ExtendedDataSq
return nil, err
}

return da.ExtendShares(shares.ToBytes(dataSquare))
return da.ExtendShares(share.ToBytes(dataSquare))
}

// EmptyBlock returns true if the given block data is considered empty by the
Expand Down
6 changes: 3 additions & 3 deletions app/prepare_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/celestiaorg/celestia-app/v3/app/ante"
"github.com/celestiaorg/celestia-app/v3/pkg/appconsts"
"github.com/celestiaorg/celestia-app/v3/pkg/da"
"github.com/celestiaorg/go-square/shares"
"github.com/celestiaorg/go-square/square"
square "github.com/celestiaorg/go-square/v2"
"github.com/celestiaorg/go-square/v2/share"
"github.com/cosmos/cosmos-sdk/telemetry"
abci "github.com/tendermint/tendermint/abci/types"
core "github.com/tendermint/tendermint/proto/tendermint/types"
Expand Down Expand Up @@ -58,7 +58,7 @@ func (app *App) PrepareProposal(req abci.RequestPrepareProposal) abci.ResponsePr
// Erasure encode the data square to create the extended data square (eds).
// Note: uses the nmt wrapper to construct the tree. See
// pkg/wrapper/nmt_wrapper.go for more information.
eds, err := da.ExtendShares(shares.ToBytes(dataSquare))
eds, err := da.ExtendShares(share.ToBytes(dataSquare))
if err != nil {
app.Logger().Error(
"failure to erasure the data square while creating a proposal block",
Expand Down
14 changes: 9 additions & 5 deletions app/process_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"github.com/celestiaorg/celestia-app/v3/pkg/appconsts"
"github.com/celestiaorg/celestia-app/v3/pkg/da"
blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types"
"github.com/celestiaorg/go-square/blob"
"github.com/celestiaorg/go-square/shares"
"github.com/celestiaorg/go-square/square"
"github.com/celestiaorg/go-square/v2"
"github.com/celestiaorg/go-square/v2/share"
blobtx "github.com/celestiaorg/go-square/v2/tx"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"
Expand Down Expand Up @@ -56,8 +56,12 @@ 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, err := blobtx.UnmarshalBlobTx(rawTx)
if isBlobTx {
if err != nil {
logInvalidPropBlockError(app.Logger(), req.Header, fmt.Sprintf("err with blob tx %d", idx), err)
return reject()
}
tx = blobTx.Tx
}

Expand Down Expand Up @@ -135,7 +139,7 @@ func (app *App) ProcessProposal(req abci.RequestProcessProposal) (resp abci.Resp
return reject()
}

eds, err := da.ExtendShares(shares.ToBytes(dataSquare))
eds, err := da.ExtendShares(share.ToBytes(dataSquare))
if err != nil {
logInvalidPropBlockError(app.Logger(), req.Header, "failure to erasure the data square", err)
return reject()
Expand Down
6 changes: 3 additions & 3 deletions app/test/big_blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/celestiaorg/celestia-app/v3/test/util/testfactory"
"github.com/celestiaorg/celestia-app/v3/test/util/testnode"
blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types"
"github.com/celestiaorg/go-square/blob"
"github.com/celestiaorg/go-square/v2/share"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)
Expand Down Expand Up @@ -61,7 +61,7 @@ func (s *BigBlobSuite) TestErrBlobsTooLarge() {

type testCase struct {
name string
blob *blob.Blob
blob *share.Blob
// want is the expected tx response ABCI code.
want uint32
}
Expand All @@ -80,7 +80,7 @@ func (s *BigBlobSuite) TestErrBlobsTooLarge() {
s.Run(tc.name, func() {
subCtx, cancel := context.WithTimeout(s.cctx.GoContext(), 30*time.Second)
defer cancel()
res, err := txClient.SubmitPayForBlob(subCtx, []*blob.Blob{tc.blob}, user.SetGasLimitAndGasPrice(1e9, appconsts.DefaultMinGasPrice))
res, err := txClient.SubmitPayForBlob(subCtx, []*share.Blob{tc.blob}, user.SetGasLimitAndGasPrice(1e9, appconsts.DefaultMinGasPrice))
require.Error(t, err)
require.NotNil(t, res)
require.Equal(t, tc.want, res.Code, res.Logs)
Expand Down
24 changes: 14 additions & 10 deletions app/test/check_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
testutil "github.com/celestiaorg/celestia-app/v3/test/util"
"github.com/celestiaorg/celestia-app/v3/test/util/blobfactory"
blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types"
"github.com/celestiaorg/go-square/blob"
appns "github.com/celestiaorg/go-square/namespace"
"github.com/celestiaorg/go-square/v2/share"
"github.com/celestiaorg/go-square/v2/tx"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
Expand All @@ -27,7 +27,8 @@ 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, err := share.NewV0Namespace(bytes.Repeat([]byte{1}, share.NamespaceVersionZeroIDSize))
require.NoError(t, err)

accs := []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"}

Expand All @@ -51,7 +52,7 @@ func TestCheckTx(t *testing.T) {
signer := createSigner(t, kr, accs[0], encCfg.TxConfig, 1)
btx := blobfactory.RandBlobTxsWithNamespacesAndSigner(
signer,
[]appns.Namespace{ns1},
[]share.Namespace{ns1},
[]int{100},
)[0]
return btx
Expand All @@ -65,7 +66,7 @@ func TestCheckTx(t *testing.T) {
signer := createSigner(t, kr, accs[1], encCfg.TxConfig, 2)
btx := blobfactory.RandBlobTxsWithNamespacesAndSigner(
signer,
[]appns.Namespace{ns1},
[]share.Namespace{ns1},
[]int{100},
)[0]
return btx
Expand All @@ -79,13 +80,16 @@ func TestCheckTx(t *testing.T) {
signer := createSigner(t, kr, accs[2], encCfg.TxConfig, 3)
btx := blobfactory.RandBlobTxsWithNamespacesAndSigner(
signer,
[]appns.Namespace{ns1},
[]share.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, _, err := tx.UnmarshalBlobTx(btx)
require.NoError(t, err)
newBlob, err := share.NewBlob(share.RandomBlobNamespace(), dtx.Blobs[0].Data(), appconsts.DefaultShareVersion, nil)
require.NoError(t, err)
dtx.Blobs[0] = newBlob
bbtx, err := tx.MarshalBlobTx(dtx.Tx, dtx.Blobs[0])
require.NoError(t, err)
return bbtx
},
Expand All @@ -98,7 +102,7 @@ func TestCheckTx(t *testing.T) {
signer := createSigner(t, kr, accs[3], encCfg.TxConfig, 4)
btx := blobfactory.RandBlobTxsWithNamespacesAndSigner(
signer,
[]appns.Namespace{ns1},
[]share.Namespace{ns1},
[]int{100},
)[0]
dtx, _ := coretypes.UnmarshalBlobTx(btx)
Expand Down
25 changes: 16 additions & 9 deletions app/test/consistent_apphash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"github.com/celestiaorg/celestia-app/v3/test/util/blobfactory"
"github.com/celestiaorg/celestia-app/v3/test/util/testfactory"
blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types"
"github.com/celestiaorg/go-square/blob"
appns "github.com/celestiaorg/go-square/namespace"
"github.com/celestiaorg/go-square/v2/share"
"github.com/celestiaorg/go-square/v2/tx"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
Expand All @@ -37,7 +37,7 @@ import (

type BlobTx struct {
author string
blobs []*blob.Blob
blobs []*share.Blob
txOptions []user.TxOption
}

Expand Down Expand Up @@ -268,10 +268,13 @@ func TestConsistentAppHash(t *testing.T) {
thirdBlockEncodedTxs, err := processSdkMessages(valSigner, thirdBlockSdkMsgs)
require.NoError(t, err)

blob, err := share.NewBlob(fixedNamespace(), []byte{1}, appconsts.DefaultShareVersion, nil)
require.NoError(t, err)

// Create a Blob Tx
blobTx := BlobTx{
author: accountNames[1],
blobs: []*blob.Blob{blob.New(fixedNamespace(), []byte{1}, appconsts.DefaultShareVersion)},
blobs: []*share.Blob{blob},
txOptions: blobfactory.DefaultTxOpts(),
}
encodedBlobTx, _, err := signer.CreatePayForBlobs(blobTx.author, blobTx.blobs, blobTx.txOptions...)
Expand Down Expand Up @@ -300,11 +303,12 @@ func TestConsistentAppHash(t *testing.T) {
}

// fixedNamespace returns a hardcoded namespace
func fixedNamespace() appns.Namespace {
return appns.Namespace{
Version: 0,
ID: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 37, 67, 154, 200, 228, 130, 74, 147, 162, 11},
func fixedNamespace() share.Namespace {
ns, err := share.NewNamespace(0, []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 37, 67, 154, 200, 228, 130, 74, 147, 162, 11})
if err != nil {
panic(err)
}
return ns
}

// deterministicKeyRing returns a deterministic keyring and a list of deterministic public keys
Expand Down Expand Up @@ -430,10 +434,13 @@ func executeTxs(testApp *app.App, encodedBlobTx []byte, encodedSdkTxs [][]byte,
// Deliver Blob Txs
if len(encodedBlobTx) != 0 {
// Deliver Blob Tx
blob, isBlobTx := blob.UnmarshalBlobTx(encodedBlobTx)
blob, isBlobTx, err := tx.UnmarshalBlobTx(encodedBlobTx)
if !isBlobTx {
return nil, nil, fmt.Errorf("Not a valid BlobTx")
}
if err != nil {
return nil, nil, fmt.Errorf("Not a valid BlobTx: %w", err)
}

respDeliverTx := testApp.DeliverTx(abci.RequestDeliverTx{Tx: blob.Tx})
if respDeliverTx.Code != uint32(0) {
Expand Down
15 changes: 9 additions & 6 deletions app/test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ import (
"github.com/celestiaorg/celestia-app/v3/pkg/da"
"github.com/celestiaorg/celestia-app/v3/pkg/user"
blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types"
"github.com/celestiaorg/go-square/blob"
appns "github.com/celestiaorg/go-square/namespace"
"github.com/celestiaorg/go-square/square"
square "github.com/celestiaorg/go-square/v2"
"github.com/celestiaorg/go-square/v2/share"

abci "github.com/tendermint/tendermint/abci/types"
tmrand "github.com/tendermint/tendermint/libs/rand"
Expand Down Expand Up @@ -287,8 +286,12 @@ func (s *IntegrationTestSuite) TestEmptyBlock() {
}
}

func newBlobWithSize(size int) *blob.Blob {
ns := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize))
func newBlobWithSize(size int) *share.Blob {
ns := share.MustNewV0Namespace(bytes.Repeat([]byte{1}, share.NamespaceVersionZeroIDSize))
data := tmrand.Bytes(size)
return blob.New(ns, data, appconsts.ShareVersionZero)
blob, err := share.NewBlob(ns, data, appconsts.ShareVersionZero, nil)
if err != nil {
panic(err)
}
return blob
}
9 changes: 4 additions & 5 deletions app/test/prepare_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import (
testutil "github.com/celestiaorg/celestia-app/v3/test/util"
"github.com/celestiaorg/celestia-app/v3/test/util/blobfactory"
"github.com/celestiaorg/celestia-app/v3/test/util/testfactory"
"github.com/celestiaorg/go-square/blob"
appns "github.com/celestiaorg/go-square/namespace"
"github.com/celestiaorg/go-square/v2/share"
)

func TestPrepareProposalPutsPFBsAtEnd(t *testing.T) {
Expand All @@ -30,16 +29,16 @@ func TestPrepareProposalPutsPFBsAtEnd(t *testing.T) {
encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...)
infos := queryAccountInfo(testApp, accnts, kr)

protoBlob, err := share.NewBlob(share.RandomBlobNamespace(), []byte{1}, appconsts.DefaultShareVersion, nil)
require.NoError(t, err)
blobTxs := blobfactory.ManyMultiBlobTx(
t,
encCfg.TxConfig,
kr,
testutil.ChainID,
accnts[:numBlobTxs],
infos[:numBlobTxs],
testfactory.Repeat([]*blob.Blob{
blob.New(appns.RandomBlobNamespace(), []byte{1}, appconsts.DefaultShareVersion),
}, numBlobTxs),
testfactory.Repeat([]*share.Blob{protoBlob}, numBlobTxs),
)

normalTxs := testutil.SendTxsWithAccounts(
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 @@ -9,7 +9,7 @@ import (

"github.com/celestiaorg/celestia-app/v3/app"
"github.com/celestiaorg/celestia-app/v3/app/encoding"
"github.com/celestiaorg/go-square/namespace"
"github.com/celestiaorg/go-square/v2/share"

"github.com/celestiaorg/celestia-app/v3/pkg/appconsts"
"github.com/celestiaorg/celestia-app/v3/pkg/user"
Expand Down Expand Up @@ -85,7 +85,7 @@ func (s *PriorityTestSuite) TestPriorityByGasPrice() {
defer wg.Done()
// ensure that it is greater than the min gas price
gasPrice := float64(s.rand.Intn(1000)+1) * appconsts.DefaultMinGasPrice
blobs := blobfactory.ManyBlobs(s.rand, []namespace.Namespace{namespace.RandomBlobNamespace()}, []int{100})
blobs := blobfactory.ManyBlobs(s.rand, []share.Namespace{share.RandomBlobNamespace()}, []int{100})
resp, err := s.txClient.BroadcastPayForBlobWithAccount(
s.cctx.GoContext(),
accName,
Expand Down
Loading
Loading