Skip to content

Commit

Permalink
Merge branch 'itaylevyofficial/58-run-error-handling' into itaylevyof…
Browse files Browse the repository at this point in the history
…ficial/70-run-da-light-node

# Conflicts:
#	cmd/config/init/flags.go
#	cmd/config/init/init.go
#	cmd/register/bash_commands.go
#	cmd/register/register.go
#	cmd/root.go
  • Loading branch information
ItayLevyOfficial committed Jun 18, 2023
2 parents 1999f00 + 823119c commit cfd8958
Show file tree
Hide file tree
Showing 12 changed files with 239 additions and 30 deletions.
2 changes: 0 additions & 2 deletions cmd/config/init/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ package initconfig

var FlagNames = struct {
Home string
DAEndpoint string
Decimals string
RollappBinary string
HubID string
}{
Home: "home",
DAEndpoint: "data-availability-endpoint",
Decimals: "decimals",
RollappBinary: "rollapp-binary",
HubID: "hub",
Expand Down
12 changes: 6 additions & 6 deletions cmd/config/init/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ func GetInitConfig(initCmd *cobra.Command, args []string) InitConfig {
decimals := getDecimals(initCmd)
hubID := initCmd.Flag(FlagNames.HubID).Value.String()
return InitConfig{
Home: home,
RollappID: rollappId,
RollappBinary: rollappBinaryPath,
Denom: denom,
Decimals: decimals,
HubData: Hubs[hubID],
Home: home,
RollappID: rollappId,
RollappBinary: rollappBinaryPath,
Denom: denom,
Decimals: decimals,
HubData: Hubs[hubID],
}
}

Expand Down
8 changes: 2 additions & 6 deletions cmd/config/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ package initconfig
import (
"os"

"path/filepath"

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

Expand Down Expand Up @@ -37,6 +35,7 @@ func InitCmd() *cobra.Command {
os.Exit(0)
}
}

addresses, err := generateKeys(initConfig)
utils.PrettifyErrorIfExists(err)
utils.PrettifyErrorIfExists(initializeLightNodeConfig(initConfig))
Expand All @@ -54,9 +53,6 @@ func InitCmd() *cobra.Command {
AddressPrefix: consts.AddressPrefixes.Hub,
}, initConfig))
utils.PrettifyErrorIfExists(WriteConfigToTOML(initConfig))
daLightNodeAddress, err := utils.GetCelestiaAddress(filepath.Join(initConfig.Home, consts.ConfigDirName.DALightNode, KeysDirName))
utils.PrettifyErrorIfExists(err)
addresses[consts.KeyNames.DALightNode] = daLightNodeAddress
printInitOutput(addresses, initConfig.RollappID)
},
Args: cobra.ExactArgs(2),
Expand Down
6 changes: 3 additions & 3 deletions cmd/register/bash_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func getRegisterRollappCmd(rollappConfig initconfig.InitConfig) *exec.Cmd {
cmdArgs := []string{
"tx", "rollapp", "create-rollapp", rollappConfig.RollappID, "stamp1", "genesis-path/1", "3", "3", `{"Addresses":[]}`,
}
cmdArgs = append(cmdArgs, GetCommonFlags(rollappConfig)...)
cmdArgs = append(cmdArgs, getCommonFlags(rollappConfig)...)
return exec.Command(
consts.Executables.Dymension, cmdArgs...,
)
Expand Down Expand Up @@ -50,11 +50,11 @@ func getRegisterSequencerCmd(rollappConfig initconfig.InitConfig) (*exec.Cmd, er
rollappConfig.RollappID,
description,
}
cmdArgs = append(cmdArgs, GetCommonFlags(rollappConfig)...)
cmdArgs = append(cmdArgs, getCommonFlags(rollappConfig)...)
return exec.Command(consts.Executables.Dymension, cmdArgs...), nil
}

