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(rollapp): min bond is now defined on rollapp level #1579

Merged
merged 20 commits into from
Dec 3, 2024
15 changes: 7 additions & 8 deletions app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ import (
sequencertypes "github.com/dymensionxyz/dymension/v3/x/sequencer/types"
)

var (
alice = "dym1wg8p6j0pxpnsvhkwfu54ql62cnrumf0v634mft"
bond = sequencertypes.DefaultParams().MinBond
)
var alice = "dym1wg8p6j0pxpnsvhkwfu54ql62cnrumf0v634mft"

type KeeperTestHelper struct {
suite.Suite
Expand Down Expand Up @@ -64,8 +61,10 @@ func (s *KeeperTestHelper) CreateRollappByName(name string) {
Creator: alice,
RollappId: name,
InitialSequencer: "*",
Alias: strings.ToLower(rand.Str(7)),
VmType: rollapptypes.Rollapp_EVM,
MinSequencerBond: rollapptypes.DefaultMinSequencerBondGlobalCoin,

Alias: strings.ToLower(rand.Str(7)),
VmType: rollapptypes.Rollapp_EVM,
GenesisInfo: &rollapptypes.GenesisInfo{
Bech32Prefix: strings.ToLower(rand.Str(3)),
GenesisChecksum: "1234567890abcdefg",
Expand Down Expand Up @@ -102,7 +101,7 @@ func (s *KeeperTestHelper) CreateDefaultSequencer(ctx sdk.Context, rollappId str
func (s *KeeperTestHelper) CreateSequencerByPubkey(ctx sdk.Context, rollappId string, pubKey types.PubKey) error {
addr := sdk.AccAddress(pubKey.Address())
// fund account
err := bankutil.FundAccount(s.App.BankKeeper, ctx, addr, sdk.NewCoins(bond))
err := bankutil.FundAccount(s.App.BankKeeper, ctx, addr, sdk.NewCoins(rollapptypes.DefaultMinSequencerBondGlobalCoin))
s.Require().Nil(err)

pkAny, err := codectypes.NewAnyWithValue(pubKey)
Expand All @@ -111,7 +110,7 @@ func (s *KeeperTestHelper) CreateSequencerByPubkey(ctx sdk.Context, rollappId st
sequencerMsg1 := sequencertypes.MsgCreateSequencer{
Creator: addr.String(),
DymintPubKey: pkAny,
Bond: bond,
Bond: rollapptypes.DefaultMinSequencerBondGlobalCoin,
RollappId: rollappId,
Metadata: sequencertypes.SequencerMetadata{
Rpcs: []string{"https://rpc.wpd.evm.rollapp.noisnemyd.xyz:443"},
Expand Down
1 change: 1 addition & 0 deletions app/upgrades/v4/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ func ConvertOldRollappToNew(oldRollapp rollapptypes.Rollapp) rollapptypes.Rollap
},
GenesisInfo: genesisInfo,
InitialSequencer: "*",
MinSequencerBond: sdk.NewCoins(rollapptypes.DefaultMinSequencerBondGlobalCoin),
VmType: rollapptypes.Rollapp_EVM, // EVM for existing rollapps
Launched: true, // Existing rollapps are already launched
PreLaunchTime: nil, // We can just let it be zero. Existing rollapps are already launched.
Expand Down
1 change: 0 additions & 1 deletion app/upgrades/v4/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ func (s *UpgradeTestSuite) validateSequencersMigration(numSeq int) error {
s.Require().Equal(sequencertypes.DefaultKickThreshold, s.App.SequencerKeeper.GetParams(s.Ctx).KickThreshold)
s.Require().Equal(sequencertypes.DefaultLivenessSlashMultiplier, s.App.SequencerKeeper.GetParams(s.Ctx).LivenessSlashMinMultiplier)
s.Require().Equal(sequencertypes.DefaultLivenessSlashMinAbsolute, s.App.SequencerKeeper.GetParams(s.Ctx).LivenessSlashMinAbsolute)
s.Require().Equal(sequencertypes.DefaultMinBond, s.App.SequencerKeeper.GetParams(s.Ctx).MinBond)

return nil
}
Expand Down
3 changes: 2 additions & 1 deletion ibctesting/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func (s *utilSuite) createRollapp(transfersEnabled bool, channelID *string) {
s.hubChain().SenderAccount.GetAddress().String(),
rollappChainID(),
s.hubChain().SenderAccount.GetAddress().String(),
rollapptypes.DefaultMinSequencerBondGlobalCoin,
strings.ToLower(tmrand.Str(7)),
rollapptypes.Rollapp_EVM,
&rollapptypes.RollappMetadata{
Expand Down Expand Up @@ -192,7 +193,7 @@ func (s *utilSuite) setRollappLightClientID(chainID, clientID string) {
}

func (s *utilSuite) registerSequencer() {
bond := sequencertypes.DefaultParams().MinBond
bond := rollapptypes.DefaultMinSequencerBondGlobalCoin
// fund account
err := bankutil.FundAccount(s.hubApp().BankKeeper, s.hubCtx(), s.hubChain().SenderAccount.GetAddress(), sdk.NewCoins(bond))
s.Require().Nil(err)
Expand Down
6 changes: 6 additions & 0 deletions proto/dymensionxyz/dymension/rollapp/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ message Params {
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"app_registration_fee\""
];

// no rollapp can have a minimum less than this (in dym)
cosmos.base.v1beta1.Coin min_sequencer_bond_global = 8 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"min_sequencer_bond_global\""
];
}
22 changes: 16 additions & 6 deletions proto/dymensionxyz/dymension/rollapp/rollapp.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import "cosmos/msg/v1/msg.proto";

import "dymensionxyz/dymension/rollapp/state_info.proto";
import "dymensionxyz/dymension/rollapp/metadata.proto";
import "cosmos/base/v1beta1/coin.proto";
import "dymensionxyz/dymension/rollapp/genesis_info.proto";

// RollappGenesisState is a partial repr of the state the hub can expect the
Expand Down Expand Up @@ -38,22 +39,31 @@ message Rollapp {
reserved 3 to 6;
// genesis_state is a partial repr of the state the hub can expect the rollapp
// to be in upon genesis
RollappGenesisState genesis_state = 7 [ (gogoproto.nullable) = false ];
RollappGenesisState genesis_state = 7 [(gogoproto.nullable) = false];
// channel_id will be set to the canonical IBC channel of the rollapp.
string channel_id = 8;

reserved 9,10;
reserved 9, 10;

// metadata is the rollapp metadata
RollappMetadata metadata = 11;
// genesis_info keeps immutable rollapp fields
GenesisInfo genesis_info = 12 [ (gogoproto.nullable) = false ];
GenesisInfo genesis_info = 12 [(gogoproto.nullable) = false];
// initial_sequencer is an option to preset one or more coma-separated
// bech32-encoded addresses of the sequencer(s) that are allowed to initially
// register and serve for this rollapp. if left empty, no sequencer is allowed
// to register. if set to "*" any sequencer can register.
string initial_sequencer = 13;

// How much a sequencer needs to have at stake to be proposer be proposer.
// Denom is dym. It is empty or ONE coin only. Coins is just a convenience to avoid
// marshalling issues.
repeated cosmos.base.v1beta1.Coin min_sequencer_bond = 20 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"min_sequencer_bond\"",
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];

enum VMType {
Unspecified = 0;
EVM = 1;
Expand All @@ -67,7 +77,7 @@ message Rollapp {
// pre_launch_time is the timestamp indicating the time before which the
// rollapp cannot be started.
// Set when creating IRO plan for the rollapp
google.protobuf.Timestamp pre_launch_time = 16 [ (gogoproto.stdtime) = true];
google.protobuf.Timestamp pre_launch_time = 16 [(gogoproto.stdtime) = true];
// LivenessEventHeight is the height on the HUB of an upcoming liveness event (slash or
// jail against the rollapp). 0 means not set
int64 liveness_event_height = 17;
Expand All @@ -76,7 +86,7 @@ message Rollapp {
int64 liveness_countdown_start_height = 18;

// Revisions is a list of all the rollapp revisions.
repeated Revision revisions = 19 [ (gogoproto.nullable) = false ];
repeated Revision revisions = 19 [(gogoproto.nullable) = false];
}

// Revision is a representation of the rollapp revision.
Expand Down
11 changes: 11 additions & 0 deletions proto/dymensionxyz/dymension/rollapp/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import "dymensionxyz/dymension/rollapp/rollapp.proto";
import "dymensionxyz/dymension/rollapp/metadata.proto";
import "dymensionxyz/dymension/rollapp/genesis_info.proto";
import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";

// Msg defines the Msg service.
service Msg {
Expand All @@ -34,6 +35,11 @@ message MsgCreateRollapp {
// initial_sequencer takes one or more coma-separated bech32-encoded addresses of the
// sequencer(s) that are allowed to initially serve this rollappId.
string initial_sequencer = 11;
// see Rollapp for more details
cosmos.base.v1beta1.Coin min_sequencer_bond = 16 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"min_sequencer_bond\""
];
// alias is the chain alias used for display and namespace system
string alias = 12;
// metadata is the rollapp metadata
Expand All @@ -58,6 +64,11 @@ message MsgUpdateRollappInformation {
// sequencer that are allowed to initially serve this rollappId.
// wildcard '*' means any sequencer is allowed to be the first proposer.
string initial_sequencer = 3;
// see Rollapp for more details
cosmos.base.v1beta1.Coin min_sequencer_bond = 7 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"min_sequencer_bond\""
];
// metadata is the rollapp metadata
RollappMetadata metadata = 5 [(gogoproto.nullable) = true ];
// genesis_info is the genesis information
Expand Down
6 changes: 1 addition & 5 deletions proto/dymensionxyz/dymension/sequencer/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ message Params {
option (gogoproto.equal) = true;
option (gogoproto.goproto_stringer) = false;

// minimum amt that must be put up for stake to be sequencer
cosmos.base.v1beta1.Coin min_bond = 1 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "min_bond,omitempty"
];
reserved 1;

// amt where the active sequencer can be kicked if he has less or equal bond
cosmos.base.v1beta1.Coin kick_threshold = 5 [
Expand Down
13 changes: 12 additions & 1 deletion x/common/types/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import (
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/dymensionxyz/dymension/v3/app/params"
)

Expand All @@ -15,3 +14,15 @@
// DYMCoin is 1 DYM coin.
DYMCoin = sdk.NewCoin(params.BaseDenom, DYM)
)

// return DYM
func Dym(nDym math.Int) sdk.Coin {
ret := DYMCoin
ret.Amount = ret.Amount.Mul(nDym)
return ret
}

// return ADYM
func ADym(nAdym math.Int) sdk.Coin {
return sdk.NewCoin(params.BaseDenom, nAdym)

Check warning on line 27 in x/common/types/constants.go

View check run for this annotation

Codecov / codecov/patch

x/common/types/constants.go#L26-L27

Added lines #L26 - L27 were not covered by tests
}
9 changes: 5 additions & 4 deletions x/incentives/client/cli/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ func (suite *QueryTestSuite) CreateDefaultRollapp() string {
alice := sdk.AccAddress("addr1---------------")

msgCreateRollapp := rollapptypes.MsgCreateRollapp{
Creator: alice.String(),
RollappId: urand.RollappID(),
Alias: strings.ToLower(tmrand.Str(7)),
VmType: rollapptypes.Rollapp_EVM,
Creator: alice.String(),
RollappId: urand.RollappID(),
MinSequencerBond: rollapptypes.DefaultMinSequencerBondGlobalCoin,
Alias: strings.ToLower(tmrand.Str(7)),
VmType: rollapptypes.Rollapp_EVM,
GenesisInfo: &rollapptypes.GenesisInfo{
Bech32Prefix: strings.ToLower(tmrand.Str(3)),
},
Expand Down
6 changes: 4 additions & 2 deletions x/incentives/keeper/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,10 @@ func (suite *KeeperTestSuite) CreateDefaultRollapp(addr sdk.AccAddress) string {
Creator: addr.String(),
RollappId: urand.RollappID(),
InitialSequencer: addr.String(),
Alias: strings.ToLower(tmrand.Str(7)),
VmType: rollapptypes.Rollapp_EVM,
MinSequencerBond: rollapptypes.DefaultMinSequencerBondGlobalCoin,

Alias: strings.ToLower(tmrand.Str(7)),
VmType: rollapptypes.Rollapp_EVM,
GenesisInfo: &rollapptypes.GenesisInfo{
Bech32Prefix: strings.ToLower(tmrand.Str(3)),
GenesisChecksum: "checksum",
Expand Down
17 changes: 10 additions & 7 deletions x/rollapp/client/cli/flags.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
package cli

import (
rollapptypes "github.com/dymensionxyz/dymension/v3/x/rollapp/types"
flag "github.com/spf13/pflag"
)

const (
FlagInitSequencer = "init-sequencer"
FlagGenesisChecksum = "genesis-checksum"
FlagNativeDenom = "native-denom"
FlagInitialSupply = "initial-supply"
FlagMetadata = "metadata"
FlagBech32Prefix = "bech32-prefix"
FlagGenesisAccounts = "genesis-accounts"
FlagInitSequencer = "init-sequencer"
FlagMinSequencerBond = "min-sequencer-bond"
FlagGenesisChecksum = "genesis-checksum"
FlagNativeDenom = "native-denom"
FlagInitialSupply = "initial-supply"
FlagMetadata = "metadata"
FlagBech32Prefix = "bech32-prefix"
FlagGenesisAccounts = "genesis-accounts"
)

// FlagSetUpdateRollapp returns flags for updating rollapps.
func FlagSetUpdateRollapp() *flag.FlagSet {
fs := flag.NewFlagSet("", flag.ContinueOnError)

fs.String(FlagInitSequencer, "", "The address of the sequencer that will be used to initialize the rollapp")
fs.String(FlagMinSequencerBond, rollapptypes.DefaultMinSequencerBondGlobalCoin.Amount.String(), "Minimum amount of bond required to be a sequencer in DYM (not adym)")
fs.String(FlagGenesisChecksum, "", "The checksum of the genesis file of the rollapp")
fs.String(FlagNativeDenom, "", "The native denomination of the rollapp")
fs.String(FlagInitialSupply, "", "The initial supply of the rollapp")
Expand Down
12 changes: 12 additions & 0 deletions x/rollapp/client/cli/tx_create_rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
commontypes "github.com/dymensionxyz/dymension/v3/x/common/types"
"github.com/spf13/cobra"

"github.com/dymensionxyz/dymension/v3/utils"
Expand All @@ -22,6 +23,7 @@
dymd tx rollapp create-rollapp myrollapp_12345-1 RollappAlias EVM
// optional flags:
--init-sequencer '<seq_address1>,<seq_address2>'
--min-sequencer-bond 100
danwt marked this conversation as resolved.
Show resolved Hide resolved
--genesis-checksum <genesis_checksum>
--initial-supply 1000000
--native-denom native_denom.json
Expand All @@ -43,6 +45,15 @@
return err
}

minSeqBondS, err := cmd.Flags().GetString(FlagMinSequencerBond)
if err != nil {
return err
}

Check warning on line 51 in x/rollapp/client/cli/tx_create_rollapp.go

View check run for this annotation

Codecov / codecov/patch

x/rollapp/client/cli/tx_create_rollapp.go#L50-L51

Added lines #L50 - L51 were not covered by tests
minSeqBond, ok := sdk.NewIntFromString(minSeqBondS)
if !ok {
return fmt.Errorf("invalid min sequencer bond: %s", minSeqBondS)
}

Check warning on line 55 in x/rollapp/client/cli/tx_create_rollapp.go

View check run for this annotation

Codecov / codecov/patch

x/rollapp/client/cli/tx_create_rollapp.go#L54-L55

Added lines #L54 - L55 were not covered by tests

genesisInfo, err := parseGenesisInfo(cmd)
if err != nil {
return err
Expand All @@ -62,6 +73,7 @@
clientCtx.GetFromAddress().String(),
argRollappId,
initSequencer,
commontypes.ADym(minSeqBond),

Check warning on line 76 in x/rollapp/client/cli/tx_create_rollapp.go

View check run for this annotation

Codecov / codecov/patch

x/rollapp/client/cli/tx_create_rollapp.go#L76

Added line #L76 was not covered by tests
alias,
types.Rollapp_VMType(vmType),
metadata,
Expand Down
17 changes: 16 additions & 1 deletion x/rollapp/client/cli/tx_update_rollapp.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
package cli

import (
"fmt"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
commontypes "github.com/dymensionxyz/dymension/v3/x/common/types"
"github.com/spf13/cobra"

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

func CmdUpdateRollapp() *cobra.Command {
cmd := &cobra.Command{
Use: "update-rollapp [rollapp-id] [init-sequencer] [genesis_checksum] [bech32-prefix] [native-denom] [metadata] ",
Use: "update-rollapp [rollapp-id] [init-sequencer] [min-sequencer-bond] [genesis_checksum] [bech32-prefix] [native-denom] [metadata] ",
Short: "Update a new rollapp",
Example: `
dymd tx rollapp update-rollapp ROLLAPP_CHAIN_ID
--init-sequencer '<seq_address1>,<seq_address2>'
--min-sequencer-bond 100
--genesis-checksum <genesis_checksum>
--initial-supply 1000000
--native-denom native_denom.json
Expand All @@ -30,6 +35,15 @@
return
}

minSeqBondS, err := cmd.Flags().GetString(FlagMinSequencerBond)
if err != nil {
return err
}
minSeqBond, ok := sdk.NewIntFromString(minSeqBondS)
if !ok {
return fmt.Errorf("invalid min sequencer bond: %s", minSeqBondS)
}

Check warning on line 45 in x/rollapp/client/cli/tx_update_rollapp.go

View check run for this annotation

Codecov / codecov/patch

x/rollapp/client/cli/tx_update_rollapp.go#L38-L45

Added lines #L38 - L45 were not covered by tests

genesisInfo, err := parseGenesisInfo(cmd)
if err != nil {
return
Expand All @@ -49,6 +63,7 @@
clientCtx.GetFromAddress().String(),
argRollappId,
initSequencer,
commontypes.ADym(minSeqBond),

Check warning on line 66 in x/rollapp/client/cli/tx_update_rollapp.go

View check run for this annotation

Codecov / codecov/patch

x/rollapp/client/cli/tx_update_rollapp.go#L66

Added line #L66 was not covered by tests
metadata,
genesisInfo,
)
Expand Down
24 changes: 24 additions & 0 deletions x/rollapp/keeper/bond.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package keeper

import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dymensionxyz/dymension/v3/x/rollapp/types"
"github.com/dymensionxyz/gerr-cosmos/gerrc"
)

func (k *Keeper) MinBond(ctx sdk.Context, rollappID string) sdk.Coin {
ra := k.MustGetRollapp(ctx, rollappID)
return ra.MinSequencerBond[0]
}

func (k *Keeper) validMinBond(ctx sdk.Context, x sdk.Coin) error {
if err := types.ValidateBasicMinSeqBond(x); err != nil {
return err
}

Check warning on line 18 in x/rollapp/keeper/bond.go

View check run for this annotation

Codecov / codecov/patch

x/rollapp/keeper/bond.go#L17-L18

Added lines #L17 - L18 were not covered by tests
min_ := k.GetParams(ctx).MinSequencerBondGlobal
if x.IsLT(min_) {
return errorsmod.Wrapf(gerrc.ErrInvalidArgument, "min sequencer bond is less than global min sequencer bond: min: %s, got: %s", min_, x)
}
return nil
}
Loading
Loading