Skip to content

Commit

Permalink
Merge branch 'main' into itaylevyofficial/70-run-da-light-node
Browse files Browse the repository at this point in the history
  • Loading branch information
ItayLevyOfficial committed Jun 13, 2023
2 parents 53602cb + b0c360d commit 1999f00
Show file tree
Hide file tree
Showing 16 changed files with 142 additions and 145 deletions.
3 changes: 1 addition & 2 deletions cmd/config/init/DALightClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import (
)

func initializeLightNodeConfig(initConfig InitConfig) error {
initLightNodeCmd := exec.Command(consts.Executables.Celestia, "light", "init", "--p2p.network", "arabica", "--node.store",
filepath.Join(initConfig.Home, ConfigDirName.DALightNode))
initLightNodeCmd := exec.Command(consts.Executables.Celestia, "light", "init", "--p2p.network", "arabica", "--node.store", filepath.Join(initConfig.Home, consts.ConfigDirName.DALightNode))
err := initLightNodeCmd.Run()
if err != nil {
return err
Expand Down
42 changes: 0 additions & 42 deletions cmd/config/init/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,6 @@ var FlagNames = struct {
HubID: "hub",
}

var KeyNames = struct {
HubSequencer string
RollappSequencer string
RollappRelayer string
DALightNode string
HubRelayer string
}{
HubSequencer: "hub_sequencer",
RollappSequencer: "rollapp_sequencer",
RollappRelayer: "relayer-rollapp-key",
DALightNode: "my_celes_key",
HubRelayer: "relayer-hub-key",
}

var AddressPrefixes = struct {
Hub string
Rollapp string
DA string
}{
Rollapp: "rol",
Hub: "dym",
DA: "celestia",
}

var ConfigDirName = struct {
Rollapp string
Relayer string
DALightNode string
}{
Rollapp: "rollapp",
Relayer: "relayer",
DALightNode: "da-light-node",
}

const TestnetHubID = "35-C"
const StagingHubID = "internal-devnet"
const LocalHubID = "local"
Expand Down Expand Up @@ -78,13 +44,5 @@ type HubData = struct {

const defaultRollappRPC = "http://localhost:26657"

var CoinTypes = struct {
Cosmos uint32
EVM uint32
}{
Cosmos: 118,
EVM: 60,
}

const KeysDirName = "keys"
const RollerConfigFileName = "config.toml"
5 changes: 3 additions & 2 deletions cmd/config/init/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import (
"path/filepath"

"github.com/tidwall/sjson"
"github.com/dymensionxyz/roller/cmd/consts"
)

func initializeRollappGenesis(initConfig InitConfig) error {
zeros := initConfig.Decimals + 9
tokenAmount := "1" + fmt.Sprintf("%0*d", zeros, 0) + initConfig.Denom
rollappConfigDirPath := filepath.Join(initConfig.Home, ConfigDirName.Rollapp)
genesisSequencerAccountCmd := exec.Command(initConfig.RollappBinary, "add-genesis-account", KeyNames.RollappSequencer, tokenAmount, "--keyring-backend", "test", "--home", rollappConfigDirPath)
rollappConfigDirPath := filepath.Join(initConfig.Home, consts.ConfigDirName.Rollapp)
genesisSequencerAccountCmd := exec.Command(initConfig.RollappBinary, "add-genesis-account", consts.KeyNames.RollappSequencer, tokenAmount, "--keyring-backend", "test", "--home", rollappConfigDirPath)
err := genesisSequencerAccountCmd.Run()
if err != nil {
return err
Expand Down
9 changes: 5 additions & 4 deletions cmd/config/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"path/filepath"

"github.com/dymensionxyz/roller/cmd/utils"
"github.com/dymensionxyz/roller/cmd/consts"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -45,17 +46,17 @@ func InitCmd() *cobra.Command {
ID: initConfig.RollappID,
RPC: defaultRollappRPC,
Denom: initConfig.Denom,
AddressPrefix: AddressPrefixes.Rollapp,
AddressPrefix: consts.AddressPrefixes.Rollapp,
}, ChainConfig{
ID: initConfig.HubData.ID,
RPC: initConfig.HubData.RPC_URL,
Denom: "udym",
AddressPrefix: AddressPrefixes.Hub,
AddressPrefix: consts.AddressPrefixes.Hub,
}, initConfig))
utils.PrettifyErrorIfExists(WriteConfigToTOML(initConfig))
daLightNodeAddress, err := utils.GetCelestiaAddress(filepath.Join(initConfig.Home, ConfigDirName.DALightNode, KeysDirName))
daLightNodeAddress, err := utils.GetCelestiaAddress(filepath.Join(initConfig.Home, consts.ConfigDirName.DALightNode, KeysDirName))
utils.PrettifyErrorIfExists(err)
addresses[KeyNames.DALightNode] = daLightNodeAddress
addresses[consts.KeyNames.DALightNode] = daLightNodeAddress
printInitOutput(addresses, initConfig.RollappID)
},
Args: cobra.ExactArgs(2),
Expand Down
83 changes: 22 additions & 61 deletions cmd/config/init/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,10 @@ import (

"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/bech32"
"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/cmd/utils"
)

func keyInfoToBech32Address(info keyring.Info, prefix string) (string, error) {
pk := info.GetPubKey()
addr := types.AccAddress(pk.Address())
bech32Address, err := bech32.ConvertAndEncode(prefix, addr.Bytes())
if err != nil {
return "", err
}
return bech32Address, nil
}

func generateKeys(initConfig InitConfig, excludeKeys ...string) (map[string]string, error) {
keys := getDefaultKeysConfig(initConfig)
excludeKeysMap := make(map[string]struct{})
Expand All @@ -33,7 +23,7 @@ func generateKeys(initConfig InitConfig, excludeKeys ...string) (map[string]stri
if err != nil {
return nil, err
}
formattedAddress, err := keyInfoToBech32Address(keyInfo, key.Prefix)
formattedAddress, err := utils.KeyInfoToBech32Address(keyInfo, key.Prefix)
if err != nil {
return nil, err
}
Expand All @@ -43,14 +33,7 @@ func generateKeys(initConfig InitConfig, excludeKeys ...string) (map[string]stri
return addresses, nil
}

type KeyConfig struct {
Dir string
ID string
CoinType uint32
Prefix string
}

func createKey(keyConfig KeyConfig, home string) (keyring.Info, error) {
func createKey(keyConfig utils.KeyConfig, home string) (keyring.Info, error) {
kr, err := keyring.New(
"",
keyring.BackendTest,
Expand All @@ -68,53 +51,31 @@ func createKey(keyConfig KeyConfig, home string) (keyring.Info, error) {
return info, nil
}

func getDefaultKeysConfig(initConfig InitConfig) []KeyConfig {
return []KeyConfig{
func getDefaultKeysConfig(initConfig InitConfig) []utils.KeyConfig {
return []utils.KeyConfig{
{
Dir: ConfigDirName.Rollapp,
ID: KeyNames.HubSequencer,
CoinType: CoinTypes.Cosmos,
Prefix: AddressPrefixes.Hub,
Dir: consts.ConfigDirName.Rollapp,
ID: consts.KeyNames.HubSequencer,
CoinType: consts.CoinTypes.Cosmos,
Prefix: consts.AddressPrefixes.Hub,
},
{
Dir: ConfigDirName.Rollapp,
ID: KeyNames.RollappSequencer,
CoinType: CoinTypes.EVM,
Prefix: AddressPrefixes.Rollapp,
Dir: consts.ConfigDirName.Rollapp,
ID: consts.KeyNames.RollappSequencer,
CoinType: consts.CoinTypes.EVM,
Prefix: consts.AddressPrefixes.Rollapp,
},
{
Dir: path.Join(ConfigDirName.Relayer, KeysDirName, initConfig.HubData.ID),
ID: KeyNames.HubRelayer,
CoinType: CoinTypes.Cosmos,
Prefix: AddressPrefixes.Hub,
Dir: path.Join(consts.ConfigDirName.Relayer, KeysDirName, initConfig.HubData.ID),
ID: consts.KeyNames.HubRelayer,
CoinType: consts.CoinTypes.Cosmos,
Prefix: consts.AddressPrefixes.Hub,
},
{
Dir: path.Join(ConfigDirName.Relayer, KeysDirName, initConfig.RollappID),
ID: KeyNames.RollappRelayer,
CoinType: CoinTypes.EVM,
Prefix: AddressPrefixes.Rollapp,
Dir: path.Join(consts.ConfigDirName.Relayer, KeysDirName, initConfig.RollappID),
ID: consts.KeyNames.RollappRelayer,
CoinType: consts.CoinTypes.EVM,
Prefix: consts.AddressPrefixes.Rollapp,
},
}
}

func GetAddress(keyConfig KeyConfig) (string, error) {
kr, err := keyring.New(
"",
keyring.BackendTest,
keyConfig.Dir,
nil,
)
if err != nil {
return "", err
}
keyInfo, err := kr.Key(keyConfig.ID)
if err != nil {
return "", err
}
formattedAddress, err := keyInfoToBech32Address(keyInfo, keyConfig.Prefix)
if err != nil {
return "", err
}

return formattedAddress, nil
}
7 changes: 4 additions & 3 deletions cmd/config/init/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"

"github.com/olekukonko/tablewriter"
"github.com/dymensionxyz/roller/cmd/consts"
)

func printInitOutput(addresses map[string]string, rollappId string) {
Expand All @@ -13,9 +14,9 @@ func printInitOutput(addresses map[string]string, rollappId string) {
fmt.Printf("🔑 Addresses:\n\n")

data := [][]string{
{"Celestia", addresses[KeyNames.DALightNode]},
{"Sequencer", addresses[KeyNames.HubSequencer]},
{"Relayer", addresses[KeyNames.HubRelayer]},
{"Celestia", addresses[consts.KeyNames.DALightNode]},
{"Sequencer", addresses[consts.KeyNames.HubSequencer]},
{"Relayer", addresses[consts.KeyNames.HubRelayer]},
}

table := tablewriter.NewWriter(os.Stdout)
Expand Down
6 changes: 3 additions & 3 deletions cmd/config/init/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ func addChainsConfig(rollappConfig ChainConfig, hubConfig ChainConfig, relayerHo
ChainConfig: rollappConfig,
GasPrices: "0.0" + rollappConfig.Denom,
ClientType: "01-dymint",
KeyName: KeyNames.RollappRelayer,
KeyName: consts.KeyNames.RollappRelayer,
})

relayerHubConfig := getRelayerFileChainConfig(RelayerChainConfig{
ChainConfig: hubConfig,
GasPrices: "0.25" + hubConfig.Denom,
ClientType: "07-tendermint",
KeyName: KeyNames.HubRelayer,
KeyName: consts.KeyNames.HubRelayer,
})

if err := addChainToRelayer(relayerRollappConfig, relayerHome); err != nil {
Expand All @@ -130,7 +130,7 @@ func setupPath(rollappConfig ChainConfig, hubConfig ChainConfig, relayerHome str
}

func initializeRelayerConfig(rollappConfig ChainConfig, hubConfig ChainConfig, initConfig InitConfig) error {
relayerHome := filepath.Join(initConfig.Home, ConfigDirName.Relayer)
relayerHome := filepath.Join(initConfig.Home, consts.ConfigDirName.Relayer)
if err := initRelayer(relayerHome); err != nil {
return err
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/config/init/rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import (
"path/filepath"

toml "github.com/pelletier/go-toml"
"github.com/dymensionxyz/roller/cmd/consts"
)

func initializeRollappConfig(initConfig InitConfig) {
initRollappCmd := exec.Command(initConfig.RollappBinary, "init", KeyNames.HubSequencer, "--chain-id", initConfig.RollappID, "--home", filepath.Join(initConfig.Home, ConfigDirName.Rollapp))
initRollappCmd := exec.Command(initConfig.RollappBinary, "init", consts.KeyNames.HubSequencer, "--chain-id", initConfig.RollappID, "--home", filepath.Join(initConfig.Home, consts.ConfigDirName.Rollapp))
err := initRollappCmd.Run()
if err != nil {
panic(err)
}
setRollappAppConfig(filepath.Join(initConfig.Home, ConfigDirName.Rollapp, "config/app.toml"), initConfig.Denom)
setRollappAppConfig(filepath.Join(initConfig.Home, consts.ConfigDirName.Rollapp, "config/app.toml"), initConfig.Denom)
}

func setRollappAppConfig(appConfigFilePath string, denom string) {
Expand All @@ -30,5 +31,5 @@ func setRollappAppConfig(appConfigFilePath string, denom string) {
}

func RollappConfigDir(root string) string {
return filepath.Join(root, ConfigDirName.Rollapp, "config")
return filepath.Join(root, consts.ConfigDirName.Rollapp, "config")
}
28 changes: 28 additions & 0 deletions cmd/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,31 @@ var KeyNames = struct {
DALightNode: "my_celes_key",
HubRelayer: "relayer-hub-key",
}

var AddressPrefixes = struct {
Hub string
Rollapp string
DA string
}{
Rollapp: "rol",
Hub: "dym",
DA: "celestia",
}

var ConfigDirName = struct {
Rollapp string
Relayer string
DALightNode string
}{
Rollapp: "rollapp",
Relayer: "relayer",
DALightNode: "da-light-node",
}

var CoinTypes = struct {
Cosmos uint32
EVM uint32
}{
Cosmos: 118,
EVM: 60,
}
2 changes: 1 addition & 1 deletion cmd/da-light-client/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func getCelestiaCmd(rollappConfig initconfig.InitConfig) *exec.Cmd {
return exec.Command(
consts.Executables.Celestia, "light", "start",
"--core.ip", "consensus-full-arabica-8.celestia-arabica.com",
"--node.store", filepath.Join(rollappConfig.Home, initconfig.ConfigDirName.DALightNode),
"--node.store", filepath.Join(rollappConfig.Home, consts.ConfigDirName.DALightNode),
"--gateway",
"--gateway.addr", "127.0.0.1",
"--gateway.port", "26659",
Expand Down
8 changes: 4 additions & 4 deletions cmd/register/bash_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func showSequencerPubKey(rollappConfig initconfig.InitConfig) (string, error) {
"dymint",
"show-sequencer",
"--home",
filepath.Join(rollappConfig.Home, initconfig.ConfigDirName.Rollapp),
filepath.Join(rollappConfig.Home, consts.ConfigDirName.Rollapp),
)
out, err := cmd.Output()
if err != nil {
Expand All @@ -43,7 +43,7 @@ func getRegisterSequencerCmd(rollappConfig initconfig.InitConfig) (*exec.Cmd, er
return nil, err
}
description := fmt.Sprintf(`{"Moniker":"%s","Identity":"","Website":"","SecurityContact":"","Details":""}`,
initconfig.KeyNames.HubSequencer)
consts.KeyNames.HubSequencer)
cmdArgs := []string{
"tx", "sequencer", "create-sequencer",
seqPubKey,
Expand All @@ -56,9 +56,9 @@ func getRegisterSequencerCmd(rollappConfig initconfig.InitConfig) (*exec.Cmd, er

func GetCommonFlags(rollappConfig initconfig.InitConfig) []string {
return []string{
"--from", initconfig.KeyNames.HubSequencer,
"--from", consts.KeyNames.HubSequencer,
"--keyring-backend", "test",
"--keyring-dir", filepath.Join(rollappConfig.Home, initconfig.ConfigDirName.Rollapp),
"--keyring-dir", filepath.Join(rollappConfig.Home, consts.ConfigDirName.Rollapp),
"--node", rollappConfig.HubData.RPC_URL, "--output", "json",
"--yes", "--broadcast-mode", "block", "--chain-id", rollappConfig.HubData.ID,
}
Expand Down
Loading

0 comments on commit 1999f00

Please sign in to comment.