Skip to content

Commit

Permalink
chore!: migrate to go-square repo (celestiaorg#3026)
Browse files Browse the repository at this point in the history
Uses the go-square repo for square construction

---------

Co-authored-by: Rootul P <[email protected]>
  • Loading branch information
cmwaters and rootulp authored Feb 6, 2024
1 parent ac545a2 commit 2d261a2
Show file tree
Hide file tree
Showing 121 changed files with 985 additions and 8,922 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ 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)
- [pkg/wrapper](./pkg/wrapper/README.md)
- [x/blob](./x/blob/README.md)
- [x/blobstream](./x/blobstream/README.md)
Expand Down
7 changes: 5 additions & 2 deletions app/check_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package app
import (
"fmt"

"github.com/celestiaorg/celestia-app/pkg/blob"
"github.com/celestiaorg/celestia-app/pkg/appconsts"
blobtypes "github.com/celestiaorg/celestia-app/x/blob/types"
"github.com/celestiaorg/go-square/blob"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
abci "github.com/tendermint/tendermint/abci/types"
)
Expand Down Expand Up @@ -37,7 +38,9 @@ func (app *App) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx {
switch req.Type {
// new transactions must be checked in their entirety
case abci.CheckTxType_New:
err := blobtypes.ValidateBlobTx(app.txConfig, btx)
// FIXME: we have a hardcoded subtree root threshold here. This is because we can't access
// the app version because the context is not initialized
err := blobtypes.ValidateBlobTx(app.txConfig, btx, appconsts.DefaultSubtreeRootThreshold)
if err != nil {
return sdkerrors.ResponseCheckTxWithEvents(err, 0, 0, []abci.Event{}, false)
}
Expand Down
6 changes: 3 additions & 3 deletions app/errors/insufficient_gas_price_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ 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"
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"
"github.com/celestiaorg/go-square/namespace"
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 @@ -37,14 +37,14 @@ func TestInsufficientMinGasPriceIntegration(t *testing.T) {
addr := testfactory.GetAddress(kr, account)
enc := encoding.MakeConfig(app.ModuleEncodingRegisters...)
acc := testutil.DirectQueryAccount(testApp, addr)
signer, err := user.NewSigner(kr, nil, addr, enc.TxConfig, testutil.ChainID, acc.GetAccountNumber(), acc.GetSequence())
signer, err := user.NewSigner(kr, nil, addr, enc.TxConfig, testutil.ChainID, acc.GetAccountNumber(), acc.GetSequence(), appconsts.LatestVersion)
require.NoError(t, err)

fee := sdk.NewCoins(sdk.NewCoin(app.BondDenom, sdk.NewInt(feeAmount)))
b, err := blob.NewBlob(namespace.RandomNamespace(), []byte("hello world"), 0)
require.NoError(t, err)

msg, err := blob.NewMsgPayForBlobs(signer.Address().String(), b)
msg, err := blob.NewMsgPayForBlobs(signer.Address().String(), appconsts.LatestVersion, b)
require.NoError(t, err)

tx, err := signer.CreateTx([]sdk.Msg{msg}, user.SetGasLimit(gasLimit), user.SetFeeAmount(fee))
Expand Down
6 changes: 3 additions & 3 deletions app/errors/nonce_mismatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ 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"
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"
"github.com/celestiaorg/go-square/namespace"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/stretchr/testify/require"
Expand All @@ -32,13 +32,13 @@ func TestNonceMismatchIntegration(t *testing.T) {
enc := encoding.MakeConfig(app.ModuleEncodingRegisters...)
acc := testutil.DirectQueryAccount(testApp, addr)
// set the sequence to an incorrect value
signer, err := user.NewSigner(kr, nil, addr, enc.TxConfig, testutil.ChainID, acc.GetAccountNumber(), 2)
signer, err := user.NewSigner(kr, nil, addr, enc.TxConfig, testutil.ChainID, acc.GetAccountNumber(), 2, appconsts.LatestVersion)
require.NoError(t, err)

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

msg, err := blob.NewMsgPayForBlobs(signer.Address().String(), b)
msg, err := blob.NewMsgPayForBlobs(signer.Address().String(), appconsts.LatestVersion, b)
require.NoError(t, err)

tx, err := signer.CreateTx([]sdk.Msg{msg})
Expand Down
10 changes: 7 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/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/go-square/shares"
"github.com/celestiaorg/go-square/square"
"github.com/celestiaorg/rsmt2d"
coretypes "github.com/tendermint/tendermint/types"
)
Expand All @@ -13,7 +13,11 @@ import (
// version.
func ExtendBlock(data coretypes.Data, appVersion uint64) (*rsmt2d.ExtendedDataSquare, error) {
// Construct the data square from the block's transactions
dataSquare, err := square.Construct(data.Txs.ToSliceOfBytes(), appVersion, appconsts.SquareSizeUpperBound(appVersion))
dataSquare, err := square.Construct(
data.Txs.ToSliceOfBytes(),
appconsts.SquareSizeUpperBound(appVersion),
appconsts.SubtreeRootThreshold(appVersion),
)
if err != nil {
return nil, err
}
Expand Down
10 changes: 7 additions & 3 deletions app/prepare_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"time"

"github.com/celestiaorg/celestia-app/app/ante"
"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/go-square/shares"
"github.com/celestiaorg/go-square/square"
"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 @@ -62,7 +63,10 @@ func (app *App) PrepareProposal(req abci.RequestPrepareProposal) abci.ResponsePr

// build the square from the set of valid and prioritised transactions.
// The txs returned are the ones used in the square and block
dataSquare, txs, err := square.Build(txs, app.GetBaseApp().AppVersion(sdkCtx), app.GovSquareSizeUpperBound(sdkCtx))
dataSquare, txs, err := square.Build(txs,
app.GovSquareSizeUpperBound(sdkCtx),
appconsts.SubtreeRootThreshold(app.GetBaseApp().AppVersion(sdkCtx)),
)
if err != nil {
panic(err)
}
Expand Down
16 changes: 11 additions & 5 deletions app/process_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
"time"

"github.com/celestiaorg/celestia-app/app/ante"
"github.com/celestiaorg/celestia-app/pkg/appconsts"
v1 "github.com/celestiaorg/celestia-app/pkg/appconsts/v1"
"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"
blobtypes "github.com/celestiaorg/celestia-app/x/blob/types"
"github.com/celestiaorg/go-square/blob"
"github.com/celestiaorg/go-square/shares"
"github.com/celestiaorg/go-square/square"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"
Expand Down Expand Up @@ -47,6 +48,7 @@ func (app *App) ProcessProposal(req abci.RequestProcessProposal) (resp abci.Resp
app.IBCKeeper,
)
sdkCtx := app.NewProposalContext(req.Header)
subtreeRootThreshold := appconsts.SubtreeRootThreshold(app.GetBaseApp().AppVersion(sdkCtx))

// iterate over all txs and ensure that all blobTxs are valid, PFBs are correctly signed and non
// blobTxs have no PFBs present
Expand Down Expand Up @@ -100,7 +102,7 @@ func (app *App) ProcessProposal(req abci.RequestProcessProposal) (resp abci.Resp
// - that the sizes match
// - that the namespaces match between blob and PFB
// - that the share commitment is correct
if err := blobtypes.ValidateBlobTx(app.txConfig, blobTx); err != nil {
if err := blobtypes.ValidateBlobTx(app.txConfig, blobTx, subtreeRootThreshold); err != nil {
logInvalidPropBlockError(app.Logger(), req.Header, fmt.Sprintf("invalid blob tx %d", idx), err)
return reject()
}
Expand All @@ -115,7 +117,11 @@ func (app *App) ProcessProposal(req abci.RequestProcessProposal) (resp abci.Resp
}

// Construct the data square from the block's transactions
dataSquare, err := square.Construct(req.BlockData.Txs, app.GetBaseApp().AppVersion(sdkCtx), app.GovSquareSizeUpperBound(sdkCtx))
dataSquare, err := square.Construct(
req.BlockData.Txs,
app.GovSquareSizeUpperBound(sdkCtx),
subtreeRootThreshold,
)
if err != nil {
logInvalidPropBlockError(app.Logger(), req.Header, "failure to compute data square from transactions:", err)
return reject()
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,8 +4,8 @@ import (
"testing"
"time"

appns "github.com/celestiaorg/celestia-app/pkg/namespace"
"github.com/celestiaorg/celestia-app/test/util/testnode"
appns "github.com/celestiaorg/go-square/namespace"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/stretchr/testify/suite"
tmrand "github.com/tendermint/tendermint/libs/rand"
Expand Down
7 changes: 4 additions & 3 deletions app/test/check_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ 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/appconsts"
"github.com/celestiaorg/celestia-app/pkg/user"
testutil "github.com/celestiaorg/celestia-app/test/util"
"github.com/celestiaorg/celestia-app/test/util/blobfactory"
"github.com/celestiaorg/celestia-app/test/util/testfactory"
blobtypes "github.com/celestiaorg/celestia-app/x/blob/types"
"github.com/celestiaorg/go-square/blob"
appns "github.com/celestiaorg/go-square/namespace"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
Expand Down Expand Up @@ -190,7 +191,7 @@ func TestCheckTx(t *testing.T) {

func createSigner(t *testing.T, kr keyring.Keyring, accountName string, enc client.TxConfig, accNum uint64) *user.Signer {
addr := testfactory.GetAddress(kr, accountName)
signer, err := user.NewSigner(kr, nil, addr, enc, testutil.ChainID, accNum, 0)
signer, err := user.NewSigner(kr, nil, addr, enc, testutil.ChainID, accNum, 0, appconsts.LatestVersion)
require.NoError(t, err)
return signer
}
11 changes: 7 additions & 4 deletions app/test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ 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"
blobtypes "github.com/celestiaorg/celestia-app/x/blob/types"
"github.com/celestiaorg/go-square/blob"
appns "github.com/celestiaorg/go-square/namespace"
"github.com/celestiaorg/go-square/square"

abci "github.com/tendermint/tendermint/abci/types"
tmrand "github.com/tendermint/tendermint/libs/rand"
Expand Down Expand Up @@ -243,7 +243,10 @@ func (s *IntegrationTestSuite) TestShareInclusionProof() {
require.True(t, isBlobTx)

// get the blob shares
shareRange, err := square.BlobShareRange(blockRes.Block.Txs.ToSliceOfBytes(), int(txResp.Index), 0, appconsts.LatestVersion)
shareRange, err := square.BlobShareRange(blockRes.Block.Txs.ToSliceOfBytes(), int(txResp.Index), 0,
appconsts.DefaultSquareSizeUpperBound,
appconsts.DefaultSubtreeRootThreshold,
)
require.NoError(t, err)

// verify the blob shares proof
Expand Down
2 changes: 1 addition & 1 deletion app/test/max_total_blob_size_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ 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/pkg/user"
"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"
"github.com/celestiaorg/go-square/blob"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)
Expand Down
6 changes: 3 additions & 3 deletions app/test/prepare_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ 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"
testutil "github.com/celestiaorg/celestia-app/test/util"
"github.com/celestiaorg/celestia-app/test/util/blobfactory"
"github.com/celestiaorg/celestia-app/test/util/testfactory"
"github.com/celestiaorg/go-square/blob"
appns "github.com/celestiaorg/go-square/namespace"
)

func TestPrepareProposalPutsPFBsAtEnd(t *testing.T) {
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestPrepareProposalFiltering(t *testing.T) {
infos[:3],
blobfactory.NestedBlobs(
t,
appns.RandomBlobNamespaces(tmrand.NewRand(), 3),
testfactory.RandomBlobNamespaces(tmrand.NewRand(), 3),
[][]int{{100}, {1000}, {420}},
),
)
Expand Down
2 changes: 1 addition & 1 deletion app/test/priority_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ 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/test/util/blobfactory"
"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"
"github.com/celestiaorg/go-square/namespace"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
Expand Down
Loading

0 comments on commit 2d261a2

Please sign in to comment.