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.DefaultMinSequencerBondGlobal,

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(sequencertypes.TestMinBond))
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: sequencertypes.TestMinBond,
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: rollapptypes.DefaultMinSequencerBondGlobal,
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 @@ -130,6 +130,7 @@ func (s *utilSuite) createRollapp(transfersEnabled bool, channelID *string) {
s.hubChain().SenderAccount.GetAddress().String(),
rollappChainID(),
s.hubChain().SenderAccount.GetAddress().String(),
rollapptypes.DefaultMinSequencerBondGlobal,
strings.ToLower(tmrand.Str(7)),
rollapptypes.Rollapp_EVM,
&rollapptypes.RollappMetadata{
Expand Down Expand Up @@ -186,7 +187,7 @@ func (s *utilSuite) setRollappLightClientID(chainID, clientID string) {
}

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

// no rollapp can have a minimum less than this (dym, not adym)
uint64 min_sequencer_bond_global = 8;
}
2 changes: 2 additions & 0 deletions proto/dymensionxyz/dymension/rollapp/rollapp.proto
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ message Rollapp {
// 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 DYM (not aDYM) a sequencer needs (at least) to be proposer
uint64 min_sequencer_bond = 20;

enum VMType {
Unspecified = 0;
Expand Down
4 changes: 4 additions & 0 deletions proto/dymensionxyz/dymension/rollapp/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ 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
uint64 min_sequencer_bond = 16;
// alias is the chain alias used for display and namespace system
string alias = 12;
// metadata is the rollapp metadata
Expand All @@ -58,6 +60,8 @@ 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
uint64 min_sequencer_bond = 7;
// 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
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.DefaultMinSequencerBondGlobal,
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.DefaultMinSequencerBondGlobal,

Alias: strings.ToLower(tmrand.Str(7)),
VmType: rollapptypes.Rollapp_EVM,
GenesisInfo: &rollapptypes.GenesisInfo{
Bech32Prefix: strings.ToLower(tmrand.Str(3)),
GenesisChecksum: "checksum",
Expand Down
16 changes: 9 additions & 7 deletions x/rollapp/client/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@ import (
)

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.Uint64(FlagMinSequencerBond, 100, "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
7 changes: 7 additions & 0 deletions x/rollapp/client/cli/tx_create_rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,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 +44,11 @@
return err
}

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

Check warning on line 50 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#L49-L50

Added lines #L49 - L50 were not covered by tests

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

Check warning on line 71 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#L71

Added line #L71 was not covered by tests
alias,
types.Rollapp_VMType(vmType),
metadata,
Expand Down
9 changes: 8 additions & 1 deletion x/rollapp/client/cli/tx_update_rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@

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 +31,11 @@
return
}

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

Check warning on line 37 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#L34-L37

Added lines #L34 - L37 were not covered by tests

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

Check warning on line 58 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#L58

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

import (
errorsmod "cosmossdk.io/errors"
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dymensionxyz/gerr-cosmos/gerrc"
)

// Rollapp must exist - returns base units, not atto. E.g. 100 dym not 10e18 adym
func (k *Keeper) MinBond(ctx sdk.Context, rollappID string) math.Int {
ra := k.MustGetRollapp(ctx, rollappID)
return math.NewIntFromUint64(ra.MinSequencerBond)
}
danwt marked this conversation as resolved.
Show resolved Hide resolved

func (k *Keeper) validMinBond(ctx sdk.Context, x uint64) error {
if min_ := k.GetParams(ctx).MinSequencerBondGlobal; x < min_ {
return errorsmod.Wrapf(gerrc.ErrInvalidArgument, "min sequencer bond is less than global min sequencer bond: min: %d, got: %d", min_, x)
}

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L18 - L19 were not covered by tests
return nil
}
3 changes: 1 addition & 2 deletions x/rollapp/keeper/liveness_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ func (s *RollappTestSuite) TestLivenessFlow() {
tracker := newLivenessMockSequencerKeeper(s.k().SequencerK)
s.k().SetSequencerKeeper(tracker)
for _, ra := range rollapps {
s.k().SetRollapp(s.Ctx, types.NewRollapp("", ra, "",
types.Rollapp_Unspecified, nil, types.GenesisInfo{}, false))
s.k().SetRollapp(s.Ctx, types.NewRollapp("", ra, "", 100, types.Rollapp_Unspecified, nil, types.GenesisInfo{}, false))
}

hClockStart := map[string]int64{}
Expand Down
3 changes: 3 additions & 0 deletions x/rollapp/keeper/msg_server_create_rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
if err := k.CheckIfRollappExists(ctx, rollappId); err != nil {
return nil, err
}
if err := k.validMinBond(ctx, msg.MinSequencerBond); err != nil {
return nil, err
}

Check warning on line 32 in x/rollapp/keeper/msg_server_create_rollapp.go

View check run for this annotation

Codecov / codecov/patch

x/rollapp/keeper/msg_server_create_rollapp.go#L31-L32

Added lines #L31 - L32 were not covered by tests

k.SetRollapp(ctx, msg.GetRollapp())

Expand Down
24 changes: 16 additions & 8 deletions x/rollapp/keeper/msg_server_create_rollapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ func (s *RollappTestSuite) TestCreateRollappWithBechGenesisSum() {
Creator: alice,
RollappId: "rollapp_1234-1",
InitialSequencer: sample.AccAddress(),
Alias: "rollapp",
VmType: types.Rollapp_EVM,
GenesisInfo: mockGenesisInfo,
MinSequencerBond: types.DefaultMinSequencerBondGlobal,

Alias: "rollapp",
VmType: types.Rollapp_EVM,
GenesisInfo: mockGenesisInfo,
}
_, err := s.msgServer.CreateRollapp(goCtx, &rollapp)
s.Require().NoError(err)
Expand All @@ -47,8 +49,10 @@ func (s *RollappTestSuite) TestCreateRollappAlreadyExists() {
Creator: alice,
RollappId: "rollapp_1234-1",
InitialSequencer: sample.AccAddress(),
Alias: "rollapp",
VmType: types.Rollapp_EVM,
MinSequencerBond: types.DefaultMinSequencerBondGlobal,

Alias: "rollapp",
VmType: types.Rollapp_EVM,
}

_, err := s.msgServer.CreateRollapp(goCtx, &rollapp)
Expand Down Expand Up @@ -116,9 +120,11 @@ func (s *RollappTestSuite) TestOverwriteEIP155Key() {
Creator: alice,
RollappId: test.rollappId,
InitialSequencer: sample.AccAddress(),
Alias: "alias",
VmType: types.Rollapp_EVM,
GenesisInfo: mockGenesisInfo,
MinSequencerBond: types.DefaultMinSequencerBondGlobal,

Alias: "alias",
VmType: types.Rollapp_EVM,
GenesisInfo: mockGenesisInfo,
}
s.FundForAliasRegistration(rollapp)
_, err := s.msgServer.CreateRollapp(goCtx, &rollapp)
Expand Down Expand Up @@ -186,6 +192,7 @@ func (s *RollappTestSuite) createRollappWithCreatorAndVerify(
Creator: creator,
RollappId: urand.RollappID(),
InitialSequencer: address,
MinSequencerBond: 150,
Alias: strings.ToLower(rand.Str(7)),
VmType: types.Rollapp_EVM,
Metadata: &mockRollappMetadata,
Expand All @@ -199,6 +206,7 @@ func (s *RollappTestSuite) createRollappWithCreatorAndVerify(
RollappId: rollapp.GetRollappId(),
Owner: rollapp.GetCreator(),
InitialSequencer: rollapp.GetInitialSequencer(),
MinSequencerBond: 150,
VmType: types.Rollapp_EVM,
Metadata: rollapp.GetMetadata(),
GenesisInfo: *rollapp.GetGenesisInfo(),
Expand Down
Loading
Loading