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): v4 migration for proposer #1087

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions app/upgrades/v4/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,18 @@ func migrateRollapps(ctx sdk.Context, rollappkeeper *rollappkeeper.Keeper) error
}

func migrateSequencers(ctx sdk.Context, sequencerkeeper sequencerkeeper.Keeper) {
// FIXME: handle migration (https://github.com/dymensionxyz/dymension/issues/1026)

list := sequencerkeeper.GetAllSequencers(ctx)
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 @@ -144,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's same as the old code but do you know why 5?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no idea actually, saw it as well 😄
probably will be changed on

// TODO: regarding missing data - https://github.com/dymensionxyz/dymension/issues/986

GenesisChecksum: string(crypto.Sha256([]byte(oldRollapp.RollappId))), // placeholder data
VmType: rollapptypes.Rollapp_EVM, // placeholder data
Metadata: &rollapptypes.RollappMetadata{
Expand All @@ -155,6 +156,8 @@ func ConvertOldRollappToNew(oldRollapp rollapptypes.Rollapp) rollapptypes.Rollap
Telegram: "",
X: "",
},
InitialSequencer: "*",
Sealed: true,
}
}

Expand Down
52 changes: 32 additions & 20 deletions app/upgrades/v4/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,9 @@ func (s *UpgradeTestSuite) validateRollappsMigration(numRoll int) error {
}

func (s *UpgradeTestSuite) validateSequencersMigration(numSeq int) error {
// FIXME: test proposer migration (https://github.com/dymensionxyz/dymension/issues/1026)

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 @@ -215,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 @@ -246,24 +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,
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
6 changes: 3 additions & 3 deletions proto/dymensionxyz/dymension/sequencer/sequencer.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ message Sequencer {
SequencerMetadata metadata = 4 [(gogoproto.nullable) = false];
// jailed defined whether the sequencer has been jailed from bonded status or not.
bool jailed = 5;

reserved 6;

bool proposer = 6 [deprecated = true];
// status is the sequencer status (bonded/unbonding/unbonded).
OperatingStatus status = 7;
// tokens define the delegated tokens (incl. self-delegation).
Expand Down
125 changes: 84 additions & 41 deletions x/sequencer/types/sequencer.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading