Skip to content

Commit

Permalink
fix: eibc client should not rely on roller config (#1024)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemijspavlovs authored Sep 22, 2024
1 parent 61a002f commit 94dd1d0
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 13 deletions.
18 changes: 15 additions & 3 deletions cmd/eibc/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,22 @@ func Cmd() *cobra.Command {
return
}

var hd consts.HubData
rollerConfig, err := tomlconfig.LoadRollerConfig(rollerHome)
if err != nil {
pterm.Error.Println("failed to load roller config", err)
return
pterm.Warning.Println("no roller config found")
pterm.Info.Println("initializing for environment")

envs := []string{"playground"}
env, _ := pterm.DefaultInteractiveSelect.
WithDefaultText(
"select the environment you want to initialize eibc client for",
).
WithOptions(envs).
Show()
hd = consts.Hubs[env]
} else {
hd = rollerConfig.HubData
}

eibcHome := filepath.Join(home, consts.ConfigDirName.Eibc)
Expand Down Expand Up @@ -97,7 +109,7 @@ func Cmd() *cobra.Command {

eibcConfigPath := filepath.Join(eibcHome, "config.yaml")
updates := map[string]interface{}{
"node_address": rollerConfig.HubData.RPC_URL,
"node_address": hd.RPC_URL,
"whale.account_name": consts.KeysIds.Eibc,
"order_polling.interval": "25s",
"order_polling.indexer_url": "http://44.206.211.230:3000/",
Expand Down
10 changes: 5 additions & 5 deletions utils/config/tomlconfig/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ func Write(rlpCfg config.RollappConfig) error {

// TODO: should be called from root command
func LoadRollerConfig(root string) (config.RollappConfig, error) {
var config config.RollappConfig
var rc config.RollappConfig
tomlBytes, err := os.ReadFile(filepath.Join(root, consts.RollerConfigFileName))
if err != nil {
return config, err
return rc, err
}
err = naoinatoml.Unmarshal(tomlBytes, &config)
err = naoinatoml.Unmarshal(tomlBytes, &rc)
if err != nil {
return config, err
return rc, err
}

return config, nil
return rc, nil
}

func LoadHubData(root string) (consts.HubData, error) {
Expand Down
40 changes: 36 additions & 4 deletions utils/rollapp/rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import (
"strings"

dymensiontypes "github.com/dymensionxyz/dymension/v3/x/rollapp/types"

"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/cmd/utils"
globalutils "github.com/dymensionxyz/roller/utils/bash"
bashutils "github.com/dymensionxyz/roller/utils/bash"
)

func GetCurrentHeight() (*BlockInformation, error) {
cmd := getCurrentBlockCmd()
out, err := globalutils.ExecCommandWithStdout(cmd)
out, err := bashutils.ExecCommandWithStdout(cmd)
if err != nil {
return nil, err
}
Expand All @@ -41,7 +42,7 @@ func getCurrentBlockCmd() *exec.Cmd {

func GetInitialSequencerAddress(raID string, hd consts.HubData) (string, error) {
cmd := GetShowRollappCmd(raID, hd)
out, err := globalutils.ExecCommandWithStdout(cmd)
out, err := bashutils.ExecCommandWithStdout(cmd)
if err != nil {
fmt.Println(err)
}
Expand Down Expand Up @@ -70,7 +71,7 @@ func IsInitialSequencer(addr, raID string, hd consts.HubData) (bool, error) {
// TODO: most of rollapp utility functions should be tied to an entity
func IsRollappRegistered(raID string, hd consts.HubData) (bool, error) {
cmd := GetShowRollappCmd(raID, hd)
_, err := globalutils.ExecCommandWithStdout(cmd)
_, err := bashutils.ExecCommandWithStdout(cmd)
if err != nil {
if strings.Contains(err.Error(), "NotFound") {
return false, errors.New("rollapp not found ")
Expand Down Expand Up @@ -106,6 +107,37 @@ func GetRollappCmd(raID string, hd consts.HubData) *exec.Cmd {
return cmd
}

type GetProposerResponse struct {
ProposerAddr string `json:"proposerAddr"`
}

func GetCurrentProposerCmd(raID string, hd consts.HubData) *exec.Cmd {
cmd := exec.Command(
consts.Executables.Dymension,
"q", "sequencer", "proposer",
raID, "-o", "json", "--node", hd.RPC_URL, "--chain-id", hd.ID,
)

return cmd
}

func GetCurrentProposer(raID string, hd consts.HubData) (string, error) {
cmd := GetCurrentProposerCmd(raID, hd)

out, err := bashutils.ExecCommandWithStdout(cmd)
if err != nil {
return "", err
}
var resp GetProposerResponse

err = json.Unmarshal(out.Bytes(), &resp)
if err != nil {
return "", err
}

return resp.ProposerAddr, nil
}

func RollappConfigDir(root string) string {
return filepath.Join(root, consts.ConfigDirName.Rollapp, "config")
}
Expand Down
22 changes: 21 additions & 1 deletion utils/sequencer/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import (
cosmossdkmath "cosmossdk.io/math"
cosmossdktypes "github.com/cosmos/cosmos-sdk/types"
dymensionseqtypes "github.com/dymensionxyz/dymension/v3/x/sequencer/types"
"github.com/pterm/pterm"

"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/cmd/utils"
"github.com/dymensionxyz/roller/utils/bash"
"github.com/dymensionxyz/roller/utils/config"
"github.com/dymensionxyz/roller/utils/rollapp"
"github.com/dymensionxyz/roller/utils/tx"
"github.com/pterm/pterm"
)

func Register(raCfg config.RollappConfig, desiredBond cosmossdktypes.Coin) error {
Expand Down Expand Up @@ -125,6 +127,24 @@ func GetSequencerAccountAddress(cfg config.RollappConfig) (string, error) {
return seqAddr, nil
}

func GetRpcEndpointFromChain(rollappConfig config.RollappConfig) (string, error) {
seqAddr, err := rollapp.GetCurrentProposer(rollappConfig.RollappID, rollappConfig.HubData)
if err != nil {
return "", err
}

if seqAddr == "" {
return "", fmt.Errorf("no proposer found for rollapp %s", rollappConfig.RollappID)
}

metadata, err := GetMetadata(seqAddr, rollappConfig.HubData)
if err != nil {
return "", err
}

return metadata.Rpcs[0], err
}

func GetMinSequencerBondInBaseDenom(hd consts.HubData) (*cosmossdktypes.Coin, error) {
var qpr dymensionseqtypes.QueryParamsResponse
cmd := exec.Command(
Expand Down

0 comments on commit 94dd1d0

Please sign in to comment.