diff --git a/cmd/config/init/consts.go b/cmd/config/init/consts.go index 7fa1b546..974cd871 100644 --- a/cmd/config/init/consts.go +++ b/cmd/config/init/consts.go @@ -3,20 +3,21 @@ package initconfig import "github.com/dymensionxyz/roller/cmd/utils" var FlagNames = struct { - Home string TokenSupply string RollappBinary string HubID string }{ - Home: "home", TokenSupply: "token-supply", RollappBinary: "rollapp-binary", HubID: "hub", } -const StagingHubID = "internal-devnet" -const LocalHubID = "local" +const ( + StagingHubID = "internal-devnet" + LocalHubID = "local" +) +// TODO(#112): The avaialble hub networks should be read from YAML file var Hubs = map[string]utils.HubData{ StagingHubID: { API_URL: "https://rest-hub-devnet.dymension.xyz", diff --git a/cmd/config/init/flags.go b/cmd/config/init/flags.go index beb6c560..7f1a174e 100644 --- a/cmd/config/init/flags.go +++ b/cmd/config/init/flags.go @@ -4,32 +4,21 @@ import ( "fmt" "regexp" + "math/big" + "github.com/dymensionxyz/roller/cmd/consts" "github.com/dymensionxyz/roller/cmd/utils" "github.com/spf13/cobra" - "math/big" +) + +const ( + defaultTokenSupply = "1000000000" ) func addFlags(cmd *cobra.Command) { cmd.Flags().StringP(FlagNames.HubID, "", StagingHubID, fmt.Sprintf("The ID of the Dymension hub. %s", getAvailableHubsMessage())) cmd.Flags().StringP(FlagNames.RollappBinary, "", "", "The rollapp binary. Should be passed only if you built a custom rollapp") - cmd.Flags().StringP(FlagNames.TokenSupply, "", "1000000000", "The total token supply of the RollApp") - - cmd.PreRunE = func(cmd *cobra.Command, args []string) error { - err := verifyHubID(cmd) - if err != nil { - return err - } - err = verifyTokenSupply(cmd) - if err != nil { - return err - } - rollappID := args[0] - if !validateRollAppID(rollappID) { - return fmt.Errorf("invalid RollApp ID '%s'. %s", rollappID, getValidRollappIdMessage()) - } - return nil - } + cmd.Flags().StringP(FlagNames.TokenSupply, "", defaultTokenSupply, "The total token supply of the RollApp") } func getRollappBinaryPath(cmd *cobra.Command) string { @@ -61,9 +50,9 @@ func GetInitConfig(initCmd *cobra.Command, args []string) (utils.RollappConfig, }, nil } func getValidRollappIdMessage() string { - return "A valid RollApp ID should follow the format 'name_EIP155-version', where 'name' is made up of" + - " lowercase English letters, 'EIP155_version' is a 1 to 5 digit number representing the EIP155 rollapp ID, and '" + - "version' is a 1 to 5 digit number representing the version. For example: 'mars_9721_1'" + return "A valid RollApp ID should follow the format 'rollapp-name_EIP155-revision', where 'rollapp-name' is made up of" + + " lowercase English letters, 'EIP155-revision' is a 1 to 5 digit number representing the EIP155 rollapp ID, and '" + + "revision' is a 1 to 5 digit number representing the revision. For example: 'mars_9721-1'" } func getAvailableHubsMessage() string { diff --git a/cmd/config/init/genesis.go b/cmd/config/init/genesis.go index bd14b86b..6d591221 100644 --- a/cmd/config/init/genesis.go +++ b/cmd/config/init/genesis.go @@ -2,11 +2,12 @@ package initconfig import ( "fmt" - "github.com/dymensionxyz/roller/cmd/consts" - "github.com/dymensionxyz/roller/cmd/utils" "io/ioutil" "math/big" + "github.com/dymensionxyz/roller/cmd/consts" + "github.com/dymensionxyz/roller/cmd/utils" + "os/exec" "path/filepath" @@ -55,6 +56,7 @@ type PathValue struct { Value interface{} } +// TODO(#130): fix to support epochs func getDefaultGenesisParams(denom string) []PathValue { return []PathValue{ {"app_state.mint.params.mint_denom", denom}, diff --git a/cmd/config/init/init.go b/cmd/config/init/init.go index c03db78c..2333ebc7 100644 --- a/cmd/config/init/init.go +++ b/cmd/config/init/init.go @@ -1,16 +1,33 @@ package initconfig import ( + "fmt" + "os" + "github.com/dymensionxyz/roller/cmd/consts" "github.com/dymensionxyz/roller/cmd/utils" "github.com/spf13/cobra" - "os" ) func InitCmd() *cobra.Command { initCmd := &cobra.Command{ Use: "init ", Short: "Initialize a RollApp configuration on your local machine.", + PreRunE: func(cmd *cobra.Command, args []string) error { + err := verifyHubID(cmd) + if err != nil { + return err + } + err = verifyTokenSupply(cmd) + if err != nil { + return err + } + rollappID := args[0] + if !validateRollAppID(rollappID) { + return fmt.Errorf("invalid RollApp ID '%s'. %s", rollappID, getValidRollappIdMessage()) + } + return nil + }, Run: func(cmd *cobra.Command, args []string) { initConfig, err := GetInitConfig(cmd, args) utils.PrettifyErrorIfExists(err) @@ -22,13 +39,15 @@ func InitCmd() *cobra.Command { utils.PrettifyErrorIfExists(err) if shouldOverwrite { utils.PrettifyErrorIfExists(os.RemoveAll(initConfig.Home)) - utils.PrettifyErrorIfExists(os.MkdirAll(initConfig.Home, 0755)) } else { os.Exit(0) } - } else { - utils.PrettifyErrorIfExists(os.MkdirAll(initConfig.Home, 0755)) } + utils.PrettifyErrorIfExists(os.MkdirAll(initConfig.Home, 0755)) + + //TODO: create all dirs here + + /* ---------------------------- Initilize relayer --------------------------- */ utils.PrettifyErrorIfExists(initializeRelayerConfig(ChainConfig{ ID: initConfig.RollappID, RPC: consts.DefaultRollappRPC, @@ -40,8 +59,12 @@ func InitCmd() *cobra.Command { Denom: consts.Denoms.Hub, AddressPrefix: consts.AddressPrefixes.Hub, }, initConfig)) + + /* ------------------------------ Generate keys ----------------------------- */ addresses, err := generateKeys(initConfig) utils.PrettifyErrorIfExists(err) + + /* ------------------------ Initialize DA light node ------------------------ */ utils.PrettifyErrorIfExists(initializeLightNodeConfig(initConfig)) daAddress, err := utils.GetCelestiaAddress(initConfig.Home) utils.PrettifyErrorIfExists(err) @@ -49,9 +72,13 @@ func InitCmd() *cobra.Command { Addr: daAddress, Name: consts.KeysIds.DALightNode, }) + + /* --------------------------- Initiailize Rollapp -------------------------- */ utils.PrettifyErrorIfExists(initializeRollappConfig(initConfig)) utils.PrettifyErrorIfExists(initializeRollappGenesis(initConfig)) utils.PrettifyErrorIfExists(utils.WriteConfigToTOML(initConfig)) + + /* ------------------------------ Print output ------------------------------ */ printInitOutput(addresses, initConfig.RollappID) }, Args: cobra.ExactArgs(2), diff --git a/cmd/config/init/keys.go b/cmd/config/init/keys.go index ab8fdbba..691478b9 100644 --- a/cmd/config/init/keys.go +++ b/cmd/config/init/keys.go @@ -49,13 +49,15 @@ func getSequencerKeysConfig() []utils.CreateKeyConfig { { Dir: consts.ConfigDirName.HubKeys, ID: consts.KeysIds.HubSequencer, - CoinType: consts.CoinTypes.Cosmos, + CoinType: consts.CoinTypes.EVM, + Algo: consts.AlgoTypes.Secp256k1, Prefix: consts.AddressPrefixes.Hub, }, { Dir: consts.ConfigDirName.Rollapp, ID: consts.KeysIds.RollappSequencer, CoinType: consts.CoinTypes.EVM, + Algo: consts.AlgoTypes.Ethsecp256k1, Prefix: consts.AddressPrefixes.Rollapp, }, } @@ -67,24 +69,22 @@ func getRelayerKeysConfig(rollappConfig utils.RollappConfig) map[string]utils.Cr Dir: path.Join(rollappConfig.Home, consts.ConfigDirName.Relayer), ID: consts.KeysIds.RollappRelayer, CoinType: consts.CoinTypes.EVM, + Algo: consts.AlgoTypes.Ethsecp256k1, Prefix: consts.AddressPrefixes.Rollapp, }, consts.KeysIds.HubRelayer: { Dir: path.Join(rollappConfig.Home, consts.ConfigDirName.Relayer), ID: consts.KeysIds.HubRelayer, CoinType: consts.CoinTypes.Cosmos, + Algo: consts.AlgoTypes.Secp256k1, Prefix: consts.AddressPrefixes.Hub, }, } } func createAddressBinary(keyConfig utils.CreateKeyConfig, binaryPath string, home string) (string, error) { - args := []string{"keys", "add", keyConfig.ID, "--keyring-backend", "test", - "--keyring-dir", filepath.Join(home, keyConfig.Dir), "--output", "json"} - if binaryPath == consts.Executables.Dymension { - args = append(args, "--algo", "secp256k1") - } - createKeyCommand := exec.Command(binaryPath, args...) + createKeyCommand := exec.Command(binaryPath, "keys", "add", keyConfig.ID, "--keyring-backend", "test", + "--keyring-dir", filepath.Join(home, keyConfig.Dir), "--algo", keyConfig.Algo, "--output", "json") out, err := utils.ExecBashCommand(createKeyCommand) if err != nil { return "", err @@ -127,7 +127,7 @@ func generateRelayerKeys(rollappConfig utils.RollappConfig) ([]utils.AddressData func getAddRlyKeyCmd(keyConfig utils.CreateKeyConfig, chainID string) *exec.Cmd { return exec.Command( consts.Executables.Relayer, - consts.KeysDirName, + "keys", "add", chainID, keyConfig.ID, diff --git a/cmd/config/init/rollapp.go b/cmd/config/init/rollapp.go index 72a29bf4..e411bbfe 100644 --- a/cmd/config/init/rollapp.go +++ b/cmd/config/init/rollapp.go @@ -1,11 +1,12 @@ package initconfig import ( - "github.com/dymensionxyz/roller/cmd/utils" "os" "os/exec" "path/filepath" + "github.com/dymensionxyz/roller/cmd/utils" + "github.com/dymensionxyz/roller/cmd/consts" toml "github.com/pelletier/go-toml" ) @@ -26,6 +27,7 @@ func initializeRollappConfig(initConfig utils.RollappConfig) error { } func setRollappAppConfig(appConfigFilePath string, denom string) error { + //FIXME: why error not checked? config, _ := toml.LoadFile(appConfigFilePath) config.Set("minimum-gas-prices", "0"+denom) config.Set("api.enable", "true") diff --git a/cmd/consts/consts.go b/cmd/consts/consts.go index dbdcf535..5016df97 100644 --- a/cmd/consts/consts.go +++ b/cmd/consts/consts.go @@ -66,6 +66,14 @@ var CoinTypes = struct { EVM: 60, } +var AlgoTypes = struct { + Secp256k1 string + Ethsecp256k1 string +}{ + Secp256k1: "secp256k1", + Ethsecp256k1: "eth_secp256k1", +} + var Denoms = struct { Hub string Celestia string diff --git a/cmd/relayer/start/create_ibc_channel.go b/cmd/relayer/start/create_ibc_channel.go index 05578712..2aa02fe4 100644 --- a/cmd/relayer/start/create_ibc_channel.go +++ b/cmd/relayer/start/create_ibc_channel.go @@ -2,10 +2,11 @@ package start import ( "fmt" - "github.com/dymensionxyz/roller/cmd/consts" - "github.com/dymensionxyz/roller/cmd/utils" "os/exec" "path/filepath" + + "github.com/dymensionxyz/roller/cmd/consts" + "github.com/dymensionxyz/roller/cmd/utils" ) // Creates an IBC channel between the hub and the client, and return the source channel ID. @@ -47,7 +48,7 @@ func createIBCChannelIfNeeded(rollappConfig utils.RollappConfig, logFileOption u func getCreateChannelCmd(config utils.RollappConfig) *exec.Cmd { defaultRlyArgs := getRelayerDefaultArgs(config) - args := []string{"tx", "channel", "--override"} + args := []string{"tx", "channel", "-t", "300s", "--override"} args = append(args, defaultRlyArgs...) return exec.Command(consts.Executables.Relayer, args...) } @@ -65,7 +66,7 @@ func getRelayerDefaultArgs(config utils.RollappConfig) []string { func getCreateConnectionCmd(config utils.RollappConfig) *exec.Cmd { defaultRlyArgs := getRelayerDefaultArgs(config) - args := []string{"tx", "connection"} + args := []string{"tx", "connection", "-t", "300s"} args = append(args, defaultRlyArgs...) return exec.Command(consts.Executables.Relayer, args...) } diff --git a/cmd/sequencer/start/start.go b/cmd/sequencer/start/start.go index 5773cda5..c6a87bdb 100644 --- a/cmd/sequencer/start/start.go +++ b/cmd/sequencer/start/start.go @@ -47,9 +47,14 @@ var FlagNames = struct { func printOutput() { fmt.Println("💈 The Rollapp sequencer is running on your local machine!") + + //TODO: either mark the ports as default, or read from configuration file + fmt.Println("💈 EVM RPC: http://0.0.0.0:8545") fmt.Println("💈 Node RPC: http://0.0.0.0:26657") fmt.Println("💈 Rest API: http://0.0.0.0:1317") + + //TODO: print the log file path } func parseError(errMsg string) string { @@ -61,33 +66,31 @@ func parseError(errMsg string) string { } func GetStartRollappCmd(rollappConfig utils.RollappConfig, lightNodeEndpoint string) *exec.Cmd { - daConfig := fmt.Sprintf(`{"base_url": "%s", "timeout": 60000000000, "fee":20000, "gas_limit": 20000000, "namespace_id":[0,0,0,0,0,0,255,255]}`, + daConfig := fmt.Sprintf(`{"base_url": "%s", "timeout": 60000000000, "fee":20000, "gas_limit": 20000000, "namespace_id":"000000000000ffff"}`, lightNodeEndpoint) rollappConfigDir := filepath.Join(rollappConfig.Home, consts.ConfigDirName.Rollapp) hubKeysDir := filepath.Join(rollappConfig.Home, consts.ConfigDirName.HubKeys) cmd := exec.Command( rollappConfig.RollappBinary, "start", - "--dymint.aggregator", - "--json-rpc.enable", - "--json-rpc.api", "eth,txpool,personal,net,debug,web3,miner", "--dymint.da_layer", "celestia", "--dymint.da_config", daConfig, "--dymint.settlement_layer", "dymension", - // TODO: 600 - "--dymint.block_batch_size", "50", + "--dymint.block_batch_size", "500", "--dymint.namespace_id", "000000000000ffff", "--dymint.block_time", "0.2s", - "--home", rollappConfigDir, - "--log_level", "debug", - "--log-file", filepath.Join(rollappConfigDir, "rollapp.log"), - "--max-log-size", "2000", - "--module-log-level-override", "", + "--dymint.batch_submit_max_time", "100s", + "--dymint.empty_blocks_max_time", "10s", + "--dymint.settlement_config.rollapp_id", rollappConfig.RollappID, "--dymint.settlement_config.node_address", rollappConfig.HubData.RPC_URL, "--dymint.settlement_config.dym_account_name", consts.KeysIds.HubSequencer, "--dymint.settlement_config.keyring_home_dir", hubKeysDir, - "--dymint.settlement_config.gas_fees", "0udym", "--dymint.settlement_config.gas_prices", "0udym", + "--home", rollappConfigDir, + "--log_level", "info", + "--max-log-size", "2000", ) + + fmt.Println(cmd.String()) return cmd } diff --git a/cmd/utils/keys.go b/cmd/utils/keys.go index 5e041c03..02d82b50 100644 --- a/cmd/utils/keys.go +++ b/cmd/utils/keys.go @@ -4,12 +4,13 @@ import ( "bytes" "encoding/json" "fmt" - "github.com/olekukonko/tablewriter" "os" "os/exec" "path/filepath" "strings" + "github.com/olekukonko/tablewriter" + "github.com/dymensionxyz/roller/cmd/consts" ) @@ -49,6 +50,7 @@ type CreateKeyConfig struct { Dir string ID string CoinType uint32 + Algo string Prefix string }