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
2 changes: 1 addition & 1 deletion app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (

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

type KeeperTestHelper struct {
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: 100,
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
2 changes: 1 addition & 1 deletion ibctesting/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,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
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 a sequencer needs (at least) to be proposer
danwt marked this conversation as resolved.
Show resolved Hide resolved
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
12 changes: 12 additions & 0 deletions x/rollapp/keeper/bond.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package keeper

import (
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
)

// 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
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
4 changes: 4 additions & 0 deletions x/rollapp/keeper/msg_server_create_rollapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func (s *RollappTestSuite) TestCreateRollappWithBechGenesisSum() {
Creator: alice,
RollappId: "rollapp_1234-1",
InitialSequencer: sample.AccAddress(),
MinSequencerBond: 100,
Alias: "rollapp",
VmType: types.Rollapp_EVM,
GenesisInfo: mockGenesisInfo,
Expand All @@ -47,6 +48,7 @@ func (s *RollappTestSuite) TestCreateRollappAlreadyExists() {
Creator: alice,
RollappId: "rollapp_1234-1",
InitialSequencer: sample.AccAddress(),
MinSequencerBond: 100,
Alias: "rollapp",
VmType: types.Rollapp_EVM,
}
Expand Down Expand Up @@ -116,6 +118,7 @@ func (s *RollappTestSuite) TestOverwriteEIP155Key() {
Creator: alice,
RollappId: test.rollappId,
InitialSequencer: sample.AccAddress(),
MinSequencerBond: 100,
Alias: "alias",
VmType: types.Rollapp_EVM,
GenesisInfo: mockGenesisInfo,
Expand Down Expand Up @@ -199,6 +202,7 @@ func (s *RollappTestSuite) createRollappWithCreatorAndVerify(
RollappId: rollapp.GetRollappId(),
Owner: rollapp.GetCreator(),
InitialSequencer: rollapp.GetInitialSequencer(),
MinSequencerBond: 100,
VmType: types.Rollapp_EVM,
Metadata: rollapp.GetMetadata(),
GenesisInfo: *rollapp.GetGenesisInfo(),
Expand Down
41 changes: 32 additions & 9 deletions x/rollapp/keeper/msg_server_update_rollapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func (s *RollappTestSuite) TestUpdateRollapp() {
Owner: alice,
RollappId: rollappId,
InitialSequencer: initialSequencerAddress,
MinSequencerBond: 100,
VmType: types.Rollapp_EVM,
Metadata: &mockRollappMetadata,
GenesisInfo: types.GenesisInfo{
Expand All @@ -65,23 +66,26 @@ func (s *RollappTestSuite) TestUpdateRollapp() {
GenesisAccounts: &types.GenesisAccounts{},
},
},
}, {
},
{
name: "Update rollapp: fail - try to update a non-existing rollapp",
update: &types.MsgUpdateRollappInformation{
Owner: alice,
RollappId: "somerollapp_1235-1",
InitialSequencer: initialSequencerAddress,
},
expError: gerrc.ErrNotFound,
}, {
},
{
name: "Update rollapp: fail - try to update from non-creator address",
update: &types.MsgUpdateRollappInformation{
Owner: bob,
RollappId: rollappId,
InitialSequencer: initialSequencerAddress,
},
expError: sdkerrors.ErrUnauthorized,
}, {
},
{
name: "Update rollapp: fail - try to update InitialSequencer when launched",
update: &types.MsgUpdateRollappInformation{
Owner: alice,
Expand All @@ -90,7 +94,18 @@ func (s *RollappTestSuite) TestUpdateRollapp() {
},
rollappLaunched: true,
expError: types.ErrImmutableFieldUpdateAfterLaunched,
}, {
},
{
name: "Update rollapp: fail - try to update min seq bond when launched",
update: &types.MsgUpdateRollappInformation{
Owner: alice,
RollappId: rollappId,
MinSequencerBond: 150,
},
rollappLaunched: true,
expError: types.ErrImmutableFieldUpdateAfterLaunched,
},
{
name: "Update rollapp: fail - try to update genesis checksum when sealed",
update: &types.MsgUpdateRollappInformation{
Owner: alice,
Expand All @@ -103,7 +118,8 @@ func (s *RollappTestSuite) TestUpdateRollapp() {
},
genInfoSealed: true,
expError: types.ErrGenesisInfoSealed,
}, {
},
{
name: "Update rollapp: fail - try to update bech32 when sealed",
update: &types.MsgUpdateRollappInformation{
Owner: alice,
Expand All @@ -114,7 +130,8 @@ func (s *RollappTestSuite) TestUpdateRollapp() {
},
genInfoSealed: true,
expError: types.ErrGenesisInfoSealed,
}, {
},
{
name: "Update rollapp: fail - try to update native_denom when sealed",
update: &types.MsgUpdateRollappInformation{
Owner: alice,
Expand All @@ -129,7 +146,8 @@ func (s *RollappTestSuite) TestUpdateRollapp() {
},
genInfoSealed: true,
expError: types.ErrGenesisInfoSealed,
}, {
},
{
name: "Update rollapp: fail - try to update initial_supply when sealed",
update: &types.MsgUpdateRollappInformation{
Owner: alice,
Expand All @@ -140,7 +158,8 @@ func (s *RollappTestSuite) TestUpdateRollapp() {
},
genInfoSealed: true,
expError: types.ErrGenesisInfoSealed,
}, {
},
{
name: "Update rollapp: success - update metadata when sealed",
update: &types.MsgUpdateRollappInformation{
Owner: alice,
Expand All @@ -154,6 +173,7 @@ func (s *RollappTestSuite) TestUpdateRollapp() {
RollappId: rollappId,
Owner: alice,
InitialSequencer: "",
MinSequencerBond: 100,
ChannelId: "",
Launched: true,
VmType: types.Rollapp_EVM,
Expand All @@ -178,7 +198,8 @@ func (s *RollappTestSuite) TestUpdateRollapp() {
Sealed: true,
},
},
}, {
},
{
name: "Update rollapp: success - unsealed, update rollapp without genesis info",
update: &types.MsgUpdateRollappInformation{
Owner: alice,
Expand All @@ -192,6 +213,7 @@ func (s *RollappTestSuite) TestUpdateRollapp() {
RollappId: rollappId,
Owner: alice,
InitialSequencer: "",
MinSequencerBond: 100,
ChannelId: "",
Launched: false,
VmType: types.Rollapp_EVM,
Expand Down Expand Up @@ -226,6 +248,7 @@ func (s *RollappTestSuite) TestUpdateRollapp() {
RollappId: rollappId,
Owner: alice,
InitialSequencer: "",
MinSequencerBond: 100,
ChannelId: "",
Launched: tc.rollappLaunched,
VmType: types.Rollapp_EVM,
Expand Down
4 changes: 4 additions & 0 deletions x/rollapp/keeper/rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ func (k Keeper) CheckAndUpdateRollappFields(ctx sdk.Context, update *types.MsgUp
current.InitialSequencer = update.InitialSequencer
}

if 0 < update.MinSequencerBond {
danwt marked this conversation as resolved.
Show resolved Hide resolved
current.MinSequencerBond = update.MinSequencerBond
}

if update.GenesisInfo != nil {
if update.GenesisInfo.GenesisChecksum != "" {
current.GenesisInfo.GenesisChecksum = update.GenesisInfo.GenesisChecksum
Expand Down
1 change: 1 addition & 0 deletions x/rollapp/types/message_create_rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func (msg *MsgCreateRollapp) GetRollapp() Rollapp {
msg.Creator,
msg.RollappId,
msg.InitialSequencer,
msg.MinSequencerBond,
msg.VmType,
msg.Metadata,
genInfo,
Expand Down
2 changes: 1 addition & 1 deletion x/rollapp/types/message_update_rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (msg *MsgUpdateRollappInformation) ValidateBasic() error {
}

func (msg *MsgUpdateRollappInformation) UpdatingImmutableValues() bool {
return msg.InitialSequencer != ""
return msg.InitialSequencer != "" || 0 < msg.MinSequencerBond
danwt marked this conversation as resolved.
Show resolved Hide resolved
}

func (msg *MsgUpdateRollappInformation) UpdatingGenesisInfo() bool {
Expand Down
22 changes: 11 additions & 11 deletions x/rollapp/types/rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

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

"github.com/dymensionxyz/dymension/v3/testutil/sample"
)
Expand Down Expand Up @@ -40,22 +41,17 @@ var RollappTags = []string{
type AllowedDecimals uint32

const (
Decimals18 AllowedDecimals = 18
Decimals18 AllowedDecimals = 18
DefaultMinBond uint64 = 100 // dym - only used if not supplied by creator
)

func NewRollapp(
creator,
rollappId,
initialSequencer string,
vmType Rollapp_VMType,
metadata *RollappMetadata,
genInfo GenesisInfo,
transfersEnabled bool,
) Rollapp {
func NewRollapp(creator, rollappId, initialSequencer string, minSequencerBond uint64, vmType Rollapp_VMType, metadata *RollappMetadata, genInfo GenesisInfo, transfersEnabled bool) Rollapp {
minSequencerBond = max(minSequencerBond, DefaultMinBond)
return Rollapp{
RollappId: rollappId,
Owner: creator,
InitialSequencer: initialSequencer,
MinSequencerBond: minSequencerBond,
VmType: vmType,
Metadata: metadata,
GenesisInfo: genInfo,
Expand Down Expand Up @@ -85,6 +81,10 @@ func (r Rollapp) ValidateBasic() error {
return errorsmod.Wrap(ErrInvalidInitialSequencer, err.Error())
}

if r.MinSequencerBond <= 0 {
return gerrc.ErrInvalidArgument.Wrap("non positive min bond")
}

if err = r.GenesisInfo.Validate(); err != nil {
return err
}
Expand Down Expand Up @@ -112,7 +112,7 @@ func (r Rollapp) IsTransferEnabled() bool {
}

func (r Rollapp) AllImmutableFieldsAreSet() bool {
return r.InitialSequencer != "" && r.GenesisInfoFieldsAreSet()
return r.InitialSequencer != "" && r.GenesisInfoFieldsAreSet() && 0 < r.MinSequencerBond
}

func (r Rollapp) GenesisInfoFieldsAreSet() bool {
Expand Down
Loading
Loading