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

Base Fee Configs #1890

Merged
merged 17 commits into from
Oct 4, 2023
9 changes: 6 additions & 3 deletions command/default.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package command

import (
"fmt"

"github.com/umbracle/ethgo"

"github.com/0xPolygon/polygon-edge/chain"
Expand All @@ -18,9 +20,10 @@ const (
)

var (
DefaultStake = ethgo.Ether(1e6)
DefaultPremineBalance = ethgo.Ether(1e6)
DefaultGenesisBaseFee = chain.GenesisBaseFee
DefaultStake = ethgo.Ether(1e6)
DefaultPremineBalance = ethgo.Ether(1e6)
DefaultGenesisBaseFee = chain.GenesisBaseFee
DefaultGenesisBaseFeeConfig = fmt.Sprintf("%d:%d", DefaultGenesisBaseFee, DefaultGenesisBaseFeeEM)
)

const (
Expand Down
9 changes: 9 additions & 0 deletions command/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ func setFlags(cmd *cobra.Command) {
"the burn contract block and address (format: <block>:<address>[:<burn destination>])",
)

cmd.Flags().StringVar(
&params.baseFeeConfig,
genesisBaseFeeConfigFlag,
command.DefaultGenesisBaseFeeConfig,
`initial base fee(in wei) and baseFeeEM (format: <baseFee>[:<baseFeeEM>]).
rachit77 marked this conversation as resolved.
Show resolved Hide resolved
Default BaseFee is 1 Gwei and BaseFeeEM is 2.
Note: BaseFee and BaseFeeEM should be greater than 0.`,
)

cmd.Flags().StringArrayVar(
&params.bootnodes,
command.BootnodeFlag,
Expand Down
34 changes: 31 additions & 3 deletions command/genesis/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const (
epochRewardFlag = "epoch-reward"
blockGasLimitFlag = "block-gas-limit"
burnContractFlag = "burn-contract"
genesisBaseFeeConfigFlag = "genesis-base-fee-config"
posFlag = "pos"
minValidatorCount = "min-validator-count"
maxValidatorCount = "max-validator-count"
Expand Down Expand Up @@ -93,7 +94,8 @@ type genesisParams struct {
blockGasLimit uint64
isPos bool

burnContract string
burnContract string
baseFeeConfig string

minNumValidators uint64
maxNumValidators uint64
Expand Down Expand Up @@ -182,6 +184,10 @@ func (p *genesisParams) validateFlags() error {
return err
}

if err := p.validateGenesisBaseFeeConfig(); err != nil {
return err
}
rachit77 marked this conversation as resolved.
Show resolved Hide resolved

if err := p.validateRewardWallet(); err != nil {
return err
}
Expand Down Expand Up @@ -438,8 +444,9 @@ func (p *genesisParams) initGenesisConfig() error {

// burn contract can be set only for non mintable native token
if p.isBurnContractEnabled() {
chainConfig.Genesis.BaseFee = command.DefaultGenesisBaseFee
chainConfig.Genesis.BaseFeeEM = command.DefaultGenesisBaseFeeEM
baseFeeInfo, _ := parseBaseFeeConfig(p.baseFeeConfig)
Stefan-Ethernal marked this conversation as resolved.
Show resolved Hide resolved
chainConfig.Genesis.BaseFee = baseFeeInfo.baseFee
chainConfig.Genesis.BaseFeeEM = baseFeeInfo.baseFeeEM
chainConfig.Params.BurnContract = make(map[uint64]types.Address, 1)

burnContractInfo, err := parseBurnContractInfo(p.burnContract)
Expand Down Expand Up @@ -576,6 +583,27 @@ func (p *genesisParams) validateBurnContract() error {
return nil
}

func (p *genesisParams) validateGenesisBaseFeeConfig() error {
if p.baseFeeConfig == "" {
return errors.New("genesis base fee config must be set")
}
Stefan-Ethernal marked this conversation as resolved.
Show resolved Hide resolved

baseFeeInfo, err := parseBaseFeeConfig(p.baseFeeConfig)
rachit77 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}

if baseFeeInfo.baseFee <= 0 {
rachit77 marked this conversation as resolved.
Show resolved Hide resolved
return errors.New("BaseFee should be greater than 0")
}

if baseFeeInfo.baseFeeEM <= 0 {
return errors.New("BaseFeeEM should be graeter than 0")
}

return nil
}

func (p *genesisParams) validateProxyContractsAdmin() error {
if strings.TrimSpace(p.proxyContractsAdmin) == "" {
return errors.New("proxy contracts admin address must be set")
Expand Down
5 changes: 3 additions & 2 deletions command/genesis/polybft_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,9 @@ func (p *genesisParams) generatePolyBftChainConfig(o command.OutputFormatter) er
if p.isBurnContractEnabled() {
// only populate base fee and base fee multiplier values if burn contract(s)
// is provided
chainConfig.Genesis.BaseFee = command.DefaultGenesisBaseFee
chainConfig.Genesis.BaseFeeEM = command.DefaultGenesisBaseFeeEM
baseFeeInfo, _ := parseBaseFeeConfig(p.baseFeeConfig)
Stefan-Ethernal marked this conversation as resolved.
Show resolved Hide resolved
chainConfig.Genesis.BaseFee = baseFeeInfo.baseFee
chainConfig.Genesis.BaseFeeEM = baseFeeInfo.baseFeeEM
Stefan-Ethernal marked this conversation as resolved.
Show resolved Hide resolved
}

return helper.WriteGenesisConfigToDisk(chainConfig, params.genesisPath)
Expand Down
36 changes: 36 additions & 0 deletions command/genesis/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package genesis

import (
"encoding/hex"
"errors"
"fmt"
"io/ioutil"
"math/big"
Expand Down Expand Up @@ -164,6 +165,41 @@ func parseBurnContractInfo(burnContractInfoRaw string) (*polyCommon.BurnContract
}, nil
}

type baseFeeInfo struct {
baseFee uint64
baseFeeEM uint64
}

// parseBaseFeeConfig parses provided base fee configuration and returns baseFeeInfo
func parseBaseFeeConfig(baseFeeConfigRaw string) (*baseFeeInfo, error) {
baseFeeInfo := &baseFeeInfo{command.DefaultGenesisBaseFee, command.DefaultGenesisBaseFeeEM}

baseFeeConfig := strings.Split(baseFeeConfigRaw, ":")
if len(baseFeeConfig) > 2 {
igorcrevar marked this conversation as resolved.
Show resolved Hide resolved
return baseFeeInfo, errors.New("invalid number of arguments for base fee configuration")
}

if baseFeeConfig[0] != "" {
rachit77 marked this conversation as resolved.
Show resolved Hide resolved
baseFee, err := strconv.ParseUint(baseFeeConfig[0], 10, 64)
rachit77 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return baseFeeInfo, err
}

baseFeeInfo.baseFee = baseFee
}

if len(baseFeeConfig) == 2 && baseFeeConfig[1] != "" {
rachit77 marked this conversation as resolved.
Show resolved Hide resolved
baseFeeEM, err := strconv.ParseUint(baseFeeConfig[1], 10, 64)
rachit77 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return baseFeeInfo, err
}

baseFeeInfo.baseFeeEM = baseFeeEM
}

return baseFeeInfo, nil
}

// GetValidatorKeyFiles returns file names which has validator secrets
func GetValidatorKeyFiles(rootDir, filePrefix string) ([]string, error) {
if rootDir == "" {
Expand Down
Loading