Skip to content

Commit

Permalink
feat: update relayer flow to support lc (#875)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemijspavlovs authored Sep 3, 2024
1 parent ae9432f commit 4d494d5
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 145 deletions.
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ repos:
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/golangci/golangci-lint
rev: v1.59.1
hooks:
- id: golangci-lint
name: lint Go files
args: [--new-from-rev=HEAD, -v, --fix, --exclude-use-default, --sort-results]
files: \.go$
# - repo: https://github.com/golangci/golangci-lint
# rev: v1.59.1
# hooks:
# - id: golangci-lint
# name: lint Go files
# args: [--new-from-rev=HEAD, -v, --fix, --exclude-use-default, --sort-results]
# files: \.go$
- repo: https://github.com/compilerla/conventional-pre-commit
rev: v3.2.0
hooks:
Expand Down
15 changes: 7 additions & 8 deletions cmd/eibc/fulfill/denoms/set/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import (
"strconv"
"strings"

"github.com/dymensionxyz/roller/cmd/consts"
globalutils "github.com/dymensionxyz/roller/utils"
"github.com/dymensionxyz/roller/utils/config/yamlconfig"
"github.com/pterm/pterm"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"

"github.com/dymensionxyz/roller/cmd/consts"
globalutils "github.com/dymensionxyz/roller/utils"
"github.com/dymensionxyz/roller/utils/config/yamlconfig"
)

func Cmd() *cobra.Command {
Expand Down Expand Up @@ -68,10 +69,8 @@ func Cmd() *cobra.Command {
}

// Get the actual content node (usually the first child of the document node)
contentNode := &node
if node.Kind == yaml.DocumentNode && len(node.Content) > 0 {
contentNode = node.Content[0]
}
var contentNode map[interface{}]interface{}
err = yaml.Unmarshal(data, &contentNode)

err = yamlconfig.UpdateNestedYAML(
contentNode,
Expand All @@ -83,7 +82,7 @@ func Cmd() *cobra.Command {
return
}

updatedData, err := yaml.Marshal(&node)
updatedData, err := yaml.Marshal(contentNode)
if err != nil {
fmt.Printf("Error marshaling YAML: %v\n", err)
return
Expand Down
8 changes: 3 additions & 5 deletions cmd/eibc/fulfill/rollapps/set/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@ func Cmd() *cobra.Command {
}

// Get the actual content node (usually the first child of the document node)
contentNode := &node
if node.Kind == yaml.DocumentNode && len(node.Content) > 0 {
contentNode = node.Content[0]
}
var contentNode map[interface{}]interface{}
err = yaml.Unmarshal(data, &contentNode)

err = yamlconfig.UpdateNestedYAML(
contentNode,
Expand All @@ -78,7 +76,7 @@ func Cmd() *cobra.Command {
return
}

updatedData, err := yaml.Marshal(&node)
updatedData, err := yaml.Marshal(contentNode)
if err != nil {
fmt.Printf("Error marshaling YAML: %v\n", err)
return
Expand Down
17 changes: 3 additions & 14 deletions cmd/eibc/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,8 @@ func Cmd() *cobra.Command {
return
}

// Parse the YAML
var node yaml.Node
err = yaml.Unmarshal(data, &node)
if err != nil {
pterm.Error.Println("failed to unmarshal config.yaml")
return
}

// Get the actual content node (usually the first child of the document node)
contentNode := &node
if node.Kind == yaml.DocumentNode && len(node.Content) > 0 {
contentNode = node.Content[0]
}
var contentNode map[interface{}]interface{}
err = yaml.Unmarshal(data, &contentNode)

// Update the nested fields
err = yamlconfig.UpdateNestedYAML(
Expand All @@ -139,7 +128,7 @@ func Cmd() *cobra.Command {
}

// Marshal the updated YAML
updatedData, err := yaml.Marshal(&node)
updatedData, err := yaml.Marshal(contentNode)
if err != nil {
fmt.Printf("Error marshaling YAML: %v\n", err)
return
Expand Down
101 changes: 73 additions & 28 deletions cmd/relayer/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
comettypes "github.com/cometbft/cometbft/types"
"github.com/pterm/pterm"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"
"gopkg.in/yaml.v2"

initconfig "github.com/dymensionxyz/roller/cmd/config/init"
"github.com/dymensionxyz/roller/cmd/consts"
Expand Down Expand Up @@ -185,24 +185,34 @@ func Cmd() *cobra.Command {
return
}

pterm.Info.Println("updating application relayer config")
path := filepath.Join(relayerHome, "config")
data, err := os.ReadFile(filepath.Join(path, "config.yaml"))
pterm.Info.Println(
"updating dymint config to 5s block time for relayer configuration",
)
err = dymintutils.UpdateDymintConfigForIBC(home, "5s", false)
if err != nil {
fmt.Printf("Error reading file: %v\n", err)
pterm.Error.Println(
"failed to update dymint config for ibc creation",
err,
)
return
}

// Parse the YAML
var node yaml.Node
err = yaml.Unmarshal(data, &node)
if err != nil {
pterm.Error.Println("failed to unmarshal config.yaml")
if err := relayer.CreatePath(rollappConfig); err != nil {
pterm.Error.Printf("failed to create relayer IBC path: %v\n", err)
return
}

contentNode := &node
if node.Kind == yaml.DocumentNode && len(node.Content) > 0 {
contentNode = node.Content[0]
pterm.Info.Println("updating application relayer config")
relayerConfigPath := filepath.Join(relayerHome, "config", "config.yaml")
data, err := os.ReadFile(filepath.Join(relayerConfigPath))
if err != nil {
fmt.Printf("Error reading file: %v\n", err)
}

var contentNode map[interface{}]interface{}
err = yaml.Unmarshal(data, &contentNode)
if err != nil {
pterm.Error.Println("failed to unmarshal", err)
}

err = yamlconfig.UpdateNestedYAML(
Expand All @@ -215,33 +225,64 @@ func Cmd() *cobra.Command {
return
}

updatedData, err := yaml.Marshal(&node)
err = yamlconfig.UpdateNestedYAML(
contentNode,
[]string{"chains", rollappConfig.HubData.ID, "value", "is-dym-hub"},
true,
)
if err != nil {
fmt.Printf("Error marshaling YAML: %v\n", err)
fmt.Printf("Error updating YAML: %v\n", err)
return
}

// Write the updated YAML back to the original file
err = os.WriteFile(filepath.Join(path, "config.yaml"), updatedData, 0o644)
err = yamlconfig.UpdateNestedYAML(
contentNode,
[]string{"chains", rollappConfig.HubData.ID, "value", "http-addr"},
rollappConfig.HubData.API_URL,
)
if err != nil {
fmt.Printf("Error writing file: %v\n", err)
fmt.Printf("Error updating YAML: %v\n", err)
return
}

pterm.Info.Println(
"updating dymint config to 5s block time for relayer configuration",
err = yamlconfig.UpdateNestedYAML(
contentNode,
[]string{"chains", rollappConfig.RollappID, "value", "is-dym-rollapp"},
true,
)
err = dymintutils.UpdateDymintConfigForIBC(home, "5s", false)
if err != nil {
pterm.Error.Println(
"failed to update dymint config for ibc creation",
err,
)
fmt.Printf("Error updating YAML: %v\n", err)
return
}

if err := relayer.CreatePath(rollappConfig); err != nil {
pterm.Error.Printf("failed to create relayer IBC path: %v\n", err)
err = yamlconfig.UpdateNestedYAML(
contentNode,
[]string{"chains", rollappConfig.RollappID, "value", "trust-period"},
"240h",
)
if err != nil {
fmt.Printf("Error updating YAML: %v\n", err)
return
}

updatedData, err := yaml.Marshal(contentNode)
if err != nil {
fmt.Printf("Error marshaling YAML: %v\n", err)
return
}
fmt.Println("writing")
fmt.Println(string(updatedData))
fmt.Println("to")
fmt.Println(filepath.Join(relayerConfigPath, "config.yaml"))

// Write the updated YAML back to the original file
err = os.WriteFile(
filepath.Join(relayerConfigPath, "config.yaml"),
updatedData,
0o644,
)
if err != nil {
fmt.Printf("Error writing file: %v\n", err)
return
}
}
Expand Down Expand Up @@ -324,14 +365,18 @@ func Cmd() *cobra.Command {
Println("IBC transfer channel is already established!")

status := fmt.Sprintf(
"Active rollapp: %s\n<->\nhub: %s",
"Active\nrollapp: %s\n<->\nhub: %s",
rly.SrcChannel,
rly.DstChannel,
)
err := rly.WriteRelayerStatus(status)
if err != nil {
fmt.Println(err)
return
}

pterm.Info.Println(status)
return
}

if !rly.ChannelReady() {
Expand Down
1 change: 0 additions & 1 deletion cmd/utils/key_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ func IsRlyAddressWithNameInKeyring(
consts.Executables.Relayer,
"keys", "list", chainId, "--home", info.Dir,
)
fmt.Println(cmd.String())

out, err := bash.ExecCommandWithStdout(cmd)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ require (
github.com/dymensionxyz/dymension/v3 v3.1.0-rc03.0.20240823151307-f42674aede1d
github.com/gizak/termui/v3 v3.1.0
github.com/gogo/protobuf v1.3.3
github.com/ignite/cli v0.27.2
github.com/manifoldco/promptui v0.9.0
github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416
github.com/olekukonko/tablewriter v0.0.5
Expand Down
2 changes: 1 addition & 1 deletion scripts/install-binaries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ DYMD_VERSION="main"
DYMD_COMMIT="f42674ae"

EIBC_VERSION="main"
RLY_VERSION="v0.3.4-v2.5.2-relayer"
RLY_VERSION="v0.3.4-v2.5.2-relayer-canon-1"
CELESTIA_VERSION="v0.16.0-rc0"
CELESTIA_APP_VERSION="v2.0.0"

Expand Down
Loading

0 comments on commit 4d494d5

Please sign in to comment.