diff --git a/cmd/rollapp/drs/update/update.go b/cmd/rollapp/drs/update/update.go index 6c8204a9..28193bc6 100644 --- a/cmd/rollapp/drs/update/update.go +++ b/cmd/rollapp/drs/update/update.go @@ -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" @@ -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") }, } diff --git a/cmd/rollapp/migrate/migrate.go b/cmd/rollapp/migrate/migrate.go index 147e6412..47ed863a 100644 --- a/cmd/rollapp/migrate/migrate.go +++ b/cmd/rollapp/migrate/migrate.go @@ -3,6 +3,7 @@ package migrate import ( "errors" "fmt" + "path/filepath" "strings" "time" @@ -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) @@ -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, ) @@ -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 @@ -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 { @@ -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 } diff --git a/cmd/rollapp/setup/setup.go b/cmd/rollapp/setup/setup.go index f33d1873..b5f1bff6 100644 --- a/cmd/rollapp/setup/setup.go +++ b/cmd/rollapp/setup/setup.go @@ -134,6 +134,7 @@ RollApp's IRO time: %v`, raResponse.Rollapp.GenesisInfo.Bech32Prefix, bp, ) + // TODO: reinstall rollapp binary with the right bech32 prefix return } @@ -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("🔔"). diff --git a/utils/config/tomlconfig/toml.go b/utils/config/tomlconfig/toml.go index 7a945406..ce692cbf 100644 --- a/utils/config/tomlconfig/toml.go +++ b/utils/config/tomlconfig/toml.go @@ -5,6 +5,7 @@ import ( "os" "github.com/pelletier/go-toml" + "github.com/pterm/pterm" ) func Load(path string) ([]byte, error) { @@ -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) @@ -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 diff --git a/utils/upgrades/evm-upgrades.go b/utils/upgrades/evm-upgrades.go index 2a618cd0..97c43d16 100644 --- a/utils/upgrades/evm-upgrades.go +++ b/utils/upgrades/evm-upgrades.go @@ -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", }, }, }, }, - }, + } }