From c839817fcb6933cc407a95520ed6a2fe8e6d5ea3 Mon Sep 17 00:00:00 2001 From: Itay Levy Date: Thu, 29 Jun 2023 14:11:25 +0300 Subject: [PATCH] Implemented status check for the sequencer and the da --- .gitignore | 5 +++- Makefile | 31 ---------------------- cmd/config/init/consts.go | 9 +++---- cmd/config/init/flags.go | 31 +++++++++++++++------- cmd/config/init/genesis.go | 6 ++--- cmd/config/init/init.go | 35 +++---------------------- cmd/config/init/keys.go | 16 +++++------ cmd/config/init/rollapp.go | 4 +-- cmd/consts/consts.go | 16 +++++------ cmd/relayer/start/create_ibc_channel.go | 9 +++---- cmd/run/services.go | 5 ++-- cmd/run/services_status.go | 19 +++++++++++--- cmd/sequencer/start/start.go | 27 +++++++++---------- cmd/utils/fetch_accounts_data.go | 30 +++++++++++++++++++++ cmd/utils/keys.go | 4 +-- 15 files changed, 116 insertions(+), 131 deletions(-) delete mode 100644 Makefile diff --git a/.gitignore b/.gitignore index a99b0bf2..f75bab66 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ /.vscode -build/ +* +!*/ +!*.* *.exe +\.* /.vscode \ No newline at end of file diff --git a/Makefile b/Makefile deleted file mode 100644 index 62b9e127..00000000 --- a/Makefile +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/make -f -BRANCH := $(shell git rev-parse --abbrev-ref HEAD) -COMMIT := $(shell git log -1 --format='%H') -TIME ?= $(shell date +%Y-%m-%dT%H:%M:%S%z) - -# don't override user values -ifeq (,$(VERSION)) - VERSION := $(shell git describe --tags) - # if VERSION is empty, then populate it with branch's name and raw commit hash - ifeq (,$(VERSION)) - VERSION := $(BRANCH)-$(COMMIT) - endif -endif - - -ldflags = -X github.com/dymensionxyz/roller/cmd/version.BuildVersion=$(VERSION) \ - -X github.com/dymensionxyz/roller/cmd/version.BuildCommit=$(COMMIT) \ - -X github.com/dymensionxyz/roller/cmd/version.BuildTime=$(TIME)" - -BUILD_FLAGS := -ldflags '$(ldflags)' -# ---------------------------------------------------------------------------- # -# Make targets # -# ---------------------------------------------------------------------------- # -.PHONY: install -install: go.sum ## Installs the roller binary - go install -mod=readonly $(BUILD_FLAGS) . - - -.PHONY: build -build: ## Compiles the roller binary - go build -o build/roller $(BUILD_FLAGS) . diff --git a/cmd/config/init/consts.go b/cmd/config/init/consts.go index 974cd871..7fa1b546 100644 --- a/cmd/config/init/consts.go +++ b/cmd/config/init/consts.go @@ -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", diff --git a/cmd/config/init/flags.go b/cmd/config/init/flags.go index 7f1a174e..beb6c560 100644 --- a/cmd/config/init/flags.go +++ b/cmd/config/init/flags.go @@ -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 { @@ -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 { diff --git a/cmd/config/init/genesis.go b/cmd/config/init/genesis.go index 6d591221..bd14b86b 100644 --- a/cmd/config/init/genesis.go +++ b/cmd/config/init/genesis.go @@ -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" @@ -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}, diff --git a/cmd/config/init/init.go b/cmd/config/init/init.go index 2333ebc7..c03db78c 100644 --- a/cmd/config/init/init.go +++ b/cmd/config/init/init.go @@ -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 ", 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) @@ -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, @@ -59,12 +40,8 @@ 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) @@ -72,13 +49,9 @@ 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 691478b9..ab8fdbba 100644 --- a/cmd/config/init/keys.go +++ b/cmd/config/init/keys.go @@ -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, }, } @@ -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 @@ -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, diff --git a/cmd/config/init/rollapp.go b/cmd/config/init/rollapp.go index e411bbfe..72a29bf4 100644 --- a/cmd/config/init/rollapp.go +++ b/cmd/config/init/rollapp.go @@ -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" ) @@ -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") diff --git a/cmd/consts/consts.go b/cmd/consts/consts.go index 5016df97..b85c68c0 100644 --- a/cmd/consts/consts.go +++ b/cmd/consts/consts.go @@ -1,6 +1,9 @@ package consts -import "fmt" +import ( + "fmt" + "math/big" +) const binsDir = "/usr/local/bin" @@ -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 @@ -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) diff --git a/cmd/relayer/start/create_ibc_channel.go b/cmd/relayer/start/create_ibc_channel.go index 2aa02fe4..05578712 100644 --- a/cmd/relayer/start/create_ibc_channel.go +++ b/cmd/relayer/start/create_ibc_channel.go @@ -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. @@ -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...) } @@ -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...) } diff --git a/cmd/run/services.go b/cmd/run/services.go index 38edc533..9994c370 100644 --- a/cmd/run/services.go +++ b/cmd/run/services.go @@ -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) @@ -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)) { diff --git a/cmd/run/services_status.go b/cmd/run/services_status.go index 80c022d0..671276dd 100644 --- a/cmd/run/services_status.go +++ b/cmd/run/services_status.go @@ -29,22 +29,33 @@ func processDataResults(results chan fetchResult, size int, logger *log.Logger) return data } +func activeIfSufficientBalance(currentBalance, threshold *big.Int) string { + if currentBalance.Cmp(threshold) >= 0 { + return "Active" + } else { + return "Stopped" + } +} + func buildServiceData(data []*utils.AccountData, rollappConfig utils.RollappConfig) []ServiceData { + rolRlyData := data[2] return []ServiceData{ { Name: "Sequencer", Balance: data[0].Balance.String() + consts.Denoms.Hub, - Status: "Active", + // TODO: for now, we just check if the balance of the rollapp relayer is greater than 0 + // in the future, we should have a better way to check the rollapp health. + Status: activeIfSufficientBalance(rolRlyData.Balance, big.NewInt(1)), }, { Name: "DA Light Client", Balance: data[3].Balance.String() + consts.Denoms.Celestia, - Status: "Active", + Status: activeIfSufficientBalance(data[3].Balance, consts.OneDAWritePrice), }, { Name: "Relayer", Balance: data[1].Balance.String() + consts.Denoms.Hub + ", " + - data[2].Balance.String() + rollappConfig.Denom, + rolRlyData.Balance.String() + rollappConfig.Denom, Status: "Starting...", }, } @@ -65,7 +76,7 @@ func PrintServicesStatus(rollappConfig utils.RollappConfig) { ui.Render(p, table) events := ui.PollEvents() - ticker := time.NewTicker(time.Second * 5).C + ticker := time.NewTicker(time.Second * 1).C config := ServiceStatusConfig{ rollappConfig: rollappConfig, diff --git a/cmd/sequencer/start/start.go b/cmd/sequencer/start/start.go index c6a87bdb..5773cda5 100644 --- a/cmd/sequencer/start/start.go +++ b/cmd/sequencer/start/start.go @@ -47,14 +47,9 @@ 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 { @@ -66,31 +61,33 @@ 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":"000000000000ffff"}`, + daConfig := fmt.Sprintf(`{"base_url": "%s", "timeout": 60000000000, "fee":20000, "gas_limit": 20000000, "namespace_id":[0,0,0,0,0,0,255,255]}`, 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", - "--dymint.block_batch_size", "500", + // TODO: 600 + "--dymint.block_batch_size", "50", "--dymint.namespace_id", "000000000000ffff", "--dymint.block_time", "0.2s", - "--dymint.batch_submit_max_time", "100s", - "--dymint.empty_blocks_max_time", "10s", - "--dymint.settlement_config.rollapp_id", rollappConfig.RollappID, + "--home", rollappConfigDir, + "--log_level", "debug", + "--log-file", filepath.Join(rollappConfigDir, "rollapp.log"), + "--max-log-size", "2000", + "--module-log-level-override", "", "--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/fetch_accounts_data.go b/cmd/utils/fetch_accounts_data.go index 379d32ac..2b9e8b9e 100644 --- a/cmd/utils/fetch_accounts_data.go +++ b/cmd/utils/fetch_accounts_data.go @@ -1,8 +1,10 @@ package utils import ( + "encoding/json" "fmt" "github.com/dymensionxyz/roller/cmd/consts" + "math/big" "path/filepath" ) @@ -88,3 +90,31 @@ func GetCelLCAccData(rollappConfig RollappConfig) (*AccountData, error) { Balance: balance, }, nil } + +func GetCelLCAccDataFromLocalLC(rollappConfig RollappConfig) (*AccountData, error) { + celAddress, err := GetCelestiaAddress(rollappConfig.Home) + if err != nil { + return nil, err + } + var restQueryUrl = fmt.Sprintf( + "%s/balance", + consts.DefaultDALCRPC, + ) + balancesJson, err := RestQueryJson(restQueryUrl) + if err != nil { + return nil, err + } + var balanceResp Balance + err = json.Unmarshal(balancesJson.Bytes(), &balanceResp) + if err != nil { + return nil, err + } + balanceInt, ok := new(big.Int).SetString(balanceResp.Amount, 10) + if !ok { + return nil, fmt.Errorf("failed to parse balance") + } + return &AccountData{ + Address: celAddress, + Balance: balanceInt, + }, nil +} diff --git a/cmd/utils/keys.go b/cmd/utils/keys.go index 02d82b50..5e041c03 100644 --- a/cmd/utils/keys.go +++ b/cmd/utils/keys.go @@ -4,13 +4,12 @@ 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" ) @@ -50,7 +49,6 @@ type CreateKeyConfig struct { Dir string ID string CoinType uint32 - Algo string Prefix string }