From f02b0386425b2fc2813688878c8db3a773230fdd Mon Sep 17 00:00:00 2001 From: Omri Date: Mon, 30 Oct 2023 21:55:32 +0100 Subject: [PATCH] fix: Added migration to change hub rpc in relayer to point to archive node (#578) --- cmd/config/init/consts.go | 34 ++++++++++++++++++++++++++++++++++ cmd/config/init/init.go | 2 +- cmd/consts/consts.go | 28 ++++++++++++++++------------ cmd/migrate/migrate.go | 2 ++ cmd/migrate/v0_1_18.go | 29 +++++++++++++++++++++++++++++ config/config.go | 9 +++++---- 6 files changed, 87 insertions(+), 17 deletions(-) create mode 100644 cmd/migrate/v0_1_18.go diff --git a/cmd/config/init/consts.go b/cmd/config/init/consts.go index 79f51ac7..65ec8ddf 100644 --- a/cmd/config/init/consts.go +++ b/cmd/config/init/consts.go @@ -1,5 +1,7 @@ package initconfig +import "github.com/dymensionxyz/roller/config" + var FlagNames = struct { TokenSupply string RollappBinary string @@ -19,3 +21,35 @@ var FlagNames = struct { VMType: "vm-type", NoOutput: "no-output", } + +const ( + StagingHubName = "devnet" + FroopylandHubName = "froopyland" + LocalHubName = "local" + LocalHubID = "dymension_100-1" +) + +// TODO(#112): The avaialble hub networks should be read from YAML file +var Hubs = map[string]config.HubData{ + StagingHubName: { + API_URL: "https://dymension-devnet.api.silknodes.io:443", + ID: "devnet_304-1", + RPC_URL: "https://dymension-devnet.rpc.silknodes.io:443", + ARCHIVE_RPC_URL: "https://dymension-devnet.rpc.silknodes.io:443", + GAS_PRICE: "0.25", + }, + FroopylandHubName: { + API_URL: "https://froopyland.api.silknodes.io:443", + ID: "froopyland_100-1", + RPC_URL: "https://froopyland.rpc.silknodes.io:443", + ARCHIVE_RPC_URL: "https://froopy-archive.rpc.silknodes.io:443", + GAS_PRICE: "0.25", + }, + LocalHubName: { + API_URL: "http://localhost:1318", + ID: LocalHubID, + RPC_URL: "http://localhost:36657", + ARCHIVE_RPC_URL: "http://localhost:36657", + GAS_PRICE: "0", + }, +} diff --git a/cmd/config/init/init.go b/cmd/config/init/init.go index af52ef42..a73337cc 100644 --- a/cmd/config/init/init.go +++ b/cmd/config/init/init.go @@ -114,7 +114,7 @@ func runInit(cmd *cobra.Command, args []string) error { GasPrices: "0", }, relayer.ChainConfig{ ID: initConfig.HubData.ID, - RPC: initConfig.HubData.RPC_URL, + RPC: initConfig.HubData.ARCHIVE_RPC_URL, Denom: consts.Denoms.Hub, AddressPrefix: consts.AddressPrefixes.Hub, GasPrices: initConfig.HubData.GAS_PRICE, diff --git a/cmd/consts/consts.go b/cmd/consts/consts.go index 7d01cac7..4879b28d 100644 --- a/cmd/consts/consts.go +++ b/cmd/consts/consts.go @@ -2,6 +2,7 @@ package consts import ( "fmt" + "github.com/dymensionxyz/roller/config" ) @@ -84,26 +85,29 @@ var SpinnerMsgs = struct { } var FroopylandHubData = config.HubData{ - API_URL: "https://froopyland.api.silknodes.io:443", - ID: FroopylandHubID, - RPC_URL: "https://froopyland.rpc.silknodes.io:443", - GAS_PRICE: "0.25", + API_URL: "https://froopyland.api.silknodes.io:443", + ID: FroopylandHubID, + RPC_URL: "https://froopyland.rpc.silknodes.io:443", + ARCHIVE_RPC_URL: "https://froopy-archive.rpc.silknodes.io:443", + GAS_PRICE: "0.25", } // TODO(#112): The available hub networks should be read from YAML file var Hubs = map[string]config.HubData{ StagingHubName: { - API_URL: "https://dymension-devnet.api.silknodes.io:443", - ID: StagingHubID, - RPC_URL: "https://dymension-devnet.rpc.silknodes.io:443", - GAS_PRICE: "0.25", + API_URL: "https://dymension-devnet.api.silknodes.io:443", + ID: StagingHubID, + RPC_URL: "https://dymension-devnet.rpc.silknodes.io:443", + ARCHIVE_RPC_URL: "https://dymension-devnet.rpc.silknodes.io:443", + GAS_PRICE: "0.25", }, FroopylandHubName: FroopylandHubData, LocalHubName: { - API_URL: "http://localhost:1318", - ID: LocalHubID, - RPC_URL: "http://localhost:36657", - GAS_PRICE: "0", + API_URL: "http://localhost:1318", + ID: LocalHubID, + RPC_URL: "http://localhost:36657", + ARCHIVE_RPC_URL: "http://localhost:36657", + GAS_PRICE: "0", }, // TODO: Add mainnet hub data MainnetHubName: FroopylandHubData, diff --git a/cmd/migrate/migrate.go b/cmd/migrate/migrate.go index 4c9c92fa..cbd97761 100644 --- a/cmd/migrate/migrate.go +++ b/cmd/migrate/migrate.go @@ -2,6 +2,7 @@ package migrate import ( "fmt" + "github.com/dymensionxyz/roller/cmd/utils" "github.com/dymensionxyz/roller/config" "github.com/dymensionxyz/roller/version" @@ -16,6 +17,7 @@ var migrationsRegistry = []VersionMigrator{ &VersionMigratorV0111{}, &VersionMigratorV0112{}, &VersionMigratorV0113{}, + &VersionMigratorV0118{}, } func Cmd() *cobra.Command { diff --git a/cmd/migrate/v0_1_18.go b/cmd/migrate/v0_1_18.go new file mode 100644 index 00000000..de8b46e6 --- /dev/null +++ b/cmd/migrate/v0_1_18.go @@ -0,0 +1,29 @@ +package migrate + +import ( + initconfig "github.com/dymensionxyz/roller/cmd/config/init" + "github.com/dymensionxyz/roller/config" + "github.com/dymensionxyz/roller/relayer" +) + +type VersionMigratorV0118 struct{} + +func (v *VersionMigratorV0118) ShouldMigrate(prevVersion VersionData) bool { + return prevVersion.Major < 1 && prevVersion.Minor < 2 && prevVersion.Patch < 18 +} + +func (v *VersionMigratorV0118) PerformMigration(rlpCfg config.RollappConfig) error { + rlyCfg, err := relayer.ReadRlyConfig(rlpCfg.Home) + if err != nil { + return err + } + hubRpcAddress := rlyCfg["chains"].(map[interface{}]interface{})[rlpCfg.HubData.ID].(map[interface{}]interface{})["value"].(map[interface{}]interface{})["rpc-addr"].(string) + if hubRpcAddress == initconfig.Hubs[initconfig.FroopylandHubName].RPC_URL { + if err := relayer.UpdateRlyConfigValue(rlpCfg, []string{"chains", rlpCfg.HubData.ID, "value", "rpc-addr"}, initconfig.Hubs[initconfig.FroopylandHubName].ARCHIVE_RPC_URL); err != nil { + return err + } + + } + return nil + +} diff --git a/config/config.go b/config/config.go index e10c7558..933224a1 100644 --- a/config/config.go +++ b/config/config.go @@ -40,10 +40,11 @@ type RollappConfig struct { } type HubData = struct { - API_URL string - ID string - RPC_URL string - GAS_PRICE string + API_URL string + ID string + RPC_URL string + ARCHIVE_RPC_URL string + GAS_PRICE string } func (c RollappConfig) Validate() error {