diff --git a/cmd/config/init/consts.go b/cmd/config/init/consts.go index 169d9b51..531cd528 100644 --- a/cmd/config/init/consts.go +++ b/cmd/config/init/consts.go @@ -19,18 +19,18 @@ var FlagNames = struct { } const ( - StagingHubID = "devnet" - LocalHubID = "local" + StagingHubName = "devnet" + LocalHubName = "local" ) // TODO(#112): The avaialble hub networks should be read from YAML file var Hubs = map[string]config.HubData{ - StagingHubID: { + StagingHubName: { API_URL: "https://dymension.devnet.api.silknodes.io:443", ID: "devnet_304-1", RPC_URL: "https://dymension.devnet.rpc.silknodes.io:443", }, - LocalHubID: { + LocalHubName: { API_URL: "http://localhost:1318", ID: "dymension_100-1", RPC_URL: "http://localhost:36657", diff --git a/cmd/config/init/flags.go b/cmd/config/init/flags.go index ba660ee9..b5ef27e4 100644 --- a/cmd/config/init/flags.go +++ b/cmd/config/init/flags.go @@ -15,7 +15,7 @@ const ( ) func addFlags(cmd *cobra.Command) error { - cmd.Flags().StringP(FlagNames.HubID, "", StagingHubID, fmt.Sprintf("The ID of the Dymension hub. %s", getAvailableHubsMessage())) + cmd.Flags().StringP(FlagNames.HubID, "", StagingHubName, fmt.Sprintf("The ID of the Dymension hub. %s", getAvailableHubsMessage())) cmd.Flags().StringP(FlagNames.RollappBinary, "", consts.Executables.RollappEVM, "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().BoolP(FlagNames.Interactive, "i", false, "Run roller in interactive mode") @@ -62,5 +62,5 @@ func GetInitConfig(initCmd *cobra.Command, args []string) (config.RollappConfig, } func getAvailableHubsMessage() string { - return fmt.Sprintf("Acceptable values are '%s' or '%s'", StagingHubID, LocalHubID) + return fmt.Sprintf("Acceptable values are '%s' or '%s'", StagingHubName, LocalHubName) } diff --git a/cmd/config/init/output.go b/cmd/config/init/output.go index 3b48c26c..6ec13298 100644 --- a/cmd/config/init/output.go +++ b/cmd/config/init/output.go @@ -7,21 +7,23 @@ import ( "github.com/dymensionxyz/roller/cmd/consts" "github.com/dymensionxyz/roller/cmd/utils" "github.com/dymensionxyz/roller/config" + datalayer "github.com/dymensionxyz/roller/data_layer" ) func printInitOutput(rollappConfig config.RollappConfig, addresses []utils.AddressData, rollappId string) { fmt.Printf("šŸ’ˆ RollApp '%s' configuration files have been successfully generated on your local machine. Congratulations!\n\n", rollappId) fmt.Println(FormatTokenSupplyLine(rollappConfig)) fmt.Println() - utils.PrintAddresses(formatAddresses(addresses)) + utils.PrintAddresses(formatAddresses(rollappConfig, addresses)) fmt.Printf("\nšŸ”” Please fund these addresses to register and run the rollapp.\n") } -func formatAddresses(addresses []utils.AddressData) []utils.AddressData { +func formatAddresses(rollappConfig config.RollappConfig, addresses []utils.AddressData) []utils.AddressData { + damanager := datalayer.NewDAManager(rollappConfig.DA, rollappConfig.Home) requireFundingKeys := map[string]string{ - consts.KeysIds.HubSequencer: "Sequencer", - consts.KeysIds.HubRelayer: "Relayer", - consts.KeysIds.DALightNode: "Celestia", + consts.KeysIds.HubSequencer: fmt.Sprintf("Sequencer, %s Hub", rollappConfig.HubData.ID), + consts.KeysIds.HubRelayer: fmt.Sprintf("Relayer, %s Hub", rollappConfig.HubData.ID), + consts.KeysIds.DALightNode: fmt.Sprintf("DA, %s Network", damanager.GetNetworkName()), } filteredAddresses := make([]utils.AddressData, 0) for _, address := range addresses { diff --git a/cmd/consts/consts.go b/cmd/consts/consts.go index 73952cc9..1405c745 100644 --- a/cmd/consts/consts.go +++ b/cmd/consts/consts.go @@ -35,7 +35,7 @@ var KeysIds = struct { HubSequencer: "hub_sequencer", RollappSequencer: "rollapp_sequencer", RollappRelayer: "relayer-rollapp-key", - DALightNode: "my_celes_key", + DALightNode: "da-key", HubRelayer: "relayer-hub-key", } @@ -86,13 +86,10 @@ var Denoms = struct { } const ( - KeysDirName = "keys" - DefaultRelayerPath = "hub-rollapp" - DefaultRollappRPC = "http://localhost:26657" - DefaultDALCRPC = "http://localhost:26659" - CelestiaRestApiEndpoint = "https://api-mocha.pops.one" - DefaultCelestiaRPC = "rpc-mocha.pops.one" - DefaultCeletiaNetowrk = "mocha" + KeysDirName = "keys" + DefaultRelayerPath = "hub-rollapp" + DefaultRollappRPC = "http://localhost:26657" + DefaultDALCRPC = "http://localhost:26659" ) // TODO: Check DA LC write price on arabica and update this value. diff --git a/cmd/da-light-client/start/start.go b/cmd/da-light-client/start/start.go index 4c2acfb9..c318a7fd 100644 --- a/cmd/da-light-client/start/start.go +++ b/cmd/da-light-client/start/start.go @@ -4,7 +4,6 @@ import ( "errors" "fmt" - "github.com/dymensionxyz/roller/cmd/consts" "github.com/dymensionxyz/roller/cmd/utils" "github.com/dymensionxyz/roller/config" datalayer "github.com/dymensionxyz/roller/data_layer" @@ -29,10 +28,13 @@ func Cmd() *cobra.Command { damanager := datalayer.NewDAManager(rollappConfig.DA, rollappConfig.Home) insufficientBalances, err := damanager.CheckDABalance() utils.PrettifyErrorIfExists(err) - utils.PrintInsufficientBalancesIfAny(insufficientBalances) - rpcEndpoint := cmd.Flag(rpcEndpointFlag).Value.String() + utils.PrintInsufficientBalancesIfAny(insufficientBalances, rollappConfig) - startDALCCmd := damanager.GetStartDACmd(rpcEndpoint) + rpcEndpoint := cmd.Flag(rpcEndpointFlag).Value.String() + if rpcEndpoint != "" { + damanager.SetRPCEndpoint(rpcEndpoint) + } + startDALCCmd := damanager.GetStartDACmd() if startDALCCmd == nil { utils.PrettifyErrorIfExists(errors.New("can't run mock DA. It runs automatically with the app")) } @@ -48,7 +50,7 @@ func Cmd() *cobra.Command { } func addFlags(cmd *cobra.Command) { - cmd.Flags().StringP(rpcEndpointFlag, "", consts.DefaultCelestiaRPC, "The DA rpc endpoint to connect to.") + cmd.Flags().StringP(rpcEndpointFlag, "", "", "The DA rpc endpoint to connect to.") } func printOutput() { diff --git a/cmd/register/register.go b/cmd/register/register.go index 117aa072..7b057b72 100644 --- a/cmd/register/register.go +++ b/cmd/register/register.go @@ -8,6 +8,8 @@ import ( "math/big" "strings" + "github.com/dymensionxyz/roller/cmd/consts" + initconfig "github.com/dymensionxyz/roller/cmd/config/init" "github.com/dymensionxyz/roller/cmd/consts" "github.com/dymensionxyz/roller/cmd/utils" @@ -47,7 +49,7 @@ func register(cmd *cobra.Command, args []string) error { } if len(notFundedAddrs) > 0 { spin.Stop() - utils.PrintInsufficientBalancesIfAny(notFundedAddrs) + utils.PrintInsufficientBalancesIfAny(notFundedAddrs, rollappConfig) } spin.Suffix = consts.SpinnerMsgs.UniqueIdVerification spin.Restart() diff --git a/cmd/relayer/start/start.go b/cmd/relayer/start/start.go index 454ddbf4..46b6778f 100644 --- a/cmd/relayer/start/start.go +++ b/cmd/relayer/start/start.go @@ -60,7 +60,7 @@ func getRelayPacketsCmd(config config.RollappConfig, srcChannel string) *exec.Cm func VerifyRelayerBalances(rolCfg config.RollappConfig) { insufficientBalances, err := GetRelayerInsufficientBalances(rolCfg) utils.PrettifyErrorIfExists(err) - utils.PrintInsufficientBalancesIfAny(insufficientBalances) + utils.PrintInsufficientBalancesIfAny(insufficientBalances, rolCfg) } func GetRlyHubInsufficientBalances(config config.RollappConfig) ([]utils.NotFundedAddressData, error) { @@ -84,6 +84,7 @@ func GetRlyHubInsufficientBalances(config config.RollappConfig) ([]utils.NotFund CurrentBalance: HubRlyBalance.Amount, RequiredBalance: oneDayRelayPriceHub, Denom: consts.Denoms.Hub, + Network: config.HubData.ID, }) } return insufficientBalances, nil @@ -105,6 +106,7 @@ func GetRelayerInsufficientBalances(config config.RollappConfig) ([]utils.NotFun CurrentBalance: rolRlyData.Balance.Amount, RequiredBalance: oneDayRelayPriceRollapp, Denom: config.Denom, + Network: config.RollappID, }) } return insufficientBalances, nil diff --git a/cmd/run/run.go b/cmd/run/run.go index 3ad5d26b..f5d2f792 100644 --- a/cmd/run/run.go +++ b/cmd/run/run.go @@ -73,7 +73,7 @@ func getStartRelayerCmd(config config.RollappConfig) *exec.Cmd { func runDaWithRestarts(rollappConfig config.RollappConfig, serviceConfig *servicemanager.ServiceConfig) { damanager := datalayer.NewDAManager(rollappConfig.DA, rollappConfig.Home) daLogFilePath := utils.GetDALogFilePath(rollappConfig.Home) - startDALCCmd := damanager.GetStartDACmd(consts.DefaultCelestiaRPC) + startDALCCmd := damanager.GetStartDACmd() if startDALCCmd == nil { return } @@ -111,6 +111,5 @@ func verifyBalances(rollappConfig config.RollappConfig) { rlyAddrs, err := relayer_start.GetRlyHubInsufficientBalances(rollappConfig) utils.PrettifyErrorIfExists(err) insufficientBalances = append(insufficientBalances, rlyAddrs...) - - utils.PrintInsufficientBalancesIfAny(insufficientBalances) + utils.PrintInsufficientBalancesIfAny(insufficientBalances, rollappConfig) } diff --git a/cmd/sequencer/start/start.go b/cmd/sequencer/start/start.go index 60541b17..a923bf67 100644 --- a/cmd/sequencer/start/start.go +++ b/cmd/sequencer/start/start.go @@ -38,7 +38,7 @@ func StartCmd() *cobra.Command { sequencerInsufficientAddrs, err := utils.GetSequencerInsufficientAddrs(rollappConfig, OneDaySequencePrice) utils.PrettifyErrorIfExists(err) - utils.PrintInsufficientBalancesIfAny(sequencerInsufficientAddrs) + utils.PrintInsufficientBalancesIfAny(sequencerInsufficientAddrs, rollappConfig) LightNodeEndpoint := cmd.Flag(FlagNames.DAEndpoint).Value.String() startRollappCmd := GetStartRollappCmd(rollappConfig, LightNodeEndpoint) utils.RunBashCmdAsync(startRollappCmd, printOutput, parseError, diff --git a/cmd/utils/balance.go b/cmd/utils/balance.go index c64dcfd4..addf6ea5 100644 --- a/cmd/utils/balance.go +++ b/cmd/utils/balance.go @@ -90,6 +90,7 @@ func GetSequencerInsufficientAddrs(cfg config.RollappConfig, requiredBalance *bi CurrentBalance: seq.Balance.Amount, RequiredBalance: requiredBalance, KeyName: consts.KeysIds.HubSequencer, + Network: cfg.HubData.ID, }, }, nil } diff --git a/cmd/utils/output.go b/cmd/utils/output.go index 58311cfe..fe898d9a 100644 --- a/cmd/utils/output.go +++ b/cmd/utils/output.go @@ -3,17 +3,20 @@ package utils import ( "errors" "fmt" - "github.com/briandowns/spinner" - "github.com/olekukonko/tablewriter" "math/big" "os" "time" + + "github.com/briandowns/spinner" + "github.com/dymensionxyz/roller/config" + "github.com/olekukonko/tablewriter" ) -func PrintInsufficientBalancesIfAny(addressesData []NotFundedAddressData) { +func PrintInsufficientBalancesIfAny(addressesData []NotFundedAddressData, config config.RollappConfig) { if len(addressesData) == 0 { return } + printAddresses := func() { data := make([][]string, len(addressesData)) for i, addressData := range addressesData { @@ -22,10 +25,11 @@ func PrintInsufficientBalancesIfAny(addressesData []NotFundedAddressData) { addressData.Address, addressData.CurrentBalance.String() + addressData.Denom, addressData.RequiredBalance.String() + addressData.Denom, + addressData.Network, } } table := tablewriter.NewWriter(os.Stdout) - table.SetHeader([]string{"Name", "Address", "Current Balance", "Required Balance"}) + table.SetHeader([]string{"Name", "Address", "Current", "Required", "Network"}) table.SetAlignment(tablewriter.ALIGN_LEFT) table.SetHeaderAlignment(tablewriter.ALIGN_LEFT) table.SetBorder(false) @@ -45,6 +49,7 @@ type NotFundedAddressData struct { CurrentBalance *big.Int RequiredBalance *big.Int Denom string + Network string } func GetLoadingSpinner() *spinner.Spinner { diff --git a/data_layer/celestia/celestia.go b/data_layer/celestia/celestia.go index e2671f73..d59e2172 100644 --- a/data_layer/celestia/celestia.go +++ b/data_layer/celestia/celestia.go @@ -13,8 +13,11 @@ import ( // TODO: test how much is enough to run the LC for one day and set the minimum balance accordingly. const ( - gatewayAddr = "0.0.0.0" - gatewayPort = "26659" + gatewayAddr = "0.0.0.0" + gatewayPort = "26659" + CelestiaRestApiEndpoint = "https://api-mocha.pops.one" + DefaultCelestiaRPC = "rpc-mocha.pops.one" + DefaultCelestiaNetwork = "mocha" ) var ( @@ -23,7 +26,8 @@ var ( ) type Celestia struct { - Root string + Root string + rpcEndpoint string } func (c *Celestia) GetLightNodeEndpoint() string { @@ -47,7 +51,7 @@ func (c *Celestia) GetDAAccountAddress() (string, error) { // TODO: wrap in some DA interfafce to be used for Avail as well func (c *Celestia) InitializeLightNodeConfig() error { - initLightNodeCmd := exec.Command(consts.Executables.Celestia, "light", "init", "--p2p.network", consts.DefaultCeletiaNetowrk, "--node.store", filepath.Join(c.Root, consts.ConfigDirName.DALightNode)) + initLightNodeCmd := exec.Command(consts.Executables.Celestia, "light", "init", "--p2p.network", DefaultCelestiaNetwork, "--node.store", filepath.Join(c.Root, consts.ConfigDirName.DALightNode)) err := initLightNodeCmd.Run() if err != nil { return err @@ -62,7 +66,7 @@ func (c *Celestia) getDAAccData(config.RollappConfig) (*utils.AccountData, error } var restQueryUrl = fmt.Sprintf( "%s/cosmos/bank/v1beta1/balances/%s", - consts.CelestiaRestApiEndpoint, celAddress, + CelestiaRestApiEndpoint, celAddress, ) balancesJson, err := utils.RestQueryJson(restQueryUrl) if err != nil { @@ -96,19 +100,28 @@ func (c *Celestia) CheckDABalance() ([]utils.NotFundedAddressData, error) { RequiredBalance: lcMinBalance, KeyName: consts.KeysIds.DALightNode, Denom: consts.Denoms.Celestia, + Network: DefaultCelestiaNetwork, }) } return insufficientBalances, nil } -func (c *Celestia) GetStartDACmd(rpcEndpoint string) *exec.Cmd { +func (c *Celestia) GetStartDACmd() *exec.Cmd { return exec.Command( consts.Executables.Celestia, "light", "start", - "--core.ip", rpcEndpoint, + "--core.ip", c.rpcEndpoint, "--node.store", filepath.Join(c.Root, consts.ConfigDirName.DALightNode), "--gateway", "--gateway.addr", gatewayAddr, "--gateway.port", gatewayPort, - "--p2p.network", consts.DefaultCeletiaNetowrk, + "--p2p.network", DefaultCelestiaNetwork, ) } + +func (c *Celestia) SetRPCEndpoint(rpc string) { + c.rpcEndpoint = rpc +} + +func (c *Celestia) GetNetworkName() string { + return DefaultCelestiaNetwork +} diff --git a/data_layer/da_layer.go b/data_layer/da_layer.go index 2e6fb4c5..bf3d8754 100644 --- a/data_layer/da_layer.go +++ b/data_layer/da_layer.go @@ -13,9 +13,11 @@ type DataLayer interface { GetDAAccountAddress() (string, error) InitializeLightNodeConfig() error CheckDABalance() ([]utils.NotFundedAddressData, error) - GetStartDACmd(rpcEndpoint string) *exec.Cmd + GetStartDACmd() *exec.Cmd GetDAAccData(c config.RollappConfig) ([]utils.AccountData, error) GetLightNodeEndpoint() string + SetRPCEndpoint(string) + GetNetworkName() string } type DAManager struct { diff --git a/data_layer/damock/damock.go b/data_layer/damock/damock.go index 199d8b98..df74e6cf 100644 --- a/data_layer/damock/damock.go +++ b/data_layer/damock/damock.go @@ -28,7 +28,7 @@ func (d *DAMock) CheckDABalance() ([]utils.NotFundedAddressData, error) { return []utils.NotFundedAddressData{}, nil } -func (d *DAMock) GetStartDACmd(rpcEndpoint string) *exec.Cmd { +func (d *DAMock) GetStartDACmd() *exec.Cmd { return nil } @@ -47,3 +47,10 @@ func (d *DAMock) GetDAAccData(c config.RollappConfig) ([]utils.AccountData, erro func (d *DAMock) GetLightNodeEndpoint() string { return "" } + +func (d *DAMock) SetRPCEndpoint(string) { +} + +func (d *DAMock) GetNetworkName() string { + return "mock" +}