Skip to content
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

feat: Add support for setting sequencer as sole governer by default #376

Merged
merged 2 commits into from
Aug 13, 2023
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
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