Skip to content

Commit

Permalink
Disable london hardfork if burn contract address is not provided (#1454)
Browse files Browse the repository at this point in the history
  • Loading branch information
begmaroman committed May 1, 2023
1 parent 66c7cea commit fff84d1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 22 deletions.
33 changes: 21 additions & 12 deletions command/genesis/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,12 @@ func (p *genesisParams) generateGenesis() error {
}

func (p *genesisParams) initGenesisConfig() error {
// Disable london hardfork if burn contract address is not provided
enabledForks := chain.AllForksEnabled
if len(p.burnContracts) == 0 {
enabledForks.London = nil
}

chainConfig := &chain.Chain{
Name: p.name,
Genesis: &chain.Genesis{
Expand All @@ -364,25 +370,28 @@ func (p *genesisParams) initGenesisConfig() error {
Alloc: map[types.Address]*chain.GenesisAccount{},
ExtraData: p.extraData,
GasUsed: command.DefaultGenesisGasUsed,
BaseFee: command.DefaultGenesisBaseFee,
BaseFeeEM: command.DefaultGenesisBaseFeeEM,
},
Params: &chain.Params{
ChainID: int64(p.chainID),
Forks: chain.AllForksEnabled,
Engine: p.consensusEngineConfig,
BurnContract: map[uint64]string{},
ChainID: int64(p.chainID),
Forks: enabledForks,
Engine: p.consensusEngineConfig,
},
Bootnodes: p.bootnodes,
}

for _, burnContract := range p.burnContracts {
block, address, err := parseBurnContractInfo(burnContract)
if err != nil {
return err
}
if len(p.burnContracts) > 0 {
chainConfig.Genesis.BaseFee = command.DefaultGenesisBaseFee
chainConfig.Genesis.BaseFeeEM = command.DefaultGenesisBaseFeeEM
chainConfig.Params.BurnContract = make(map[uint64]string, len(p.burnContracts))

for _, burnContract := range p.burnContracts {
block, address, err := parseBurnContractInfo(burnContract)
if err != nil {
return err
}

chainConfig.Params.BurnContract[block] = address.String()
chainConfig.Params.BurnContract[block] = address.String()
}
}

// Predeploy staking smart contract if needed
Expand Down
34 changes: 24 additions & 10 deletions command/genesis/polybft_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,20 @@ func (p *genesisParams) generatePolyBftChainConfig(o command.OutputFormatter) er
NativeTokenConfig: p.nativeTokenConfig,
}

// Disable london hardfork if burn contract address is not provided
enabledForks := chain.AllForksEnabled
if len(p.burnContracts) == 0 {
enabledForks.London = nil
}

chainConfig := &chain.Chain{
Name: p.name,
Params: &chain.Params{
ChainID: int64(p.chainID),
Forks: chain.AllForksEnabled,
Forks: enabledForks,
Engine: map[string]interface{}{
string(server.PolyBFTConsensus): polyBftConfig,
},
BurnContract: map[uint64]string{},
},
Bootnodes: p.bootnodes,
}
Expand Down Expand Up @@ -156,13 +161,17 @@ func (p *genesisParams) generatePolyBftChainConfig(o command.OutputFormatter) er
}
}

for _, burnContract := range p.burnContracts {
block, addr, err := parseBurnContractInfo(burnContract)
if err != nil {
return err
}
if len(p.burnContracts) > 0 {
chainConfig.Params.BurnContract = make(map[uint64]string, len(p.burnContracts))

chainConfig.Params.BurnContract[block] = addr.String()
for _, burnContract := range p.burnContracts {
block, addr, err := parseBurnContractInfo(burnContract)
if err != nil {
return err
}

chainConfig.Params.BurnContract[block] = addr.String()
}
}

validatorMetadata := make([]*polybft.ValidatorMetadata, len(initialValidators))
Expand Down Expand Up @@ -195,8 +204,6 @@ func (p *genesisParams) generatePolyBftChainConfig(o command.OutputFormatter) er
ExtraData: genesisExtraData,
GasUsed: command.DefaultGenesisGasUsed,
Mixhash: polybft.PolyBFTMixDigest,
BaseFee: chain.GenesisBaseFee,
BaseFeeEM: chain.GenesisBaseFeeEM,
}

if len(p.contractDeployerAllowListAdmin) != 0 {
Expand Down Expand Up @@ -253,6 +260,13 @@ func (p *genesisParams) generatePolyBftChainConfig(o command.OutputFormatter) er
}
}

if len(p.burnContracts) > 0 {
// 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
}

return helper.WriteGenesisConfigToDisk(chainConfig, params.genesisPath)
}

Expand Down

0 comments on commit fff84d1

Please sign in to comment.