Skip to content

Commit

Permalink
[RFC-191] On-chain governance (#1519)
Browse files Browse the repository at this point in the history
* Add governance parameters to genesis an polybft config

* Add Governance as fork (#1700)

* [RFC-191] Add `governorAdmin` flag (#1728)

* Add governorAdmin flag

* Comments fix

* [RFC-191]: Add governance `proposal-quorum` flag (#1730)

* Add proposal-quorum flag

* Comments fix

* [RFC-191]: EVM-740 - Move distribute rewards to first block in epoch (#1735)

* Move distribute rewards to first block of epoch

* Modification of reward distribution as part of governance fork

* Small change

* Comments fix

* Rebase fix

* [RFC-191]: EVM-556 - Deploy governance contracts (#1733)

* Add contracts

* Fix integration test

* [RFC-191]: EVM-558 - Update client configuration based on governance proposals (#1749)

* GovernanceManager

* PostEpoch

* PostBlock and update of client config

* Lint fix

* UTs

* Comments fix

* Retry in PostEpoch as well

* Comments fix

* Rebase fix

* [RFC-191]: EVM-750 - Governance e2e tests (#1761)

* Governance e2e tests

* Comments fix

* [RFC-191]: EVM-760 - Utilize `ForkParams` contract (#1788)

* Add forks activation based on ForkParams contract

* Comments fix

* Don't use hardcoded addresses for governance contracts (#1790)

* Rebase fix

* Minor optimization (#1798)

* Rebase fix

* Small fixes

* Small fix

* Comments fix

* Fix cluster script (provide governor-admin only for polybft consensus)

* Increase E2E tests timeout

* Comments fix

* Comments fix

* Comments fix

---------

Co-authored-by: Stefan Negovanović <93934272+Stefan-Ethernal@users.noreply.github.com>
Co-authored-by: Stefan Negovanović <stefan@ethernal.tech>
  • Loading branch information
3 people committed Sep 5, 2023
1 parent 0635afe commit 3cae93a
Show file tree
Hide file tree
Showing 48 changed files with 3,430 additions and 688 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ test-e2e: check-go
test-e2e-polybft: check-go
go build -o artifacts/polygon-edge .
env EDGE_BINARY=${PWD}/artifacts/polygon-edge E2E_TESTS=true E2E_LOGS=true \
go test -v -timeout=1h10m ./e2e-polybft/e2e/...
go test -v -timeout=1h30m ./e2e-polybft/e2e/...

.PHONY: test-property-polybft
test-property-polybft: check-go
Expand Down
6 changes: 5 additions & 1 deletion chain/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const (
QuorumCalcAlignment = "quorumcalcalignment"
TxHashWithType = "txHashWithType"
LondonFix = "londonfix"
Governance = "governance"
)

// Forks is map which contains all forks and their starting blocks from genesis
Expand Down Expand Up @@ -127,6 +128,7 @@ func (f *Forks) At(block uint64) ForksInTime {
QuorumCalcAlignment: f.IsActive(QuorumCalcAlignment, block),
TxHashWithType: f.IsActive(TxHashWithType, block),
LondonFix: f.IsActive(LondonFix, block),
Governance: f.IsActive(Governance, block),
}
}

Expand Down Expand Up @@ -156,7 +158,8 @@ type ForksInTime struct {
EIP155,
QuorumCalcAlignment,
TxHashWithType,
LondonFix bool
LondonFix,
Governance bool
}

// AllForksEnabled should contain all supported forks by current edge version
Expand All @@ -173,4 +176,5 @@ var AllForksEnabled = &Forks{
QuorumCalcAlignment: NewFork(0),
TxHashWithType: NewFork(0),
LondonFix: NewFork(0),
Governance: NewFork(0),
}
6 changes: 3 additions & 3 deletions command/bridge/deposit/erc1155/deposit_erc1155.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ func runCommand(cmd *cobra.Command, _ []string) {
return
}

receivers := make([]ethgo.Address, len(dp.Receivers))
receivers := make([]types.Address, len(dp.Receivers))
for i, receiverRaw := range dp.Receivers {
receivers[i] = ethgo.Address(types.StringToAddress(receiverRaw))
receivers[i] = types.StringToAddress(receiverRaw)
}

// deposit tokens
Expand Down Expand Up @@ -245,7 +245,7 @@ func runCommand(cmd *cobra.Command, _ []string) {
}

// createDepositTxn encodes parameters for deposit function on rootchain predicate contract
func createDepositTxn(sender ethgo.Address, receivers []ethgo.Address,
func createDepositTxn(sender ethgo.Address, receivers []types.Address,
amounts, tokenIDs []*big.Int) (*ethgo.Transaction, error) {
depositBatchFn := &contractsapi.DepositBatchRootERC1155PredicateFn{
RootToken: types.StringToAddress(dp.TokenAddr),
Expand Down
6 changes: 3 additions & 3 deletions command/bridge/deposit/erc721/deposit_erc721.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func runCommand(cmd *cobra.Command, _ []string) {
return
}

receivers := make([]ethgo.Address, len(dp.Receivers))
receivers := make([]types.Address, len(dp.Receivers))
tokenIDs := make([]*big.Int, len(dp.Receivers))

for i, tokenIDRaw := range dp.TokenIDs {
Expand All @@ -106,7 +106,7 @@ func runCommand(cmd *cobra.Command, _ []string) {
return
}

receivers[i] = ethgo.Address(types.StringToAddress(dp.Receivers[i]))
receivers[i] = types.StringToAddress(dp.Receivers[i])
tokenIDs[i] = tokenID
}

Expand Down Expand Up @@ -220,7 +220,7 @@ func runCommand(cmd *cobra.Command, _ []string) {

// createDepositTxn encodes parameters for deposit function on rootchain predicate contract
func createDepositTxn(sender ethgo.Address,
receivers []ethgo.Address, tokenIDs []*big.Int) (*ethgo.Transaction, error) {
receivers []types.Address, tokenIDs []*big.Int) (*ethgo.Transaction, error) {
depositToRoot := &contractsapi.DepositBatchRootERC721PredicateFn{
RootToken: types.StringToAddress(dp.TokenAddr),
Receivers: receivers,
Expand Down
6 changes: 3 additions & 3 deletions command/bridge/withdraw/erc1155/withdraw_erc1155.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ func runCommand(cmd *cobra.Command, _ []string) {
return
}

receivers := make([]ethgo.Address, len(wp.Receivers))
receivers := make([]types.Address, len(wp.Receivers))
amounts := make([]*big.Int, len(wp.Receivers))
TokenIDs := make([]*big.Int, len(wp.Receivers))

for i, receiverRaw := range wp.Receivers {
receivers[i] = ethgo.Address(types.StringToAddress(receiverRaw))
receivers[i] = types.StringToAddress(receiverRaw)
amountRaw := wp.Amounts[i]
tokenIDRaw := wp.TokenIDs[i]

Expand Down Expand Up @@ -173,7 +173,7 @@ func runCommand(cmd *cobra.Command, _ []string) {
}

// createWithdrawTxn encodes parameters for withdraw function on child chain predicate contract
func createWithdrawTxn(receivers []ethgo.Address, amounts, TokenIDs []*big.Int) (*ethgo.Transaction, error) {
func createWithdrawTxn(receivers []types.Address, amounts, TokenIDs []*big.Int) (*ethgo.Transaction, error) {
withdrawFn := &contractsapi.WithdrawBatchChildERC1155PredicateFn{
ChildToken: types.StringToAddress(wp.TokenAddr),
Receivers: receivers,
Expand Down
6 changes: 3 additions & 3 deletions command/bridge/withdraw/erc721/withdraw_erc721.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func run(cmd *cobra.Command, _ []string) {
return
}

receivers := make([]ethgo.Address, len(wp.Receivers))
receivers := make([]types.Address, len(wp.Receivers))
tokenIDs := make([]*big.Int, len(wp.Receivers))

for i, tokenIDRaw := range wp.TokenIDs {
Expand All @@ -103,7 +103,7 @@ func run(cmd *cobra.Command, _ []string) {
return
}

receivers[i] = ethgo.Address(types.StringToAddress(wp.Receivers[i]))
receivers[i] = types.StringToAddress(wp.Receivers[i])
tokenIDs[i] = tokenID
}

Expand Down Expand Up @@ -152,7 +152,7 @@ func run(cmd *cobra.Command, _ []string) {
}

// createWithdrawTxn encodes parameters for withdraw function on child chain predicate contract
func createWithdrawTxn(receivers []ethgo.Address, tokenIDs []*big.Int) (*ethgo.Transaction, error) {
func createWithdrawTxn(receivers []types.Address, tokenIDs []*big.Int) (*ethgo.Transaction, error) {
withdrawToFn := &contractsapi.WithdrawBatchChildERC721PredicateFn{
ChildToken: types.StringToAddress(wp.TokenAddr),
Receivers: receivers,
Expand Down
55 changes: 54 additions & 1 deletion command/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func setFlags(cmd *cobra.Command) {
cmd.Flags().Uint64Var(
&params.minNumValidators,
minValidatorCount,
1,
4,
"the minimum number of validators in the validator set for PoS",
)

Expand Down Expand Up @@ -235,6 +235,59 @@ func setFlags(cmd *cobra.Command) {
defaultBlockTimeDrift,
"configuration for block time drift value (in seconds)",
)

cmd.Flags().Uint64Var(
&params.checkpointInterval,
checkpointIntervalFlag,
defaultCheckpointInterval,
"checkpoint submission interval in blocks",
)

cmd.Flags().Uint64Var(
&params.withdrawalWaitPeriod,
withdrawalWaitPeriodFlag,
defaultWithdrawalWaitPeriod,
"number of epochs after which withdrawal can be done from child chain",
)
}

// Governance
{
cmd.Flags().StringVar(
&params.voteDelay,
voteDelayFlag,
defaultVotingDelay,
"number of blocks after proposal is submitted before voting starts",
)

cmd.Flags().StringVar(
&params.votingPeriod,
votePeriodFlag,
defaultVotingPeriod,
"number of blocks that the voting period for a proposal lasts",
)

cmd.Flags().StringVar(
&params.proposalThreshold,
voteProposalThresholdFlag,
defaultVoteProposalThreshold,
"number of vote tokens (in wei) required in order for a voter to submit a proposal",
)

cmd.Flags().StringVar(
&params.governorAdmin,
governorAdminFlag,
"",
"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
60 changes: 46 additions & 14 deletions command/genesis/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,27 @@ import (
)

const (
dirFlag = "dir"
nameFlag = "name"
premineFlag = "premine"
chainIDFlag = "chain-id"
epochSizeFlag = "epoch-size"
epochRewardFlag = "epoch-reward"
blockGasLimitFlag = "block-gas-limit"
burnContractFlag = "burn-contract"
posFlag = "pos"
minValidatorCount = "min-validator-count"
maxValidatorCount = "max-validator-count"
nativeTokenConfigFlag = "native-token-config"
rewardTokenCodeFlag = "reward-token-code"
rewardWalletFlag = "reward-wallet"
dirFlag = "dir"
nameFlag = "name"
premineFlag = "premine"
chainIDFlag = "chain-id"
epochSizeFlag = "epoch-size"
epochRewardFlag = "epoch-reward"
blockGasLimitFlag = "block-gas-limit"
burnContractFlag = "burn-contract"
posFlag = "pos"
minValidatorCount = "min-validator-count"
maxValidatorCount = "max-validator-count"
nativeTokenConfigFlag = "native-token-config"
rewardTokenCodeFlag = "reward-token-code"
rewardWalletFlag = "reward-wallet"
checkpointIntervalFlag = "checkpoint-interval"
withdrawalWaitPeriodFlag = "withdrawal-wait-period"
voteDelayFlag = "vote-delay"
votePeriodFlag = "vote-period"
voteProposalThresholdFlag = "vote-proposal-threshold"
governorAdminFlag = "governor-admin"
proposalQuorumFlag = "proposal-quorum"

defaultNativeTokenName = "Polygon"
defaultNativeTokenSymbol = "MATIC"
Expand All @@ -63,6 +70,8 @@ var (
"(<name:symbol:decimals count:mintable flag:[mintable token owner address]>)")
errRewardWalletAmountZero = errors.New("reward wallet amount can not be zero or negative")
errReserveAccMustBePremined = errors.New("it is mandatory to premine reserve account (0x0 address)")
errInvalidVotingPeriod = errors.New("voting period can not be zero")
errInvalidGovernorAdmin = errors.New("governor admin address must be defined")
)

type genesisParams struct {
Expand Down Expand Up @@ -131,6 +140,16 @@ type genesisParams struct {
// rewards
rewardTokenCode string
rewardWallet string

checkpointInterval uint64
withdrawalWaitPeriod uint64

// governance
voteDelay string
votingPeriod string
proposalThreshold string
proposalQuorum uint64
governorAdmin string
}

func (p *genesisParams) validateFlags() error {
Expand Down Expand Up @@ -166,6 +185,10 @@ func (p *genesisParams) validateFlags() error {
if err := p.validatePremineInfo(); err != nil {
return err
}

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

// Check if the genesis file already exists
Expand Down Expand Up @@ -512,6 +535,15 @@ func (p *genesisParams) validatePremineInfo() error {
return errReserveAccMustBePremined
}

// validateGovernorAdminAddr validates governor admin address
func (p *genesisParams) validateGovernorAdminAddr() error {
if err := types.IsValidAddress(p.governorAdmin); err != nil {
return fmt.Errorf("governor admin address is not valid: %w", err)
}

return nil
}

// validateBurnContract validates burn contract. If native token is mintable,
// burn contract flag must not be set. If native token is non mintable only one burn contract
// can be set and the specified address will be used to predeploy default EIP1559 burn contract.
Expand Down
Loading

0 comments on commit 3cae93a

Please sign in to comment.