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!: allow for hardcoded upgrade schedules #2583

Merged
merged 16 commits into from
Oct 10, 2023
Merged
8 changes: 6 additions & 2 deletions app/test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ func (s *IntegrationTestSuite) TestMaxBlockSize() {
require.GreaterOrEqual(t, size, uint64(appconsts.MinSquareSize))

// assert that the app version is correctly set
require.Equal(t, appconsts.LatestVersion, blockRes.Block.Header.Version.App)
// FIXME: This should return the latest version but tendermint v0.34.x doesn't copy
// over the version when converting from proto so it disappears
require.EqualValues(t, 0, blockRes.Block.Header.Version.App)

sizes = append(sizes, size)
ExtendBlobTest(t, blockRes.Block)
Expand Down Expand Up @@ -329,7 +331,9 @@ func (s *IntegrationTestSuite) TestShareInclusionProof() {
blockRes, err := node.Block(context.Background(), &txResp.Height)
require.NoError(t, err)

require.Equal(t, appconsts.LatestVersion, blockRes.Block.Header.Version.App)
// FIXME: This should return the latest version but tendermint v0.34.x doesn't copy
// over the version when converting from proto so it disappears
require.EqualValues(t, 0, blockRes.Block.Header.Version.App)

_, isBlobTx := coretypes.UnmarshalBlobTx(blockRes.Block.Txs[txResp.Index])
require.True(t, isBlobTx)
Expand Down
1 change: 0 additions & 1 deletion proto/celestia/blob/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package celestia.blob.v1;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "celestia/blob/v1/params.proto";

option go_package = "github.com/celestiaorg/celestia-app/x/blob/types";
Expand Down
1 change: 0 additions & 1 deletion proto/celestia/qgb/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package celestia.qgb.v1;
import "celestia/qgb/v1/genesis.proto";
import "celestia/qgb/v1/types.proto";
import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";
import "google/protobuf/any.proto";
Expand Down
4 changes: 2 additions & 2 deletions proto/celestia/upgrade/v1/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package celestia.upgrade.v1;

option go_package = "github.com/celestiaorg/celestia-app/x/upgrade";

// MsgPayForBlobs pays for the inclusion of a blob in the block.
// MsgVersionChange is a message that signals an app version change
message MsgVersionChange {
// the new version to propose the change to
// the app version this message proposes upgrading to
uint64 version = 1;
}
1 change: 1 addition & 0 deletions test/util/testnode/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ func DefaultParams() *tmproto.ConsensusParams {
cparams := types.DefaultConsensusParams()
cparams.Block.TimeIotaMs = 1
cparams.Block.MaxBytes = appconsts.DefaultMaxBytes
cparams.Version.AppVersion = appconsts.LatestVersion
return cparams
}

Expand Down
2 changes: 1 addition & 1 deletion x/upgrade/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (k Keeper) SetUpgradedConsensusState(ctx sdk.Context, planHeight int64, bz
return nil
}

// GetUpgradedConsensusState set the expected upgraded consensus state for the next version of this chain
// GetUpgradedConsensusState get the expected upgraded consensus state for the next version of this chain
func (k Keeper) GetUpgradedConsensusState(ctx sdk.Context, lastHeight int64) ([]byte, bool) {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.UpgradedConsStateKey(lastHeight))
Expand Down
File renamed without changes.
40 changes: 36 additions & 4 deletions x/upgrade/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ import (
"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/test/util"
"github.com/celestiaorg/celestia-app/test/util/testfactory"
"github.com/celestiaorg/celestia-app/x/upgrade"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/types"
bank "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
Expand All @@ -21,7 +26,15 @@ import (
)

func TestUpgradeAppVersion(t *testing.T) {
testApp := setupTestApp(t, upgrade.NewSchedule(upgrade.NewPlan(3, 5, 2)))
testApp, kr := setupTestApp(t, upgrade.NewSchedule(upgrade.NewPlan(3, 5, 2)))
addr := testfactory.GetAddress(kr, "account")
encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...)
signer, err := user.NewSigner(kr, nil, addr, encCfg.TxConfig, testApp.GetChainID(), 1, 0)
require.NoError(t, err)
coins := types.NewCoins(types.NewCoin("utia", types.NewInt(10)))
sendMsg := bank.NewMsgSend(addr, addr, coins)
sendTx, err := signer.CreateTx([]types.Msg{sendMsg}, user.SetGasLimitAndFee(1e6, 1))
require.NoError(t, err)

upgradeTx, err := upgrade.NewMsgVersionChange(testApp.GetTxConfig(), 3)
require.NoError(t, err)
Expand Down Expand Up @@ -66,6 +79,25 @@ func TestUpgradeAppVersion(t *testing.T) {
require.EqualValues(t, 2, msg.Version)
}

{
// we send the same proposal but now with an existing message and a
// smaller BlockDataSize. It should kick out the tx in place of the
// upgrade tx
resp := testApp.PrepareProposal(abci.RequestPrepareProposal{
Height: 2,
ChainId: testApp.GetChainID(),
BlockData: &tmproto.Data{Txs: [][]byte{sendTx}},
BlockDataSize: 1e2,
})
require.Len(t, resp.BlockData.Txs, 1)
tx, err := testApp.GetTxConfig().TxDecoder()(resp.BlockData.Txs[0])
require.NoError(t, err)
require.Len(t, tx.GetMsgs(), 1)
msg, ok := tx.GetMsgs()[0].(*upgrade.MsgVersionChange)
require.True(t, ok)
require.EqualValues(t, 2, msg.Version)
}
rootulp marked this conversation as resolved.
Show resolved Hide resolved

{
// Height 5 however is outside the range and thus the upgrade
// message should not be prepended
Expand Down Expand Up @@ -153,7 +185,7 @@ func TestUpgradeAppVersion(t *testing.T) {
require.Len(t, respPrepareProposal.BlockData.Txs, 0)
}

func setupTestApp(t *testing.T, schedule upgrade.Schedule) *app.App {
func setupTestApp(t *testing.T, schedule upgrade.Schedule) (*app.App, keyring.Keyring) {
t.Helper()

db := dbm.NewMemDB()
Expand All @@ -163,7 +195,7 @@ func setupTestApp(t *testing.T, schedule upgrade.Schedule) *app.App {
upgradeSchedule[chainID] = schedule
testApp := app.New(log.NewNopLogger(), db, nil, true, 0, encCfg, upgradeSchedule, util.EmptyAppOptions{})

genesisState, _, _ := util.GenesisStateWithSingleValidator(testApp)
genesisState, _, kr := util.GenesisStateWithSingleValidator(testApp, "account")

stateBytes, err := json.MarshalIndent(genesisState, "", " ")
require.NoError(t, err)
Expand Down Expand Up @@ -194,5 +226,5 @@ func setupTestApp(t *testing.T, schedule upgrade.Schedule) *app.App {
require.EqualValues(t, app.DefaultConsensusParams().Version.AppVersion, testApp.GetBaseApp().AppVersion())

_ = testApp.Commit()
return testApp
return testApp, kr
}