Skip to content

Commit

Permalink
fix: relayer setup and start commands should handle metadata from…
Browse files Browse the repository at this point in the history
… chain (#1044)
  • Loading branch information
artemijspavlovs authored Sep 27, 2024
1 parent d3e3913 commit 15bf087
Show file tree
Hide file tree
Showing 16 changed files with 451 additions and 275 deletions.
1 change: 1 addition & 0 deletions cmd/consts/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type RollappData = struct {
ApiUrl string `toml:"api_url"`
RpcUrl string `toml:"rpc_url"`
GasPrice string `toml:"gas_price"`
Denom string `toml:"denom"`
}

type DaData = struct {
Expand Down
11 changes: 8 additions & 3 deletions cmd/da-light-client/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (
"errors"
"fmt"

"github.com/pterm/pterm"
"github.com/spf13/cobra"

"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/cmd/utils"
datalayer "github.com/dymensionxyz/roller/data_layer"
"github.com/dymensionxyz/roller/utils/bash"
"github.com/dymensionxyz/roller/utils/config/tomlconfig"
"github.com/dymensionxyz/roller/utils/errorhandling"
"github.com/pterm/pterm"
"github.com/spf13/cobra"
)

const (
Expand Down Expand Up @@ -48,7 +49,11 @@ func Cmd() *cobra.Command {
pterm.Info.Println("checking for da address balance")
insufficientBalances, err := damanager.CheckDABalance()
errorhandling.PrettifyErrorIfExists(err)
utils.PrintInsufficientBalancesIfAny(insufficientBalances)
err = utils.PrintInsufficientBalancesIfAny(insufficientBalances)
if err != nil {
pterm.Error.Println("failed to retrieve insufficient balances: ", err)
return
}

damanager.SetRPCEndpoint(rollappConfig.DA.StateNode)
if metricsEndpoint != "" {
Expand Down
149 changes: 65 additions & 84 deletions cmd/relayer/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,55 @@ func Cmd() *cobra.Command {
rly.SetLogger(relayerLogger)
logFileOption := utils.WithLoggerLogging(relayerLogger)

rollappChainData, err := tomlconfig.LoadRollappMetadataFromChain(
rollappChainData, err := tomlconfig.GetRollappMetadataFromChain(
home,
raData.ID,
&hd,
string(rollerData.VMType),
)
errorhandling.PrettifyErrorIfExists(err)

outputHandler := initconfig.NewOutputHandler(false)
isRelayerInitialized, err := filesystem.DirNotEmpty(relayerHome)
if err != nil {
pterm.Error.Printf("failed to check %s: %v\n", relayerHome, err)
return
}

var shouldOverwrite bool
if isRelayerInitialized {
outputHandler.StopSpinner()
shouldOverwrite, err = outputHandler.PromptOverwriteConfig(relayerHome)
if err != nil {
pterm.Error.Printf("failed to get your input: %v\n", err)
return
}
}

if shouldOverwrite {
pterm.Info.Println("overriding the existing relayer configuration")
err = os.RemoveAll(relayerHome)
if err != nil {
pterm.Error.Printf(
"failed to recuresively remove %s: %v\n",
relayerHome,
err,
)
return
}

err := servicemanager.RemoveServiceFiles(consts.RelayerSystemdServices)
if err != nil {
pterm.Error.Printf("failed to remove relayer systemd services: %v\n", err)
return
}

err = os.MkdirAll(relayerHome, 0o755)
if err != nil {
pterm.Error.Printf("failed to create %s: %v\n", relayerHome, err)
return
}
}

srcIbcChannel, dstIbcChannel, err := rly.LoadActiveChannel(raData, hd)
if err != nil {
pterm.Error.Printf("failed to load active channel, %v", err)
Expand Down Expand Up @@ -203,47 +244,6 @@ func Cmd() *cobra.Command {
pterm.Error.Printf("rollapp did not reach valid height: %v\n", err)
return
}
outputHandler := initconfig.NewOutputHandler(false)
isRelayerInitialized, err := filesystem.DirNotEmpty(relayerHome)
if err != nil {
pterm.Error.Printf("failed to check %s: %v\n", relayerHome, err)
return
}

var shouldOverwrite bool
if isRelayerInitialized {
outputHandler.StopSpinner()
shouldOverwrite, err = outputHandler.PromptOverwriteConfig(relayerHome)
if err != nil {
pterm.Error.Printf("failed to get your input: %v\n", err)
return
}
}

if shouldOverwrite {
pterm.Info.Println("overriding the existing relayer configuration")
err = os.RemoveAll(relayerHome)
if err != nil {
pterm.Error.Printf(
"failed to recuresively remove %s: %v\n",
relayerHome,
err,
)
return
}

err := servicemanager.RemoveServiceFiles(consts.RelayerSystemdServices)
if err != nil {
pterm.Error.Printf("failed to remove relayer systemd services: %v\n", err)
return
}

err = os.MkdirAll(relayerHome, 0o755)
if err != nil {
pterm.Error.Printf("failed to create %s: %v\n", relayerHome, err)
return
}
}

if !isRelayerInitialized || shouldOverwrite {
// preflight checks
Expand Down Expand Up @@ -454,7 +454,7 @@ func Cmd() *cobra.Command {
}
}

err = verifyRelayerBalances(rollerData)
err = verifyRelayerBalances(raData, hd)
if err != nil {
return
}
Expand Down Expand Up @@ -504,7 +504,7 @@ func Cmd() *cobra.Command {

// TODO: look up relayer keys
if createIbcChannels || shouldOverwrite {
err = verifyRelayerBalances(rollerData)
err = verifyRelayerBalances(raData, hd)
if err != nil {
pterm.Error.Printf("failed to verify relayer balances: %v\n", err)
return
Expand Down Expand Up @@ -544,48 +544,16 @@ func Cmd() *cobra.Command {
}

// TODO: remove code duplication
isRelayerInitialized, err := filesystem.DirNotEmpty(relayerHome)
_, err = os.Stat(relayerHome)
if err != nil {
pterm.Error.Printf("failed to check %s: %v\n", relayerHome, err)
return
}

outputHandler := initconfig.NewOutputHandler(false)

var shouldOverwrite bool
if isRelayerInitialized {
outputHandler.StopSpinner()
shouldOverwrite, err = outputHandler.PromptOverwriteConfig(relayerHome)
if err != nil {
pterm.Error.Printf("failed to get your input: %v\n", err)
pterm.Error.Printf("failed to create %s: %v\n", relayerHome, err)
return
}
}

if shouldOverwrite {
pterm.Info.Println("overriding the existing relayer configuration")
err = os.RemoveAll(relayerHome)
if err != nil {
pterm.Error.Printf(
"failed to recuresively remove %s: %v\n",
relayerHome,
err,
)
return
}

err := servicemanager.RemoveServiceFiles(consts.RelayerSystemdServices)
if err != nil {
pterm.Error.Printf("failed to remove relayer systemd services: %v\n", err)
return
}
fmt.Println("rollapp chain data denom: ", rollappChainData.Denom)

err = os.MkdirAll(relayerHome, 0o755)
if err != nil {
pterm.Error.Printf("failed to create %s: %v\n", relayerHome, err)
return
}
}
pterm.Info.Println("initializing relayer config")
err = initconfig.InitializeRelayerConfig(
relayer.ChainConfig{
Expand All @@ -600,7 +568,7 @@ func Cmd() *cobra.Command {
Denom: consts.Denoms.Hub,
AddressPrefix: consts.AddressPrefixes.Hub,
GasPrices: rollappChainData.HubData.GAS_PRICE,
}, rollerData,
}, *rollappChainData,
)
if err != nil {
pterm.Error.Printf(
Expand Down Expand Up @@ -639,6 +607,12 @@ func Cmd() *cobra.Command {
return
}

rollappIbcConnection, hubIbcConnection, err := rly.GetActiveConnections(raData, hd)
if err != nil {
pterm.Error.Printf("failed to retrieve active connections: %v\n", err)
return
}

pterm.Info.Println("updating application relayer config")
relayerConfigPath := filepath.Join(relayerHome, "config", "config.yaml")
updates := map[string]interface{}{
Expand All @@ -653,6 +627,10 @@ func Cmd() *cobra.Command {
"extra-codecs": []string{
"ethermint",
},
fmt.Sprintf("paths.%s.dst.client-id", consts.DefaultRelayerPath): rollappIbcConnection.ClientID,
fmt.Sprintf("paths.%s.dst.connection-id", consts.DefaultRelayerPath): rollappIbcConnection.ID,
fmt.Sprintf("paths.%s.src.client-id", consts.DefaultRelayerPath): hubIbcConnection.ClientID,
fmt.Sprintf("paths.%s.src.connection-id", consts.DefaultRelayerPath): hubIbcConnection.ID,
}
err = yamlconfig.UpdateNestedYAML(relayerConfigPath, updates)
if err != nil {
Expand All @@ -670,12 +648,15 @@ func Cmd() *cobra.Command {
return relayerStartCmd
}

func verifyRelayerBalances(rolCfg configutils.RollappConfig) error {
insufficientBalances, err := relayer.GetRelayerInsufficientBalances(rolCfg)
func verifyRelayerBalances(raData consts.RollappData, hd consts.HubData) error {
insufficientBalances, err := relayer.GetRelayerInsufficientBalances(raData, hd)
if err != nil {
return err
}
err = utils.PrintInsufficientBalancesIfAny(insufficientBalances)
if err != nil {
return err
}
utils.PrintInsufficientBalancesIfAny(insufficientBalances)

return nil
}
Loading

0 comments on commit 15bf087

Please sign in to comment.