Skip to content

Commit

Permalink
upgrade: rename hardfork to Luban & Plato (bnb-chain#1504)
Browse files Browse the repository at this point in the history
  • Loading branch information
brilliant-lx authored Apr 21, 2023
1 parent 54be51f commit 0222ce7
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 96 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ FEATURE
* [\#1325](https://github.com/bnb-chain/bsc/pull/1325) genesis: add BEP174 changes to relayer contract
* [\#1357](https://github.com/bnb-chain/bsc/pull/1357) Integration API for EIP-4337 bundler with an L2 validator/sequencer
* [\#1463](https://github.com/bnb-chain/bsc/pull/1463) BEP-221: implement cometBFT light block validation
* [\#1493](https://github.com/bnb-chain/bsc/pull/1493) bep: update the bytecode of boneh fork after the contract release
* [\#1493](https://github.com/bnb-chain/bsc/pull/1493) bep: update the bytecode of luban fork after the contract release

IMPROVEMENT
* [\#1486](https://github.com/bnb-chain/bsc/pull/1486) feature: remove diff protocol registration
Expand Down Expand Up @@ -91,7 +91,6 @@ BUGFIX

## v1.1.18
IMPROVEMENT

* [\#1209](https://github.com/bnb-chain/bsc/pull/1209) metrics: add build info into metrics server
* [\#1204](https://github.com/bnb-chain/bsc/pull/1204) worker: NewTxsEvent and triePrefetch reuse in mining task
* [\#1195](https://github.com/bnb-chain/bsc/pull/1195) hardfork: update Gibbs fork height and system contract code
Expand Down
2 changes: 1 addition & 1 deletion consensus/parlia/abi.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package parlia

const validatorSetABIBeforeBoneh = `
const validatorSetABIBeforeLuban = `
[
{
"anonymous": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/ethereum/go-ethereum/rpc"
)

func (p *Parlia) getCurrentValidatorsBeforeBoneh(blockHash common.Hash, blockNumber *big.Int) ([]common.Address, error) {
func (p *Parlia) getCurrentValidatorsBeforeLuban(blockHash common.Hash, blockNumber *big.Int) ([]common.Address, error) {
blockNr := rpc.BlockNumberOrHashWithHash(blockHash, false)

// prepare different method
Expand All @@ -25,7 +25,7 @@ func (p *Parlia) getCurrentValidatorsBeforeBoneh(blockHash common.Hash, blockNum
ctx, cancel := context.WithCancel(context.Background())
// cancel when we are finished consuming integers
defer cancel()
data, err := p.validatorSetABIBeforeBoneh.Pack(method)
data, err := p.validatorSetABIBeforeLuban.Pack(method)
if err != nil {
log.Error("Unable to pack tx for getValidators", "error", err)
return nil, err
Expand All @@ -44,6 +44,6 @@ func (p *Parlia) getCurrentValidatorsBeforeBoneh(blockHash common.Hash, blockNum
}

var valSet []common.Address
err = p.validatorSetABIBeforeBoneh.UnpackIntoInterface(&valSet, method, result)
err = p.validatorSetABIBeforeLuban.UnpackIntoInterface(&valSet, method, result)
return valSet, err
}
52 changes: 26 additions & 26 deletions consensus/parlia/parlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ const (
extraSeal = 65 // Fixed number of extra-data suffix bytes reserved for signer seal
nextForkHashSize = 4 // Fixed number of extra-data suffix bytes reserved for nextForkHash.

validatorBytesLengthBeforeBoneh = common.AddressLength
validatorBytesLengthBeforeLuban = common.AddressLength
validatorBytesLength = common.AddressLength + types.BLSPublicKeyLength
validatorNumberSize = 1 // Fixed number of extra prefix bytes reserved for validator number after Boneh
validatorNumberSize = 1 // Fixed number of extra prefix bytes reserved for validator number after Luban

wiggleTime = uint64(1) // second, Random delay (per signer) to allow concurrent signers
initialBackOffTime = uint64(1) // second
Expand Down Expand Up @@ -217,7 +217,7 @@ type Parlia struct {

ethAPI *ethapi.PublicBlockChainAPI
VotePool consensus.VotePool
validatorSetABIBeforeBoneh abi.ABI
validatorSetABIBeforeLuban abi.ABI
validatorSetABI abi.ABI
slashABI abi.ABI

Expand Down Expand Up @@ -249,7 +249,7 @@ func New(
if err != nil {
panic(err)
}
vABIBeforeBoneh, err := abi.JSON(strings.NewReader(validatorSetABIBeforeBoneh))
vABIBeforeLuban, err := abi.JSON(strings.NewReader(validatorSetABIBeforeLuban))
if err != nil {
panic(err)
}
Expand All @@ -269,7 +269,7 @@ func New(
ethAPI: ethAPI,
recentSnaps: recentSnaps,
signatures: signatures,
validatorSetABIBeforeBoneh: vABIBeforeBoneh,
validatorSetABIBeforeLuban: vABIBeforeLuban,
validatorSetABI: vABI,
slashABI: sABI,
signer: types.NewEIP155Signer(chainConfig.ChainID),
Expand Down Expand Up @@ -333,16 +333,16 @@ func (p *Parlia) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*typ

// getValidatorBytesFromHeader returns the validators bytes extracted from the header's extra field if exists.
// The validators bytes would be contained only in the epoch block's header, and its each validator bytes length is fixed.
// On boneh fork, we introduce vote attestation into the header's extra field, so extra format is different from before.
// Before boneh fork: |---Extra Vanity---|---Validators Bytes (or Empty)---|---Extra Seal---|
// After boneh fork: |---Extra Vanity---|---Validators Number and Validators Bytes (or Empty)---|---Vote Attestation (or Empty)---|---Extra Seal---|
// On luban fork, we introduce vote attestation into the header's extra field, so extra format is different from before.
// Before luban fork: |---Extra Vanity---|---Validators Bytes (or Empty)---|---Extra Seal---|
// After luban fork: |---Extra Vanity---|---Validators Number and Validators Bytes (or Empty)---|---Vote Attestation (or Empty)---|---Extra Seal---|
func getValidatorBytesFromHeader(header *types.Header, chainConfig *params.ChainConfig, parliaConfig *params.ParliaConfig) []byte {
if len(header.Extra) <= extraVanity+extraSeal {
return nil
}

if !chainConfig.IsBoneh(header.Number) {
if header.Number.Uint64()%parliaConfig.Epoch == 0 && (len(header.Extra)-extraSeal-extraVanity)%validatorBytesLengthBeforeBoneh != 0 {
if !chainConfig.IsLuban(header.Number) {
if header.Number.Uint64()%parliaConfig.Epoch == 0 && (len(header.Extra)-extraSeal-extraVanity)%validatorBytesLengthBeforeLuban != 0 {
return nil
}
return header.Extra[extraVanity : len(header.Extra)-extraSeal]
Expand All @@ -366,7 +366,7 @@ func getVoteAttestationFromHeader(header *types.Header, chainConfig *params.Chai
return nil, nil
}

if !chainConfig.IsBoneh(header.Number) {
if !chainConfig.IsLuban(header.Number) {
return nil, nil
}

Expand Down Expand Up @@ -596,7 +596,7 @@ func (p *Parlia) verifyCascadingFields(chain consensus.ChainHeaderReader, header

// Verify vote attestation for fast finality.
if err := p.verifyVoteAttestation(chain, header, parents); err != nil {
if chain.Config().IsLynn(header.Number) {
if chain.Config().IsPlato(header.Number) {
return err
}
log.Warn("Verify vote attestation failed", "error", err, "hash", header.Hash(), "number", header.Number,
Expand Down Expand Up @@ -691,9 +691,9 @@ func (p *Parlia) snapshot(chain consensus.ChainHeaderReader, number uint64, hash

verifiedAttestations := make(map[common.Hash]struct{}, len(headers))
for index, header := range headers {
// vote attestation should be checked here to decide whether to update attestation of snapshot between [Boneh,Lynn)
// because err of verifyVoteAttestation is ignored when importing blocks and headers before Lynn.
if p.chainConfig.IsBoneh(header.Number) && !p.chainConfig.IsLynn(header.Number) && p.verifyVoteAttestation(chain, header, headers[:index]) == nil {
// vote attestation should be checked here to decide whether to update attestation of snapshot between [Luban,Plato)
// because err of verifyVoteAttestation is ignored when importing blocks and headers before Plato.
if p.chainConfig.IsLuban(header.Number) && !p.chainConfig.IsPlato(header.Number) && p.verifyVoteAttestation(chain, header, headers[:index]) == nil {
verifiedAttestations[header.Hash()] = struct{}{}
}
}
Expand Down Expand Up @@ -792,7 +792,7 @@ func (p *Parlia) prepareValidators(header *types.Header) error {
}
// sort validator by address
sort.Sort(validatorsAscending(newValidators))
if !p.chainConfig.IsBoneh(header.Number) {
if !p.chainConfig.IsLuban(header.Number) {
for _, validator := range newValidators {
header.Extra = append(header.Extra, validator.Bytes()...)
}
Expand All @@ -807,7 +807,7 @@ func (p *Parlia) prepareValidators(header *types.Header) error {
}

func (p *Parlia) assembleVoteAttestation(chain consensus.ChainHeaderReader, header *types.Header) error {
if !p.chainConfig.IsBoneh(header.Number) || header.Number.Uint64() < 2 {
if !p.chainConfig.IsLuban(header.Number) || header.Number.Uint64() < 2 {
return nil
}

Expand Down Expand Up @@ -942,10 +942,10 @@ func (p *Parlia) verifyValidators(header *types.Header) error {
sort.Sort(validatorsAscending(newValidators))
var validatorsBytes []byte
validatorsNumber := len(newValidators)
if !p.chainConfig.IsBoneh(header.Number) {
validatorsBytes = make([]byte, validatorsNumber*validatorBytesLengthBeforeBoneh)
if !p.chainConfig.IsLuban(header.Number) {
validatorsBytes = make([]byte, validatorsNumber*validatorBytesLengthBeforeLuban)
for i, validator := range newValidators {
copy(validatorsBytes[i*validatorBytesLengthBeforeBoneh:], validator.Bytes())
copy(validatorsBytes[i*validatorBytesLengthBeforeLuban:], validator.Bytes())
}
} else {
if uint8(validatorsNumber) != header.Extra[extraVanity] {
Expand Down Expand Up @@ -1090,7 +1090,7 @@ func (p *Parlia) Finalize(chain consensus.ChainHeaderReader, header *types.Heade
return err
}

if p.chainConfig.IsLynn(header.Number) {
if p.chainConfig.IsPlato(header.Number) {
if err := p.distributeFinalityReward(chain, state, header, cx, txs, receipts, systemTxs, usedGas, false); err != nil {
return err
}
Expand Down Expand Up @@ -1147,7 +1147,7 @@ func (p *Parlia) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *
return nil, nil, err
}

if p.chainConfig.IsLynn(header.Number) {
if p.chainConfig.IsPlato(header.Number) {
if err := p.distributeFinalityReward(chain, state, header, cx, &txs, &receipts, nil, &header.GasUsed, true); err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -1479,8 +1479,8 @@ func (p *Parlia) getCurrentValidators(blockHash common.Hash, blockNum *big.Int)
// block
blockNr := rpc.BlockNumberOrHashWithHash(blockHash, false)

if !p.chainConfig.IsBoneh(blockNum) {
validators, err := p.getCurrentValidatorsBeforeBoneh(blockHash, blockNum)
if !p.chainConfig.IsLuban(blockNum) {
validators, err := p.getCurrentValidatorsBeforeLuban(blockHash, blockNum)
return validators, nil, err
}

Expand Down Expand Up @@ -1723,7 +1723,7 @@ func (p *Parlia) GetJustifiedNumberAndHash(chain consensus.ChainHeaderReader, he
}

if snap.Attestation == nil {
if p.chainConfig.IsBoneh(header.Number) {
if p.chainConfig.IsLuban(header.Number) {
log.Debug("once one attestation generated, attestation of snap would not be nil forever basically")
}
return 0, chain.GetHeaderByNumber(0).Hash(), nil
Expand All @@ -1739,7 +1739,7 @@ func (p *Parlia) GetFinalizedHeader(chain consensus.ChainHeaderReader, header *t
if chain == nil || header == nil {
return nil
}
if !chain.Config().IsLynn(header.Number) {
if !chain.Config().IsPlato(header.Number) {
return chain.GetHeaderByNumber(0)
}
if header.Number.Uint64() < backward {
Expand Down
16 changes: 8 additions & 8 deletions consensus/parlia/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func newSnapshot(
Validators: make(map[common.Address]*ValidatorInfo),
}
for idx, v := range validators {
// The boneh fork from the genesis block
// The luban fork from the genesis block
if len(voteAddrs) == len(validators) {
snap.Validators[v] = &ValidatorInfo{
VoteAddress: voteAddrs[idx],
Expand All @@ -84,7 +84,7 @@ func newSnapshot(
}
}

// The boneh fork from the genesis block
// The luban fork from the genesis block
if len(voteAddrs) == len(validators) {
validators := snap.validators()
for idx, v := range validators {
Expand Down Expand Up @@ -249,7 +249,7 @@ func (s *Snapshot) apply(headers []*types.Header, chain consensus.ChainHeaderRea
}
newVals := make(map[common.Address]*ValidatorInfo, len(newValArr))
for idx, val := range newValArr {
if !chainConfig.IsBoneh(header.Number) {
if !chainConfig.IsLuban(header.Number) {
newVals[val] = &ValidatorInfo{}
} else {
newVals[val] = &ValidatorInfo{
Expand All @@ -272,7 +272,7 @@ func (s *Snapshot) apply(headers []*types.Header, chain consensus.ChainHeaderRea
}
}
snap.Validators = newVals
if chainConfig.IsBoneh(header.Number) {
if chainConfig.IsLuban(header.Number) {
validators := snap.validators()
for idx, val := range validators {
snap.Validators[val].Index = idx + 1 // offset by 1
Expand All @@ -281,7 +281,7 @@ func (s *Snapshot) apply(headers []*types.Header, chain consensus.ChainHeaderRea
}

_, voteAssestationNoErr := verifiedAttestations[header.Hash()]
if chainConfig.IsLynn(header.Number) || (chainConfig.IsBoneh(header.Number) && voteAssestationNoErr) {
if chainConfig.IsPlato(header.Number) || (chainConfig.IsLuban(header.Number) && voteAssestationNoErr) {
snap.updateAttestation(header, chainConfig, s.config)
}

Expand Down Expand Up @@ -355,11 +355,11 @@ func parseValidators(header *types.Header, chainConfig *params.ChainConfig, parl
return nil, nil, errors.New("invalid validators bytes")
}

if !chainConfig.IsBoneh(header.Number) {
n := len(validatorsBytes) / validatorBytesLengthBeforeBoneh
if !chainConfig.IsLuban(header.Number) {
n := len(validatorsBytes) / validatorBytesLengthBeforeLuban
result := make([]common.Address, n)
for i := 0; i < n; i++ {
result[i] = common.BytesToAddress(validatorsBytes[i*validatorBytesLengthBeforeBoneh : (i+1)*validatorBytesLengthBeforeBoneh])
result[i] = common.BytesToAddress(validatorsBytes[i*validatorBytesLengthBeforeLuban : (i+1)*validatorBytesLengthBeforeLuban])
}
return result, nil, nil
}
Expand Down
4 changes: 2 additions & 2 deletions core/forkchoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ func (f *ForkChoice) ReorgNeededWithFastFinality(current *types.Header, header *
}

justifiedNumber, curJustifiedNumber := uint64(0), uint64(0)
if f.chain.Config().IsLynn(header.Number) {
if f.chain.Config().IsPlato(header.Number) {
justifiedNumber = f.chain.GetJustifiedNumber(header)
}
if f.chain.Config().IsLynn(current.Number) {
if f.chain.Config().IsPlato(current.Number) {
curJustifiedNumber = f.chain.GetJustifiedNumber(current)
}
if justifiedNumber == curJustifiedNumber {
Expand Down
18 changes: 9 additions & 9 deletions core/systemcontracts/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var (

planckUpgrade = make(map[string]*Upgrade)

bonehUpgrade = make(map[string]*Upgrade)
lubanUpgrade = make(map[string]*Upgrade)
)

func init() {
Expand Down Expand Up @@ -553,8 +553,8 @@ func init() {
},
}

bonehUpgrade[mainNet] = &Upgrade{
UpgradeName: "boneh",
lubanUpgrade[mainNet] = &Upgrade{
UpgradeName: "luban",
Configs: []*UpgradeConfig{
{
ContractAddr: common.HexToAddress(ValidatorContract),
Expand Down Expand Up @@ -584,8 +584,8 @@ func init() {
},
}

bonehUpgrade[chapelNet] = &Upgrade{
UpgradeName: "boneh",
lubanUpgrade[chapelNet] = &Upgrade{
UpgradeName: "luban",
Configs: []*UpgradeConfig{
{
ContractAddr: common.HexToAddress(ValidatorContract),
Expand Down Expand Up @@ -615,8 +615,8 @@ func init() {
},
}

bonehUpgrade[rialtoNet] = &Upgrade{
UpgradeName: "boneh",
lubanUpgrade[rialtoNet] = &Upgrade{
UpgradeName: "luban",
Configs: []*UpgradeConfig{
{
ContractAddr: common.HexToAddress(ValidatorContract),
Expand Down Expand Up @@ -697,8 +697,8 @@ func UpgradeBuildInSystemContract(config *params.ChainConfig, blockNumber *big.I
applySystemContractUpgrade(planckUpgrade[network], blockNumber, statedb, logger)
}

if config.IsOnBoneh(blockNumber) {
applySystemContractUpgrade(bonehUpgrade[network], blockNumber, statedb, logger)
if config.IsOnLuban(blockNumber) {
applySystemContractUpgrade(lubanUpgrade[network], blockNumber, statedb, logger)
}

/*
Expand Down
16 changes: 8 additions & 8 deletions core/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ var PrecompiledContractsBerlin = map[common.Address]PrecompiledContract{
common.BytesToAddress([]byte{9}): &blake2F{},
}

// PrecompiledContractsBoneh contains the default set of pre-compiled Ethereum
// contracts used in the Boneh release.
var PrecompiledContractsBoneh = map[common.Address]PrecompiledContract{
// PrecompiledContractsLuban contains the default set of pre-compiled Ethereum
// contracts used in the Luban release.
var PrecompiledContractsLuban = map[common.Address]PrecompiledContract{
common.BytesToAddress([]byte{1}): &ecrecover{},
common.BytesToAddress([]byte{2}): &sha256hash{},
common.BytesToAddress([]byte{3}): &ripemd160hash{},
Expand Down Expand Up @@ -175,7 +175,7 @@ var PrecompiledContractsBLS = map[common.Address]PrecompiledContract{
}

var (
PrecompiledAddressesBoneh []common.Address
PrecompiledAddressesLuban []common.Address
PrecompiledAddressesPlanck []common.Address
PrecompiledAddressesMoran []common.Address
PrecompiledAddressesNano []common.Address
Expand Down Expand Up @@ -207,16 +207,16 @@ func init() {
for k := range PrecompiledContractsPlanck {
PrecompiledAddressesPlanck = append(PrecompiledAddressesPlanck, k)
}
for k := range PrecompiledContractsBoneh {
PrecompiledAddressesBoneh = append(PrecompiledAddressesBoneh, k)
for k := range PrecompiledContractsLuban {
PrecompiledAddressesLuban = append(PrecompiledAddressesLuban, k)
}
}

// ActivePrecompiles returns the precompiles enabled with the current configuration.
func ActivePrecompiles(rules params.Rules) []common.Address {
switch {
case rules.IsBoneh:
return PrecompiledAddressesBoneh
case rules.IsLuban:
return PrecompiledAddressesLuban
case rules.IsPlanck:
return PrecompiledAddressesPlanck
case rules.IsMoran:
Expand Down
Loading

0 comments on commit 0222ce7

Please sign in to comment.