Skip to content

Commit

Permalink
fix: Added migration to change hub rpc in relayer to point to archive…
Browse files Browse the repository at this point in the history
… node (#578)
  • Loading branch information
omritoptix authored and mtsitrin committed Dec 10, 2023
1 parent 68ff3b6 commit 3489386
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 17 deletions.
34 changes: 34 additions & 0 deletions cmd/config/init/consts.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package initconfig

import "github.com/dymensionxyz/roller/config"

var FlagNames = struct {
TokenSupply string
RollappBinary string
Expand All @@ -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",
},
}
2 changes: 1 addition & 1 deletion cmd/config/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
28 changes: 16 additions & 12 deletions cmd/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package consts

import (
"fmt"

"github.com/dymensionxyz/roller/config"
)

Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions cmd/migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package migrate

import (
"fmt"

"github.com/dymensionxyz/roller/cmd/utils"
"github.com/dymensionxyz/roller/config"
"github.com/dymensionxyz/roller/version"
Expand All @@ -16,6 +17,7 @@ var migrationsRegistry = []VersionMigrator{
&VersionMigratorV0111{},
&VersionMigratorV0112{},
&VersionMigratorV0113{},
&VersionMigratorV0118{},
}

func Cmd() *cobra.Command {
Expand Down
29 changes: 29 additions & 0 deletions cmd/migrate/v0_1_18.go
Original file line number Diff line number Diff line change
@@ -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

}
9 changes: 5 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3489386

Please sign in to comment.