Skip to content

Commit

Permalink
feat: run relayer using roller (#819)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemijspavlovs authored Jul 29, 2024
1 parent 94c93d8 commit cf84f05
Show file tree
Hide file tree
Showing 27 changed files with 816 additions and 337 deletions.
8 changes: 4 additions & 4 deletions cmd/config/export/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func Cmd() *cobra.Command {
coinType = 60
}
rly := relayer.NewRelayer(rlpCfg.Home, rlpCfg.RollappID, rlpCfg.HubData.ID)
srcChannel, hubChannel, err := rly.LoadActiveChannel()
if err != nil || srcChannel == "" || hubChannel == "" {
_, _, err = rly.LoadActiveChannel()
if err != nil || rly.SrcChannel == "" || rly.DstChannel == "" {
utils.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 All @@ -62,8 +62,8 @@ func Cmd() *cobra.Command {
Website: "",
Logo: logoDefaultPath,
Ibc: IbcConfig{
HubChannel: hubChannel,
Channel: srcChannel,
HubChannel: rly.SrcChannel,
Channel: rly.DstChannel,
Timeout: 172800000,
},
Type: RollApp,
Expand Down
38 changes: 27 additions & 11 deletions cmd/config/init/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,17 @@ func GetGenesisFilePath(root string) string {

// TODO(#130): fix to support epochs
func getDefaultGenesisParams(
sequencerAddr, genesisOperatorAddress string,
sequencerAddr, genesisOperatorAddress string, raCfg *config.RollappConfig,
) []PathValue {
return []PathValue{
// these should be injected from the genesis creator
// {"consensus_params.block.max_gas", "40000000"},
// {"app_state.feemarket.params.no_base_fee", true},
// {"app_state.feemarket.params.min_gas_price", "0.0"},
// {"app_state.distribution.params.base_proposer_reward", "0.8"},
// {"app_state.distribution.params.community_tax", "0.00002"},
// {"app_state.gov.voting_params.voting_period", "300s"},
// {"app_state.staking.params.unbonding_time", "3628800s"},
// {"app_state.bank.denom_metadata", getBankDenomMetadata(denom, decimals)},
{"consensus_params.block.max_gas", "40000000"},
{"app_state.feemarket.params.no_base_fee", true},
{"app_state.feemarket.params.min_gas_price", "0.0"},
{"app_state.distribution.params.base_proposer_reward", "0.8"},
{"app_state.distribution.params.community_tax", "0.00002"},
{"app_state.gov.voting_params.voting_period", "300s"},
{"app_state.bank.denom_metadata", getBankDenomMetadata(raCfg.BaseDenom, raCfg.Decimals)},

{"app_state.sequencers.genesis_operator_address", genesisOperatorAddress},
{
Expand Down Expand Up @@ -73,7 +72,7 @@ func UpdateJSONParams(jsonFilePath string, params []PathValue) error {
return nil
}

func UpdateGenesisParams(home string) error {
func UpdateGenesisParams(home string, raCfg *config.RollappConfig) error {
oa, err := getGenesisOperatorAddress(home)
if err != nil {
return err
Expand All @@ -87,8 +86,9 @@ func UpdateGenesisParams(home string) error {
if err != nil {
return err
}
params := getDefaultGenesisParams(sa, oa)
params := getDefaultGenesisParams(sa, oa, raCfg)

// TODO: move to generalized helper
addGenAccountCmd := exec.Command(
consts.Executables.RollappEVM,
"add-genesis-account",
Expand All @@ -109,6 +109,22 @@ func UpdateGenesisParams(home string) error {
return UpdateJSONParams(genesisFilePath, params)
}

func GetAddGenesisAccountCmd(addr, amount string, raCfg *config.RollappConfig) *exec.Cmd {
home := utils.GetRollerRootDir()
cmd := exec.Command(
consts.Executables.RollappEVM,
"add-genesis-account",
addr,
fmt.Sprintf("%s%s", consts.DefaultTokenSupply, raCfg.BaseDenom),
"--home",
fmt.Sprintf("%s/%s", home, consts.ConfigDirName.Rollapp),
"--keyring-backend",
"test",
)

return cmd
}

func getGenesisOperatorAddress(home string) (string, error) {
rollappConfigDirPath := filepath.Join(home, consts.ConfigDirName.Rollapp)
getOperatorAddrCommand := exec.Command(
Expand Down
249 changes: 155 additions & 94 deletions cmd/config/init/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,17 @@ package initconfig
import (
"fmt"
"os/exec"
"path"
"path/filepath"

"github.com/pterm/pterm"

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

func GenerateKeys(rollappConfig config.RollappConfig) ([]utils.KeyInfo, error) {
// var addresses []utils.KeyInfo

sequencerAddresses, err := generateSequencersKeys(rollappConfig)
if err != nil {
fmt.Println("failed to generate sequencerAddresses")
return nil, err
}

// addresses = append(addresses, sequencerAddresses...)

// relayerAddresses, err := generateRelayerKeys(rollappConfig)
// if err != nil {
// return nil, err
// }
// addresses = append(addresses, relayerAddresses...)

return sequencerAddresses, nil
}

func generateSequencersKeys(initConfig config.RollappConfig) ([]utils.KeyInfo, error) {
func GenerateSequencersKeys(initConfig config.RollappConfig) ([]utils.KeyInfo, error) {
keys := getSequencerKeysConfig(initConfig)
addresses := make([]utils.KeyInfo, 0)
for _, key := range keys {
Expand All @@ -40,11 +23,13 @@ func generateSequencersKeys(initConfig config.RollappConfig) ([]utils.KeyInfo, e
if err != nil {
return nil, err
}
addresses = append(addresses, utils.KeyInfo{
Address: address.Address,
Name: key.ID,
Mnemonic: address.Mnemonic,
})
addresses = append(
addresses, utils.KeyInfo{
Address: address.Address,
Name: key.ID,
Mnemonic: address.Mnemonic,
},
)
}
return addresses, nil
}
Expand All @@ -68,6 +53,13 @@ func getSequencerKeysConfig(rollappConfig config.RollappConfig) []utils.KeyConfi
// Eventhough the hub can get evm signatures, we still use the native
Type: config.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,
},
{
Dir: consts.ConfigDirName.Rollapp,
ID: consts.KeysIds.RollappSequencer,
Expand All @@ -77,22 +69,22 @@ func getSequencerKeysConfig(rollappConfig config.RollappConfig) []utils.KeyConfi
}
}

// func getRelayerKeysConfig(rollappConfig config.RollappConfig) map[string]utils.KeyConfig {
// return map[string]utils.KeyConfig{
// consts.KeysIds.RollappRelayer: {
// Dir: path.Join(rollappConfig.Home, consts.ConfigDirName.Relayer),
// ID: consts.KeysIds.RollappRelayer,
// ChainBinary: rollappConfig.RollappBinary,
// Type: rollappConfig.VMType,
// },
// consts.KeysIds.HubRelayer: {
// Dir: path.Join(rollappConfig.Home, consts.ConfigDirName.Relayer),
// ID: consts.KeysIds.HubRelayer,
// ChainBinary: consts.Executables.Dymension,
// Type: config.SDK_ROLLAPP,
// },
// }
// }
func getRelayerKeysConfig(rollappConfig config.RollappConfig) map[string]utils.KeyConfig {
return map[string]utils.KeyConfig{
consts.KeysIds.RollappRelayer: {
Dir: path.Join(rollappConfig.Home, consts.ConfigDirName.Relayer),
ID: consts.KeysIds.RollappRelayer,
ChainBinary: rollappConfig.RollappBinary,
Type: rollappConfig.VMType,
},
consts.KeysIds.HubRelayer: {
Dir: path.Join(rollappConfig.Home, consts.ConfigDirName.Relayer),
ID: consts.KeysIds.HubRelayer,
ChainBinary: consts.Executables.Dymension,
Type: config.SDK_ROLLAPP,
},
}
}

func CreateAddressBinary(
keyConfig utils.KeyConfig,
Expand All @@ -111,55 +103,124 @@ func CreateAddressBinary(
return utils.ParseAddressFromOutput(out)
}

// func generateRelayerKeys(rollappConfig config.RollappConfig) ([]utils.AddressData, error) {
// relayerAddresses := make([]utils.AddressData, 0)
// keys := getRelayerKeysConfig(rollappConfig)
// createRollappKeyCmd := getAddRlyKeyCmd(
// keys[consts.KeysIds.RollappRelayer],
// rollappConfig.RollappID,
// )
// createHubKeyCmd := getAddRlyKeyCmd(keys[consts.KeysIds.HubRelayer], rollappConfig.HubData.ID)
// out, err := utils.ExecBashCommandWithStdout(createRollappKeyCmd)
// if err != nil {
// return nil, err
// }
// relayerRollappAddress, err := utils.ParseAddressFromOutput(out)
// if err != nil {
// return nil, err
// }
// relayerAddresses = append(relayerAddresses, utils.AddressData{
// Addr: relayerRollappAddress,
// Name: consts.KeysIds.RollappRelayer,
// })
// out, err = utils.ExecBashCommandWithStdout(createHubKeyCmd)
// if err != nil {
// return nil, err
// }
// relayerHubAddress, err := utils.ParseAddressFromOutput(out)
// if err != nil {
// return nil, err
// }
// relayerAddresses = append(relayerAddresses, utils.AddressData{
// Addr: relayerHubAddress,
// Name: consts.KeysIds.HubRelayer,
// })
// return relayerAddresses, err
// }

// func getAddRlyKeyCmd(keyConfig utils.KeyConfig, chainID string) *exec.Cmd {
// coinType := "118"
// if keyConfig.Type == config.EVM_ROLLAPP {
// coinType = "60"
// }
// return exec.Command(
// consts.Executables.Relayer,
// "keys",
// "add",
// chainID,
// keyConfig.ID,
// "--home",
// keyConfig.Dir,
// "--coin-type",
// coinType,
// )
// }
func GetRelayerKeys(rollappConfig config.RollappConfig) ([]utils.KeyInfo, error) {
pterm.Info.Println("getting relayer keys")
relayerAddresses := make([]utils.KeyInfo, 0)
keys := getRelayerKeysConfig(rollappConfig)

showRollappKeyCmd := getShowRlyKeyCmd(
keys[consts.KeysIds.RollappRelayer],
rollappConfig.RollappID,
)
showHubKeyCmd := getShowRlyKeyCmd(
keys[consts.KeysIds.HubRelayer],
rollappConfig.HubData.ID,
)

out, err := utils.ExecBashCommandWithStdout(showRollappKeyCmd)
if err != nil {
pterm.Error.Printf("failed to retrieve rollapp key: %v\n", err)
}
relayerRollappAddress, err := utils.ParseAddressFromOutput(out)
if err != nil {
pterm.Error.Printf("failed to extract rollapp key: %v\n", err)
}
fmt.Println(relayerRollappAddress)

out, err = utils.ExecBashCommandWithStdout(showHubKeyCmd)
if err != nil {
pterm.Error.Printf("failed to retrieve hub key: %v\n", err)
}
relayerHubAddress, err := utils.ParseAddressFromOutput(out)
if err != nil {
pterm.Error.Printf("failed to extract hub key: %v\n", err)
}
fmt.Println(relayerHubAddress)

relayerAddresses = append(
relayerAddresses, *relayerRollappAddress,
)
relayerAddresses = append(
relayerAddresses, *relayerHubAddress,
)

return relayerAddresses, nil
}

func GenerateRelayerKeys(rollappConfig config.RollappConfig) ([]utils.KeyInfo, error) {
pterm.Info.Println("creating relayer keys")
relayerAddresses := make([]utils.KeyInfo, 0)
keys := getRelayerKeysConfig(rollappConfig)

createRollappKeyCmd := getAddRlyKeyCmd(
keys[consts.KeysIds.RollappRelayer],
rollappConfig.RollappID,
)
createHubKeyCmd := getAddRlyKeyCmd(keys[consts.KeysIds.HubRelayer], rollappConfig.HubData.ID)

pterm.Info.Println("creating relayer rollapp key")
out, err := utils.ExecBashCommandWithStdout(createRollappKeyCmd)
if err != nil {
return nil, err
}
relayerRollappAddress, err := utils.ParseAddressFromOutput(out)
relayerRollappAddress.Name = consts.KeysIds.RollappRelayer
if err != nil {
return nil, err
}
relayerAddresses = append(
relayerAddresses, *relayerRollappAddress,
)

pterm.Info.Println("creating relayer hub key")
out, err = utils.ExecBashCommandWithStdout(createHubKeyCmd)
if err != nil {
return nil, err
}
relayerHubAddress, err := utils.ParseAddressFromOutput(out)
relayerHubAddress.Name = consts.KeysIds.HubRelayer
if err != nil {
return nil, err
}
relayerAddresses = append(
relayerAddresses, *relayerHubAddress,
)

return relayerAddresses, nil
}

func getAddRlyKeyCmd(keyConfig utils.KeyConfig, chainID string) *exec.Cmd {
coinType := "118"
if keyConfig.Type == config.EVM_ROLLAPP {
coinType = "60"
}
return exec.Command(
consts.Executables.Relayer,
"keys",
"add",
chainID,
keyConfig.ID,
"--home",
keyConfig.Dir,
"--coin-type",
coinType,
)
}

func getShowRlyKeyCmd(keyConfig utils.KeyConfig, chainID string) *exec.Cmd {
coinType := "118"
if keyConfig.Type == config.EVM_ROLLAPP {
coinType = "60"
}
return exec.Command(
consts.Executables.Relayer,
"keys",
"show",
chainID,
keyConfig.ID,
"--home",
keyConfig.Dir,
"--coin-type",
coinType,
)
}
9 changes: 6 additions & 3 deletions cmd/config/init/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ func (o *OutputHandler) PromptOverwriteConfig(home string) (bool, error) {
if o.NoOutput {
return true, nil
}
return utils.PromptBool(
fmt.Sprintf("Directory %s is not empty. Do you want to overwrite", home),
)

shouldOverwrite, _ := pterm.DefaultInteractiveConfirm.WithDefaultText(
fmt.Sprintf("Directory %s is not empty. Do you want to overwrite it?", home),
).WithDefaultValue(false).Show()

return shouldOverwrite, nil
}
Loading

0 comments on commit cf84f05

Please sign in to comment.