Skip to content

Commit

Permalink
Implemented sequencer registration on roller register command
Browse files Browse the repository at this point in the history
  • Loading branch information
ItayLevyOfficial committed Jun 15, 2023
1 parent eaa2728 commit 11cd784
Show file tree
Hide file tree
Showing 13 changed files with 241 additions and 47 deletions.
3 changes: 0 additions & 3 deletions cmd/config/init/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ import (

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

"github.com/dymensionxyz/roller/cmd/utils"
)

func addFlags(cmd *cobra.Command) {
cmd.Flags().StringP(FlagNames.HubID, "", TestnetHubID, fmt.Sprintf("The ID of the Dymension hub. %s", getAvailableHubsMessage()))
cmd.Flags().StringP(FlagNames.DAEndpoint, "", "", "The data availability light node endpoint. Runs an Arabica Celestia light node if not provided")
cmd.Flags().StringP(FlagNames.RollappBinary, "", "", "The rollapp binary. Should be passed only if you built a custom rollapp")
cmd.Flags().Uint64P(FlagNames.Decimals, "", 18, "The number of decimal places a rollapp token supports")
cmd.Flags().StringP(FlagNames.Home, "", utils.GetRollerRootDir(), "The directory of the roller config files")

cmd.PreRunE = func(cmd *cobra.Command, args []string) error {
hubID, err := cmd.Flags().GetString(FlagNames.HubID)
Expand Down
8 changes: 4 additions & 4 deletions cmd/config/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type InitConfig struct {
}

func InitCmd() *cobra.Command {
cmd := &cobra.Command{
initCmd := &cobra.Command{
Use: "init <chain-id> <denom>",
Short: "Initialize a RollApp configuration on your local machine.",
Run: func(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -59,7 +59,7 @@ func InitCmd() *cobra.Command {
},
Args: cobra.ExactArgs(2),
}

addFlags(cmd)
return cmd
utils.AddGlobalFlags(initCmd)
addFlags(initCmd)
return initCmd
}
65 changes: 65 additions & 0 deletions cmd/register/bash_commands.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package register

import (
"os/exec"
"path/filepath"

"fmt"

"strings"

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

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)...)
return exec.Command(
consts.Executables.Dymension, cmdArgs...,
)
}

func showSequencerPubKey(rollappConfig initconfig.InitConfig) (string, error) {
cmd := exec.Command(
consts.Executables.RollappEVM,
"dymint",
"show-sequencer",
"--home",
filepath.Join(rollappConfig.Home, consts.ConfigDirName.Rollapp),
)
out, err := cmd.Output()
if err != nil {
return "", err
}
return strings.ReplaceAll(strings.ReplaceAll(string(out), "\n", ""), "\\", ""), nil
}

func getRegisterSequencerCmd(rollappConfig initconfig.InitConfig) (*exec.Cmd, error) {
seqPubKey, err := showSequencerPubKey(rollappConfig)
if err != nil {
return nil, err
}
description := fmt.Sprintf(`{"Moniker":"%s","Identity":"","Website":"","SecurityContact":"","Details":""}`,
consts.KeyNames.HubSequencer)
cmdArgs := []string{
"tx", "sequencer", "create-sequencer",
seqPubKey,
rollappConfig.RollappID,
description,
}
cmdArgs = append(cmdArgs, GetCommonFlags(rollappConfig)...)
return exec.Command(consts.Executables.Dymension, cmdArgs...), nil
}

func GetCommonFlags(rollappConfig initconfig.InitConfig) []string {
return []string{
"--from", consts.KeyNames.HubSequencer,
"--keyring-backend", "test",
"--keyring-dir", filepath.Join(rollappConfig.Home, consts.ConfigDirName.Rollapp),
"--node", rollappConfig.HubData.RPC_URL, "--output", "json",
"--yes", "--broadcast-mode", "block", "--chain-id", rollappConfig.HubData.ID,
}
}
22 changes: 8 additions & 14 deletions cmd/register/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ package register
import (
"bytes"
"errors"
"os/exec"
"github.com/dymensionxyz/roller/cmd/consts"
"path/filepath"

"fmt"

"strings"

"encoding/json"

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

func RegisterCmd() *cobra.Command {
Expand All @@ -26,6 +27,10 @@ func RegisterCmd() *cobra.Command {
utils.PrettifyErrorIfExists(err)
utils.PrettifyErrorIfExists(initconfig.VerifyUniqueRollappID(rollappConfig.RollappID, rollappConfig))
utils.PrettifyErrorIfExists(registerRollapp(rollappConfig))
registerSequencerCmd, err := getRegisterSequencerCmd(rollappConfig)
utils.PrettifyErrorIfExists(err)
err = registerSequencerCmd.Run()
utils.PrettifyErrorIfExists(err)
printRegisterOutput(rollappConfig)
},
}
Expand Down Expand Up @@ -97,17 +102,6 @@ func handleStdOut(stdout bytes.Buffer, rollappConfig initconfig.InitConfig) erro
return nil
}

func getRegisterRollappCmd(rollappConfig initconfig.InitConfig) *exec.Cmd {
return exec.Command(
consts.Executables.Dymension, "tx", "rollapp", "create-rollapp",
"--from", consts.KeyNames.HubSequencer,
"--keyring-backend", "test",
"--keyring-dir", filepath.Join(rollappConfig.Home, consts.ConfigDirName.Rollapp),
rollappConfig.RollappID, "stamp1", "genesis-path/1", "3", "3", `{"Addresses":[]}`, "--output", "json",
"--node", rollappConfig.HubData.RPC_URL, "--yes", "--broadcast-mode", "block", "--chain-id", rollappConfig.HubData.ID,
)
}

func printRegisterOutput(rollappConfig initconfig.InitConfig) {
fmt.Printf("💈 Rollapp '%s' has been successfully registered on the hub.\n", rollappConfig.RollappID)
}
22 changes: 22 additions & 0 deletions cmd/utils/global_flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package utils

import (
"os"
"path/filepath"

"github.com/spf13/cobra"
)

func AddGlobalFlags(command *cobra.Command) {
command.Flags().StringP(FlagNames.Home, "", GetRollerRootDir(), "The directory of the roller config files")
}

var FlagNames = struct {
Home string
}{
Home: "home",
}

func GetRollerRootDir() string {
return filepath.Join(os.Getenv("HOME"), ".roller")
}
11 changes: 0 additions & 11 deletions cmd/utils/utils.go

This file was deleted.

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 11cd784

Please sign in to comment.