Skip to content

Commit

Permalink
feat!: version the application constants (celestiaorg#1768)
Browse files Browse the repository at this point in the history
Closes: celestiaorg#1625

---------

Co-authored-by: CHAMI Rachid <[email protected]>
Co-authored-by: Rootul P <[email protected]>
  • Loading branch information
3 people authored May 25, 2023
1 parent 578c71c commit 5b35a01
Show file tree
Hide file tree
Showing 50 changed files with 677 additions and 460 deletions.
5 changes: 4 additions & 1 deletion app/default_overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type stakingModule struct {
// DefaultGenesis returns custom x/staking module genesis state.
func (stakingModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
params := stakingtypes.DefaultParams()
params.UnbondingTime = appconsts.DefaultUnbondingTime
params.BondDenom = BondDenom

return cdc.MustMarshalJSON(&stakingtypes.GenesisState{
Expand Down Expand Up @@ -138,7 +139,9 @@ func DefaultConsensusParams() *tmproto.ConsensusParams {
Block: DefaultBlockParams(),
Evidence: coretypes.DefaultEvidenceParams(),
Validator: coretypes.DefaultValidatorParams(),
Version: coretypes.DefaultVersionParams(), // TODO: set the default version to 1
Version: tmproto.VersionParams{
AppVersion: appconsts.LatestVersion,
},
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/prepare_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ 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.GovMaxSquareSize(sdkCtx))
dataSquare, txs, err := square.Build(txs, app.GetBaseApp().AppVersion(), app.GovSquareSizeUpperBound(sdkCtx))
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion app/process_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (app *App) ProcessProposal(req abci.RequestProcessProposal) abci.ResponsePr
}

// Construct the data square from the block's transactions
dataSquare, err := square.Construct(req.BlockData.Txs, app.GovMaxSquareSize(sdkCtx))
dataSquare, err := square.Construct(req.BlockData.Txs, app.GetBaseApp().AppVersion(), app.GovSquareSizeUpperBound(sdkCtx))
if err != nil {
logInvalidPropBlockError(app.Logger(), req.Header, "failure to compute data square from transactions:", err)
return reject()
Expand Down
12 changes: 6 additions & 6 deletions app/square_size.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

// GovMaxSquareSize returns the maximum square size that can be used for a block
// GovSquareSizeUpperBound returns the maximum square size that can be used for a block
// using the governance parameter blob.GovMaxSquareSize.
func (app *App) GovMaxSquareSize(ctx sdk.Context) int {
func (app *App) GovSquareSizeUpperBound(ctx sdk.Context) int {
// TODO: fix hack that forces the max square size for the first height to
// 64. This is due to tendermint not technically supposed to be calling
// PrepareProposal when heights are not >= 1. This is remedied in versions
Expand All @@ -18,11 +18,11 @@ func (app *App) GovMaxSquareSize(ctx sdk.Context) int {
return int(appconsts.DefaultGovMaxSquareSize)
}

gmax := app.BlobKeeper.GovMaxSquareSize(ctx)
gmax := int(app.BlobKeeper.GovSquareSizeUpperBound(ctx))
// perform a secondary check on the max square size.
if gmax > appconsts.MaxSquareSize {
gmax = appconsts.MaxSquareSize
if gmax > appconsts.SquareSizeUpperBound(app.AppVersion()) {
gmax = appconsts.SquareSizeUpperBound(app.AppVersion())
}

return int(gmax)
return gmax
}
11 changes: 6 additions & 5 deletions app/test/fuzz_abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestPrepareProposalConsistency(t *testing.T) {
for i := range accounts {
accounts[i] = tmrand.Str(20)
}
maxShareCount := int64(appconsts.DefaultSquareSizeUpperBound * appconsts.DefaultSquareSizeUpperBound)

type test struct {
name string
Expand All @@ -48,7 +49,7 @@ func TestPrepareProposalConsistency(t *testing.T) {
type testSize struct {
name string
maxBytes int64
govMaxSquareSize uint64
govMaxSquareSize int
}
sizes := []testSize{
{
Expand All @@ -58,12 +59,12 @@ func TestPrepareProposalConsistency(t *testing.T) {
},
{
"max",
appconsts.MaxShareCount * appconsts.ContinuationSparseShareContentSize,
appconsts.MaxSquareSize,
maxShareCount * appconsts.ContinuationSparseShareContentSize,
appconsts.DefaultSquareSizeUpperBound,
},
{
"larger MaxBytes than SquareSize",
appconsts.MaxShareCount * appconsts.ContinuationSparseShareContentSize,
maxShareCount * appconsts.ContinuationSparseShareContentSize,
appconsts.DefaultGovMaxSquareSize,
},
{
Expand Down Expand Up @@ -119,7 +120,7 @@ func TestPrepareProposalConsistency(t *testing.T) {

// check that the square size is smaller than or equal to
// the specified size
require.LessOrEqual(t, resp.BlockData.SquareSize, size.govMaxSquareSize)
require.LessOrEqual(t, resp.BlockData.SquareSize, uint64(size.govMaxSquareSize))

res := testApp.ProcessProposal(abci.RequestProcessProposal{
BlockData: resp.BlockData,
Expand Down
138 changes: 135 additions & 3 deletions app/test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/celestiaorg/celestia-app/test/util/testnode"
"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
cosmosnet "github.com/cosmos/cosmos-sdk/testutil/network"

Expand Down Expand Up @@ -92,6 +93,135 @@ func (s *IntegrationTestSuite) WaitForBlocks(blockCount int) {
}
}

func (s *IntegrationTestSuite) TestMaxBlockSize() {
require := s.Require()
assert := s.Assert()
val := s.network.Validators[0]

// tendermint's default tx size limit is 1Mb, so we get close to that
equallySized1MbTxGen := func(c client.Context) []coretypes.Tx {
return blobfactory.RandBlobTxsWithAccounts(
s.cfg.TxConfig.TxEncoder(),
s.kr,
c.GRPCClient,
950000,
1,
false,
s.cfg.ChainID,
s.accounts[:20],
)
}

// Tendermint's default tx size limit is 1 MiB, so we get close to that by
// generating transactions of size 600 KiB because 3 blobs per transaction *
// 200,000 bytes each = 600,000 total bytes = 600 KiB per transaction.
randMultiBlob1MbTxGen := func(c client.Context) []coretypes.Tx {
return blobfactory.RandBlobTxsWithAccounts(
s.cfg.TxConfig.TxEncoder(),
s.kr,
c.GRPCClient,
200000, // 200 KiB
3,
false,
s.cfg.ChainID,
s.accounts[20:40],
)
}

// Generate 80 randomly sized txs (max size == 50 KiB). Generate these
// transactions using some of the same accounts as the previous generator to
// ensure that the sequence number is being utilized correctly in blob
// txs
randoTxGen := func(c client.Context) []coretypes.Tx {
return blobfactory.RandBlobTxsWithAccounts(
s.cfg.TxConfig.TxEncoder(),
s.kr,
c.GRPCClient,
50000,
8,
true,
s.cfg.ChainID,
s.accounts[40:120],
)
}

type test struct {
name string
txGenerator func(clientCtx client.Context) []coretypes.Tx
}

tests := []test{
{
"20 1Mb txs",
equallySized1MbTxGen,
},
{
"20 1Mb multiblob txs",
randMultiBlob1MbTxGen,
},
{
"80 random txs",
randoTxGen,
},
}
for _, tc := range tests {
s.Run(tc.name, func() {
txs := tc.txGenerator(val.ClientCtx)
hashes := make([]string, len(txs))

for i, tx := range txs {
res, err := val.ClientCtx.BroadcastTxSync(tx)
require.NoError(err)
assert.Equal(abci.CodeTypeOK, res.Code)
if res.Code != abci.CodeTypeOK {
continue
}
hashes[i] = res.TxHash
}

s.WaitForBlocks(10)

heights := make(map[int64]int)
for _, hash := range hashes {
resp, err := testnode.QueryTx(val.ClientCtx, hash, true)
require.NoError(err)
assert.NotNil(resp)
if resp == nil {
continue
}
require.Equal(abci.CodeTypeOK, resp.TxResult.Code, resp.TxResult.Log)
heights[resp.Height]++
// ensure that some gas was used
require.GreaterOrEqual(resp.TxResult.GasUsed, int64(10))
}

require.Greater(len(heights), 0)

sizes := []uint64{}
// check the square size
for height := range heights {
node, err := val.ClientCtx.GetNode()
require.NoError(err)
blockRes, err := node.Block(context.Background(), &height)
require.NoError(err)
size := blockRes.Block.Data.SquareSize

// perform basic checks on the size of the square
require.LessOrEqual(size, uint64(appconsts.DefaultGovMaxSquareSize))
require.GreaterOrEqual(size, uint64(appconsts.MinSquareSize))

// assert that the app version is correctly set
require.Equal(appconsts.LatestVersion, blockRes.Block.Header.Version.App)

sizes = append(sizes, size)
}
// ensure that at least one of the blocks used the max square size
assert.Contains(sizes, uint64(appconsts.DefaultGovMaxSquareSize))
})
require.NoError(s.network.WaitForNextBlock())
}
}

func (s *IntegrationTestSuite) TestSubmitPayForBlob() {
require := s.Require()
val := s.network.Validators[0]
Expand Down Expand Up @@ -202,11 +332,11 @@ func (s *IntegrationTestSuite) TestShareInclusionProof() {
for i, tx := range txs {
res, err := val.ClientCtx.BroadcastTxSync(tx)
require.NoError(err)
require.Equal(abci.CodeTypeOK, res.Code)
require.Equal(abci.CodeTypeOK, res.Code, res.RawLog)
hashes[i] = res.TxHash
}

s.WaitForBlocks(20)
s.WaitForBlocks(10)

for _, hash := range hashes {
txResp, err := testnode.QueryTx(val.ClientCtx, hash, true)
Expand All @@ -218,11 +348,13 @@ func (s *IntegrationTestSuite) TestShareInclusionProof() {
blockRes, err := node.Block(context.Background(), &txResp.Height)
require.NoError(err)

require.Equal(appconsts.LatestVersion, blockRes.Block.Header.Version.App)

_, isBlobTx := coretypes.UnmarshalBlobTx(blockRes.Block.Txs[txResp.Index])
require.True(isBlobTx)

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

// verify the blob shares proof
Expand Down
4 changes: 2 additions & 2 deletions app/test/process_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func TestProcessProposal(t *testing.T) {
d.Txs = [][]byte{blobTx}

// Erasure code the data to update the data root so this doesn't doesn't fail on an incorrect data root.
dataSquare, err := square.Construct(d.Txs, appconsts.MaxSquareSize)
dataSquare, err := square.Construct(d.Txs, appconsts.LatestVersion, appconsts.DefaultSquareSizeUpperBound)
require.NoError(t, err)
eds, err := da.ExtendShares(shares.ToBytes(dataSquare))
require.NoError(t, err)
Expand Down Expand Up @@ -280,7 +280,7 @@ func TestProcessProposal(t *testing.T) {
Txs: coretypes.Txs(sendTxs).ToSliceOfBytes(),
},
mutator: func(d *core.Data) {
dataSquare, err := square.Construct(d.Txs, appconsts.MaxSquareSize)
dataSquare, err := square.Construct(d.Txs, appconsts.LatestVersion, appconsts.DefaultSquareSizeUpperBound)
require.NoError(t, err)

b := shares.NewEmptyBuilder().ImportRawShare(dataSquare[1].ToBytes())
Expand Down
Loading

0 comments on commit 5b35a01

Please sign in to comment.