Skip to content
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
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ RUN ignite scaffold chain gm --no-module --skip-git --address-prefix gm

WORKDIR /workspace/gm

RUN ignite app install github.com/ignite/apps/evolve@${IGNITE_EVOLVE_APP_VERSION} && \
# pin to commit before c5ac031 which introduced tools/local-da dependency not present in tagged ev-node versions
RUN ignite app install github.com/ignite/apps/evolve@1ace9dd && \
ignite evolve add && \
ignite evolve add-migrate

Expand Down
4 changes: 3 additions & 1 deletion Dockerfile.cosmos-sdk
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ RUN ignite scaffold chain gm --no-module --skip-git --address-prefix gm

WORKDIR /workspace/gm

RUN ignite app install -g github.com/ignite/apps/evolve@main
# pin to commit before c5ac031 which introduced tools/local-da dependency not present in tagged ev-node versions
RUN ignite app install -g github.com/ignite/apps/evolve@1ace9dd

# Add only the evolve migrate command (do not scaffold full evolve integration)
RUN ignite evolve add-migrate
Expand All @@ -35,6 +36,7 @@ RUN go mod edit -replace github.com/evstack/ev-node=github.com/evstack/ev-node@$
go mod edit -replace github.com/libp2p/go-libp2p-quic-transport=github.com/libp2p/go-libp2p-quic-transport@v0.33.1 && \
go mod edit -replace github.com/libp2p/go-libp2p=github.com/libp2p/go-libp2p@v0.43.0 && \
go mod edit -replace github.com/quic-go/quic-go=github.com/quic-go/quic-go@v0.54.1 && \
go mod edit -replace github.com/quic-go/qpack=github.com/quic-go/qpack@v0.5.1 && \
go mod edit -replace github.com/quic-go/webtransport-go=github.com/quic-go/webtransport-go@v0.9.0 && \
go mod tidy

Expand Down
8 changes: 8 additions & 0 deletions modules/migrationmngr/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper"

"github.com/evstack/ev-abci/modules/migrationmngr/keeper"
modulev1 "github.com/evstack/ev-abci/modules/migrationmngr/module"
Expand All @@ -33,6 +34,12 @@ type ModuleInputs struct {
StoreService store.KVStoreService
AddressCodec address.Codec
StakingKeeper types.StakingKeeper
MintKeeper mintkeeper.Keeper
}

// mintKeeperAdapter returns a types.MintKeeper implementation wrapping the SDK's mintkeeper.Keeper.
func mintKeeperAdapter(mk mintkeeper.Keeper) types.MintKeeper {
return types.MintKeeperAdapter{Keeper: mk}
}

