Skip to content

Commit

Permalink
feat: update validator balance handling and enhance genesis configura… (
Browse files Browse the repository at this point in the history
#90)

feat: update validator balance handling and enhance genesis configuration

- Upgrade elys-network/elys dependency to v1.0.0 for improved functionality.
- Remove deprecated validator balance flags and replace them with a new flag for multiple validator balances.
- Update command logic to handle the new validator balances format in both chain initialization and proposal submission commands.
- Refactor genesis account addition and update functions to accommodate the new balance structure, ensuring accurate supply updates for validators.
- Enhance asset profile and oracle configurations by adding support for WBTC and WETH, including their respective prices and decimals.
  • Loading branch information
cosmic-vagabond authored Dec 16, 2024
1 parent 662efab commit 5921715
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 57 deletions.
21 changes: 8 additions & 13 deletions cmd/chaininit/chain-init-cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@ func ChainInitCmd() *cobra.Command {
log.Fatalf(types.ColorRed + "validator key name is required")
}

validatorBalance, _ := cmd.Flags().GetString(flags.FlagValidatorBalance)
if validatorBalance == "" {
log.Fatalf(types.ColorRed + "validator balance is required")
}

validatorSelfDelegation, _ := cmd.Flags().GetString(flags.FlagValidatorSelfDelegation)
if validatorSelfDelegation == "" {
log.Fatalf(types.ColorRed + "validator self delegation is required")
Expand Down Expand Up @@ -128,11 +123,6 @@ func ChainInitCmd() *cobra.Command {
log.Fatalf(types.ColorRed + "validator key name 2 is required")
}

validatorBalance2, _ := cmd.Flags().GetString(flags.FlagValidatorBalance2)
if validatorBalance2 == "" {
log.Fatalf(types.ColorRed + "validator balance 2 is required")
}

validatorSelfDelegation2, _ := cmd.Flags().GetString(flags.FlagValidatorSelfDelegation2)
if validatorSelfDelegation2 == "" {
log.Fatalf(types.ColorRed + "validator self delegation 2 is required")
Expand Down Expand Up @@ -163,6 +153,11 @@ func ChainInitCmd() *cobra.Command {
log.Fatalf(types.ColorRed + "api 2 is required")
}

validatorBalances, _ := cmd.Flags().GetStringSlice(flags.FlagValidatorBalances)
if len(validatorBalances) == 0 {
log.Fatalf(types.ColorRed + "validator balances are required")
}

// download and run old binary
oldBinaryPath, oldVersion, err := utils.DownloadAndRunVersion(oldBinaryUrl, skipBinary)
if err != nil {
Expand Down Expand Up @@ -199,8 +194,8 @@ func ChainInitCmd() *cobra.Command {
_ = utils.AddKey(oldBinaryPath, validatorKeyName2, validatorMnemonic2, homePath2, keyringBackend)

// add genesis accounts
utils.AddGenesisAccount(oldBinaryPath, validatorAddress, validatorBalance, homePath)
utils.AddGenesisAccount(oldBinaryPath, validatorAddress2, validatorBalance2, homePath)
utils.AddGenesisAccount(oldBinaryPath, validatorAddress, homePath, validatorBalances)
utils.AddGenesisAccount(oldBinaryPath, validatorAddress2, homePath, validatorBalances)

// generate genesis tx
utils.GenTx(oldBinaryPath, validatorKeyName, validatorSelfDelegation, chainId, homePath, keyringBackend)
Expand All @@ -215,7 +210,7 @@ func ChainInitCmd() *cobra.Command {
utils.BackupGenesisInitFile(homePath)

// update genesis
utils.UpdateGenesis(validatorBalance, oldBinaryPath, homePath, genesisFilePath)
utils.UpdateGenesis(oldBinaryPath, homePath, genesisFilePath, validatorBalances, validatorAddress)
},
}

Expand Down
10 changes: 8 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func main() {
rootCmd.PersistentFlags().String(flags.FlagHome, homeEnv+"/.elys", "home directory")
rootCmd.PersistentFlags().String(flags.FlagMoniker, "alice", "moniker")
rootCmd.PersistentFlags().String(flags.FlagValidatorKeyName, "validator", "validator key name")
rootCmd.PersistentFlags().String(flags.FlagValidatorBalance, "200000000000000", "validator balance")
rootCmd.PersistentFlags().String(flags.FlagValidatorSelfDelegation, "50000000000000", "validator self delegation")
rootCmd.PersistentFlags().String(flags.FlagValidatorMnemonic, "shrug census ancient uniform sausage own oil boss tool captain ride year conduct welcome siren protect mutual zero funny universe candy gown rack sister", "validator mnemonic")
rootCmd.PersistentFlags().String(flags.FlagRpc, "tcp://0.0.0.0:26657", "rpc")
Expand All @@ -62,14 +61,21 @@ func main() {
rootCmd.PersistentFlags().String(flags.FlagHome2, homeEnv+"/.elys2", "home directory 2")
rootCmd.PersistentFlags().String(flags.FlagMoniker2, "bob", "moniker 2")
rootCmd.PersistentFlags().String(flags.FlagValidatorKeyName2, "validator-2", "validator key name 2")
rootCmd.PersistentFlags().String(flags.FlagValidatorBalance2, "200000000000000", "validator balance 2")
rootCmd.PersistentFlags().String(flags.FlagValidatorSelfDelegation2, "1000000", "validator self delegation 2")
rootCmd.PersistentFlags().String(flags.FlagValidatorMnemonic2, "august viable pet tone normal below almost blush portion example trick circle pumpkin citizen conduct outdoor universe wolf ankle asthma deliver correct pool juice", "validator mnemonic 2")
rootCmd.PersistentFlags().String(flags.FlagRpc2, "tcp://0.0.0.0:26667", "rpc")
rootCmd.PersistentFlags().String(flags.FlagP2p2, "tcp://0.0.0.0:26666", "p2p")
rootCmd.PersistentFlags().String(flags.FlagPprof2, "localhost:6061", "pprof")
rootCmd.PersistentFlags().String(flags.FlagApi2, "tcp://localhost:1318", "api")

rootCmd.PersistentFlags().StringSlice(flags.FlagValidatorBalances, []string{
"200000000000000uelys",
"100000000000000ibc/F082B65C88E4B6D5EF1DB243CDA1D331D002759E938A0F5CD3FFDC5D53B3E349",
"100000000000000ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9",
"10000000000000000wbtc-satoshi",
"100000000000000000000000000weth-wei",
}, "list of balance+denomination pairs for validator accounts (e.g., '100000000uelys,200000000uatom')")

rootCmd.AddCommand(version.VersionCmd())
rootCmd.AddCommand(chainsnapshotexport.ChainSnapshotExportCmd())
rootCmd.AddCommand(chaininit.ChainInitCmd())
Expand Down
15 changes: 5 additions & 10 deletions cmd/submitnewproposal/submit-new-proposal-cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ func SubmitNewProposalCmd() *cobra.Command {
log.Fatalf(types.ColorRed + "validator key name is required")
}

validatorBalance, _ := cmd.Flags().GetString(flags.FlagValidatorBalance)
if validatorBalance == "" {
log.Fatalf(types.ColorRed + "validator balance is required")
}

validatorSelfDelegation, _ := cmd.Flags().GetString(flags.FlagValidatorSelfDelegation)
if validatorSelfDelegation == "" {
log.Fatalf(types.ColorRed + "validator self delegation is required")
Expand Down Expand Up @@ -130,11 +125,6 @@ func SubmitNewProposalCmd() *cobra.Command {
log.Fatalf(types.ColorRed + "validator key name 2 is required")
}

validatorBalance2, _ := cmd.Flags().GetString(flags.FlagValidatorBalance2)
if validatorBalance2 == "" {
log.Fatalf(types.ColorRed + "validator balance 2 is required")
}

validatorSelfDelegation2, _ := cmd.Flags().GetString(flags.FlagValidatorSelfDelegation2)
if validatorSelfDelegation2 == "" {
log.Fatalf(types.ColorRed + "validator self delegation 2 is required")
Expand Down Expand Up @@ -165,6 +155,11 @@ func SubmitNewProposalCmd() *cobra.Command {
log.Fatalf(types.ColorRed + "api 2 is required")
}

validatorBalances, _ := cmd.Flags().GetStringSlice(flags.FlagValidatorBalances)
if len(validatorBalances) == 0 {
log.Fatalf(types.ColorRed + "validator balances are required")
}

timeOutWaitForNode, err := cmd.Flags().GetInt(flags.FlagTimeOutToWaitForNode)

if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const (
FlagHome = "home"
FlagMoniker = "moniker"
FlagValidatorKeyName = "validator-key-name"
FlagValidatorBalance = "validator-balance"
FlagValidatorSelfDelegation = "validator-self-delegation"
FlagValidatorMnemonic = "validator-mnemonic"
FlagRpc = "rpc"
Expand All @@ -31,11 +30,12 @@ const (
FlagHome2 = "home-2"
FlagMoniker2 = "moniker-2"
FlagValidatorKeyName2 = "validator-key-name-2"
FlagValidatorBalance2 = "validator-balance-2"
FlagValidatorSelfDelegation2 = "validator-self-delegation-2"
FlagValidatorMnemonic2 = "validator-mnemonic-2"
FlagRpc2 = "rpc-2"
FlagP2p2 = "p2p-2"
FlagPprof2 = "pprof-2"
FlagApi2 = "api-2"

FlagValidatorBalances = "validator-balances"
)
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/cosmos/cosmos-sdk v0.50.9
github.com/cosmos/ibc-go/modules/capability v1.0.1
github.com/cosmos/ibc-go/v8 v8.5.1
github.com/elys-network/elys v0.54.1-0.20241206102245-13c05fc80d44
github.com/elys-network/elys v1.0.0
github.com/spf13/cobra v1.8.1
github.com/vbauerster/mpb/v8 v8.8.3
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1415,8 +1415,8 @@ github.com/elazarl/goproxy v0.0.0-20170405201442-c4fc26588b6e/go.mod h1:/Zj4wYkg
github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
github.com/elys-network/bandchain-packet v0.0.3-sdk47 h1:W4sP/JOXAoABhsV+ck1NTphLuqpuxGg+uul1nDLbgxk=
github.com/elys-network/bandchain-packet v0.0.3-sdk47/go.mod h1:/CtU24lu2E4RbPRcZFJfEagwW6TUdFcxv7pX0cYYSgk=
github.com/elys-network/elys v0.54.1-0.20241206102245-13c05fc80d44 h1:xQYZuQf+SZI43CsT7l0fYOMFrYhgpNkcbQiuy6AlSa8=
github.com/elys-network/elys v0.54.1-0.20241206102245-13c05fc80d44/go.mod h1:NZ52jlKhFT3/l4C2Y6boQqeUga+npWmlE7opK9BtZVA=
github.com/elys-network/elys v1.0.0 h1:iQEcZNYT0pRkewhq1wJj298E5bRX9FetrLEKmDLjxHY=
github.com/elys-network/elys v1.0.0/go.mod h1:NZ52jlKhFT3/l4C2Y6boQqeUga+npWmlE7opK9BtZVA=
github.com/emicklei/dot v1.6.2 h1:08GN+DD79cy/tzN6uLCT84+2Wk9u+wvqP+Hkx/dIR8A=
github.com/emicklei/dot v1.6.2/go.mod h1:DeV7GvQtIw4h2u73RKBkkFdvVAz0D9fzeJrgPW6gy/s=
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
Expand Down
39 changes: 33 additions & 6 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,16 @@ type Commitment struct {
type CommitmentParams struct {
commitmenttypes.Params

VestingInfos []CommitmentVestingInfo `json:"vesting_infos"`
NumberOfCommitments json.Number `json:"number_of_commitments"`
VestingInfos []CommitmentVestingInfo `json:"vesting_infos"`
NumberOfCommitments json.Number `json:"number_of_commitments"`
StartAtomStakersHeight json.Number `json:"start_atom_stakers_height"`
EndAtomStakersHeight json.Number `json:"end_atom_stakers_height"`
StartCadetsHeight json.Number `json:"start_cadets_height"`
EndCadetsHeight json.Number `json:"end_cadets_height"`
StartNftHoldersHeight json.Number `json:"start_nft_holders_height"`
EndNftHoldersHeight json.Number `json:"end_nft_holders_height"`
StartGovernorsHeight json.Number `json:"start_governors_height"`
EndGovernorsHeight json.Number `json:"end_governors_height"`
}

type CommitmentVestingInfo struct {
Expand All @@ -331,7 +339,13 @@ type CommitmentVestingInfo struct {
type AssetProfile struct {
assetprofiletypes.GenesisState

EntryList []interface{} `json:"entry_list"`
EntryList []AssetProfileEntry `json:"entry_list"`
}

type AssetProfileEntry struct {
assetprofiletypes.Entry

Decimals json.Number `json:"decimals"`
}

type Amm struct {
Expand Down Expand Up @@ -363,9 +377,22 @@ type EvidenceState struct {
type Oracle struct {
oracletypes.GenesisState

Params OracleParams `json:"params"`
AssetInfos []interface{} `json:"asset_infos"`
Prices []interface{} `json:"prices"`
Params OracleParams `json:"params"`
AssetInfos []OracleAssetInfo `json:"asset_infos"`
Prices []OraclePrice `json:"prices"`
}

type OracleAssetInfo struct {
oracletypes.AssetInfo

Decimal json.Number `json:"decimal"`
}

type OraclePrice struct {
oracletypes.Price

Timestamp json.Number `json:"timestamp"`
BlockHeight json.Number `json:"block_height"`
}

type OracleParams struct {
Expand Down
19 changes: 15 additions & 4 deletions utils/add-genesis-account.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,30 @@ package utils
import (
"log"
"os/exec"
"strings"

"github.com/elys-network/post-upgrade-snapshot-generator/types"
)

func AddGenesisAccount(cmdPath, address, balance, homePath string) {
func AddGenesisAccount(cmdPath, address, homePath string, balances []string) {
// Build the balance string
balanceStr := strings.Join(balances, ",")

// Command and arguments
args := []string{"genesis", "add-genesis-account", address, balance + "uelys," + balance + "ibc/F082B65C88E4B6D5EF1DB243CDA1D331D002759E938A0F5CD3FFDC5D53B3E349," + balance + "ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9", "--home", homePath}
args := []string{
"genesis",
"add-genesis-account",
address,
balanceStr,
"--home",
homePath,
}

// Execute the command
if err := exec.Command(cmdPath, args...).Run(); err != nil {
log.Fatalf(types.ColorRed+"Command execution failed: %v", err) // nolint: goconst
log.Fatalf(types.ColorRed+"Command execution failed: %v", err)
}

// If execution reaches here, the command was successful
log.Printf(types.ColorYellow+"add genesis account with address %s, balance: %s and home path %s successfully", address, balance, homePath)
log.Printf(types.ColorYellow+"add genesis account with address %s, balance: %s and home path %s successfully", address, balanceStr, homePath)
}
Loading

0 comments on commit 5921715

Please sign in to comment.