Skip to content

Commit

Permalink
feat: support latest RDK on devnet (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsitrin authored Jun 29, 2023
1 parent d3f6ead commit 17698eb
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 57 deletions.
9 changes: 5 additions & 4 deletions cmd/config/init/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
31 changes: 10 additions & 21 deletions cmd/config/init/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions cmd/config/init/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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},
Expand Down
35 changes: 31 additions & 4 deletions cmd/config/init/init.go
Original file line number Diff line number Diff line change
@@ -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 <chain-id> <denom>",
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)
Expand All @@ -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,
Expand All @@ -40,18 +59,26 @@ 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)
addresses = append(addresses, utils.AddressData{
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),
Expand Down
16 changes: 8 additions & 8 deletions cmd/config/init/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion cmd/config/init/rollapp.go
Original file line number Diff line number Diff line change
@@ -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"
)
Expand All @@ -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")
Expand Down
8 changes: 8 additions & 0 deletions cmd/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions cmd/relayer/start/create_ibc_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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...)
}
Expand All @@ -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...)
}
27 changes: 15 additions & 12 deletions cmd/sequencer/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
4 changes: 3 additions & 1 deletion cmd/utils/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -49,6 +50,7 @@ type CreateKeyConfig struct {
Dir string
ID string
CoinType uint32
Algo string
Prefix string
}

Expand Down

0 comments on commit 17698eb

Please sign in to comment.