// Dependency Injection Outputs
Expand All @@ -55,6 +62,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {
in.StoreService,
in.AddressCodec,
in.StakingKeeper,
mintKeeperAdapter(in.MintKeeper),
authority.String(),
)
m := NewAppModule(in.Cdc, k)
Expand Down
2 changes: 1 addition & 1 deletion modules/migrationmngr/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (k Keeper) EndBlock(ctx context.Context) ([]abci.ValidatorUpdate, error) {
var updates []abci.ValidatorUpdate
// Always perform immediate migration updates at the start height.
if uint64(sdkCtx.BlockHeight()) == start {
updates, err = k.migrateNow(ctx, migration, validatorSet)
updates, err = k.MigrateNow(ctx, migration, validatorSet)
if err != nil {
return nil, err
}
Expand Down
29 changes: 29 additions & 0 deletions modules/migrationmngr/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -87,11 +88,36 @@ func (m *mockStakingKeeper) IterateBondedValidatorsByPower(ctx context.Context,
return nil
}

func (m *mockStakingKeeper) GetParams(ctx context.Context) (stakingtypes.Params, error) {
return stakingtypes.DefaultParams(), nil
}

func (m *mockStakingKeeper) SetParams(ctx context.Context, params stakingtypes.Params) error {
return nil
}

type mockMintKeeper struct {
params minttypes.Params
}

func (m *mockMintKeeper) GetParams(ctx context.Context) (minttypes.Params, error) {
if m.params.MintDenom == "" {
return minttypes.DefaultParams(), nil
}
return m.params, nil
}

func (m *mockMintKeeper) SetParams(ctx context.Context, params minttypes.Params) error {
m.params = params
return nil
}

type fixture struct {
ctx sdk.Context
kvStoreKey *storetypes.KVStoreKey

stakingKeeper *mockStakingKeeper
mintKeeper *mockMintKeeper
keeper keeper.Keeper
queryServer types.QueryServer
msgServer types.MsgServer
Expand All @@ -101,6 +127,7 @@ func initFixture(tb testing.TB) *fixture {
tb.Helper()

stakingKeeper := &mockStakingKeeper{}
mintKeeper := &mockMintKeeper{}
key := storetypes.NewKVStoreKey(types.ModuleName)
storeService := runtime.NewKVStoreService(key)
encCfg := moduletestutil.MakeTestEncodingConfig(migrationmngr.AppModuleBasic{})
Expand All @@ -112,13 +139,15 @@ func initFixture(tb testing.TB) *fixture {
storeService,
addressCodec,
stakingKeeper,
mintKeeper,
sdk.AccAddress(address.Module(types.ModuleName)).String(),
)

return &fixture{
ctx: ctx,
kvStoreKey: key,
stakingKeeper: stakingKeeper,
mintKeeper: mintKeeper,
keeper: k,
queryServer: keeper.NewQueryServer(k),
msgServer: keeper.NewMsgServerImpl(k),
Expand Down
3 changes: 3 additions & 0 deletions modules/migrationmngr/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Keeper struct {
authority string

stakingKeeper types.StakingKeeper
mintKeeper types.MintKeeper

Schema collections.Schema
Sequencer collections.Item[types.Sequencer]
Expand All @@ -34,6 +35,7 @@ func NewKeeper(
storeService corestore.KVStoreService,
addressCodec address.Codec,
stakingKeeper types.StakingKeeper,
mintKeeper types.MintKeeper,
authority string,
) Keeper {
// ensure that authority is a valid account address
Expand All @@ -48,6 +50,7 @@ func NewKeeper(
authority: authority,
addressCodec: addressCodec,
stakingKeeper: stakingKeeper,
mintKeeper: mintKeeper,
Sequencer: collections.NewItem(
sb,
types.SequencerKey,
Expand Down
57 changes: 55 additions & 2 deletions modules/migrationmngr/keeper/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package keeper

import (
"context"
"time"

"cosmossdk.io/math"
abci "github.com/cometbft/cometbft/abci/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand All @@ -11,14 +13,19 @@ import (
"github.com/evstack/ev-abci/modules/migrationmngr/types"
)

const (
// postMigrationUnbondingTime is the unbonding time after migration (1 day).
postMigrationUnbondingTime = 24 * time.Hour
)

// IBCSmoothingFactor is the factor used to smooth the migration process when IBC is enabled. It determines how many blocks the migration will take.
var IBCSmoothingFactor uint64 = 30

// migrateNow migrates the chain to evolve immediately.
// MigrateNow migrates the chain to evolve immediately.
// this method is used when ibc is not enabled, so no migration smoothing is needed.
// If StayOnComet is true, delegations are unbonded and empty updates returned.
// Otherwise, ABCI ValidatorUpdates are returned directly for rollup migration.
func (k Keeper) migrateNow(
func (k Keeper) MigrateNow(
ctx context.Context,
migrationData types.EvolveMigration,
lastValidatorSet []stakingtypes.Validator,
Expand All @@ -33,6 +40,16 @@ func (k Keeper) migrateNow(
// explicitly set the final CometBFT validator set to a single validator with power=1.
k.Logger(ctx).Info("StayOnComet: immediate undelegation and explicit valset update")

// update staking params: set unbonding time to 3 days

Choose a reason for hiding this comment

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

This is very tied to Nillion, do we do it here or in an upgrade handler?

if err := k.updateStakingParams(ctx); err != nil {
return nil, err
}

// update mint params: set inflation to 0
if err := k.updateMintParams(ctx); err != nil {
return nil, err
}

// unbond all validator delegations
for _, val := range lastValidatorSet {
if err := k.unbondValidatorDelegations(ctx, val); err != nil {
Expand Down Expand Up @@ -208,3 +225,39 @@ func getValidatorsToRemove(migrationData types.EvolveMigration, lastValidatorSet
}
return validatorsToRemove
}

// updateStakingParams updates staking params to set unbonding time to 3 days.
func (k Keeper) updateStakingParams(ctx context.Context) error {
params, err := k.stakingKeeper.GetParams(ctx)
if err != nil {
return sdkerrors.ErrLogic.Wrapf("failed to get staking params: %v", err)
}

params.UnbondingTime = postMigrationUnbondingTime
k.Logger(ctx).Info("updating staking params", "unbonding_time", params.UnbondingTime)

if err := k.stakingKeeper.SetParams(ctx, params); err != nil {
return sdkerrors.ErrLogic.Wrapf("failed to set staking params: %v", err)
}

return nil
}

// updateMintParams updates mint params to set inflation to 0.
func (k Keeper) updateMintParams(ctx context.Context) error {
params, err := k.mintKeeper.GetParams(ctx)
if err != nil {
return sdkerrors.ErrLogic.Wrapf("failed to get mint params: %v", err)
}

params.InflationMin = math.LegacyZeroDec()
params.InflationMax = math.LegacyZeroDec()
params.InflationRateChange = math.LegacyZeroDec()
k.Logger(ctx).Info("updating mint params", "inflation_min", params.InflationMin, "inflation_max", params.InflationMax)

if err := k.mintKeeper.SetParams(ctx, params); err != nil {
return sdkerrors.ErrLogic.Wrapf("failed to set mint params: %v", err)
}

return nil
}
25 changes: 25 additions & 0 deletions modules/migrationmngr/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (

"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

Expand All @@ -16,4 +18,27 @@ type StakingKeeper interface {
IterateBondedValidatorsByPower(context.Context, func(index int64, validator stakingtypes.ValidatorI) (stop bool)) error
GetValidatorDelegations(ctx context.Context, valAddr sdk.ValAddress) ([]stakingtypes.Delegation, error)
Undelegate(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress, sharesAmount math.LegacyDec) (time.Time, math.Int, error)
GetParams(ctx context.Context) (stakingtypes.Params, error)
SetParams(ctx context.Context, params stakingtypes.Params) error
}

// MintKeeper defines the expected mint keeper interface.
type MintKeeper interface {
GetParams(ctx context.Context) (minttypes.Params, error)
SetParams(ctx context.Context, params minttypes.Params) error
}

// MintKeeperAdapter wraps the SDK's mintkeeper.Keeper to implement the MintKeeper interface.
type MintKeeperAdapter struct {
Keeper mintkeeper.Keeper
}

// GetParams returns the mint module params.
func (a MintKeeperAdapter) GetParams(ctx context.Context) (minttypes.Params, error) {
return a.Keeper.Params.Get(ctx)
}

// SetParams sets the mint module params.
func (a MintKeeperAdapter) SetParams(ctx context.Context, params minttypes.Params) error {
return a.Keeper.Params.Set(ctx, params)
}
19 changes: 15 additions & 4 deletions modules/staking/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/staking/types"
)

Expand All @@ -19,14 +20,24 @@ func NewMsgServerImpl(ms types.MsgServer) MsgServer {
}
}

func (MsgServer) CreateValidator(ctx context.Context, msg *types.MsgCreateValidator) (*types.MsgCreateValidatorResponse, error) {
return &types.MsgCreateValidatorResponse{}, fmt.Errorf("CreateValidator is disabled")
func (ms MsgServer) CreateValidator(ctx context.Context, msg *types.MsgCreateValidator) (*types.MsgCreateValidatorResponse, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)
if sdkCtx.BlockHeight() > 1 { // genesis block deliverTX should be allowed
return &types.MsgCreateValidatorResponse{}, fmt.Errorf("CreateValidator is disabled")
}

return ms.MsgServer.CreateValidator(ctx, msg)
}

func (MsgServer) BeginRedelegate(ctx context.Context, msg *types.MsgBeginRedelegate) (*types.MsgBeginRedelegateResponse, error) {
return &types.MsgBeginRedelegateResponse{}, fmt.Errorf("BeginRedelegate is disabled")
}

func (MsgServer) Delegate(ctx context.Context, msg *types.MsgDelegate) (*types.MsgDelegateResponse, error) {
return &types.MsgDelegateResponse{}, fmt.Errorf("Delegate is disabled")
func (ms MsgServer) Delegate(ctx context.Context, msg *types.MsgDelegate) (*types.MsgDelegateResponse, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)
if sdkCtx.BlockHeight() > 1 {
return &types.MsgDelegateResponse{}, fmt.Errorf("Delegate is disabled")
}

return ms.MsgServer.Delegate(ctx, msg)
}
3 changes: 2 additions & 1 deletion tests/integration/docker/Dockerfile.gm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ COPY . /workspace/ev-abci
# Scaffold GM app and apply evolve plugin
RUN ignite scaffold chain gm --no-module --skip-git --address-prefix celestia
WORKDIR /workspace/gm
RUN ignite app install github.com/ignite/apps/evolve@${IGNITE_EVOLVE_APP_VERSION}
# pin to commit before c5ac031 which introduced tools/local-da dependency not present in tagged ev-node versions
RUN ignite app install github.com/ignite/apps/evolve@1ace9dd
RUN ignite evolve add

# Inject App wiring for ev-abci network module before building
Expand Down
Loading