Skip to content

Commit

Permalink
feat: full node flow (#827)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemijspavlovs authored Aug 11, 2024
1 parent 6e3ea30 commit 95a9bff
Show file tree
Hide file tree
Showing 87 changed files with 1,310 additions and 813 deletions.
2 changes: 1 addition & 1 deletion cmd/config/export/bech32.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

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

func getBech32Prefix(rlpCfg config.RollappConfig) (string, error) {
Expand Down
22 changes: 12 additions & 10 deletions cmd/config/export/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import (

"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/cmd/utils"
"github.com/dymensionxyz/roller/config"
"github.com/dymensionxyz/roller/relayer"
"github.com/dymensionxyz/roller/utils/config"
"github.com/dymensionxyz/roller/utils/config/tomlconfig"
"github.com/dymensionxyz/roller/utils/errorhandling"
)

func Cmd() *cobra.Command {
Expand All @@ -20,10 +22,10 @@ func Cmd() *cobra.Command {
Short: "Export the rollapp configurations jsons needed to list your rollapp.",
Run: func(cmd *cobra.Command, args []string) {
home := cmd.Flag(utils.FlagNames.Home).Value.String()
rlpCfg, err := config.LoadRollerConfigFromTOML(home)
utils.PrettifyErrorIfExists(err)
rlpCfg, err := tomlconfig.LoadRollerConfig(home)
errorhandling.PrettifyErrorIfExists(err)
bech32, err := getBech32Prefix(rlpCfg)
utils.PrettifyErrorIfExists(err)
errorhandling.PrettifyErrorIfExists(err)
faucetUrls := map[string]string{
consts.LocalHubID: "",
consts.TestnetHubID: "https://discord.com/channels/956961633165529098/1196803789911498763",
Expand All @@ -32,13 +34,13 @@ func Cmd() *cobra.Command {
baseDenom := rlpCfg.Denom

coinType := 118
if rlpCfg.VMType == config.EVM_ROLLAPP {
if rlpCfg.VMType == consts.EVM_ROLLAPP {
coinType = 60
}
rly := relayer.NewRelayer(rlpCfg.Home, rlpCfg.RollappID, rlpCfg.HubData.ID)
_, _, err = rly.LoadActiveChannel()
if err != nil || rly.SrcChannel == "" || rly.DstChannel == "" {
utils.PrettifyErrorIfExists(
errorhandling.PrettifyErrorIfExists(
errors.New(
"failed to export rollapp json." +
" Please verify that the rollapp is running on your local machine and a relayer channel has been established",
Expand Down Expand Up @@ -73,23 +75,23 @@ func Cmd() *cobra.Command {
Type: RollApp,
Analytics: true,
}
if rlpCfg.VMType == config.EVM_ROLLAPP {
if rlpCfg.VMType == consts.EVM_ROLLAPP {
evmID := config.GetEthID(rlpCfg.RollappID)
hexEvmID, err := decimalToHexStr(evmID)
utils.PrettifyErrorIfExists(err)
errorhandling.PrettifyErrorIfExists(err)
networkJson.Evm = &EvmConfig{
ChainId: hexEvmID,
Rpc: "",
}
}
if rlpCfg.DA == config.Avail {
if rlpCfg.DA == consts.Avail {
networkJson.Da = Avail
} else {
networkJson.Da = Celestia
}

networkJsonString, err := json.MarshalIndent(networkJson, "", " ")
utils.PrettifyErrorIfExists(err)
errorhandling.PrettifyErrorIfExists(err)
println("💈 networks.json:")
println(string(networkJsonString))
},
Expand Down
6 changes: 4 additions & 2 deletions cmd/config/init/consts.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package initconfig

import "github.com/dymensionxyz/roller/config"
import (
"github.com/dymensionxyz/roller/cmd/consts"
)

var FlagNames = struct {
TokenSupply string
Expand Down Expand Up @@ -30,7 +32,7 @@ const (
)

// TODO(#112): The available hub networks should be read from YAML file
var Hubs = map[string]config.HubData{
var Hubs = map[string]consts.HubData{
StagingHubName: {
API_URL: "https://dymension-devnet.api.silknodes.io:443",
ID: "devnet_304-1",
Expand Down
14 changes: 7 additions & 7 deletions cmd/config/init/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"strings"

"github.com/BurntSushi/toml"
cmdutils "github.com/dymensionxyz/roller/cmd/utils"
"github.com/dymensionxyz/roller/utils/config"
"github.com/spf13/cobra"

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

Expand All @@ -31,7 +31,7 @@ func AddFlags(cmd *cobra.Command) error {
"The rollapp binary. Should be passed only if you built a custom rollapp",
)
cmd.Flags().
StringP(FlagNames.VMType, "", string(config.EVM_ROLLAPP), "The rollapp type [evm, sdk]. Defaults to evm")
StringP(FlagNames.VMType, "", string(consts.EVM_ROLLAPP), "The rollapp type [evm, sdk]. Defaults to evm")
cmd.Flags().
StringP(FlagNames.TokenSupply, "", consts.DefaultTokenSupply, "The total token supply of the RollApp")
// cmd.Flags().BoolP(FlagNames.Interactive, "i", false, "Run roller in interactive mode")
Expand Down Expand Up @@ -64,12 +64,12 @@ func GetInitConfig(
) (*config.RollappConfig, error) {
var cfg config.RollappConfig

home, err := globalutils.ExpandHomePath(initCmd.Flag(utils.FlagNames.Home).Value.String())
home, err := globalutils.ExpandHomePath(initCmd.Flag(cmdutils.FlagNames.Home).Value.String())
if err != nil {
fmt.Println("failed to expand home path: ", err)
}

rollerConfigFilePath := filepath.Join(home, config.RollerConfigFileName)
rollerConfigFilePath := filepath.Join(home, consts.RollerConfigFileName)
if _, err := toml.DecodeFile(rollerConfigFilePath, &cfg); err != nil {
return nil, err
}
Expand All @@ -82,7 +82,7 @@ func GetInitConfig(

// token supply is provided in the pre-created genesis
// cfg.TokenSupply = initCmd.Flag(FlagNames.TokenSupply).Value.String()
cfg.DA = config.DAType(strings.ToLower(string(cfg.DA)))
cfg.DA = consts.DAType(strings.ToLower(string(cfg.DA)))

var hubID string

Expand All @@ -105,7 +105,7 @@ func GetInitConfig(
// cfg.RollappID = raID
// cfg.Denom = raBaseDenom

if cfg.VMType == config.EVM_ROLLAPP {
if cfg.VMType == consts.EVM_ROLLAPP {
cfg.Decimals = 18
} else {
cfg.Decimals = 6
Expand Down
2 changes: 1 addition & 1 deletion cmd/config/init/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"fmt"
"strings"

"github.com/dymensionxyz/roller/utils/config"
"github.com/pterm/pterm"

"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/cmd/utils"
"github.com/dymensionxyz/roller/config"
datalayer "github.com/dymensionxyz/roller/data_layer"
)

Expand Down
19 changes: 10 additions & 9 deletions cmd/config/init/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"

"github.com/tidwall/sjson"

"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/cmd/utils"
"github.com/dymensionxyz/roller/config"
"github.com/dymensionxyz/roller/utils/bash"
"github.com/dymensionxyz/roller/utils/config"
"github.com/dymensionxyz/roller/utils/config/tomlconfig"
)

// const (
Expand Down Expand Up @@ -79,7 +80,7 @@ func UpdateGenesisParams(home string, raCfg *config.RollappConfig) error {
if err != nil {
return err
}
cfg, err := config.LoadRollerConfigFromTOML(home)
cfg, err := tomlconfig.LoadRollerConfig(home)
if err != nil {
return err
}
Expand All @@ -102,7 +103,7 @@ func UpdateGenesisParams(home string, raCfg *config.RollappConfig) error {
"test",
)

_, err = utils.ExecBashCommandWithStdout(addGenAccountCmd)
_, err = bash.ExecCommandWithStdout(addGenAccountCmd)
if err != nil {
return err
}
Expand Down Expand Up @@ -143,13 +144,13 @@ func getGenesisOperatorAddress(home string) (string, error) {
"val",
)

addr, err := utils.ExecBashCommandWithStdout(getOperatorAddrCommand)
addr, err := bash.ExecCommandWithStdout(getOperatorAddrCommand)
if err != nil {
fmt.Println("val addr failed")
return "", err
}

a := strings.TrimSpace(addr.String())
a := addr.String()
return a, nil
}

Expand All @@ -159,7 +160,7 @@ func GetRollappSequencerAddress(home string) (string, error) {
Dir: rollappConfigDirPath,
ID: consts.KeysIds.RollappSequencer,
ChainBinary: consts.Executables.RollappEVM,
Type: config.EVM_ROLLAPP,
Type: consts.EVM_ROLLAPP,
}
addr, err := utils.GetAddressBinary(seqKeyConfig, consts.Executables.RollappEVM)
if err != nil {
Expand All @@ -182,7 +183,7 @@ func GetRollappSequencerAddress(home string) (string, error) {
// "--home",
// rollappConfigDirPath,
// )
// _, err = utils.ExecBashCommandWithStdout(collectGentx)
// _, err = utils.ExecCommandWithStdout(collectGentx)
// if err != nil {
// return err
// }
Expand Down Expand Up @@ -220,7 +221,7 @@ func GetRollappSequencerAddress(home string) (string, error) {
// "--home",
// rollappConfigDirPath,
// )
// _, err = utils.ExecBashCommandWithStdout(gentxCmd)
// _, err = utils.ExecCommandWithStdout(gentxCmd)
// if err != nil {
// return err
// }
Expand Down
23 changes: 12 additions & 11 deletions cmd/config/init/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import (

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

func GenerateSequencersKeys(initConfig config.RollappConfig) ([]utils.KeyInfo, error) {
Expand Down Expand Up @@ -51,14 +52,14 @@ func getSequencerKeysConfig(rollappConfig config.RollappConfig) []utils.KeyConfi
ID: consts.KeysIds.HubSequencer,
ChainBinary: consts.Executables.Dymension,
// Eventhough the hub can get evm signatures, we still use the native
Type: config.SDK_ROLLAPP,
Type: consts.SDK_ROLLAPP,
},
{
Dir: consts.ConfigDirName.HubKeys,
ID: consts.KeysIds.HubGenesis,
ChainBinary: consts.Executables.Dymension,
// Eventhough the hub can get evm signatures, we still use the native
Type: config.SDK_ROLLAPP,
Type: consts.SDK_ROLLAPP,
},
{
Dir: consts.ConfigDirName.Rollapp,
Expand All @@ -81,7 +82,7 @@ func getRelayerKeysConfig(rollappConfig config.RollappConfig) map[string]utils.K
Dir: path.Join(rollappConfig.Home, consts.ConfigDirName.Relayer),
ID: consts.KeysIds.HubRelayer,
ChainBinary: consts.Executables.Dymension,
Type: config.SDK_ROLLAPP,
Type: consts.SDK_ROLLAPP,
},
}
}
Expand All @@ -96,7 +97,7 @@ func CreateAddressBinary(
"--output", "json",
}
createKeyCommand := exec.Command(keyConfig.ChainBinary, args...)
out, err := utils.ExecBashCommandWithStdout(createKeyCommand)
out, err := bash.ExecCommandWithStdout(createKeyCommand)
if err != nil {
return nil, err
}
Expand All @@ -117,7 +118,7 @@ func GetRelayerKeys(rollappConfig config.RollappConfig) ([]utils.KeyInfo, error)
rollappConfig.HubData.ID,
)

out, err := utils.ExecBashCommandWithStdout(showRollappKeyCmd)
out, err := bash.ExecCommandWithStdout(showRollappKeyCmd)
if err != nil {
pterm.Error.Printf("failed to retrieve rollapp key: %v\n", err)
}
Expand All @@ -127,7 +128,7 @@ func GetRelayerKeys(rollappConfig config.RollappConfig) ([]utils.KeyInfo, error)
}
fmt.Println(relayerRollappAddress)

out, err = utils.ExecBashCommandWithStdout(showHubKeyCmd)
out, err = bash.ExecCommandWithStdout(showHubKeyCmd)
if err != nil {
pterm.Error.Printf("failed to retrieve hub key: %v\n", err)
}
Expand Down Expand Up @@ -159,7 +160,7 @@ func GenerateRelayerKeys(rollappConfig config.RollappConfig) ([]utils.KeyInfo, e
createHubKeyCmd := getAddRlyKeyCmd(keys[consts.KeysIds.HubRelayer], rollappConfig.HubData.ID)

pterm.Info.Println("creating relayer rollapp key")
out, err := utils.ExecBashCommandWithStdout(createRollappKeyCmd)
out, err := bash.ExecCommandWithStdout(createRollappKeyCmd)
if err != nil {
return nil, err
}
Expand All @@ -173,7 +174,7 @@ func GenerateRelayerKeys(rollappConfig config.RollappConfig) ([]utils.KeyInfo, e
)

pterm.Info.Println("creating relayer hub key")
out, err = utils.ExecBashCommandWithStdout(createHubKeyCmd)
out, err = bash.ExecCommandWithStdout(createHubKeyCmd)
if err != nil {
return nil, err
}
Expand All @@ -191,7 +192,7 @@ func GenerateRelayerKeys(rollappConfig config.RollappConfig) ([]utils.KeyInfo, e

func getAddRlyKeyCmd(keyConfig utils.KeyConfig, chainID string) *exec.Cmd {
coinType := "118"
if keyConfig.Type == config.EVM_ROLLAPP {
if keyConfig.Type == consts.EVM_ROLLAPP {
coinType = "60"
}
return exec.Command(
Expand All @@ -209,7 +210,7 @@ func getAddRlyKeyCmd(keyConfig utils.KeyConfig, chainID string) *exec.Cmd {

func getShowRlyKeyCmd(keyConfig utils.KeyConfig, chainID string) *exec.Cmd {
coinType := "118"
if keyConfig.Type == config.EVM_ROLLAPP {
if keyConfig.Type == consts.EVM_ROLLAPP {
coinType = "60"
}
return exec.Command(
Expand Down
2 changes: 1 addition & 1 deletion cmd/config/init/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

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

type OutputHandler struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/config/init/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"os/exec"
"path/filepath"

"github.com/dymensionxyz/roller/utils/config"
"github.com/pterm/pterm"

"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/config"
"github.com/dymensionxyz/roller/relayer"
)

Expand Down
6 changes: 3 additions & 3 deletions cmd/config/init/rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"path/filepath"

"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/cmd/utils"
"github.com/dymensionxyz/roller/config"
"github.com/dymensionxyz/roller/sequencer"
"github.com/dymensionxyz/roller/utils/bash"
"github.com/dymensionxyz/roller/utils/config"
)

func InitializeRollappConfig(initConfig config.RollappConfig) error {
Expand All @@ -23,7 +23,7 @@ func InitializeRollappConfig(initConfig config.RollappConfig) error {
home,
)

_, err := utils.ExecBashCommandWithStdout(initRollappCmd)
_, err := bash.ExecCommandWithStdout(initRollappCmd)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 95a9bff

Please sign in to comment.