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

EVM-707 Remove balance field from initial validators in genesis.json #1736

Merged
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
21 changes: 2 additions & 19 deletions command/genesis/polybft_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (p *genesisParams) generatePolyBftChainConfig(o command.OutputFormatter) er
rewardTokenAddr = contracts.RewardTokenContract
}

initialValidators, err := p.getValidatorAccounts(premineBalances)
initialValidators, err := p.getValidatorAccounts()
if err != nil {
return fmt.Errorf("failed to retrieve genesis validators: %w", err)
}
Expand Down Expand Up @@ -484,8 +484,7 @@ func (p *genesisParams) deployContracts(
}

// getValidatorAccounts gathers validator accounts info either from CLI or from provided local storage
func (p *genesisParams) getValidatorAccounts(
premineBalances map[types.Address]*premineInfo) ([]*validator.GenesisValidator, error) {
func (p *genesisParams) getValidatorAccounts() ([]*validator.GenesisValidator, error) {
// populate validators premine info
if len(p.validators) > 0 {
validators := make([]*validator.GenesisValidator, len(p.validators))
Expand Down Expand Up @@ -516,7 +515,6 @@ func (p *genesisParams) getValidatorAccounts(
MultiAddr: parts[0],
Address: addr,
BlsKey: trimmedBLSKey,
Balance: getPremineAmount(addr, premineBalances, big.NewInt(0)),
Stake: big.NewInt(0),
}
}
Expand All @@ -534,24 +532,9 @@ func (p *genesisParams) getValidatorAccounts(
return nil, err
}

for _, v := range validators {
v.Balance = getPremineAmount(v.Address, premineBalances, big.NewInt(0))
v.Stake = big.NewInt(0)
}

return validators, nil
}

// getPremineAmount retrieves amount from the premine map or if not provided, returns default amount
func getPremineAmount(addr types.Address, premineMap map[types.Address]*premineInfo,
defaultAmount *big.Int) *big.Int {
if premine, exists := premineMap[addr]; exists {
return premine.amount
}

return defaultAmount
}

func stringSliceToAddressSlice(addrs []string) []types.Address {
res := make([]types.Address, len(addrs))
for indx, addr := range addrs {
Expand Down
8 changes: 4 additions & 4 deletions command/genesis/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ func ReadValidatorsByPrefix(dir, prefix string) ([]*validator.GenesisValidator,
}

validators[i] = &validator.GenesisValidator{
Address: types.Address(account.Ecdsa.Address()),
BlsPrivateKey: account.Bls,
BlsKey: hex.EncodeToString(account.Bls.PublicKey().Marshal()),
MultiAddr: fmt.Sprintf("/ip4/%s/tcp/%d/p2p/%s", "127.0.0.1", bootnodePortStart+int64(i), nodeID),
Address: types.Address(account.Ecdsa.Address()),
BlsKey: hex.EncodeToString(account.Bls.PublicKey().Marshal()),
MultiAddr: fmt.Sprintf("/ip4/%s/tcp/%d/p2p/%s", "127.0.0.1", bootnodePortStart+int64(i), nodeID),
Stake: big.NewInt(0),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ import (
var params stakeManagerDeployParams

func GetCommand() *cobra.Command {
registerCmd := &cobra.Command{
stakeMgrDeployCmd := &cobra.Command{
Use: "stake-manager-deploy",
Short: "Command for deploying stake manager contract on rootchain",
PreRunE: runPreRun,
RunE: runCommand,
}

setFlags(registerCmd)
setFlags(stakeMgrDeployCmd)

return registerCmd
return stakeMgrDeployCmd
}

func runPreRun(cmd *cobra.Command, _ []string) error {
Expand Down
1 change: 0 additions & 1 deletion consensus/polybft/sc_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ func TestIntegration_CommitEpoch(t *testing.T) {
// create validator data for polybft config
initValidators[i] = &validator.GenesisValidator{
Address: val.Address,
Balance: val.VotingPower,
Stake: val.VotingPower,
BlsKey: hex.EncodeToString(val.BlsKey.Marshal()),
}
Expand Down
33 changes: 9 additions & 24 deletions consensus/polybft/validator/genesis_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,28 @@ import (

// GenesisValidator represents public information about validator accounts which are the part of genesis
type GenesisValidator struct {
Address types.Address
BlsPrivateKey *bls.PrivateKey
BlsKey string
Balance *big.Int
Stake *big.Int
MultiAddr string
Address types.Address
BlsKey string
Stake *big.Int
MultiAddr string
}

type genesisValidatorRaw struct {
Address types.Address `json:"address"`
BlsKey string `json:"blsKey"`
Balance *string `json:"balance"`
Stake *string `json:"stake"`
MultiAddr string `json:"multiAddr"`
}

func (v *GenesisValidator) MarshalJSON() ([]byte, error) {
raw := &genesisValidatorRaw{Address: v.Address, BlsKey: v.BlsKey, MultiAddr: v.MultiAddr}
raw.Balance = types.EncodeBigInt(v.Balance)
raw.Stake = types.EncodeBigInt(v.Stake)

return json.Marshal(raw)
}

func (v *GenesisValidator) UnmarshalJSON(data []byte) error {
var (
raw genesisValidatorRaw
err error
)
func (v *GenesisValidator) UnmarshalJSON(data []byte) (err error) {
var raw genesisValidatorRaw

if err = json.Unmarshal(data, &raw); err != nil {
return err
Expand All @@ -50,17 +43,9 @@ func (v *GenesisValidator) UnmarshalJSON(data []byte) error {
v.BlsKey = raw.BlsKey
v.MultiAddr = raw.MultiAddr

v.Balance, err = types.ParseUint256orHex(raw.Balance)
if err != nil {
return err
}

v.Stake, err = types.ParseUint256orHex(raw.Stake)
if err != nil {
return err
}

return nil
return err
}

// UnmarshalBLSPublicKey unmarshals the hex encoded BLS public key
Expand Down Expand Up @@ -92,6 +77,6 @@ func (v *GenesisValidator) ToValidatorMetadata() (*ValidatorMetadata, error) {

// String implements fmt.Stringer interface
func (v *GenesisValidator) String() string {
return fmt.Sprintf("Address=%s; Balance=%d; Stake=%d; P2P Multi addr=%s; BLS Key=%s;",
v.Address, v.Balance, v.Stake, v.MultiAddr, v.BlsKey)
return fmt.Sprintf("Address=%s; Stake=%d; P2P Multi addr=%s; BLS Key=%s;",
v.Address, v.Stake, v.MultiAddr, v.BlsKey)
}
1 change: 0 additions & 1 deletion consensus/polybft/validator/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ func (v *TestValidator) ParamsValidator() *GenesisValidator {
return &GenesisValidator{
Address: v.Address(),
BlsKey: hex.EncodeToString(bls),
Balance: big.NewInt(1000),
Stake: big.NewInt(1000),
}
}
Expand Down
Loading