Skip to content

Commit

Permalink
feat: sequencer registration (#821)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemijspavlovs authored Aug 5, 2024
1 parent 8603b74 commit 8e7fe60
Show file tree
Hide file tree
Showing 60 changed files with 2,060 additions and 725 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
workflow_dispatch:
jobs:
end_to_end_test:
runs-on: ["arm-linux"]
runs-on: ["self-hosted"]
env:
GOPRIVATE: "github.com/dymensionxyz/*"
GH_ACCESS_TOKEN: "${{ secrets.GH_ACCESS_TOKEN }}"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:
jobs:
golangci-lint:
name: lint
runs-on: ubuntu-latest
runs-on: ["self-hosted"]
env:
GOPRIVATE: "github.com/dymensionxyz/*"
GH_ACCESS_TOKEN: "${{ secrets.GH_ACCESS_TOKEN }}"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/markdownlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- '**/*.md'
jobs:
markdownlint:
runs-on: ubuntu-latest
runs-on: ["self-hosted"]
steps:
- uses: actions/checkout@v3
- name: markdownlint-cli
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
jobs:
release:
name: release
runs-on: ubuntu-latest
runs-on: ["self-hosted"]
permissions:
pull-requests: write
actions: read
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ on:
- go.sum
jobs:
build:
runs-on: ["arm-linux"]
runs-on: ["self-hosted"]
env:
GOPRIVATE: "github.com/dymensionxyz/*"
GH_ACCESS_TOKEN: "${{ secrets.GH_ACCESS_TOKEN }}"
Expand Down
3 changes: 3 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ repos:
rev: v1.59.1
hooks:
- id: golangci-lint
name: lint Go files
args: [--new-from-rev=HEAD, -v, --fix, --exclude-use-default, --sort-results]
files: \.go$
- repo: https://github.com/compilerla/conventional-pre-commit
rev: v3.2.0
hooks:
Expand Down
10 changes: 6 additions & 4 deletions cmd/config/export/bech32.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import (
)

func getBech32Prefix(rlpCfg config.RollappConfig) (string, error) {
rollappSeqAddrInfo, err := utils.GetAddressBinary(utils.KeyConfig{
Dir: filepath.Join(rlpCfg.Home, consts.ConfigDirName.Rollapp),
ID: consts.KeysIds.RollappSequencer,
}, rlpCfg.RollappBinary)
rollappSeqAddrInfo, err := utils.GetAddressInfoBinary(
utils.KeyConfig{
Dir: filepath.Join(rlpCfg.Home, consts.ConfigDirName.Rollapp),
ID: consts.KeysIds.RollappSequencer,
}, rlpCfg.RollappBinary,
)
if err != nil {
return "", err
}
Expand Down
10 changes: 7 additions & 3 deletions cmd/config/export/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func Cmd() *cobra.Command {
Short: "Export the rollapp configurations jsons needed to list your rollapp.",
Run: func(cmd *cobra.Command, args []string) {
home := cmd.Flag(utils.FlagNames.Home).Value.String()
rlpCfg, err := config.LoadConfigFromTOML(home)
rlpCfg, err := config.LoadRollerConfigFromTOML(home)
utils.PrettifyErrorIfExists(err)
bech32, err := getBech32Prefix(rlpCfg)
utils.PrettifyErrorIfExists(err)
Expand All @@ -38,8 +38,12 @@ func Cmd() *cobra.Command {
rly := relayer.NewRelayer(rlpCfg.Home, rlpCfg.RollappID, rlpCfg.HubData.ID)
_, _, err = rly.LoadActiveChannel()
if err != nil || rly.SrcChannel == "" || rly.DstChannel == "" {
utils.PrettifyErrorIfExists(errors.New("failed to export rollapp json." +
" Please verify that the rollapp is running on your local machine and a relayer channel has been established"))
utils.PrettifyErrorIfExists(
errors.New(
"failed to export rollapp json." +
" Please verify that the rollapp is running on your local machine and a relayer channel has been established",
),
)
}
logoDefaultPath := fmt.Sprintf("/logos/%s.png", rlpCfg.RollappID)
networkJson := NetworkJson{
Expand Down
21 changes: 0 additions & 21 deletions cmd/config/init/denom_metadata.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package initconfig

import (
"encoding/json"
"fmt"
"os"
"strings"
)

Expand Down Expand Up @@ -48,22 +46,3 @@ func getBankDenomMetadata(denom string, decimals uint) []BankDenomMetadata {
}
return metadata
}

func createTokenMetadaJSON(metadataPath string, denom string, decimals uint) error {
metadata := getBankDenomMetadata(denom, decimals)
json, err := json.Marshal(metadata)
if err != nil {
return err
}

file, err := os.Create(metadataPath)
if err != nil {
return err
}
_, err = file.WriteString(string(json))
if err != nil {
return err
}

return nil
}
38 changes: 15 additions & 23 deletions cmd/config/init/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
"github.com/dymensionxyz/roller/config"
)

const (
totalSupplyToStakingRatio = 2
)
// const (
// totalSupplyToStakingRatio = 2
// )

type PathValue struct {
Path string
Expand Down Expand Up @@ -67,7 +67,7 @@ func UpdateJSONParams(jsonFilePath string, params []PathValue) error {
}

// nolint:gofumpt
err = os.WriteFile(jsonFilePath, []byte(jsonFileContentString), 0644)
err = os.WriteFile(jsonFilePath, []byte(jsonFileContentString), 0o644)
if err != nil {
return err
}
Expand All @@ -79,12 +79,12 @@ func UpdateGenesisParams(home string, raCfg *config.RollappConfig) error {
if err != nil {
return err
}
cfg, err := config.LoadConfigFromTOML(home)
cfg, err := config.LoadRollerConfigFromTOML(home)
if err != nil {
return err
}

sa, err := getSequencerAddress(home)
sa, err := GetRollappSequencerAddress(home)
if err != nil {
return err
}
Expand Down Expand Up @@ -153,28 +153,20 @@ func getGenesisOperatorAddress(home string) (string, error) {
return a, nil
}

func getSequencerAddress(home string) (string, error) {
func GetRollappSequencerAddress(home string) (string, error) {
rollappConfigDirPath := filepath.Join(home, consts.ConfigDirName.Rollapp)
getOperatorAddrCommand := exec.Command(
consts.Executables.RollappEVM,
"keys",
"show",
consts.KeysIds.RollappSequencer,
"-a",
"--keyring-backend",
"test",
"--home",
rollappConfigDirPath,
)

addr, err := utils.ExecBashCommandWithStdout(getOperatorAddrCommand)
seqKeyConfig := utils.KeyConfig{
Dir: rollappConfigDirPath,
ID: consts.KeysIds.RollappSequencer,
ChainBinary: consts.Executables.RollappEVM,
Type: config.EVM_ROLLAPP,
}
addr, err := utils.GetAddressBinary(seqKeyConfig, seqKeyConfig.Dir)
if err != nil {
fmt.Println("seq addr failed")
return "", err
}

a := strings.TrimSpace(addr.String())
return a, nil
return addr, nil
}

// func generateGenesisTx(initConfig config.RollappConfig) error {
Expand Down
1 change: 0 additions & 1 deletion cmd/config/init/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ func CreateAddressBinary(
"--output", "json",
}
createKeyCommand := exec.Command(keyConfig.ChainBinary, args...)
fmt.Println(createKeyCommand.String())
out, err := utils.ExecBashCommandWithStdout(createKeyCommand)
if err != nil {
return nil, err
Expand Down
53 changes: 22 additions & 31 deletions cmd/config/init/unique_rollapp_id.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
package initconfig

import (
"encoding/json"
"os/exec"

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

type Rollapp struct {
ID string `json:"rollappId"`
}
Expand All @@ -17,25 +8,25 @@ type RollappsListResponse struct {
Rollapps []Rollapp `json:"rollapp"`
}

func isEthIdentifierUnique(ethID string, rlpCfg config.RollappConfig) (bool, error) {
commonDymdFlags := utils.GetCommonDymdFlags(rlpCfg)
// TODO: Move the filtering by ethereum rollapp ID logic to the hub
args := []string{"q", "rollapp", "list", "--limit", "1000000"}
args = append(args, commonDymdFlags...)
listRollappCmd := exec.Command(consts.Executables.Dymension, args...)
out, err := utils.ExecBashCommandWithStdout(listRollappCmd)
if err != nil {
return false, err
}
rollappsListResponse := RollappsListResponse{}
err = json.Unmarshal(out.Bytes(), &rollappsListResponse)
if err != nil {
return false, err
}
for _, rollapp := range rollappsListResponse.Rollapps {
if config.GetEthID(rollapp.ID) == ethID {
return false, nil
}
}
return true, nil
}
// func isEthIdentifierUnique(ethID string, rlpCfg config.RollappConfig) (bool, error) {
// commonDymdFlags := utils.GetCommonDymdFlags(rlpCfg)
// // TODO: Move the filtering by ethereum rollapp ID logic to the hub
// args := []string{"q", "rollapp", "list", "--limit", "1000000"}
// args = append(args, commonDymdFlags...)
// listRollappCmd := exec.Command(consts.Executables.Dymension, args...)
// out, err := utils.ExecBashCommandWithStdout(listRollappCmd)
// if err != nil {
// return false, err
// }
// rollappsListResponse := RollappsListResponse{}
// err = json.Unmarshal(out.Bytes(), &rollappsListResponse)
// if err != nil {
// return false, err
// }
// for _, rollapp := range rollappsListResponse.Rollapps {
// if config.GetEthID(rollapp.ID) == ethID {
// return false, nil
// }
// }
// return true, nil
// }
19 changes: 13 additions & 6 deletions cmd/config/set/da.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/dymensionxyz/roller/config"
datalayer "github.com/dymensionxyz/roller/data_layer"
"github.com/dymensionxyz/roller/sequencer"
global_utils "github.com/dymensionxyz/roller/utils"
globalutils "github.com/dymensionxyz/roller/utils"
)

func setDA(rlpCfg config.RollappConfig, value string) error {
Expand All @@ -27,10 +27,11 @@ func setDA(rlpCfg config.RollappConfig, value string) error {

func updateDaConfig(rlpCfg config.RollappConfig, newDa config.DAType) error {
daCfgDirPath := filepath.Join(rlpCfg.Home, consts.ConfigDirName.DALightNode)
dirExist, err := global_utils.DirNotEmpty(daCfgDirPath)
dirExist, err := globalutils.DirNotEmpty(daCfgDirPath)
if err != nil {
return err
}

if dirExist {
if yes, err := utils.PromptBool("Changing DA will remove the old DA keys permanently. Are you sure you want to proceed"); err != nil {
return err
Expand All @@ -41,18 +42,22 @@ func updateDaConfig(rlpCfg config.RollappConfig, newDa config.DAType) error {
if err := os.RemoveAll(daCfgDirPath); err != nil {
return err
}

daManager := datalayer.NewDAManager(newDa, rlpCfg.Home)
_, err = daManager.InitializeLightNodeConfig()
if err != nil {
return err
}

rlpCfg.DA = newDa
if err := sequencer.UpdateDymintDAConfig(rlpCfg); err != nil {
return err
}

if err := config.WriteConfigToTOML(rlpCfg); err != nil {
return err
}

fmt.Printf("💈 RollApp DA has been successfully set to '%s'\n\n", newDa)
if newDa != config.Local {
addresses := make([]utils.KeyInfo, 0)
Expand All @@ -61,10 +66,12 @@ func updateDaConfig(rlpCfg config.RollappConfig, newDa config.DAType) error {
if err != nil {
return err
}
addresses = append(addresses, utils.KeyInfo{
Name: damanager.GetKeyName(),
Address: daAddress.Address,
})
addresses = append(
addresses, utils.KeyInfo{
Name: damanager.GetKeyName(),
Address: daAddress.Address,
},
)

utils.PrintAddressesWithTitle(addresses)
fmt.Printf("\n🔔 Please fund this address to run the DA light client.\n")
Expand Down
5 changes: 3 additions & 2 deletions cmd/config/set/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"fmt"
"strings"

"github.com/spf13/cobra"

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

var keyUpdateFuncs = map[string]func(cfg config.RollappConfig, value string) error{
Expand All @@ -31,7 +32,7 @@ func Cmd() *cobra.Command {
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
home := cmd.Flag(utils.FlagNames.Home).Value.String()
rlpCfg, err := config.LoadConfigFromTOML(home)
rlpCfg, err := config.LoadRollerConfigFromTOML(home)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ var KeysIds = struct {
RollappSequencer string
RollappRelayer string
HubRelayer string
Celestia string
}{
HubSequencer: "hub_sequencer",
HubGenesis: "hub_genesis",
RollappSequencer: "rollapp_genesis_account",
RollappRelayer: "relayer-rollapp-key",
HubRelayer: "relayer-hub-key",
Celestia: "my_celes_key",
}

var AddressPrefixes = struct {
Expand Down Expand Up @@ -115,7 +117,6 @@ var LocalHubData = config.HubData{
RPC_URL: "http://localhost:36657",
ARCHIVE_RPC_URL: "http://localhost:36657",
GAS_PRICE: "100000000",
SEQ_MIN_BOND: "100dym",
}

var MockHubData = config.HubData{
Expand All @@ -124,7 +125,6 @@ var MockHubData = config.HubData{
RPC_URL: "",
ARCHIVE_RPC_URL: "",
GAS_PRICE: "",
SEQ_MIN_BOND: "",
}

// TODO(#112): The available hub networks should be read from YAML file
Expand Down
Loading

0 comments on commit 8e7fe60

Please sign in to comment.