Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

[RFC-191]: Add governance proposal-quorum flag #1730

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
7 changes: 7 additions & 0 deletions command/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,13 @@ func setFlags(cmd *cobra.Command) {
"address of a governance admin (governance admin can add new or remove old proposers "+
"of governance proposals, and add new and remove old executors of accepted proposals)",
)

cmd.Flags().Uint64Var(
&params.proposalQuorum,
proposalQuorumFlag,
defaultProposalQuorumPercentage,
"percentage of total validator stake needed for a governance proposal to be accepted (from 0 to 100%)",
)
}

// Access Control Lists
Expand Down
2 changes: 2 additions & 0 deletions command/genesis/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const (
votePeriodFlag = "vote-period"
voteProposalThresholdFlag = "vote-proposal-threshold"
governorAdminFlag = "governor-admin"
proposalQuorumFlag = "proposal-quorum"

defaultNativeTokenName = "Polygon"
defaultNativeTokenSymbol = "MATIC"
Expand Down Expand Up @@ -146,6 +147,7 @@ type genesisParams struct {
voteDelay string
votingPeriod string
proposalThreshold string
proposalQuorum uint64
governorAdmin string
}

Expand Down
38 changes: 23 additions & 15 deletions command/genesis/polybft_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,18 @@ const (

blockTimeDriftFlag = "block-time-drift"

defaultEpochSize = uint64(10)
defaultSprintSize = uint64(5)
defaultValidatorSetSize = 100
defaultBlockTime = 2 * time.Second
defaultEpochReward = 1
defaultBlockTimeDrift = uint64(10)
defaultCheckpointInterval = uint64(900)
defaultWithdrawalWaitPeriod = uint64(1)
defaultVotingDelay = "10"
defaultVotingPeriod = "20"
defaultVoteProposalThreshold = "1000"
defaultEpochSize = uint64(10)
defaultSprintSize = uint64(5)
defaultValidatorSetSize = 100
defaultBlockTime = 2 * time.Second
defaultEpochReward = 1
defaultBlockTimeDrift = uint64(10)
defaultCheckpointInterval = uint64(900)
defaultWithdrawalWaitPeriod = uint64(1)
defaultVotingDelay = "10"
defaultVotingPeriod = "20"
defaultVoteProposalThreshold = "1000"
defaultProposalQuorumPercentage = uint64(67)

contractDeployerAllowListAdminFlag = "contract-deployer-allow-list-admin"
contractDeployerAllowListEnabledFlag = "contract-deployer-allow-list-enabled"
Expand Down Expand Up @@ -163,6 +164,12 @@ func (p *genesisParams) generatePolyBftChainConfig(o command.OutputFormatter) er
governorAdminAddr = types.StringToAddress(p.governorAdmin)
}

proposalQuorum := p.proposalQuorum
if proposalQuorum > 100 {
// proposal can be from 0 to 100, so we sanitize the value
proposalQuorum = 100
}

polyBftConfig := &polybft.PolyBFTConfig{
InitialValidatorSet: initialValidators,
BlockTime: common.Duration{Duration: p.blockTime},
Expand All @@ -184,10 +191,11 @@ func (p *genesisParams) generatePolyBftChainConfig(o command.OutputFormatter) er
},
BlockTimeDrift: p.blockTimeDrift,
GovernanceConfig: &polybft.GovernanceConfig{
VotingDelay: voteDelay,
VotingPeriod: votingPeriod,
ProposalThreshold: proposalThreshold,
GovernorAdmin: governorAdminAddr,
VotingDelay: voteDelay,
VotingPeriod: votingPeriod,
ProposalThreshold: proposalThreshold,
ProposalQuorumPercentage: proposalQuorum,
GovernorAdmin: governorAdminAddr,
},
}

Expand Down
22 changes: 14 additions & 8 deletions consensus/polybft/polybft_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,18 @@ type GovernanceConfig struct {
// GovernorAdmin is the address of governance contract admin
// (he is the only one able to add new and remove old executors and proposers)
GovernorAdmin types.Address
// ProposalQuorumPercentage is the percentage of total validator stake needed for a
// governance proposal to be accepted
ProposalQuorumPercentage uint64
}

func (g *GovernanceConfig) MarshalJSON() ([]byte, error) {
raw := &governanceConfigRaw{
VotingDelay: types.EncodeBigInt(g.VotingDelay),
VotingPeriod: types.EncodeBigInt(g.VotingPeriod),
ProposalThreshold: types.EncodeBigInt(g.ProposalThreshold),
GovernorAdmin: g.GovernorAdmin,
VotingDelay: types.EncodeBigInt(g.VotingDelay),
VotingPeriod: types.EncodeBigInt(g.VotingPeriod),
ProposalThreshold: types.EncodeBigInt(g.ProposalThreshold),
GovernorAdmin: g.GovernorAdmin,
ProposalQuorumPercentage: g.ProposalQuorumPercentage,
}

return json.Marshal(raw)
Expand Down Expand Up @@ -287,13 +291,15 @@ func (g *GovernanceConfig) UnmarshalJSON(data []byte) error {
}

g.GovernorAdmin = raw.GovernorAdmin
g.ProposalQuorumPercentage = raw.ProposalQuorumPercentage

return nil
}

type governanceConfigRaw struct {
VotingDelay *string `json:"votingDelay"`
VotingPeriod *string `json:"votingPeriod"`
ProposalThreshold *string `json:"proposalThreshold"`
GovernorAdmin types.Address `json:"governorAdmin"`
VotingDelay *string `json:"votingDelay"`
VotingPeriod *string `json:"votingPeriod"`
ProposalThreshold *string `json:"proposalThreshold"`
GovernorAdmin types.Address `json:"governorAdmin"`
ProposalQuorumPercentage uint64 `json:"proposalQuorumPercentage"`
}