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(sequencers): validate sequencer unbonding_time greater than dispute_period #1115

2 changes: 1 addition & 1 deletion app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,9 @@ func (a *AppKeepers) InitKeepers(
a.SequencerKeeper = *sequencermodulekeeper.NewKeeper(
appCodec,
a.keys[sequencermoduletypes.StoreKey],
a.GetSubspace(sequencermoduletypes.ModuleName),
a.BankKeeper,
a.RollappKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

a.RollappKeeper.SetSequencerKeeper(a.SequencerKeeper)
Expand Down
12 changes: 6 additions & 6 deletions app/keepers/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ import (
rollappmoduleclient "github.com/dymensionxyz/dymension/v3/x/rollapp/client"
rollappmoduletypes "github.com/dymensionxyz/dymension/v3/x/rollapp/types"
"github.com/dymensionxyz/dymension/v3/x/sequencer"
sequencermoduletypes "github.com/dymensionxyz/dymension/v3/x/sequencer/types"
sequencertypes "github.com/dymensionxyz/dymension/v3/x/sequencer/types"
"github.com/dymensionxyz/dymension/v3/x/streamer"
streamermoduleclient "github.com/dymensionxyz/dymension/v3/x/streamer/client"
streamermoduletypes "github.com/dymensionxyz/dymension/v3/x/streamer/types"
Expand Down Expand Up @@ -195,7 +195,7 @@ func (a *AppKeepers) SetupModules(
packetforwardmiddleware.NewAppModule(a.PacketForwardMiddlewareKeeper, a.GetSubspace(packetforwardtypes.ModuleName)),
ibctransfer.NewAppModule(a.TransferKeeper),
rollappmodule.NewAppModule(appCodec, a.RollappKeeper, a.AccountKeeper, a.BankKeeper),
sequencermodule.NewAppModule(appCodec, a.SequencerKeeper, a.AccountKeeper, a.BankKeeper),
sequencermodule.NewAppModule(appCodec, a.SequencerKeeper, a.AccountKeeper, a.BankKeeper, a.GetSubspace(sequencertypes.ModuleName)),
sponsorship.NewAppModule(a.SponsorshipKeeper),
streamermodule.NewAppModule(a.StreamerKeeper, a.AccountKeeper, a.BankKeeper, a.EpochsKeeper),
delayedackmodule.NewAppModule(appCodec, a.DelayedAckKeeper),
Expand Down Expand Up @@ -239,7 +239,7 @@ var maccPerms = map[string][]string{
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
sequencermoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner, authtypes.Staking},
sequencertypes.ModuleName: {authtypes.Minter, authtypes.Burner, authtypes.Staking},
rollappmoduletypes.ModuleName: {authtypes.Burner},
sponsorshiptypes.ModuleName: nil,
streamermoduletypes.ModuleName: nil,
Expand Down Expand Up @@ -276,7 +276,7 @@ var BeginBlockers = []string{
feegrant.ModuleName,
paramstypes.ModuleName,
rollappmoduletypes.ModuleName,
sequencermoduletypes.ModuleName,
sequencertypes.ModuleName,
sponsorshiptypes.ModuleName,
streamermoduletypes.ModuleName,
denommetadatamoduletypes.ModuleName,
Expand Down Expand Up @@ -314,7 +314,7 @@ var EndBlockers = []string{
ibctransfertypes.ModuleName,
packetforwardtypes.ModuleName,
rollappmoduletypes.ModuleName,
sequencermoduletypes.ModuleName,
sequencertypes.ModuleName,
sponsorshiptypes.ModuleName,
streamermoduletypes.ModuleName,
denommetadatamoduletypes.ModuleName,
Expand Down Expand Up @@ -353,7 +353,7 @@ var InitGenesis = []string{
packetforwardtypes.ModuleName,
feegrant.ModuleName,
rollappmoduletypes.ModuleName,
sequencermoduletypes.ModuleName,
sequencertypes.ModuleName,
sponsorshiptypes.ModuleName,
streamermoduletypes.ModuleName,
denommetadatamoduletypes.ModuleName, // must after `x/bank` to trigger hooks
Expand Down
22 changes: 18 additions & 4 deletions app/upgrades/v4/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ func CreateUpgradeHandler(
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
logger := ctx.Logger().With("upgrade", UpgradeName)

LoadDeprecatedParamsSubspaces(keepers)

migrateModuleParams(ctx, keepers)
migrateDelayedAckParams(ctx, keepers.DelayedAckKeeper)
migrateRollappParams(ctx, keepers.RollappKeeper)
if err := migrateRollapps(ctx, keepers.RollappKeeper); err != nil {
return nil, err
}

migrateSequencers(ctx, keepers.SequencerKeeper)

// TODO: create rollapp gauges for each existing rollapp (https://github.com/dymensionxyz/dymension/issues/1005)
Expand All @@ -60,10 +63,18 @@ func CreateUpgradeHandler(

//nolint:staticcheck
func migrateModuleParams(ctx sdk.Context, keepers *keepers.AppKeepers) {
// Set param key table for params module migration
// Migrate Tendermint consensus parameters from x/params module to a dedicated x/consensus module.
baseAppLegacySS := keepers.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable())
baseapp.MigrateParams(ctx, baseAppLegacySS, &keepers.ConsensusParamsKeeper)
}

// LoadDeprecatedParamsSubspaces loads the deprecated param subspaces for each module
// used to support the migration from x/params to each module's own store
func LoadDeprecatedParamsSubspaces(keepers *keepers.AppKeepers) {
for _, subspace := range keepers.ParamsKeeper.GetSubspaces() {
var keyTable paramstypes.KeyTable
switch subspace.Name() {
// Cosmos SDK modules
case authtypes.ModuleName:
keyTable = authtypes.ParamKeyTable()
case banktypes.ModuleName:
Expand All @@ -81,6 +92,12 @@ func migrateModuleParams(ctx sdk.Context, keepers *keepers.AppKeepers) {
case crisistypes.ModuleName:
keyTable = crisistypes.ParamKeyTable()

// Dymension modules
case rollapptypes.ModuleName:
keyTable = rollapptypes.ParamKeyTable()
case sequencertypes.ModuleName:
keyTable = sequencertypes.ParamKeyTable()

// Ethermint modules
case evmtypes.ModuleName:
keyTable = evmtypes.ParamKeyTable()
Expand All @@ -94,9 +111,6 @@ func migrateModuleParams(ctx sdk.Context, keepers *keepers.AppKeepers) {
subspace.WithKeyTable(keyTable)
}
}
// Migrate Tendermint consensus parameters from x/params module to a dedicated x/consensus module.
baseAppLegacySS := keepers.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable())
baseapp.MigrateParams(ctx, baseAppLegacySS, &keepers.ConsensusParamsKeeper)
}

func migrateDelayedAckParams(ctx sdk.Context, delayedAckKeeper delayedackkeeper.Keeper) {
Expand Down
4 changes: 4 additions & 0 deletions app/upgrades/v4/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,21 @@ func (s *UpgradeTestSuite) TestUpgrade() {
msg: "Test that upgrade does not panic and sets correct parameters and migrates rollapp module",
numRollapps: 5,
preUpgrade: func(numRollapps int) error {
v4.LoadDeprecatedParamsSubspaces(&s.App.AppKeepers)

// Create and store rollapps
s.seedAndStoreRollapps(numRollapps)

// Create and store sequencers
s.seedAndStoreSequencers(numRollapps)

return nil
},
upgrade: func() {
// Run upgrade
s.Ctx = s.Ctx.WithBlockHeight(dummyUpgradeHeight - 1)
plan := upgradetypes.Plan{Name: "v4", Height: dummyUpgradeHeight}

err := s.App.UpgradeKeeper.ScheduleUpgrade(s.Ctx, plan)
s.Require().NoError(err)
_, exists := s.App.UpgradeKeeper.GetUpgradePlan(s.Ctx)
Expand Down
27 changes: 25 additions & 2 deletions proto/dymensionxyz/dymension/sequencer/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,48 @@ import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "google/protobuf/timestamp.proto";
import "cosmos/msg/v1/msg.proto";
import "dymensionxyz/dymension/sequencer/params.proto";

import "dymensionxyz/dymension/sequencer/metadata.proto";

// Msg defines the Msg service.
service Msg {
option (cosmos.msg.v1.service) = true;

// CreateSequencer defines a method for creating a new sequencer.
rpc CreateSequencer (MsgCreateSequencer) returns (MsgCreateSequencerResponse);
// UpdateSequencerInformation defines a method for updating the sequencer's metadata.
rpc UpdateSequencerInformation (MsgUpdateSequencerInformation) returns (MsgUpdateSequencerInformationResponse);
// Unbond defines a method for removing coins from sequencer's bond
rpc Unbond (MsgUnbond) returns (MsgUnbondResponse);

// IncreaseBond defines a method for increasing a sequencer's bond amount
rpc IncreaseBond (MsgIncreaseBond) returns (MsgIncreaseBondResponse);

// DecreaseBond defines a method for decreasing the bond of a sequencer.
rpc DecreaseBond (MsgDecreaseBond) returns (MsgDecreaseBondResponse);
// UpdateParams defines a (governance) operation for updating the module parameters.
// Since: cosmos-sdk 0.47
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
zale144 marked this conversation as resolved.
Show resolved Hide resolved
}

// MsgUpdateParams is the Msg/UpdateParams request type.
// Since: cosmos-sdk 0.47
message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";

// authority is the address that controls the module (defaults to x/gov unless overwritten).
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// NOTE: All parameters must be supplied.
Params params = 2 [(gogoproto.nullable) = false];
}

// MsgUpdateParamsResponse defines the response structure for executing a
// MsgUpdateParams message.
//
// Since: cosmos-sdk 0.47
message MsgUpdateParamsResponse {}



message MsgCreateSequencer {
option (cosmos.msg.v1.signer) = "creator";
// creator is the bech32-encoded address of the sequencer account which is the account that the message was sent from.
Expand Down
10 changes: 2 additions & 8 deletions testutil/keeper/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"github.com/cosmos/cosmos-sdk/store"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
typesparams "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/stretchr/testify/require"

"github.com/dymensionxyz/dymension/v3/testutil/sample"
rollappkeeper "github.com/dymensionxyz/dymension/v3/x/rollapp/keeper"
"github.com/dymensionxyz/dymension/v3/x/sequencer/keeper"
"github.com/dymensionxyz/dymension/v3/x/sequencer/types"
Expand All @@ -32,18 +32,12 @@ func SequencerKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
registry := codectypes.NewInterfaceRegistry()
cdc := codec.NewProtoCodec(registry)

paramsSubspace := typesparams.NewSubspace(cdc,
types.Amino,
storeKey,
memStoreKey,
"SequencerParams",
)
k := keeper.NewKeeper(
cdc,
storeKey,
paramsSubspace,
nil,
&rollappkeeper.Keeper{},
sample.AccAddress(),
)

ctx := sdk.NewContext(stateStore, cometbftproto.Header{}, false, log.NewNopLogger())
Expand Down
28 changes: 13 additions & 15 deletions x/sequencer/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,37 @@
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"

"github.com/dymensionxyz/dymension/v3/x/sequencer/types"
)

type (
Keeper struct {
cdc codec.BinaryCodec
storeKey storetypes.StoreKey
paramstore paramtypes.Subspace
bankKeeper types.BankKeeper
rollappKeeper types.RollappKeeper
}
)
type Keeper struct {
authority string // authority is the x/gov module account

cdc codec.BinaryCodec
storeKey storetypes.StoreKey
bankKeeper types.BankKeeper
rollappKeeper types.RollappKeeper
}

func NewKeeper(
cdc codec.BinaryCodec,
storeKey storetypes.StoreKey,
ps paramtypes.Subspace,
bankKeeper types.BankKeeper,
rollappKeeper types.RollappKeeper,
authority string,
) *Keeper {
// set KeyTable if it has not already been set
if !ps.HasKeyTable() {
ps = ps.WithKeyTable(types.ParamKeyTable())
_, err := sdk.AccAddressFromBech32(authority)
if err != nil {
panic(fmt.Errorf("invalid x/sequencer authority address: %w", err))

Check warning on line 33 in x/sequencer/keeper/keeper.go

View check run for this annotation

Codecov / codecov/patch

x/sequencer/keeper/keeper.go#L33

Added line #L33 was not covered by tests
}

return &Keeper{
cdc: cdc,
storeKey: storeKey,
paramstore: ps,
bankKeeper: bankKeeper,
rollappKeeper: rollappKeeper,
authority: authority,
}
}

Expand Down
26 changes: 26 additions & 0 deletions x/sequencer/keeper/msg_server_update_params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package keeper

import (
"context"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

"github.com/dymensionxyz/dymension/v3/x/sequencer/types"
)

func (k msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

if k.authority != msg.Authority {
return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "invalid authority; expected %s, got %s", k.authority, msg.Authority)
}

Check warning on line 18 in x/sequencer/keeper/msg_server_update_params.go

View check run for this annotation

Codecov / codecov/patch

x/sequencer/keeper/msg_server_update_params.go#L13-L18

Added lines #L13 - L18 were not covered by tests

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

Check warning on line 22 in x/sequencer/keeper/msg_server_update_params.go

View check run for this annotation

Codecov / codecov/patch

x/sequencer/keeper/msg_server_update_params.go#L20-L22

Added lines #L20 - L22 were not covered by tests

k.SetParams(ctx, msg.Params)
return &types.MsgUpdateParamsResponse{}, nil

Check warning on line 25 in x/sequencer/keeper/msg_server_update_params.go

View check run for this annotation

Codecov / codecov/patch

x/sequencer/keeper/msg_server_update_params.go#L24-L25

Added lines #L24 - L25 were not covered by tests
}
Loading
Loading