Skip to content

Commit

Permalink
chore: Add network ID when displaying addresses that require funding (#…
Browse files Browse the repository at this point in the history
…173)

Co-authored-by: Michael Tsitrin <[email protected]>
  • Loading branch information
ItayLevyOfficial and mtsitrin authored Jul 5, 2023
1 parent 969670b commit 9a0bce3
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 44 deletions.
8 changes: 4 additions & 4 deletions cmd/config/init/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions cmd/config/init/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
}
12 changes: 7 additions & 5 deletions cmd/config/init/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 5 additions & 8 deletions cmd/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}

Expand Down Expand Up @@ -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.
Expand Down
12 changes: 7 additions & 5 deletions cmd/da-light-client/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"))
}
Expand All @@ -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() {
Expand Down
4 changes: 3 additions & 1 deletion cmd/register/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion cmd/relayer/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions cmd/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion cmd/sequencer/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions cmd/utils/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
13 changes: 9 additions & 4 deletions cmd/utils/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -45,6 +49,7 @@ type NotFundedAddressData struct {
CurrentBalance *big.Int
RequiredBalance *big.Int
Denom string
Network string
}

func GetLoadingSpinner() *spinner.Spinner {
Expand Down
29 changes: 21 additions & 8 deletions data_layer/celestia/celestia.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -23,7 +26,8 @@ var (
)

type Celestia struct {
Root string
Root string
rpcEndpoint string
}

func (c *Celestia) GetLightNodeEndpoint() string {
Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
4 changes: 3 additions & 1 deletion data_layer/da_layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 8 additions & 1 deletion data_layer/damock/damock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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"
}

0 comments on commit 9a0bce3

Please sign in to comment.