Skip to content

Commit

Permalink
Implemented status check for the sequencer and the da
Browse files Browse the repository at this point in the history
  • Loading branch information
ItayLevyOfficial committed Jun 29, 2023
1 parent 17698eb commit c839817
Show file tree
Hide file tree
Showing 15 changed files with 116 additions and 131 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/.vscode
build/
*
!*/
!*.*
*.exe
\.*
/.vscode
31 changes: 0 additions & 31 deletions Makefile

This file was deleted.

9 changes: 4 additions & 5 deletions cmd/config/init/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@ 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"
LocalHubID = "local"
)
const StagingHubID = "internal-devnet"
const 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: 21 additions & 10 deletions cmd/config/init/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,32 @@ import (
"fmt"
"regexp"

"math/big"

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

const (
defaultTokenSupply = "1000000000"
"math/big"
)

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, "", defaultTokenSupply, "The total token supply of the 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
}
}

func getRollappBinaryPath(cmd *cobra.Command) string {
Expand Down Expand Up @@ -50,9 +61,9 @@ func GetInitConfig(initCmd *cobra.Command, args []string) (utils.RollappConfig,
}, nil
}
func getValidRollappIdMessage() string {
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'"
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'"
}

func getAvailableHubsMessage() string {
Expand Down
6 changes: 2 additions & 4 deletions cmd/config/init/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package initconfig

import (
"fmt"
"io/ioutil"
"math/big"

"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/cmd/utils"
"io/ioutil"
"math/big"

"os/exec"
"path/filepath"
Expand Down Expand Up @@ -56,7 +55,6 @@ 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: 4 additions & 31 deletions cmd/config/init/init.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,16 @@
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 @@ -39,15 +22,13 @@ 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 @@ -59,26 +40,18 @@ 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,15 +49,13 @@ func getSequencerKeysConfig() []utils.CreateKeyConfig {
{
Dir: consts.ConfigDirName.HubKeys,
ID: consts.KeysIds.HubSequencer,
CoinType: consts.CoinTypes.EVM,
Algo: consts.AlgoTypes.Secp256k1,
CoinType: consts.CoinTypes.Cosmos,
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 @@ -69,22 +67,24 @@ 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) {
createKeyCommand := exec.Command(binaryPath, "keys", "add", keyConfig.ID, "--keyring-backend", "test",
"--keyring-dir", filepath.Join(home, keyConfig.Dir), "--algo", keyConfig.Algo, "--output", "json")
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...)
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,
"keys",
consts.KeysDirName,
"add",
chainID,
keyConfig.ID,
Expand Down
4 changes: 1 addition & 3 deletions cmd/config/init/rollapp.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
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 @@ -27,7 +26,6 @@ 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
16 changes: 7 additions & 9 deletions cmd/consts/consts.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package consts

import "fmt"
import (
"fmt"
"math/big"
)

const binsDir = "/usr/local/bin"

Expand Down Expand Up @@ -66,14 +69,6 @@ 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 All @@ -88,3 +83,6 @@ const DefaultRollappRPC = "http://localhost:26657"
const DefaultDALCRPC = "http://localhost:26659"
const CelestiaRestApiEndpoint = "https://api-arabica-8.consensus.celestia-arabica.com"
const DefaultCelestiaRPC = "consensus-full-arabica-8.celestia-arabica.com"

var OneSequencePrice = big.NewInt(1)
var OneDAWritePrice = big.NewInt(1)
9 changes: 4 additions & 5 deletions cmd/relayer/start/create_ibc_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package start

import (
"fmt"
"os/exec"
"path/filepath"

"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/cmd/utils"
"os/exec"
"path/filepath"
)

// Creates an IBC channel between the hub and the client, and return the source channel ID.
Expand Down Expand Up @@ -48,7 +47,7 @@ func createIBCChannelIfNeeded(rollappConfig utils.RollappConfig, logFileOption u

func getCreateChannelCmd(config utils.RollappConfig) *exec.Cmd {
defaultRlyArgs := getRelayerDefaultArgs(config)
args := []string{"tx", "channel", "-t", "300s", "--override"}
args := []string{"tx", "channel", "--override"}
args = append(args, defaultRlyArgs...)
return exec.Command(consts.Executables.Relayer, args...)
}
Expand All @@ -66,7 +65,7 @@ func getRelayerDefaultArgs(config utils.RollappConfig) []string {

func getCreateConnectionCmd(config utils.RollappConfig) *exec.Cmd {
defaultRlyArgs := getRelayerDefaultArgs(config)
args := []string{"tx", "connection", "-t", "300s"}
args := []string{"tx", "connection"}
args = append(args, defaultRlyArgs...)
return exec.Command(consts.Executables.Relayer, args...)
}
5 changes: 3 additions & 2 deletions cmd/run/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func fetchServicesData(rollappConfig utils.RollappConfig, logger *log.Logger) ([
utils.GetSequencerData,
utils.GetHubRlyAccData,
utils.GetRolRlyAccData,
utils.GetCelLCAccData,
utils.GetCelLCAccDataFromLocalLC,
}
results := fetchAsync(fetchFuncs, rollappConfig)
data := processDataResults(results, len(fetchFuncs), logger)
Expand All @@ -49,7 +49,8 @@ func getInitialServiceData() []ServiceData {
}
}

func fetchAsync(fetchFuncs []func(utils.RollappConfig) (*utils.AccountData, error), rollappConfig utils.RollappConfig) chan fetchResult {
func fetchAsync(fetchFuncs []func(utils.RollappConfig) (*utils.AccountData, error), rollappConfig utils.RollappConfig,
) chan fetchResult {
results := make(chan fetchResult, len(fetchFuncs))
for i, fn := range fetchFuncs {
go func(id int, fn func(utils.RollappConfig) (*utils.AccountData, error)) {
Expand Down
Loading

0 comments on commit c839817

Please sign in to comment.