8000 feat: add flags to setup node by artemijspavlovs · Pull Request #1349 · dymensionxyz/roller · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: add flags to setup node #1349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions cmd/rollapp/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/dymensionxyz/roller/utils/config/scripts"
"github.com/dymensionxyz/roller/utils/config/tomlconfig"
"github.com/dymensionxyz/roller/utils/dependencies"
"github.com/dymensionxyz/roller/utils/filesystem"
rollerfs "github.com/dymensionxyz/roller/utils/filesystem"
"github.com/dymensionxyz/roller/utils/keys"
"github.com/dymensionxyz/roller/utils/rollapp"
"github.com/dymensionxyz/roller/utils/roller"
Expand All @@ -33,14 +33,18 @@ func Cmd() *cobra.Command {
Run: func(cmd *cobra.Command, args []string) {
shouldUseMockBackend, _ := cmd.Flags().GetBool("mock")
shouldSkipBinaryInstallation, _ := cmd.Flags().GetBool("skip-binary-installation")
shouldGenerateSequencerAddress, _ := cmd.Flags().GetBool("generate-sequencer-address")
forceOverwrite, _ := cmd.Flags().GetBool("overwrite")

envFromFlag, _ := cmd.Flags().GetString("env")

err := initconfig.AddFlags(cmd)
if err != nil {
pterm.Error.Println("failed to initialize rollapp: ", err)
return
}

home, err := filesystem.ExpandHomePath(
home, err := rollerfs.ExpandHomePath(
cmd.Flag(initconfig.GlobalFlagNames.Home).Value.String(),
)
if err != nil {
Expand All @@ -53,7 +57,7 @@ func Cmd() *cobra.Command {
var env string
var raID string

isRootExist, err := filesystem.DirNotEmpty(home)
isRootExist, err := rollerfs.DirNotEmpty(home)
if err != nil {
pterm.Error.Printf(
"failed to check if roller home directory (%s) is empty: %v\n",
Expand Down Expand Up @@ -100,7 +104,7 @@ func Cmd() *cobra.Command {
return
}

err = filesystem.CreateRollerRootWithOptionalOverride(home)
err = rollerfs.CreateRollerRootWithOptionalOverride(home, forceOverwrite)
if err != nil {
pterm.Error.Printf(
"failed to create roller home directory (%s): %v\n",
Expand All @@ -119,11 +123,15 @@ func Cmd() *cobra.Command {
if shouldUseMockBackend {
env = "mock"
} else {
envs := []string{"mock", "playground", "blumbus", "custom", "mainnet"}
env, _ = pterm.DefaultInteractiveSelect.
WithDefaultText("select the environment you want to initialize for").
WithOptions(envs).
Show()
if envFromFlag == "" {
envs := []string{"mock", "playground", "blumbus", "custom", "mainnet"}
env, _ = pterm.DefaultInteractiveSelect.
WithDefaultText("select the environment you want to initialize for").
WithOptions(envs).
Show()
} else {
env = envFromFlag
}
}

if env == "mainnet" {
Expand Down Expand Up @@ -182,7 +190,8 @@ func Cmd() *cobra.Command {
GasPrice: chd.GasPrice,
}

hdws, _ := pterm.DefaultInteractiveTextInput.WithDefaultText("provide hub websocket endpoint, only fill this in when RPC and WebSocket are separate (optional)").Show()
hdws, _ := pterm.DefaultInteractiveTextInput.WithDefaultText("provide hub websocket endpoint, only fill this in when RPC and WebSocket are separate (optional)").
Show()
if hdws == "" {
hd.WsUrl = hd.RpcUrl
} else {
Expand Down Expand Up @@ -219,6 +228,7 @@ func Cmd() *cobra.Command {
hd,
raRespMock,
kb,
shouldGenerateSequencerAddress,
)
if err != nil {
fmt.Println("failed to run init: ", err)
Expand All @@ -227,7 +237,8 @@ func Cmd() *cobra.Command {
return
case "mainnet":
hd = consts.Hubs[env]
hdws, _ := pterm.DefaultInteractiveTextInput.WithDefaultText("provide hub websocket endpoint, only fill this in when RPC and WebSocket are separate (optional)").Show()
hdws, _ := pterm.DefaultInteractiveTextInput.WithDefaultText("provide hub websocket endpoint, only fill this in when RPC and WebSocket are separate (optional)").
Show()
if hdws == "" {
hd.WsUrl = hd.RpcUrl
} else {
Expand Down Expand Up @@ -303,7 +314,7 @@ func Cmd() *cobra.Command {

// TODO: all above should be wrapped in "InitDependencies"

err = runInit(home, env, hd, *raResponse, kb)
err = runInit(home, env, hd, *raResponse, kb, shouldGenerateSequencerAddress)
if err != nil {
pterm.Error.Printf("failed to initialize the RollApp: %v\n", err)
return
Expand Down Expand Up @@ -350,6 +361,10 @@ func Cmd() *cobra.Command {

cmd.Flags().Bool("mock", false, "initialize the rollapp with mock backend")
cmd.Flags().Bool("skip-binary-installation", false, "skips the binary installation")
cmd.Flags().Bool("generate-sequencer-address", true, "generates a sequencer address")
cmd.Flags().String("env", "", "environment to initialize the rollapp for")
cmd.Flags().
Bool("overwrite", false, "DANGER! overwrites the existing roller home directory without prompting")

return cmd
}
12 changes: 9 additions & 3 deletions cmd/rollapp/init/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func runInit(
hubData consts.HubData,
raResp rollapp.ShowRollappResponse,
kb consts.SupportedKeyringBackend,
shouldGenerateSequencerAddress bool,
) error {
raID := raResp.Rollapp.RollappId

Expand Down Expand Up @@ -54,7 +55,7 @@ func runInit(
/* ------------------------------ Generate keys ----------------------------- */
var addresses []keys.KeyInfo

sequencerKeys, err := initSequencerKeys(home, env, ic)
sequencerKeys, err := initSequencerKeys(home, env, ic, shouldGenerateSequencerAddress)
if err != nil {
return err
}
Expand Down Expand Up @@ -175,12 +176,17 @@ func runInit(
return nil
}

func initSequencerKeys(home string, env string, ic roller.RollappConfig) ([]keys.KeyInfo, error) {
func initSequencerKeys(
home string,
env string,
ic roller.RollappConfig,
shouldGenerateSequencerAddress bool,
) ([]keys.KeyInfo, error) {
err := keys.CreateSequencerOsKeyringPswFile(home)
if err != nil {
return nil, err
}
sequencerKeys, err := keys.GenerateSequencerKeys(home, env, ic)
sequencerKeys, err := keys.GenerateSequencerKeys(home, env, ic, shouldGenerateSequencerAddress)
if err != nil {
return nil, err
}
Expand Down
47 changes: 35 additions & 12 deletions cmd/rollapp/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ func Cmd() *cobra.Command {
Long: ``,
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
nodeTypes := []string{"sequencer", "fullnode"}
fullNodeTypes := []string{"rpc", "archive"}

nodeTypeFromFlag, _ := cmd.Flags().GetString("node-type")
fullNodeTypeFromFlag, _ := cmd.Flags().GetString("full-node-type")

err := initconfig.AddFlags(cmd)
if err != nil {
pterm.Error.Println("failed to add flags")
Expand Down Expand Up @@ -138,11 +144,15 @@ RollApp's IRO time: %v`,
return
}

options := []string{"sequencer", "fullnode"}
nodeType, _ := pterm.DefaultInteractiveSelect.
WithDefaultText("select the node type you want to run").
WithOptions(options).
Show()
var nodeType string
if slices.Contains(nodeTypes, nodeTypeFromFlag) {
nodeType = nodeTypeFromFlag
} else {
nodeType, _ = pterm.DefaultInteractiveSelect.
WithDefaultText("select the node type you want to run").
WithOptions(nodeTypes).
Show()
}

rollerConfigFilePath := filepath.Join(home, consts.RollerConfigFileName)
err = tomlconfig.UpdateFieldInFile(rollerConfigFilePath, "node_type", nodeType)
Expand Down Expand Up @@ -706,11 +716,16 @@ RollApp's IRO time: %v`,
return
}

fullNodeTypes := []string{"rpc", "archive"}
fullNodeType, _ := pterm.DefaultInteractiveSelect.
WithDefaultText("select the environment you want to initialize for").
WithOptions(fullNodeTypes).
Show()
var fullNodeType string
if slices.Contains(fullNodeTypes, fullNodeTypeFromFlag) {
fullNodeType = fullNodeTypeFromFlag
} else {
fullNodeType, _ = pterm.DefaultInteractiveSelect.
WithDefaultText("select the environment you want to initialize for").
WithOptions(fullNodeTypes).
Show()
}

var fnVtu map[string]any

switch fullNodeType {
Expand Down Expand Up @@ -783,6 +798,9 @@ RollApp's IRO time: %v`,
},
}

cmd.Flags().String("node-type", "", "node type ( supported values: [sequencer, fullnode] )")
cmd.Flags().String("full-node-type", "", "full node type ( supported values: [rpc, archive] )")

return cmd
}

Expand Down Expand Up @@ -1078,8 +1096,13 @@ func getDaLayer(home string, raResponse *rollapp.ShowRollappResponse, daType con
}
}

func getDaConfig(dataLayer datalayer.DataLayer, nodeType string, home string, raResponse *rollapp.ShowRollappResponse, rollappConfig *roller.RollappConfig) any {

func getDaConfig(
dataLayer datalayer.DataLayer,
nodeType string,
home string,
raResponse *rollapp.ShowRollappResponse,
rollappConfig *roller.RollappConfig,
) any {
daConfig := dataLayer.GetSequencerDAConfig(consts.NodeType.Sequencer)

drsVersion, err := genesis.GetDrsVersionFromGenesis(home, raResponse)
Expand Down
17 changes: 10 additions & 7 deletions utils/filesystem/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func DirNotEmpty(path string) (bool, error) {
return len(files) > 0, err
}

func CreateRollerRootWithOptionalOverride(home string) error {
func CreateRollerRootWithOptionalOverride(home string, forceOverwrite bool) error {
isRootExist, err := DirNotEmpty(home)
if err != nil {
return err
Expand All @@ -43,14 +43,17 @@ func CreateRollerRootWithOptionalOverride(home string) error {
if isRootExist {
fmt.Printf("Directory %s is not empty.\n", home)

shouldOverwrite, err := pterm.DefaultInteractiveConfirm.WithDefaultText(fmt.Sprintf("Do you want to overwrite %s?", home)).
WithDefaultValue(false).
Show()
if err != nil {
return err
var shouldOverwrite bool
if !forceOverwrite {
shouldOverwrite, err = pterm.DefaultInteractiveConfirm.WithDefaultText(fmt.Sprintf("Do you want to overwrite %s?", home)).
WithDefaultValue(false).
Show()
if err != nil {
return err
}
}

if shouldOverwrite {
if shouldOverwrite || forceOverwrite {
err = os.RemoveAll(home)
if err != nil {
return err
Expand Down
23 changes: 17 additions & 6 deletions utils/keys/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ func CreateDaOsKeyringPswFile(home string) error {
return config.WritePasswordToFile(daFp)
}

func GenerateSequencerKeys(home, env string, rollerData roller.RollappConfig) ([]KeyInfo, error) {
func GenerateSequencerKeys(
home, env string,
rollerData roller.RollappConfig,
shouldGenerateSequencerAddress bool,
) ([]KeyInfo, error) {
var k []KeyInfo
var err error

Expand All @@ -55,7 +59,7 @@ func GenerateSequencerKeys(home, env string, rollerData roller.RollappConfig) ([
return nil, err
}
} else {
k, err = generateRaSequencerKeys(home, rollerData)
k, err = generateRaSequencerKeys(home, rollerData, shouldGenerateSequencerAddress)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -86,10 +90,17 @@ func generateMockSequencerKeys(initConfig roller.RollappConfig) ([]KeyInfo, erro
return addresses, nil
}

func generateRaSequencerKeys(home string, rollerData roller.RollappConfig) ([]KeyInfo, error) {
useExistingSequencerWallet, _ := pterm.DefaultInteractiveConfirm.WithDefaultText(
"would you like to import an existing sequencer key?",
).Show()
func generateRaSequencerKeys(
home string,
rollerData roller.RollappConfig,
shouldGenerateSequencerAddress bool,
) ([]KeyInfo, error) {
var useExistingSequencerWallet bool
if !shouldGenerateSequencerAddress {
useExistingSequencerWallet, _ = pterm.DefaultInteractiveConfirm.WithDefaultText(
"would you like to import an existing sequencer key?",
).Show()
}

var addr []KeyInfo
var err error
Expand Down
Loading
0