Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Reliable status for rollapp sequencer and relayer #204

Merged
merged 6 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions cmd/relayer/start/create_ibc_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package start

import (
"fmt"
"github.com/dymensionxyz/roller/relayer"
"os/exec"
"path/filepath"

Expand All @@ -11,47 +12,48 @@ import (
)

// Creates an IBC channel between the hub and the client, and return the source channel ID.
func createIBCChannelIfNeeded(rollappConfig config.RollappConfig, logFileOption utils.CommandOption) (string, error) {
func createIBCChannelIfNeeded(rollappConfig config.RollappConfig, logFileOption utils.CommandOption) (
relayer.ConnectionChannels, error) {
createClientsCmd := getCreateClientsCmd(rollappConfig, rollappConfig.RollappID, rollappConfig.HubData.ID)
fmt.Println("Creating clients...")
if err := utils.ExecBashCmdWithOSOutput(createClientsCmd, logFileOption); err != nil {
return "", err
return relayer.ConnectionChannels{}, err
}
dstConnectionId, err := GetDstConnectionIDFromYAMLFile(filepath.Join(rollappConfig.Home, consts.ConfigDirName.Relayer,
dstConnectionId, err := relayer.GetDstConnectionIDFromYAMLFile(filepath.Join(rollappConfig.Home, consts.ConfigDirName.Relayer,
"config", "config.yaml"))
if err != nil {
return "", err
return relayer.ConnectionChannels{}, err
}
if dstConnectionId == "" {
// Before setting up the connection, we need to call update clients
updateClientsCmd := getUpdateClientsCmd(rollappConfig)
fmt.Println("Updating clients...")
if err := utils.ExecBashCmdWithOSOutput(updateClientsCmd, logFileOption); err != nil {
return "", err
return relayer.ConnectionChannels{}, err
}

createConnectionCmd := getCreateConnectionCmd(rollappConfig)
fmt.Println("Creating connection...")
if err := utils.ExecBashCmdWithOSOutput(createConnectionCmd, logFileOption); err != nil {
return "", err
return relayer.ConnectionChannels{}, err
}
}
srcChannelId, err := GetSourceChannelForConnection(dstConnectionId, rollappConfig)
connectionChannels, err := relayer.GetConnectionChannels(dstConnectionId, rollappConfig)
if err != nil {
return "", err
return relayer.ConnectionChannels{}, err
}
if srcChannelId == "" {
if connectionChannels.Src == "" {
createChannelCmd := getCreateChannelCmd(rollappConfig)
fmt.Println("Creating channel...")
if err := utils.ExecBashCmdWithOSOutput(createChannelCmd, logFileOption); err != nil {
return "", err
return relayer.ConnectionChannels{}, err
}
srcChannelId, err = GetSourceChannelForConnection(dstConnectionId, rollappConfig)
connectionChannels, err = relayer.GetConnectionChannels(dstConnectionId, rollappConfig)
if err != nil {
return "", err
return relayer.ConnectionChannels{}, err
}
}
return srcChannelId, nil
return connectionChannels, nil
}

func getCreateChannelCmd(config config.RollappConfig) *exec.Cmd {
Expand Down
37 changes: 0 additions & 37 deletions cmd/relayer/start/get_dst_connection_id.go

This file was deleted.

7 changes: 4 additions & 3 deletions cmd/relayer/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ func Start() *cobra.Command {
utils.PrettifyErrorIfExists(err)
relayerLogFilePath := utils.GetRelayerLogPath(rollappConfig)
logFileOption := utils.WithLogging(relayerLogFilePath)
srcChannelId, err := createIBCChannelIfNeeded(rollappConfig, logFileOption)
connectionChannels, err := createIBCChannelIfNeeded(rollappConfig, logFileOption)
utils.PrettifyErrorIfExists(err)
updateClientsCmd := getUpdateClientsCmd(rollappConfig)
utils.RunCommandEvery(updateClientsCmd.Path, updateClientsCmd.Args[1:], 60, logFileOption)
relayPacketsCmd := getRelayPacketsCmd(rollappConfig, srcChannelId)
relayPacketsCmd := getRelayPacketsCmd(rollappConfig, connectionChannels.Src)
utils.RunCommandEvery(relayPacketsCmd.Path, relayPacketsCmd.Args[1:], 30, logFileOption)
fmt.Printf("💈 The relayer is running successfully on you local machine on channel %s!", srcChannelId)
fmt.Printf("💈 The relayer is running successfully on you local machine! Channels: src, %s <-> %s, dst",
connectionChannels.Src, connectionChannels.Dst)
select {}
},
}
Expand Down
29 changes: 17 additions & 12 deletions cmd/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package run

import (
"context"
"github.com/dymensionxyz/roller/relayer"
"github.com/dymensionxyz/roller/sequencer"
"os"
"os/exec"
"sync"
Expand Down Expand Up @@ -53,10 +55,11 @@ func Cmd() *cobra.Command {

func runRelayerWithRestarts(cfg config.RollappConfig, serviceConfig *servicemanager.ServiceConfig) {
startRelayerCmd := getStartRelayerCmd(cfg)
service := servicemanager.ServiceData{
Command: startRelayerCmd,
FetchFn: utils.GetRelayerAddresses,
UIData: servicemanager.UIData{Name: "Relayer"},
service := servicemanager.Service{
Command: startRelayerCmd,
FetchFn: utils.GetRelayerAccountsData,
UIData: servicemanager.UIData{Name: "Relayer"},
StatusFn: relayer.GetRelayerStatus,
}
serviceConfig.AddService("Relayer", service)
serviceConfig.RunServiceWithRestart("Relayer")
Expand All @@ -78,21 +81,23 @@ func runDaWithRestarts(rollappConfig config.RollappConfig, serviceConfig *servic
return
}

service := servicemanager.ServiceData{
Command: startDALCCmd,
FetchFn: damanager.GetDAAccData,
UIData: servicemanager.UIData{Name: "DA Light Client"},
service := servicemanager.Service{
Command: startDALCCmd,
FetchFn: damanager.GetDAAccData,
StatusFn: damanager.GetStatus,
UIData: servicemanager.UIData{Name: "DA Light Client"},
}
serviceConfig.AddService("DA Light Client", service)
serviceConfig.RunServiceWithRestart("DA Light Client", utils.WithLogging(daLogFilePath))
}

func runSequencerWithRestarts(rollappConfig config.RollappConfig, serviceConfig *servicemanager.ServiceConfig) {
startRollappCmd := sequnecer_start.GetStartRollappCmd(rollappConfig, consts.DefaultDALCRPC)
service := servicemanager.ServiceData{
Command: startRollappCmd,
FetchFn: utils.GetSequencerData,
UIData: servicemanager.UIData{Name: "Sequencer"},
service := servicemanager.Service{
Command: startRollappCmd,
FetchFn: utils.GetSequencerData,
StatusFn: sequencer.GetSequencerStatus,
UIData: servicemanager.UIData{Name: "Sequencer"},
}
serviceConfig.AddService("Sequencer", service)
serviceConfig.RunServiceWithRestart("Sequencer", utils.WithLogging(utils.GetSequencerLogPath(rollappConfig)))
Expand Down
2 changes: 1 addition & 1 deletion cmd/utils/fetch_accounts_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/dymensionxyz/roller/config"
)

func GetRelayerAddresses(cfg config.RollappConfig) ([]AccountData, error) {
func GetRelayerAccountsData(cfg config.RollappConfig) ([]AccountData, error) {
data := []AccountData{}
rollappRlyAcc, err := GetRolRlyAccData(cfg)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions data_layer/celestia/celestia.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ type Celestia struct {
rpcEndpoint string
}

func (c2 *Celestia) GetStatus(c config.RollappConfig) string {
mtsitrin marked this conversation as resolved.
Show resolved Hide resolved
//TODO implement me
return ""
}

func (c *Celestia) GetLightNodeEndpoint() string {
return LCEndpoint
}
Expand Down
1 change: 1 addition & 0 deletions data_layer/da_layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type DataLayer interface {
GetLightNodeEndpoint() string
SetRPCEndpoint(string)
GetNetworkName() string
GetStatus(c config.RollappConfig) string
}

type DAManager struct {
Expand Down
4 changes: 4 additions & 0 deletions data_layer/damock/damock.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import (
type DAMock struct {
}

func (d *DAMock) GetStatus(c config.RollappConfig) string {
return ""
}

func NewDAMock() *DAMock {
return &DAMock{}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
package start
package relayer

import (
"encoding/json"
"os/exec"

"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/cmd/utils"
"github.com/dymensionxyz/roller/config"
"os/exec"
)

// GetSourceChannelForConnection Returns the open source channel for the given destination connection ID. If no open channel exists, it returns an
// empty string.
func GetSourceChannelForConnection(dstConnectionID string, rollappConfig config.RollappConfig) (string, error) {
func GetConnectionChannels(dstConnectionID string, rollappConfig config.RollappConfig) (
ConnectionChannels, error) {
commonDymdFlags := utils.GetCommonDymdFlags(rollappConfig)
args := []string{"query", "ibc", "channel", "connections", dstConnectionID}
args = append(args, commonDymdFlags...)
cmd := exec.Command(consts.Executables.Dymension, args...)
out, err := cmd.Output()
if err != nil {
return "", err
return ConnectionChannels{}, err
}
channelId, err := GetOpenStateChannelID(out)
channels, err := extractChannelsFromResponse(out)
if err != nil {
return "", err
return ConnectionChannels{}, err
}
return channelId, nil
return channels, nil
}

type Channel struct {
State string `json:"state"`
ChannelID string `json:"channel_id"`
Counterparty struct {
ChannelID string `json:"channel_id"`
} `json:"counterparty"`
Expand All @@ -38,16 +37,23 @@ type ChannelList struct {
Channels []Channel `json:"channels"`
}

func GetOpenStateChannelID(jsonData []byte) (string, error) {
type ConnectionChannels struct {
Src string
Dst string
}

func extractChannelsFromResponse(jsonData []byte) (ConnectionChannels, error) {
var channels ChannelList
if err := json.Unmarshal(jsonData, &channels); err != nil {
return "", err
return ConnectionChannels{}, err
}

for _, channel := range channels.Channels {
if channel.State == "STATE_OPEN" {
return channel.Counterparty.ChannelID, nil
return ConnectionChannels{
Src: channel.Counterparty.ChannelID,
Dst: channel.ChannelID,
}, nil
}
}
return "", nil
return ConnectionChannels{}, nil
}
64 changes: 64 additions & 0 deletions relayer/query_relayer_data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package relayer

import (
"fmt"
"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/config"
"gopkg.in/yaml.v2"
"io/ioutil"
"path/filepath"
)

func GetRelayerStatus(config config.RollappConfig) string {
mtsitrin marked this conversation as resolved.
Show resolved Hide resolved
channels, err := GetChannels(config)
if err != nil || channels.Src == "" {
return fmt.Sprintf("Starting...")
}
return fmt.Sprintf("Active src, %s <-> %s, dst", channels.Src, channels.Dst)
}

func GetChannels(rollappConfig config.RollappConfig) (ConnectionChannels, error) {
dstConnectionId, err := GetDstConnectionIDFromYAMLFile(filepath.Join(rollappConfig.Home, consts.ConfigDirName.Relayer,
"config", "config.yaml"))
if err != nil {
return ConnectionChannels{}, err
}
if dstConnectionId == "" {
return ConnectionChannels{}, nil
}
connectionChannels, err := GetConnectionChannels(dstConnectionId, rollappConfig)
if err != nil {
return ConnectionChannels{}, err
}
return connectionChannels, nil
}

// GetDstConnectionIDFromYAMLFile Returns the destination connection ID if it been created already, an empty string otherwise.
func GetDstConnectionIDFromYAMLFile(filename string) (string, error) {

data, err := ioutil.ReadFile(filename)
if err != nil {
return "", err
}
var config RelayerConfigFile
err = yaml.Unmarshal(data, &config)
if err != nil {
return "", err
}
for _, path := range config.Paths {
return path.Dst.ConnectionID, nil
}
return "", fmt.Errorf("No paths found in YAML data")
}

type RelayerConfigFile struct {
Paths map[string]Path `yaml:"paths"`
}

type Path struct {
Dst Destination `yaml:"dst"`
}

type Destination struct {
ConnectionID string `yaml:"connection-id"`
}
Loading