Skip to content

Commit

Permalink
new governance flag
Browse files Browse the repository at this point in the history
add a new mandatory flag for the governance address;
apply the value to be the governance for the core contracts;
update the polybft_setup docs;
  • Loading branch information
Vitomir2 committed Dec 2, 2024
1 parent b4be493 commit 500a6eb
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
8 changes: 8 additions & 0 deletions command/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ func setFlags(cmd *cobra.Command) {
"admin for proxy contracts",
)

cmd.Flags().StringVar(
&params.governance,
governanceFlag,
"",
"a mandatory flag that represents governance address that controls essential functions across the "+
"core contracts infrastructure",
)

cmd.Flags().StringVar(
&params.secretsConfigPath,
command.SecretsConfigFlag,
Expand Down
24 changes: 24 additions & 0 deletions command/genesis/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const (
nativeTokenConfigFlag = "native-token-config"
blockTrackerPollIntervalFlag = "block-tracker-poll-interval"
proxyContractsAdminFlag = "proxy-contracts-admin"
governanceFlag = "governance"
)

// Legacy flags that need to be preserved for running clients
Expand Down Expand Up @@ -129,6 +130,7 @@ type genesisParams struct {
blockTrackerPollInterval time.Duration

proxyContractsAdmin string
governance string

secretsConfigPath string
secretsConfig *secrets.SecretsManagerConfig
Expand Down Expand Up @@ -172,6 +174,10 @@ func (p *genesisParams) validateFlags() error {
if err := p.validateProxyContractsAdmin(); err != nil {
return err
}

if err := p.validateGovernanceAddress(); err != nil {
return err
}
}

// Check if the genesis file already exists
Expand Down Expand Up @@ -222,6 +228,7 @@ func (p *genesisParams) getRequiredFlags() []string {
if p.isIBFTConsensus() {
return []string{
command.BootnodeFlag,
governanceFlag,
}
}

Expand Down Expand Up @@ -598,3 +605,20 @@ func (p *genesisParams) getResult() command.CommandResult {
Message: fmt.Sprintf("\nGenesis written to %s\n", p.genesisPath),
}
}

func (p *genesisParams) validateGovernanceAddress() error {
if strings.TrimSpace(p.governance) == "" {
return errors.New("governance address must be set")
}

proxyContractsAdminAddr := types.StringToAddress(p.proxyContractsAdmin)
if proxyContractsAdminAddr == types.ZeroAddress {
return errors.New("governance address must not be zero address")
}

if proxyContractsAdminAddr == contracts.SystemCaller {
return errors.New("governance address must not be system caller address")
}

return nil
}
13 changes: 6 additions & 7 deletions command/genesis/polybft_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,12 @@ func (p *genesisParams) generatePolyBftChainConfig(o command.OutputFormatter) er
}

polyBftConfig := &polybft.PolyBFTConfig{
InitialValidatorSet: initialValidators,
BlockTime: common.Duration{Duration: p.blockTime},
EpochSize: p.epochSize,
SprintSize: p.sprintSize,
EpochReward: p.epochReward,
// use 1st account as governance address
Governance: initialValidators[0].Address,
InitialValidatorSet: initialValidators,
BlockTime: common.Duration{Duration: p.blockTime},
EpochSize: p.epochSize,
SprintSize: p.sprintSize,
EpochReward: p.epochReward,
Governance: types.StringToAddress(p.governance),
InitialTrieRoot: types.StringToHash(p.initialStateRoot),
NativeTokenConfig: p.nativeTokenConfig,
MinValidatorSetSize: p.minNumValidators,
Expand Down
4 changes: 2 additions & 2 deletions h_docs/polybft_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ I am describing our custom process, because it is different.

3. Generate genesis file

We need to set native token to be mintable, so we can premine balances to different addresses. Keep in mind that the validators need some premined coins, so, add it before generating the genesis. They are needed in order validators to feed the Price Oracle (executing transactions).
We need to set native token to be mintable, so we can premine balances to different addresses. Keep in mind that the validators need some premined coins, so, add it before generating the genesis. They are needed in order validators to feed the Price Oracle (executing transactions). Use the command below to generate the file. Make sure to update the proxy contracts admin and governance flags according to your requirements.

```
./hydra genesis --block-gas-limit 10000000 --epoch-size 10 --validators-path ./ --validators-prefix test-chain- --consensus polybft --native-token-config Hydra:HDR:18:true:0x211881Bb4893dd733825A2D97e48bFc38cc70a0c --premine 0x211881Bb4893dd733825A2D97e48bFc38cc70a0c:70000000000000000000000 --premine 0xdC3312E368A178e24850C6dAC169646c5fD14b93:30000000000000000000000 --proxy-contracts-admin 0x211881Bb4893dd733825A2D97e48bFc38cc70a0c --chain-id 8844
./hydra genesis --block-gas-limit 10000000 --epoch-size 10 --validators-path ./ --validators-prefix test-chain- --consensus polybft --native-token-config Hydra:HDR:18:true:0x211881Bb4893dd733825A2D97e48bFc38cc70a0c --premine 0x211881Bb4893dd733825A2D97e48bFc38cc70a0c:70000000000000000000000 --premine 0xdC3312E368A178e24850C6dAC169646c5fD14b93:30000000000000000000000 --proxy-contracts-admin 0x211881Bb4893dd733825A2D97e48bFc38cc70a0c --governance 0x0000000000000000000000000000000000000000 --chain-id 8844
```

4. Run the chain
Expand Down

0 comments on commit 500a6eb

Please sign in to comment.