[R4R]: add Euler Hardfork, including BEP-127 and BEP-131 (#885)
* feat: add BEP-127 and BEP-131 hardfork bytecode to upgrade * feat: force check that Euler height cannot be a multiple of 200, fix getCurrentValidators, raise SystemTxsGas after Euler fork Co-authored-by: goth <goth>
This commit is contained in:
parent
5b5abc4e22
commit
4feb52e5b0
File diff suppressed because it is too large
Load Diff
@ -616,7 +616,7 @@ func (p *Parlia) Prepare(chain consensus.ChainHeaderReader, header *types.Header
|
||||
header.Extra = append(header.Extra, nextForkHash[:]...)
|
||||
|
||||
if number%p.config.Epoch == 0 {
|
||||
newValidators, err := p.getCurrentValidators(header.ParentHash)
|
||||
newValidators, err := p.getCurrentValidators(header.ParentHash, new(big.Int).Sub(header.Number, common.Big1))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -662,7 +662,7 @@ func (p *Parlia) Finalize(chain consensus.ChainHeaderReader, header *types.Heade
|
||||
// If the block is a epoch end block, verify the validator list
|
||||
// The verification can only be done when the state is ready, it can't be done in VerifyHeader.
|
||||
if header.Number.Uint64()%p.config.Epoch == 0 {
|
||||
newValidators, err := p.getCurrentValidators(header.ParentHash)
|
||||
newValidators, err := p.getCurrentValidators(header.ParentHash, new(big.Int).Sub(header.Number, common.Big1))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -997,12 +997,15 @@ func (p *Parlia) Close() error {
|
||||
// ========================== interaction with contract/account =========
|
||||
|
||||
// getCurrentValidators get current validators
|
||||
func (p *Parlia) getCurrentValidators(blockHash common.Hash) ([]common.Address, error) {
|
||||
func (p *Parlia) getCurrentValidators(blockHash common.Hash, blockNumber *big.Int) ([]common.Address, error) {
|
||||
// block
|
||||
blockNr := rpc.BlockNumberOrHashWithHash(blockHash, false)
|
||||
|
||||
// method
|
||||
method := "getValidators"
|
||||
if p.chainConfig.IsEuler(blockNumber) {
|
||||
method = "getMiningValidators"
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel() // cancel when we are finished consuming integers
|
||||
|
File diff suppressed because one or more lines are too long
@ -83,6 +83,7 @@ func generateTestChainWithFork(n int, fork int) (*core.Genesis, []*types.Block,
|
||||
NielsBlock: big.NewInt(0),
|
||||
MirrorSyncBlock: big.NewInt(0),
|
||||
BrunoBlock: big.NewInt(0),
|
||||
EulerBlock: big.NewInt(0),
|
||||
|
||||
Ethash: new(params.EthashConfig),
|
||||
}
|
||||
|
@ -761,7 +761,12 @@ func (w *worker) commitTransactions(txs *types.TransactionsByPriceAndNonce, coin
|
||||
|
||||
if w.current.gasPool == nil {
|
||||
w.current.gasPool = new(core.GasPool).AddGas(w.current.header.GasLimit)
|
||||
w.current.gasPool.SubGas(params.SystemTxsGas)
|
||||
if w.chain.Config().IsEuler(w.current.header.Number) {
|
||||
w.current.gasPool.SubGas(params.SystemTxsGas * 3)
|
||||
} else {
|
||||
w.current.gasPool.SubGas(params.SystemTxsGas)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var coalescedLogs []*types.Log
|
||||
|
@ -34,7 +34,7 @@ var (
|
||||
|
||||
BSCGenesisHash = common.HexToHash("0x0d21840abff46b96c84b2ac9e10e4f5cdaeb5693cb665db62a2f3b02d2d57b5b")
|
||||
ChapelGenesisHash = common.HexToHash("0x6d3c66c5357ec91d5c43af47e234a939b22557cbb552dc45bebbceeed90fbe34")
|
||||
RialtoGenesisHash = common.HexToHash("0xaabe549bfa85c84f7aee9da7010b97453ad686f2c2d8ce00503d1a00c72cad54")
|
||||
RialtoGenesisHash = common.HexToHash("0xee835a629f9cf5510b48b6ba41d69e0ff7d6ef10f977166ef939db41f59f5501")
|
||||
YoloV3GenesisHash = common.HexToHash("0xf1f2876e8500c77afcc03228757b39477eceffccf645b734967fe3c7e16967b7")
|
||||
)
|
||||
|
||||
@ -76,6 +76,7 @@ var (
|
||||
NielsBlock: big.NewInt(0),
|
||||
MirrorSyncBlock: big.NewInt(0),
|
||||
BrunoBlock: big.NewInt(0),
|
||||
EulerBlock: big.NewInt(0),
|
||||
BerlinBlock: big.NewInt(12_244_000),
|
||||
Ethash: new(EthashConfig),
|
||||
}
|
||||
@ -120,6 +121,7 @@ var (
|
||||
NielsBlock: big.NewInt(0),
|
||||
MirrorSyncBlock: big.NewInt(0),
|
||||
BrunoBlock: big.NewInt(0),
|
||||
EulerBlock: big.NewInt(0),
|
||||
BerlinBlock: big.NewInt(9_812_189),
|
||||
Ethash: new(EthashConfig),
|
||||
}
|
||||
@ -164,6 +166,7 @@ var (
|
||||
NielsBlock: big.NewInt(0),
|
||||
MirrorSyncBlock: big.NewInt(0),
|
||||
BrunoBlock: big.NewInt(0),
|
||||
EulerBlock: big.NewInt(0),
|
||||
BerlinBlock: big.NewInt(8_290_928),
|
||||
Clique: &CliqueConfig{
|
||||
Period: 15,
|
||||
@ -207,6 +210,7 @@ var (
|
||||
NielsBlock: big.NewInt(0),
|
||||
MirrorSyncBlock: big.NewInt(0),
|
||||
BrunoBlock: big.NewInt(0),
|
||||
EulerBlock: big.NewInt(0),
|
||||
IstanbulBlock: big.NewInt(1_561_651),
|
||||
MuirGlacierBlock: nil,
|
||||
BerlinBlock: big.NewInt(4_460_644),
|
||||
@ -251,6 +255,10 @@ var (
|
||||
NielsBlock: big.NewInt(0),
|
||||
MirrorSyncBlock: big.NewInt(5184000),
|
||||
BrunoBlock: big.NewInt(13082000),
|
||||
|
||||
// TODO modify blockNumber
|
||||
EulerBlock: nil,
|
||||
|
||||
Parlia: &ParliaConfig{
|
||||
Period: 3,
|
||||
Epoch: 200,
|
||||
@ -272,6 +280,10 @@ var (
|
||||
NielsBlock: big.NewInt(1014369),
|
||||
MirrorSyncBlock: big.NewInt(5582500),
|
||||
BrunoBlock: big.NewInt(13837000),
|
||||
|
||||
// TODO modify blockNumber
|
||||
EulerBlock: nil,
|
||||
|
||||
Parlia: &ParliaConfig{
|
||||
Period: 3,
|
||||
Epoch: 200,
|
||||
@ -293,6 +305,10 @@ var (
|
||||
NielsBlock: big.NewInt(0),
|
||||
MirrorSyncBlock: big.NewInt(400),
|
||||
BrunoBlock: big.NewInt(400),
|
||||
|
||||
// TODO
|
||||
EulerBlock: nil,
|
||||
|
||||
Parlia: &ParliaConfig{
|
||||
Period: 3,
|
||||
Epoch: 200,
|
||||
@ -316,6 +332,7 @@ var (
|
||||
NielsBlock: big.NewInt(0),
|
||||
MirrorSyncBlock: big.NewInt(0),
|
||||
BrunoBlock: big.NewInt(0),
|
||||
EulerBlock: big.NewInt(0),
|
||||
MuirGlacierBlock: nil,
|
||||
BerlinBlock: nil, // Don't enable Berlin directly, we're YOLOing it
|
||||
YoloV3Block: big.NewInt(0),
|
||||
@ -330,16 +347,16 @@ var (
|
||||
//
|
||||
// This configuration is intentionally not using keyed fields to force anyone
|
||||
// adding flags to the config to also have to set these fields.
|
||||
AllEthashProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), new(EthashConfig), nil, nil}
|
||||
AllEthashProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), new(EthashConfig), nil, nil}
|
||||
|
||||
// AllCliqueProtocolChanges contains every protocol change (EIPs) introduced
|
||||
// and accepted by the Ethereum core developers into the Clique consensus.
|
||||
//
|
||||
// This configuration is intentionally not using keyed fields to force anyone
|
||||
// adding flags to the config to also have to set these fields.
|
||||
AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, &CliqueConfig{Period: 0, Epoch: 30000}, nil}
|
||||
AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, &CliqueConfig{Period: 0, Epoch: 30000}, nil}
|
||||
|
||||
TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), new(EthashConfig), nil, nil}
|
||||
TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), new(EthashConfig), nil, nil}
|
||||
|
||||
TestRules = TestChainConfig.Rules(new(big.Int))
|
||||
)
|
||||
@ -427,6 +444,7 @@ type ChainConfig struct {
|
||||
NielsBlock *big.Int `json:"nielsBlock,omitempty" toml:",omitempty"` // nielsBlock switch block (nil = no fork, 0 = already activated)
|
||||
MirrorSyncBlock *big.Int `json:"mirrorSyncBlock,omitempty" toml:",omitempty"` // mirrorSyncBlock switch block (nil = no fork, 0 = already activated)
|
||||
BrunoBlock *big.Int `json:"brunoBlock,omitempty" toml:",omitempty"` // brunoBlock switch block (nil = no fork, 0 = already activated)
|
||||
EulerBlock *big.Int `json:"eulerBlock,omitempty" toml:",omitempty"` // eulerBlock switch block (nil = no fork, 0 = already activated)
|
||||
|
||||
// Various consensus engines
|
||||
Ethash *EthashConfig `json:"ethash,omitempty" toml:",omitempty"`
|
||||
@ -477,7 +495,7 @@ func (c *ChainConfig) String() string {
|
||||
default:
|
||||
engine = "unknown"
|
||||
}
|
||||
return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Petersburg: %v Istanbul: %v, Muir Glacier: %v, Ramanujan: %v, Niels: %v, MirrorSync: %v, Bruno: %v, Berlin: %v, YOLO v3: %v, Engine: %v}",
|
||||
return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Petersburg: %v Istanbul: %v, Muir Glacier: %v, Ramanujan: %v, Niels: %v, MirrorSync: %v, Bruno: %v, Berlin: %v, YOLO v3: %v, Euler: %v, Engine: %v}",
|
||||
c.ChainID,
|
||||
c.HomesteadBlock,
|
||||
c.DAOForkBlock,
|
||||
@ -496,6 +514,7 @@ func (c *ChainConfig) String() string {
|
||||
c.BrunoBlock,
|
||||
c.BerlinBlock,
|
||||
c.YoloV3Block,
|
||||
c.EulerBlock,
|
||||
engine,
|
||||
)
|
||||
}
|
||||
@ -575,6 +594,16 @@ func (c *ChainConfig) IsOnBruno(num *big.Int) bool {
|
||||
return configNumEqual(c.BrunoBlock, num)
|
||||
}
|
||||
|
||||
// IsEuler returns whether num is either equal to the euler fork block or greater.
|
||||
func (c *ChainConfig) IsEuler(num *big.Int) bool {
|
||||
return isForked(c.EulerBlock, num)
|
||||
}
|
||||
|
||||
// IsOnEuler returns whether num is equal to the euler fork block
|
||||
func (c *ChainConfig) IsOnEuler(num *big.Int) bool {
|
||||
return configNumEqual(c.EulerBlock, num)
|
||||
}
|
||||
|
||||
// IsMuirGlacier returns whether num is either equal to the Muir Glacier (EIP-2384) fork block or greater.
|
||||
func (c *ChainConfig) IsMuirGlacier(num *big.Int) bool {
|
||||
return isForked(c.MuirGlacierBlock, num)
|
||||
@ -637,6 +666,7 @@ func (c *ChainConfig) CheckConfigForkOrder() error {
|
||||
for _, cur := range []fork{
|
||||
{name: "mirrorSyncBlock", block: c.MirrorSyncBlock},
|
||||
{name: "brunoBlock", block: c.BrunoBlock},
|
||||
{name: "eulerBlock", block: c.EulerBlock},
|
||||
{name: "berlinBlock", block: c.BerlinBlock},
|
||||
} {
|
||||
if lastFork.name != "" {
|
||||
@ -719,6 +749,9 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, head *big.Int) *Confi
|
||||
if isForkIncompatible(c.BrunoBlock, newcfg.BrunoBlock, head) {
|
||||
return newCompatError("bruno fork block", c.BrunoBlock, newcfg.BrunoBlock)
|
||||
}
|
||||
if isForkIncompatible(c.EulerBlock, newcfg.EulerBlock, head) {
|
||||
return newCompatError("euler fork block", c.EulerBlock, newcfg.EulerBlock)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user