func GetCommonFlags(rollappConfig initconfig.InitConfig) []string {
func getCommonFlags(rollappConfig initconfig.InitConfig) []string {
return []string{
"--from", consts.KeyNames.HubSequencer,
"--keyring-backend", "test",
Expand Down
5 changes: 2 additions & 3 deletions cmd/register/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"encoding/json"

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

Expand All @@ -26,8 +26,7 @@ func RegisterCmd() *cobra.Command {
rollappConfig, err := initconfig.LoadConfigFromTOML(home)
utils.PrettifyErrorIfExists(err)
utils.PrettifyErrorIfExists(initconfig.VerifyUniqueRollappID(rollappConfig.RollappID, rollappConfig))
err = registerRollapp(rollappConfig)
utils.PrettifyErrorIfExists(err)
utils.PrettifyErrorIfExists(registerRollapp(rollappConfig))
registerSequencerCmd, err := getRegisterSequencerCmd(rollappConfig)
utils.PrettifyErrorIfExists(err)
err = registerSequencerCmd.Run()
Expand Down
90 changes: 90 additions & 0 deletions cmd/run/run.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package run

import (
"fmt"
"github.com/dymensionxyz/roller/cmd/consts"
"os/exec"
"path/filepath"

"errors"

"bytes"

"strings"

initconfig "github.com/dymensionxyz/roller/cmd/config/init"
"github.com/dymensionxyz/roller/cmd/utils"
"github.com/spf13/cobra"
)

const daLightClientEndpointFlag = "da-light-client-endpoint"

func RunCmd() *cobra.Command {
runCmd := &cobra.Command{
Use: "run",
Short: "Runs the rollapp sequencer.",
Run: func(cmd *cobra.Command, args []string) {
home := cmd.Flag(utils.FlagNames.Home).Value.String()
rollappConfig, err := initconfig.LoadConfigFromTOML(home)
utils.PrettifyErrorIfExists(err)
startRollappCmd := getStartRollapCmd(rollappConfig, cmd.Flag(daLightClientEndpointFlag).Value.String())
var stderr bytes.Buffer
startRollappCmd.Stderr = &stderr
startRollappErr := startRollappCmd.Start()
if startRollappErr != nil {
errMsg := parseError(stderr.String())
utils.PrettifyErrorIfExists(errors.New(errMsg))
}
utils.PrettifyErrorIfExists(startRollappErr)
fmt.Println("💈 The Rollapp sequencer is running on your local machine!")
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")
err = startRollappCmd.Wait()
if err != nil {
errMsg := parseError(stderr.String())
utils.PrettifyErrorIfExists(errors.New(errMsg))
}
},
}
utils.AddGlobalFlags(runCmd)
addFlags(runCmd)
return runCmd
}

func addFlags(cmd *cobra.Command) {
cmd.Flags().StringP(daLightClientEndpointFlag, "", "http://localhost:26659", "The DA light client endpoint.")
}
func parseError(errMsg string) string {
lines := strings.Split(errMsg, "\n")
if len(lines) > 0 && lines[0] == "Error: failed to initialize database: resource temporarily unavailable" {
return "The Rollapp sequencer is already running. Only one sequencer can run on the machine at any given time."
}
return errMsg
}

func getStartRollapCmd(rollappConfig initconfig.InitConfig, daEndpoint 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]}`, daEndpoint)
rollappConfigDir := filepath.Join(rollappConfig.Home, consts.ConfigDirName.Rollapp)
settlementConfig := fmt.Sprintf(`{"node_address": "%s", "rollapp_id": "%s", "dym_account_name": "%s", "keyring_home_dir": "%s", "keyring_backend":"test", "gas_fees": "2000000udym"}`, rollappConfig.HubData.RPC_URL, rollappConfig.RollappID,
consts.KeyNames.HubSequencer, rollappConfigDir)

return 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.settlement_config", settlementConfig,
"--dymint.block_batch_size", "1200",
"--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", "",
)
}
37 changes: 35 additions & 2 deletions test/config/init/goldens/init_with_flags/rollapp/config/app.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
app-db-backend = ""
halt-height = 0
halt-time = 0
iavl-cache-size = 781250
iavl-disable-fastnode = true
iavl-disable-fastnode = false
iavl-lazy-loading = false
index-events = []
inter-block-cache = true
min-retain-blocks = 0
minimum-gas-prices = "0udym"
pruning = "default"
pruning-interval = "0"
pruning-keep-every = "0"
pruning-keep-recent = "0"

[api]
Expand All @@ -21,19 +22,47 @@ pruning-keep-recent = "0"
rpc-write-timeout = 0
swagger = false

[evm]
max-tx-gas-wanted = 0
tracer = ""

[grpc]
address = "0.0.0.0:9090"
enable = true
max-recv-msg-size = "10485760"
max-send-msg-size = "2147483647"

[grpc-web]
address = "0.0.0.0:9091"
enable = true
enable-unsafe-cors = false

[json-rpc]
address = "0.0.0.0:8545"
allow-unprotected-txs = false
api = "eth,net,web3"
block-range-cap = 10000
enable = true
enable-indexer = false
evm-timeout = "5s"
feehistory-cap = 100
filter-cap = 200
gas-cap = 25000000
http-idle-timeout = "2m0s"
http-timeout = "30s"
logs-cap = 10000
max-open-connections = 0
metrics-address = "0.0.0.0:6065"
txfee-cap = 1
ws-address = "0.0.0.0:8546"

[rosetta]
address = ":8080"
blockchain = "app"
denom-to-suggest = "uatom"
enable = false
enable-fee-suggestion = false
gas-to-suggest = 200000
network = "network"
offline = false
retries = 3
Expand Down Expand Up @@ -63,3 +92,7 @@ pruning-keep-recent = "0"
global-labels = []
prometheus-retention-time = 0
service-name = ""

[tls]
certificate-path = ""
key-path = ""
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
###############################################################################

# The network chain ID
chain-id = ""
chain-id = "mars"
# The keyring's backend, where the keys are stored (os|file|kwallet|pass|test|memory)
keyring-backend = "os"
# CLI output format (text|json)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,23 @@
"index": "1",
"owners": []
},
"claims": {
"params": {
"enable_claims": true,
"airdrop_start_time": "0001-01-01T00:00:00Z",
"duration_until_decay": "2629800s",
"duration_of_decay": "5259600s",
"claims_denom": "aevmos",
"authorized_channels": [
"channel-0",
"channel-3"
],
"evm_channels": [
"channel-2"
]
},
"claims_records": []
},
"crisis": {
"constant_fee": {
"denom": "udym",
Expand Down Expand Up @@ -130,7 +147,9 @@
"london_block": "0",
"arrow_glacier_block": "0",
"gray_glacier_block": "0",
"merge_netsplit_block": "0"
"merge_netsplit_block": "0",
"shanghai_block": "0",
"cancun_block": "0"
},
"allow_unprotected_txs": false
}
Expand Down Expand Up @@ -176,6 +195,16 @@
"veto_threshold": "0.334000000000000000"
}
},
"group": {
"group_seq": "0",
"groups": [],
"group_members": [],
"group_policy_seq": "0",
"group_policies": [],
"proposal_seq": "0",
"proposals": [],
"votes": []
},
"ibc": {
"client_genesis": {
"clients": [],
Expand Down Expand Up @@ -226,7 +255,8 @@
"max_validators": 100,
"max_entries": 7,
"historical_entries": 10000,
"bond_denom": "udym"
"bond_denom": "udym",
"min_commission_rate": "0.050000000000000000"
},
"last_total_power": "0",
"last_validator_powers": [],
Expand Down
Loading

0 comments on commit cfd8958

Please sign in to comment.