Skip to content

Commit

Permalink
feat: Add support for setting sequencer as sole governer by default (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
omritoptix authored Aug 13, 2023
1 parent 2c2ad89 commit b2ea7e6
Show file tree
Hide file tree
Showing 9 changed files with 1,130 additions and 205 deletions.
48 changes: 48 additions & 0 deletions cmd/config/init/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"math/big"
"os"
"strconv"
"strings"

"github.com/dymensionxyz/roller/cmd/consts"
Expand All @@ -16,6 +17,10 @@ import (
"github.com/tidwall/sjson"
)

const (
totalSupplyToStakingRatio = 2
)

func initializeRollappGenesis(initConfig config.RollappConfig) error {
totalTokenSupply, success := new(big.Int).SetString(initConfig.TokenSupply, 10)
if !success {
Expand Down Expand Up @@ -44,6 +49,10 @@ func initializeRollappGenesis(initConfig config.RollappConfig) error {
if err != nil {
return err
}
err = generateGenesisTx(initConfig)
if err != nil {
return err
}
err = updateGenesisParams(GetGenesisFilePath(initConfig.Home), initConfig.Denom, initConfig.Decimals)
if err != nil {
return err
Expand Down Expand Up @@ -139,3 +148,42 @@ func updateGenesisParams(genesisFilePath string, denom string, decimals uint) er
params := getDefaultGenesisParams(denom, decimals)
return UpdateJSONParams(genesisFilePath, params)
}

func generateGenesisTx(initConfig config.RollappConfig) error {
err := registerSequencerAsGoverner(initConfig)
if err != nil {
return err
}
// collect gentx
rollappConfigDirPath := filepath.Join(initConfig.Home, consts.ConfigDirName.Rollapp)
collectGentx := exec.Command(initConfig.RollappBinary, "collect-gentxs", "--home", rollappConfigDirPath)
_, err = utils.ExecBashCommandWithStdout(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(initConfig.TokenSupply)
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.ExecBashCommandWithStdout(gentxCmd)
if err != nil {
return err
}
return nil
}
7 changes: 4 additions & 3 deletions cmd/config/init/rollapp.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package initconfig

import (
"github.com/dymensionxyz/roller/sequencer"
"os/exec"
"path/filepath"

"github.com/dymensionxyz/roller/sequencer"

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

Expand All @@ -23,9 +24,9 @@ func initializeRollappConfig(initConfig config.RollappConfig) error {
if err != nil {
return err
}
setGentxCmd := exec.Command(initConfig.RollappBinary, "gentx_seq",
gentxSeqCmd := exec.Command(initConfig.RollappBinary, "gentx_seq",
"--pubkey", seqPubKey, "--from", consts.KeysIds.RollappSequencer, "--keyring-backend", "test", "--home", home)
_, err = utils.ExecBashCommandWithStdout(setGentxCmd)
_, err = utils.ExecBashCommandWithStdout(gentxSeqCmd)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit b2ea7e6

Please sign in to comment.