Skip to content

Commit

Permalink
feat: handle sequencer bond (#906)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemijspavlovs committed Sep 9, 2024
1 parent d00987b commit c18e989
Show file tree
Hide file tree
Showing 22 changed files with 491 additions and 218 deletions.
6 changes: 4 additions & 2 deletions cmd/binaries/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func Cmd() *cobra.Command {
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
// TODO: instead of relying on dymd binary, query the rpc for rollapp
envs := []string{"devnet", "playground"}
envs := []string{"playground"}
env, _ := pterm.DefaultInteractiveSelect.
WithDefaultText("select the environment you want to initialize for").
WithOptions(envs).
Expand Down Expand Up @@ -109,7 +109,7 @@ func installBinaries(bech32 string) {
buildableDeps := map[string]dependencies.Dependency{
"rollapp": {
Repository: "https://github.com/dymensionxyz/rollapp-evm.git",
Release: "559d878e83800717c885e89f2fbe619ee081b2a1", // 20240905 light client support
Release: "e68f8190f1301b317846623a9e83be7acc2ad56e", // 20240909 rolapparams module
Binaries: []dependencies.BinaryPathPair{
{
Binary: "./build/rollapp-evm",
Expand Down Expand Up @@ -330,6 +330,8 @@ func downloadRelease(url, destination string, dep dependencies.Dependency) error
if err != nil {
return err
}

// nolint errcheck
defer resp.Body.Close()
err = archives.ExtractTarGz(destination, resp.Body, dep)
if err != nil {
Expand Down
85 changes: 0 additions & 85 deletions cmd/config/init/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"

"github.com/tidwall/sjson"

Expand Down Expand Up @@ -99,32 +98,6 @@ func GetAddGenesisAccountCmd(addr, amount string, raCfg *config.RollappConfig) *
return cmd
}

func getGenesisOperatorAddress(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,
"--bech",
"val",
)

addr, err := bash.ExecCommandWithStdout(getOperatorAddrCommand)
if err != nil {
fmt.Println("val addr failed")
return "", err
}

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

func GetRollappSequencerAddress(home string) (string, error) {
seqKeyConfig := utils.KeyConfig{
Dir: consts.ConfigDirName.Rollapp,
Expand All @@ -139,61 +112,3 @@ func GetRollappSequencerAddress(home string) (string, error) {

return addr, nil
}

// func generateGenesisTx(initConfig config.RollappConfig) error {
// err := registerSequencerAsGoverner(initConfig)
// if err != nil {
// return fmt.Errorf("failed to execute gentx command: %v", err)
// }
// // collect gentx
// rollappConfigDirPath := filepath.Join(initConfig.Home, consts.ConfigDirName.Rollapp)
// collectGentx := exec.Command(
// initConfig.RollappBinary,
// "collect-gentxs",
// "--home",
// rollappConfigDirPath,
// )
// _, err = utils.ExecCommandWithStdout(collectGentx)
// if err != nil {
// return err
// }
// return nil
// }
//
// // registerSequencerAsGoverner registers the sequencer as a governor of the rollapp chain.
// // currently it sets the staking amount to half of the total token supply.
// // TODO: make the staking amount configurable
// func registerSequencerAsGoverner(initConfig config.RollappConfig) error {
// totalSupply, err := strconv.Atoi(consts.DefaultTokenSupply)
// if err != nil {
// return fmt.Errorf("error converting string to integer: %w", err)
// }
//
// // Convert to token supply with decimals
// stakedSupply := big.NewInt(int64(totalSupply / totalSupplyToStakingRatio))
// multiplier := new(big.Int).Exp(big.NewInt(10), big.NewInt(int64(initConfig.Decimals)), nil)
// stakedSupply.Mul(stakedSupply, multiplier)
//
// // Build and run the gentx command
// rollappConfigDirPath := filepath.Join(initConfig.Home, consts.ConfigDirName.Rollapp)
// gentxCmd := exec.Command(
// initConfig.RollappBinary,
// "gentx",
// consts.KeysIds.RollappSequencer,
// fmt.Sprint(
// stakedSupply,
// initConfig.Denom,
// ),
// "--chain-id",
// initConfig.RollappID,
// "--keyring-backend",
// "test",
// "--home",
// rollappConfigDirPath,
// )
// _, err = utils.ExecCommandWithStdout(gentxCmd)
// if err != nil {
// return err
// }
// return nil
// }
3 changes: 2 additions & 1 deletion cmd/eibc/fulfill/denoms/denoms.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package denoms

import (
"github.com/spf13/cobra"

"github.com/dymensionxyz/roller/cmd/eibc/fulfill/denoms/list"
"github.com/dymensionxyz/roller/cmd/eibc/fulfill/denoms/remove"
"github.com/dymensionxyz/roller/cmd/eibc/fulfill/denoms/set"
"github.com/spf13/cobra"
)

func Cmd() *cobra.Command {
Expand Down
14 changes: 11 additions & 3 deletions cmd/eibc/fulfill/denoms/set/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,17 @@ import (

func Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "set <ibc-denom-id> <value>",
Short: "Commands to manage the whitelist of RollApps to fulfill eibc orders for",
Args: cobra.ExactArgs(2),
Use: "set <ibc-denom-id> <fee-percentage>",
Short: "Commands to manage the whitelist of ibc-denoms to fulfill eibc orders for",
Long: `Commands to manage the whitelist of ibc-denoms to fulfill eibc orders for
The fee-percentage is a float number between 0 and 100 which represents
the minimal percentage of the order fee that you want to receive for fulfilling an order.
Assume there's an eibc order for 100<token> with a fee of 3<token>,
if the percentage is set to 4, this order will be ignored by your eibc client
instance.
`,
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
home, err := os.UserHomeDir()
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions cmd/eibc/fulfill/rollapps/rollapps.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package rollapps

import (
"github.com/spf13/cobra"

"github.com/dymensionxyz/roller/cmd/eibc/fulfill/rollapps/list"
"github.com/dymensionxyz/roller/cmd/eibc/fulfill/rollapps/remove"
"github.com/dymensionxyz/roller/cmd/eibc/fulfill/rollapps/set"
"github.com/spf13/cobra"
)

func Cmd() *cobra.Command {
Expand Down
19 changes: 14 additions & 5 deletions cmd/eibc/fulfill/rollapps/set/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,27 @@ import (
"path/filepath"
"strconv"

"github.com/pterm/pterm"
"github.com/spf13/cobra"

"github.com/dymensionxyz/roller/cmd/consts"
globalutils "github.com/dymensionxyz/roller/utils"
"github.com/dymensionxyz/roller/utils/config/yamlconfig"
"github.com/pterm/pterm"
"github.com/spf13/cobra"
)

func Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "set <rollapp-id> <value>",
Use: "set <rollapp-id> <fee-percentage>",
Short: "Commands to manage the whitelist of RollApps to fulfill eibc orders for",
Args: cobra.ExactArgs(2),
Long: `Commands to manage the whitelist of RollApps to fulfill eibc orders for
The fee-percentage is a float number between 0 and 100 which represents
the minimal percentage of the order fee that you want to receive for fulfilling an order.
Assume there's an eibc order for 100<token> with a fee of 3<token>,
if the percentage is set to 4, this order will be ignored by your eibc client
instance.
`,
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
home, err := os.UserHomeDir()
if err != nil {
Expand Down Expand Up @@ -48,7 +57,7 @@ func Cmd() *cobra.Command {
}

updates := map[string]interface{}{
fmt.Sprintf("fulfill_criteria.min_fee_percentage.asset.%s", rollAppID): valueFloat,
fmt.Sprintf("fulfill_criteria.min_fee_percentage.chain.%s", rollAppID): valueFloat,
}
err = yamlconfig.UpdateNestedYAML(eibcConfigPath, updates)
if err != nil {
Expand Down
47 changes: 25 additions & 22 deletions cmd/relayer/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strconv"

comettypes "github.com/cometbft/cometbft/types"
Expand Down Expand Up @@ -110,28 +111,30 @@ func Cmd() *cobra.Command {
return
}

pterm.Info.Println("removing old systemd services")
for _, svc := range consts.RelayerSystemdServices {
svcFileName := fmt.Sprintf("%s.service", svc)
pterm.Info.Printf("removing %s", svcFileName)
svcFilePath := filepath.Join("/etc/systemd/system/", svcFileName)
c := exec.Command("sudo", "systemctl", "stop", svcFileName)
_, err := bash.ExecCommandWithStdout(c)
if err != nil {
pterm.Error.Printf("failed to remove systemd services: %v\n", err)
return
}
c = exec.Command("sudo", "systemctl", "disable", svcFileName)
_, err = bash.ExecCommandWithStdout(c)
if err != nil {
pterm.Error.Printf("failed to remove systemd services: %v\n", err)
return
}
c = exec.Command("sudo", "rm", svcFilePath)
_, err = bash.ExecCommandWithStdout(c)
if err != nil {
pterm.Error.Printf("failed to remove systemd services: %v\n", err)
return
if runtime.GOOS == "linux" {
pterm.Info.Println("removing old systemd services")
for _, svc := range consts.RelayerSystemdServices {
svcFileName := fmt.Sprintf("%s.service", svc)
pterm.Info.Printf("removing %s", svcFileName)
svcFilePath := filepath.Join("/etc/systemd/system/", svcFileName)
c := exec.Command("sudo", "systemctl", "stop", svcFileName)
_, err := bash.ExecCommandWithStdout(c)
if err != nil {
pterm.Error.Printf("failed to remove systemd services: %v\n", err)
return
}
c = exec.Command("sudo", "systemctl", "disable", svcFileName)
_, err = bash.ExecCommandWithStdout(c)
if err != nil {
pterm.Error.Printf("failed to remove systemd services: %v\n", err)
return
}
c = exec.Command("sudo", "rm", svcFilePath)
_, err = bash.ExecCommandWithStdout(c)
if err != nil {
pterm.Error.Printf("failed to remove systemd services: %v\n", err)
return
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/relayer/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (
"fmt"
"os"

"github.com/spf13/cobra"

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

func Cmd() *cobra.Command {
Expand Down
2 changes: 1 addition & 1 deletion cmd/rollapp/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func Cmd() *cobra.Command {
return
}

envs := []string{"devnet", "playground"}
envs := []string{"playground"}
env, _ := pterm.DefaultInteractiveSelect.
WithDefaultText("select the environment you want to initialize for").
WithOptions(envs).
Expand Down
41 changes: 22 additions & 19 deletions cmd/rollapp/init/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"

Expand Down Expand Up @@ -66,26 +67,28 @@ func runInit(cmd *cobra.Command, env string, raID string) error {
return err
}

pterm.Info.Println("removing old systemd services")
for _, svc := range consts.RollappSystemdServices {
svcFileName := fmt.Sprintf("%s.service", svc)
pterm.Info.Printf("removing %s", svcFileName)
if runtime.GOOS == "linux" {
pterm.Info.Println("removing old systemd services")
for _, svc := range consts.RollappSystemdServices {
svcFileName := fmt.Sprintf("%s.service", svc)
pterm.Info.Printf("removing %s", svcFileName)

svcFilePath := filepath.Join("/etc/systemd/system/", svcFileName)
c := exec.Command("sudo", "systemctl", "stop", svcFileName)
_, err := bash.ExecCommandWithStdout(c)
if err != nil {
return err
}
c = exec.Command("sudo", "systemctl", "disable", svcFileName)
_, err = bash.ExecCommandWithStdout(c)
if err != nil {
return err
}
c = exec.Command("sudo", "rm", svcFilePath)
_, err = bash.ExecCommandWithStdout(c)
if err != nil {
return err
svcFilePath := filepath.Join("/etc/systemd/system/", svcFileName)
c := exec.Command("sudo", "systemctl", "stop", svcFileName)
_, err := bash.ExecCommandWithStdout(c)
if err != nil {
return err
}
c = exec.Command("sudo", "systemctl", "disable", svcFileName)
_, err = bash.ExecCommandWithStdout(c)
if err != nil {
return err
}
c = exec.Command("sudo", "rm", svcFilePath)
_, err = bash.ExecCommandWithStdout(c)
if err != nil {
return err
}
}
}

Expand Down
24 changes: 24 additions & 0 deletions cmd/rollapp/sequencer/bond/bond.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package bond

import (
"github.com/spf13/cobra"

"github.com/dymensionxyz/roller/cmd/rollapp/sequencer/bond/decrease"
"github.com/dymensionxyz/roller/cmd/rollapp/sequencer/bond/get"
"github.com/dymensionxyz/roller/cmd/rollapp/sequencer/bond/increase"
"github.com/dymensionxyz/roller/cmd/rollapp/sequencer/bond/unbond"
)

func Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "bond",
Short: "Commands to manage sequencer bond",
}

cmd.AddCommand(get.Cmd())
cmd.AddCommand(increase.Cmd())
cmd.AddCommand(decrease.Cmd())
cmd.AddCommand(unbond.Cmd())

return cmd
}
Loading

0 comments on commit c18e989

Please sign in to comment.