Skip to content

Commit

Permalink
Merge branch 'main' into feat/dym-ns-6
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorTrustyDev authored Aug 20, 2024
2 parents a8c8930 + e50966c commit 1bb3e72
Show file tree
Hide file tree
Showing 74 changed files with 3,853 additions and 1,648 deletions.
30 changes: 17 additions & 13 deletions app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,24 @@ type KeeperTestHelper struct {
Ctx sdk.Context
}

func (s *KeeperTestHelper) CreateDefaultRollappWithProposer() (string, string) {
return s.CreateRollappWithNameWithProposer(urand.RollappID())
func (s *KeeperTestHelper) CreateDefaultRollappAndProposer() (string, string) {
rollappId := s.CreateDefaultRollapp()
proposer := s.CreateDefaultSequencer(s.Ctx, rollappId)
return rollappId, proposer
}

func (s *KeeperTestHelper) CreateRollappWithNameWithProposer(name string) (string, string) {
pubkey := ed25519.GenPrivKey().PubKey()
addr := sdk.AccAddress(pubkey.Address())
// creates a rollapp and return its rollappID
func (s *KeeperTestHelper) CreateDefaultRollapp() string {
rollappId := urand.RollappID()
s.CreateRollappByName(rollappId)
return rollappId
}

func (s *KeeperTestHelper) CreateRollappByName(name string) {
msgCreateRollapp := rollapptypes.MsgCreateRollapp{
Creator: alice,
RollappId: name,
InitialSequencer: addr.String(),
InitialSequencer: "*",
Bech32Prefix: strings.ToLower(rand.Str(3)),
GenesisChecksum: "1234567890abcdefg",
Alias: strings.ToLower(rand.Str(7)),
Expand All @@ -65,18 +71,16 @@ func (s *KeeperTestHelper) CreateRollappWithNameWithProposer(name string) (strin
msgServer := rollappkeeper.NewMsgServerImpl(*s.App.RollappKeeper)
_, err := msgServer.CreateRollapp(s.Ctx, &msgCreateRollapp)
s.Require().NoError(err)

err = s.CreateSequencer(s.Ctx, name, pubkey)
s.Require().NoError(err)
return name, addr.String()
}

func (s *KeeperTestHelper) CreateDefaultSequencer(ctx sdk.Context, rollappId string) (string, error) {
func (s *KeeperTestHelper) CreateDefaultSequencer(ctx sdk.Context, rollappId string) string {
pubkey := ed25519.GenPrivKey().PubKey()
return sdk.AccAddress(pubkey.Address()).String(), s.CreateSequencer(ctx, rollappId, pubkey)
err := s.CreateSequencerByPubkey(ctx, rollappId, pubkey)
s.Require().NoError(err)
return sdk.AccAddress(pubkey.Address()).String()
}

func (s *KeeperTestHelper) CreateSequencer(ctx sdk.Context, rollappId string, pubKey types.PubKey) error {
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))
Expand Down
1 change: 0 additions & 1 deletion app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ func (a *AppKeepers) InitKeepers(
a.SequencerKeeper = *sequencermodulekeeper.NewKeeper(
appCodec,
a.keys[sequencermoduletypes.StoreKey],
a.keys[sequencermoduletypes.MemStoreKey],
a.GetSubspace(sequencermoduletypes.ModuleName),
a.BankKeeper,
a.RollappKeeper,
Expand Down
12 changes: 8 additions & 4 deletions app/upgrades/v4/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func CreateUpgradeHandler(
}
migrateSequencers(ctx, keepers.SequencerKeeper)

// TODO: create rollapp gauges for each existing rollapp
// TODO: create rollapp gauges for each existing rollapp (https://github.com/dymensionxyz/dymension/issues/1005)

// Start running the module migrations
logger.Debug("running module migrations ...")
Expand Down Expand Up @@ -129,11 +129,14 @@ func migrateSequencers(ctx sdk.Context, sequencerkeeper sequencerkeeper.Keeper)
for _, oldSequencer := range list {
newSequencer := ConvertOldSequencerToNew(oldSequencer)
sequencerkeeper.SetSequencer(ctx, newSequencer)

if oldSequencer.Proposer {
sequencerkeeper.SetProposer(ctx, oldSequencer.RollappId, oldSequencer.Address)
}
}
}

func ConvertOldRollappToNew(oldRollapp rollapptypes.Rollapp) rollapptypes.Rollapp {
bech32Prefix := oldRollapp.RollappId[:5]
return rollapptypes.Rollapp{
RollappId: oldRollapp.RollappId,
Owner: oldRollapp.Owner,
Expand All @@ -142,7 +145,7 @@ func ConvertOldRollappToNew(oldRollapp rollapptypes.Rollapp) rollapptypes.Rollap
Frozen: oldRollapp.Frozen,
RegisteredDenoms: oldRollapp.RegisteredDenoms,
// TODO: regarding missing data - https://github.com/dymensionxyz/dymension/issues/986
Bech32Prefix: bech32Prefix, // placeholder data
Bech32Prefix: oldRollapp.RollappId[:5], // placeholder data
GenesisChecksum: string(crypto.Sha256([]byte(oldRollapp.RollappId))), // placeholder data
VmType: rollapptypes.Rollapp_EVM, // placeholder data
Metadata: &rollapptypes.RollappMetadata{
Expand All @@ -153,6 +156,8 @@ func ConvertOldRollappToNew(oldRollapp rollapptypes.Rollapp) rollapptypes.Rollap
Telegram: "",
X: "",
},
InitialSequencer: "*",
Sealed: true,
}
}

Expand All @@ -164,7 +169,6 @@ func ConvertOldSequencerToNew(old sequencertypes.Sequencer) sequencertypes.Seque
DymintPubKey: old.DymintPubKey,
RollappId: old.RollappId,
Status: old.Status,
Proposer: old.Proposer,
Tokens: old.Tokens,
Metadata: sequencertypes.SequencerMetadata{
Moniker: old.Metadata.Moniker,
Expand Down
53 changes: 34 additions & 19 deletions app/upgrades/v4/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ func (s *UpgradeTestSuite) TestUpgrade() {
return
}

// TODO: check for rollapp gauges creation

return
},
expPass: true,
Expand Down Expand Up @@ -184,8 +186,9 @@ func (s *UpgradeTestSuite) validateRollappsMigration(numRoll int) error {
}

func (s *UpgradeTestSuite) validateSequencersMigration(numSeq int) error {
expectSequencers := make([]sequencertypes.Sequencer, numSeq)
for i, sequencer := range s.seedSequencers(numSeq) {
testSeqs := s.seedSequencers(numSeq)
expectSequencers := make([]sequencertypes.Sequencer, len(testSeqs))
for i, sequencer := range testSeqs {
expectSequencers[i] = v4.ConvertOldSequencerToNew(sequencer)
}
sequencers := s.App.SequencerKeeper.GetAllSequencers(s.Ctx)
Expand All @@ -211,6 +214,13 @@ func (s *UpgradeTestSuite) validateSequencersMigration(numSeq int) error {

s.Require().JSONEq(string(seq), string(nSeq))
}

// check proposer
for _, rollapp := range s.App.RollappKeeper.GetAllRollapps(s.Ctx) {
_, found := s.App.SequencerKeeper.GetProposer(s.Ctx, rollapp.RollappId)
s.Assert().True(found)
}

return nil
}

Expand Down Expand Up @@ -242,25 +252,30 @@ func (s *UpgradeTestSuite) seedAndStoreSequencers(numRollapps int) {
}
}

func (s *UpgradeTestSuite) seedSequencers(numSeq int) []sequencertypes.Sequencer {
sequencers := make([]sequencertypes.Sequencer, numSeq)
for i := 0; i < numSeq; i++ {
func (s *UpgradeTestSuite) seedSequencers(numRollapps int) []sequencertypes.Sequencer {
numSeqPerRollapp := numRollapps
sequencers := make([]sequencertypes.Sequencer, 0, numSeqPerRollapp*numRollapps)
for i := 0; i < numRollapps; i++ {
rollappID := rollappIDFromIdx(i)
pk := ed25519.GenPrivKeyFromSecret([]byte(rollappID)).PubKey()
pkAny, _ := codectypes.NewAnyWithValue(pk)
sequencer := sequencertypes.Sequencer{
Address: sdk.AccAddress(pk.Address()).String(),
DymintPubKey: pkAny,
RollappId: rollappID,
Metadata: sequencertypes.SequencerMetadata{
Moniker: fmt.Sprintf("sequencer-%d", i),
Details: fmt.Sprintf("Additional details about the sequencer-%d", i),
},
Status: sequencertypes.Bonded,
Proposer: true,
Tokens: sdk.NewCoins(sdk.NewInt64Coin("dym", 100)),

for j := 0; j < numSeqPerRollapp; j++ {
uuid := fmt.Sprintf("sequencer-%d-%d", i, j)
pk := ed25519.GenPrivKeyFromSecret([]byte(uuid)).PubKey()
pkAny, _ := codectypes.NewAnyWithValue(pk)
sequencer := sequencertypes.Sequencer{
Address: sdk.AccAddress(pk.Address()).String(),
DymintPubKey: pkAny,
RollappId: rollappID,
Metadata: sequencertypes.SequencerMetadata{
Moniker: uuid,
Details: fmt.Sprintf("Additional details about the %s", uuid),
},
Status: sequencertypes.Bonded,
Tokens: sdk.NewCoins(sdk.NewInt64Coin("dym", 100)),
Proposer: j == 0, // first sequencer is proposer
}
sequencers = append(sequencers, sequencer)
}
sequencers[i] = sequencer
}
return sequencers
}
Expand Down
3 changes: 0 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,5 @@ replace (
// broken goleveldb
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7

// use cometbft
github.com/tendermint/tendermint => github.com/cometbft/cometbft v0.34.29

golang.org/x/exp => golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb
)
2 changes: 2 additions & 0 deletions proto/dymensionxyz/dymension/rollapp/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ message MsgUpdateState {
// BDs is a list of block description objects (one per block)
// the list must be ordered by height, starting from startHeight to startHeight+numBlocks-1
BlockDescriptors BDs = 7 [(gogoproto.nullable) = false];
// last is true if this is the last batch of the sequencer
bool last = 8;
}

message MsgUpdateStateResponse {
Expand Down
16 changes: 13 additions & 3 deletions proto/dymensionxyz/dymension/sequencer/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,17 @@ option go_package = "github.com/dymensionxyz/dymension/v3/x/sequencer/types";

// GenesisState defines the sequencer module's genesis state.
message GenesisState {
Params params = 1 [(gogoproto.nullable) = false];
repeated Sequencer sequencerList = 2 [(gogoproto.nullable) = false];
repeated BondReduction bondReductions = 3 [(gogoproto.nullable) = false];
Params params = 1 [ (gogoproto.nullable) = false ];
// sequencerList is a list of all defined sequencers
repeated Sequencer sequencerList = 2 [ (gogoproto.nullable) = false ];
// genesisProposers is a list of the defined genesis proposers
repeated GenesisProposer genesisProposers = 3
[ (gogoproto.nullable) = false ];
// bondReductions is a list of all bond reductions
repeated BondReduction bondReductions = 4 [(gogoproto.nullable) = false];
}

message GenesisProposer {
string address = 1;
string rollappId = 2;
}
15 changes: 9 additions & 6 deletions proto/dymensionxyz/dymension/sequencer/operating_status.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ syntax = "proto3";
package dymensionxyz.dymension.sequencer;
import "gogoproto/gogo.proto";


option go_package = "github.com/dymensionxyz/dymension/v3/x/sequencer/types";

// OperatingStatus defines the operating status of a sequencer
enum OperatingStatus {
option (gogoproto.goproto_enum_prefix) = false;
// OPERATING_STATUS_UNBONDED defines a sequencer that is not active and won't be scheduled
OPERATING_STATUS_UNBONDED = 0 [(gogoproto.enumvalue_customname) = "Unbonded"];
// OPERATING_STATUS_UNBONDED defines a sequencer that is not active and won't
// be scheduled
OPERATING_STATUS_UNBONDED = 0
[ (gogoproto.enumvalue_customname) = "Unbonded" ];
// UNBONDING defines a sequencer that is currently unbonding.
OPERATING_STATUS_UNBONDING = 1 [(gogoproto.enumvalue_customname) = "Unbonding"];
// OPERATING_STATUS_BONDED defines a sequencer that is bonded and can be scheduled
OPERATING_STATUS_BONDED= 2 [(gogoproto.enumvalue_customname) = "Bonded"];
OPERATING_STATUS_UNBONDING = 1
[ (gogoproto.enumvalue_customname) = "Unbonding" ];
// OPERATING_STATUS_BONDED defines a sequencer that is bonded and can be
// scheduled
OPERATING_STATUS_BONDED = 2 [ (gogoproto.enumvalue_customname) = "Bonded" ];
}
18 changes: 12 additions & 6 deletions proto/dymensionxyz/dymension/sequencer/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,30 @@ import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "google/protobuf/duration.proto";


option go_package = "github.com/dymensionxyz/dymension/v3/x/sequencer/types";

// Params defines the parameters for the module.
message Params {
option (gogoproto.equal) = true;
option (gogoproto.equal) = true;
option (gogoproto.goproto_stringer) = false;

cosmos.base.v1beta1.Coin min_bond = 1 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "min_bond,omitempty"
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "min_bond,omitempty"
];

// unbonding_time is the time duration of unbonding.
google.protobuf.Duration unbonding_time = 2 [(gogoproto.nullable) = false, (gogoproto.stdduration) = true];
google.protobuf.Duration unbonding_time = 2
[ (gogoproto.nullable) = false, (gogoproto.stdduration) = true ];

// notice_period is the time duration of notice period.
// notice period is the duration between the unbond request and the actual
// unbonding starting. the proposer is still bonded during this period.
google.protobuf.Duration notice_period = 3
[ (gogoproto.nullable) = false, (gogoproto.stdduration) = true ];

// LivenessSlashMultiplier multiplies with the tokens of the slashed sequencer to compute the burn amount.
string liveness_slash_multiplier = 3 [
string liveness_slash_multiplier = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.moretags) = "yaml:\"liveness_slash_multiplier\"",
(gogoproto.nullable) = false
Expand Down
Loading

0 comments on commit 1bb3e72

Please sign in to comment.