Skip to content

Commit

Permalink
feat(drs): upgrade handler for DRS 5 (#431)
Browse files Browse the repository at this point in the history
  • Loading branch information
zale144 authored Dec 26, 2024
1 parent a8e28f0 commit a656462
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fund the sequencer account (if you're using a remote hub node, you must fund the
```shell
# retrieve the minimal bond amount from hub sequencer params
# you have to account for gas fees so it should the final value should be increased
BOND_AMOUNT="$(dymd q sequencer params -o json | jq -r '.params.min_bond.amount')$(dymd q sequencer params -o json | jq -r '.params.min_bond.denom')"
BOND_AMOUNT="$(dymd q rollapp params -o json | jq -r '.params.min_sequencer_bond_global.amount')$(dymd q rollapp params -o json | jq -r '.params.min_sequencer_bond_global.denom')"

# Extract the numeric part
NUMERIC_PART=$(echo $BOND_AMOUNT | sed 's/adym//')
Expand Down
3 changes: 2 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ import (
drs2 "github.com/dymensionxyz/rollapp-evm/app/upgrades/drs-2"
drs3 "github.com/dymensionxyz/rollapp-evm/app/upgrades/drs-3"
drs4 "github.com/dymensionxyz/rollapp-evm/app/upgrades/drs-4"
drs5 "github.com/dymensionxyz/rollapp-evm/app/upgrades/drs-5"
)

const (
Expand All @@ -188,7 +189,7 @@ var (
erc20types.StoreKey,
}
// Upgrades contains the upgrade handlers for the application
Upgrades = []upgrades.Upgrade{drs2.Upgrade, drs3.Upgrade, drs4.Upgrade}
Upgrades = []upgrades.Upgrade{drs2.Upgrade, drs3.Upgrade, drs4.Upgrade, drs5.Upgrade}
)

func getGovProposalHandlers() []govclient.ProposalHandler {
Expand Down
13 changes: 7 additions & 6 deletions app/upgrades/drs-2/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
evmkeeper "github.com/evmos/evmos/v12/x/evm/keeper"

rollappparamskeeper "github.com/dymensionxyz/dymension-rdk/x/rollappparams/keeper"
rollappparamstypes "github.com/dymensionxyz/dymension-rdk/x/rollappparams/types"
evmkeeper "github.com/evmos/evmos/v12/x/evm/keeper"
)

func CreateUpgradeHandler(
Expand All @@ -16,11 +17,6 @@ func CreateUpgradeHandler(
configurator module.Configurator,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// upgrade drs to 2
if err := rpKeeper.SetVersion(ctx, uint32(2)); err != nil {
return nil, err
}

if err := HandleUpgrade(ctx, rpKeeper, evmKeeper); err != nil {
return nil, err
}
Expand All @@ -33,6 +29,11 @@ func HandleUpgrade(
rpKeeper rollappparamskeeper.Keeper,
evmKeeper *evmkeeper.Keeper,
) error {
// upgrade drs to 2
if err := rpKeeper.SetVersion(ctx, uint32(2)); err != nil {
return err
}

// migrate rollapp params with missing min-gas-prices
if err := rpKeeper.SetMinGasPrices(ctx, rollappparamstypes.DefaultParams().MinGasPrices); err != nil {
return err
Expand Down
23 changes: 15 additions & 8 deletions app/upgrades/drs-4/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,23 @@ func CreateUpgradeHandler(
configurator module.Configurator,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
if rpKeeper.Version(ctx) < 3 {
// first run drs-3 migration
if err := drs3.HandleUpgrade(ctx, rpKeeper, evmKeeper); err != nil {
return nil, err
}
}
// upgrade drs to 4
if err := rpKeeper.SetVersion(ctx, uint32(4)); err != nil {
if err := HandleUpgrade(ctx, rpKeeper, evmKeeper); err != nil {
return nil, err
}
return mm.RunMigrations(ctx, configurator, fromVM)
}
}

func HandleUpgrade(ctx sdk.Context, rpKeeper rollappparamskeeper.Keeper, evmKeeper *evmkeeper.Keeper) error {
if rpKeeper.Version(ctx) < 3 {
// first run drs-3 migration
if err := drs3.HandleUpgrade(ctx, rpKeeper, evmKeeper); err != nil {
return err
}
}
// upgrade drs to 4
if err := rpKeeper.SetVersion(ctx, uint32(4)); err != nil {
return err
}
return nil
}
17 changes: 17 additions & 0 deletions app/upgrades/drs-5/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package drs5

import (
storetypes "github.com/cosmos/cosmos-sdk/store/types"

"github.com/dymensionxyz/rollapp-evm/app/upgrades"
)

const (
UpgradeName = "drs-5"
)

var Upgrade = upgrades.Upgrade{
Name: UpgradeName,
CreateHandler: CreateUpgradeHandler,
StoreUpgrades: storetypes.StoreUpgrades{},
}
39 changes: 39 additions & 0 deletions app/upgrades/drs-5/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package drs5

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
rollappparamskeeper "github.com/dymensionxyz/dymension-rdk/x/rollappparams/keeper"
evmkeeper "github.com/evmos/evmos/v12/x/evm/keeper"

drs4 "github.com/dymensionxyz/rollapp-evm/app/upgrades/drs-4"
)

func CreateUpgradeHandler(
rpKeeper rollappparamskeeper.Keeper,
evmKeeper *evmkeeper.Keeper,
mm *module.Manager,
configurator module.Configurator,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
if err := HandleUpgrade(ctx, rpKeeper, evmKeeper); err != nil {
return nil, err
}
return mm.RunMigrations(ctx, configurator, fromVM)
}
}

func HandleUpgrade(ctx sdk.Context, rpKeeper rollappparamskeeper.Keeper, evmKeeper *evmkeeper.Keeper) error {
if rpKeeper.Version(ctx) < 4 {
// first run drs-4 migration
if err := drs4.HandleUpgrade(ctx, rpKeeper, evmKeeper); err != nil {
return err
}
}
// upgrade drs to 5
if err := rpKeeper.SetVersion(ctx, uint32(5)); err != nil {
return err
}
return nil
}
2 changes: 1 addition & 1 deletion scripts/settlement/register_sequencer_to_hub.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fi
#Register Sequencer
# DESCRIPTION="{\"Moniker\":\"${ROLLAPP_CHAIN_ID}-sequencer\",\"Identity\":\"\",\"Website\":\"\",\"SecurityContact\":\"\",\"Details\":\"\"}"
SEQ_PUB_KEY="$("$ROLLAPP_EXECUTABLE" dymint show-sequencer)"
BOND_AMOUNT="$("$SETTLEMENT_EXECUTABLE" q sequencer params -o json --node "$HUB_RPC_URL" | jq -r '.params.min_bond.amount')$("$SETTLEMENT_EXECUTABLE" q sequencer params -o json --node "$HUB_RPC_URL" | jq -r '.params.min_bond.denom')"
BOND_AMOUNT="$("$SETTLEMENT_EXECUTABLE" q rollapp params -o json --node "$HUB_RPC_URL" | jq -r '.params.min_sequencer_bond_global.amount')$("$SETTLEMENT_EXECUTABLE" q rollapp params -o json --node "$HUB_RPC_URL" | jq -r '.params.min_sequencer_bond_global.denom')"

echo "$BOND_AMOUNT"

Expand Down

0 comments on commit a656462

Please sign in to comment.