Skip to content

Commit

Permalink
fix: upgrade handler flow (#1157)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemijspavlovs authored Dec 6, 2024
1 parent 749b8d9 commit 290ccdb
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 47 deletions.
11 changes: 11 additions & 0 deletions cmd/rollapp/drs/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
initconfig "github.com/dymensionxyz/roller/cmd/config/init"
"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/utils/archives"
"github.com/dymensionxyz/roller/utils/config/tomlconfig"
"github.com/dymensionxyz/roller/utils/dependencies"
dymintutils "github.com/dymensionxyz/roller/utils/dymint"
"github.com/dymensionxyz/roller/utils/filesystem"
Expand Down Expand Up @@ -142,6 +143,16 @@ func Cmd() *cobra.Command {
// wait for healthy endpoint
dymintutils.WaitForHealthyRollApp("http://localhost:26657/health")

err = tomlconfig.UpdateFieldInFile(
filepath.Join(home, "roller.toml"),
"rollapp_binary_version",
raCommit,
)
if err != nil {
pterm.Error.Println("failed to update rollapp binary version in config: ", err)
return
}

pterm.Success.Println("update complete")
},
}
Expand Down
21 changes: 18 additions & 3 deletions cmd/rollapp/migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package migrate
import (
"errors"
"fmt"
"path/filepath"
"strings"
"time"

Expand Down Expand Up @@ -50,8 +51,9 @@ func Cmd() *cobra.Command {
case consts.EVM_ROLLAPP:
rollappType := "rollapp-evm"
err = applyMigrations(
rollerData.Home,
rollerData.RollappBinaryVersion, raUpgrade.CurrentVersionCommit, rollappType,
upgrades.EvmRollappUpgradeModules,
upgrades.EvmRollappUpgradeModules(home),
)
if err != nil {
pterm.Error.Println("failed to apply migrations: ", err)
Expand All @@ -60,6 +62,7 @@ func Cmd() *cobra.Command {
case consts.WASM_ROLLAPP:
rollappType := "rollapp-wasm"
err = applyMigrations(
rollerData.Home,
rollerData.RollappBinaryVersion, raUpgrade.CurrentVersionCommit, rollappType,
upgrades.WasmRollappUpgradeModules,
)
Expand All @@ -76,7 +79,7 @@ func Cmd() *cobra.Command {
return cmd
}

func applyMigrations(from, to, vmt string, versions []upgrades.Version) error {
func applyMigrations(home, from, to, vmt string, versions []upgrades.Version) error {
var fromTs time.Time
var toTs time.Time
var err error
Expand Down Expand Up @@ -150,7 +153,7 @@ func applyMigrations(from, to, vmt string, versions []upgrades.Version) error {

fmt.Println("version: ", upgradeVersionTimestamp, v.VersionIdentifier)
fmt.Println("from: ", fromTs, from)
fmt.Println("to: ", fromTs, to)
fmt.Println("to: ", toTs, to)

isNew := upgradeVersionTimestamp.Before(toTs) || upgradeVersionTimestamp.Equal(toTs)
if upgradeVersionTimestamp.After(fromTs) || isNew {
Expand All @@ -175,6 +178,18 @@ func applyMigrations(from, to, vmt string, versions []upgrades.Version) error {
}
}
}

err = tomlconfig.UpdateFieldInFile(
filepath.Join(home, "roller.toml"),
"rollapp_binary_version",
to,
)
if err != nil {
pterm.Error.Println("failed to update rollapp binary version: ", err)
return err
}

pterm.Info.Println("upgrade finished")
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/rollapp/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ RollApp's IRO time: %v`,
raResponse.Rollapp.GenesisInfo.Bech32Prefix,
bp,
)
// TODO: reinstall rollapp binary with the right bech32 prefix
return
}

Expand Down Expand Up @@ -295,7 +296,6 @@ RollApp's IRO time: %v`,
necBlnc.String(),
)

// check whether balance is bigger or equal to the necessaryBalance
isAddrFunded := balance.Amount.GTE(necessaryBalance)
if !isAddrFunded {
pterm.DefaultSection.WithIndentCharacter("🔔").
Expand Down
7 changes: 5 additions & 2 deletions utils/config/tomlconfig/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"

"github.com/pelletier/go-toml"
"github.com/pterm/pterm"
)

func Load(path string) ([]byte, error) {
Expand Down Expand Up @@ -79,7 +80,7 @@ func RemoveFieldFromFile(tmlFilePath, keyPath string) error {
}

if !tomlCfg.Has(keyPath) {
return fmt.Errorf("key %s does not exist", keyPath)
pterm.Warning.Printfln("key %s does not exist", keyPath)
}

err = tomlCfg.Delete(keyPath)
Expand All @@ -97,7 +98,9 @@ func ReplaceFieldInFile(tmlFilePath, oldPath, newPath string, value any) error {
}

if !tomlCfg.Has(oldPath) {
return fmt.Errorf("old key %s does not exist", oldPath)
// the assumption here is that if the value is not present, it was already migrated to the new value
pterm.Warning.Printfln("old key %s does not exist", oldPath)
return nil
}

var writeableValue any
Expand Down
84 changes: 43 additions & 41 deletions utils/upgrades/evm-upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,54 @@ import (
"github.com/dymensionxyz/roller/utils/sequencer"
)

var EvmRollappUpgradeModules = []Version{
{
VersionIdentifier: "v2.2.1-rc05",
Modules: []UpgradeModule{
{
Name: "dymint",
ConfigFilePath: sequencer.GetDymintFilePath("~/.roller"),
Values: VersionValues{
NewValues: []config.PathValue{
{
Path: "p2p_persistent_nodes",
Value: "",
func EvmRollappUpgradeModules(home string) []Version {
return []Version{
{
VersionIdentifier: "v2.2.1-rc05",
Modules: []UpgradeModule{
{
Name: "dymint",
ConfigFilePath: sequencer.GetDymintFilePath(home),
Values: VersionValues{
NewValues: []config.PathValue{
{
Path: "p2p_persistent_nodes",
Value: "",
},
{
Path: "p2p_blocksync_enabled",
Value: true,
},
{
Path: "p2p_blocksync_block_request_interval",
Value: "30s",
},
{
Path: "batch_acceptance_attempts",
Value: "5",
},
},
{
Path: "p2p_blocksync_enabled",
Value: true,
UpgradeableValues: []UpgradeableValue{
{
OldValuePath: "p2p_gossiped_blocks_cache_size",
NewValuePath: "p2p_gossip_cache_size",
Value: 50,
},
{
OldValuePath: "p2p_bootstrap_time",
NewValuePath: "p2p_bootstrap_retry_time",
},
{
OldValuePath: "p2p_advertising",
NewValuePath: "p2p_advertising_enabled",
},
},
{
Path: "p2p_blocksync_block_request_interval",
Value: "30s",
DeprecatedValues: []string{
"aggregator",
},
{
Path: "batch_acceptance_attempts",
Value: "5",
},
},
UpgradeableValues: []UpgradeableValue{
{
OldValuePath: "p2p_gossiped_blocks_cache_size",
NewValuePath: "p2p_gossip_cache_size",
Value: 50,
},
{
OldValuePath: "p2p_bootstrap_time",
NewValuePath: "p2p_bootstrap_retry_time",
},
{
OldValuePath: "p2p_advertising",
NewValuePath: "p2p_advertising_enabled",
},
},
DeprecatedValues: []string{
"aggregator",
},
},
},
},
},
}
}

0 comments on commit 290ccdb

Please sign in to comment.