mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
consensus/ethash, params: implement eip-2384: bump difficulty bomb
This commit is contained in:
parent
c5b46a79c1
commit
b039981dff
2 changed files with 17 additions and 3 deletions
|
|
@ -44,6 +44,12 @@ var (
|
||||||
maxUncles = 2 // Maximum number of uncles allowed in a single block
|
maxUncles = 2 // Maximum number of uncles allowed in a single block
|
||||||
allowedFutureBlockTime = 15 * time.Second // Max time from current time allowed for blocks, before they're considered future blocks
|
allowedFutureBlockTime = 15 * time.Second // Max time from current time allowed for blocks, before they're considered future blocks
|
||||||
|
|
||||||
|
// calcDifficultyEip2384 is the difficulty adjustment algorithm as specified by EIP 2384.
|
||||||
|
// It offsets the bomb 4M blocks from Constantinople, so in total 9M blocks.
|
||||||
|
// Specification EIP-2384 :https://github.com/ethereum/EIPs/pull/2384
|
||||||
|
// TODO: change link once it's merged
|
||||||
|
calcDifficultyEip2384 = makeDifficultyCalculator(big.NewInt(9000000))
|
||||||
|
|
||||||
// calcDifficultyConstantinople is the difficulty adjustment algorithm for Constantinople.
|
// calcDifficultyConstantinople is the difficulty adjustment algorithm for Constantinople.
|
||||||
// It returns the difficulty that a new block should have when created at time given the
|
// It returns the difficulty that a new block should have when created at time given the
|
||||||
// parent block's time and difficulty. The calculation uses the Byzantium rules, but with
|
// parent block's time and difficulty. The calculation uses the Byzantium rules, but with
|
||||||
|
|
@ -311,6 +317,8 @@ func (ethash *Ethash) CalcDifficulty(chain consensus.ChainReader, time uint64, p
|
||||||
func CalcDifficulty(config *params.ChainConfig, time uint64, parent *types.Header) *big.Int {
|
func CalcDifficulty(config *params.ChainConfig, time uint64, parent *types.Header) *big.Int {
|
||||||
next := new(big.Int).Add(parent.Number, big1)
|
next := new(big.Int).Add(parent.Number, big1)
|
||||||
switch {
|
switch {
|
||||||
|
case config.IsEip2384(next):
|
||||||
|
return calcDifficultyEip2384(time, parent)
|
||||||
case config.IsConstantinople(next):
|
case config.IsConstantinople(next):
|
||||||
return calcDifficultyConstantinople(time, parent)
|
return calcDifficultyConstantinople(time, parent)
|
||||||
case config.IsByzantium(next):
|
case config.IsByzantium(next):
|
||||||
|
|
|
||||||
|
|
@ -213,16 +213,16 @@ var (
|
||||||
//
|
//
|
||||||
// This configuration is intentionally not using keyed fields to force anyone
|
// This configuration is intentionally not using keyed fields to force anyone
|
||||||
// adding flags to the config to also have to set these fields.
|
// 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), nil, new(EthashConfig), 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), nil, nil, new(EthashConfig), nil}
|
||||||
|
|
||||||
// AllCliqueProtocolChanges contains every protocol change (EIPs) introduced
|
// AllCliqueProtocolChanges contains every protocol change (EIPs) introduced
|
||||||
// and accepted by the Ethereum core developers into the Clique consensus.
|
// and accepted by the Ethereum core developers into the Clique consensus.
|
||||||
//
|
//
|
||||||
// This configuration is intentionally not using keyed fields to force anyone
|
// This configuration is intentionally not using keyed fields to force anyone
|
||||||
// adding flags to the config to also have to set these fields.
|
// 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), nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}}
|
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), nil, nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}}
|
||||||
|
|
||||||
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), nil, new(EthashConfig), 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), nil, nil, new(EthashConfig), nil}
|
||||||
TestRules = TestChainConfig.Rules(new(big.Int))
|
TestRules = TestChainConfig.Rules(new(big.Int))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -293,6 +293,7 @@ type ChainConfig struct {
|
||||||
PetersburgBlock *big.Int `json:"petersburgBlock,omitempty"` // Petersburg switch block (nil = same as Constantinople)
|
PetersburgBlock *big.Int `json:"petersburgBlock,omitempty"` // Petersburg switch block (nil = same as Constantinople)
|
||||||
IstanbulBlock *big.Int `json:"istanbulBlock,omitempty"` // Istanbul switch block (nil = no fork, 0 = already on istanbul)
|
IstanbulBlock *big.Int `json:"istanbulBlock,omitempty"` // Istanbul switch block (nil = no fork, 0 = already on istanbul)
|
||||||
EWASMBlock *big.Int `json:"ewasmBlock,omitempty"` // EWASM switch block (nil = no fork, 0 = already activated)
|
EWASMBlock *big.Int `json:"ewasmBlock,omitempty"` // EWASM switch block (nil = no fork, 0 = already activated)
|
||||||
|
EIP2384Block *big.Int `json:"eip2384Block,omitempty"` // Eip-2384 (bomb delay) switch block (nil = no fork, 0 = already activated)
|
||||||
|
|
||||||
// Various consensus engines
|
// Various consensus engines
|
||||||
Ethash *EthashConfig `json:"ethash,omitempty"`
|
Ethash *EthashConfig `json:"ethash,omitempty"`
|
||||||
|
|
@ -380,6 +381,10 @@ func (c *ChainConfig) IsConstantinople(num *big.Int) bool {
|
||||||
return isForked(c.ConstantinopleBlock, num)
|
return isForked(c.ConstantinopleBlock, num)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *ChainConfig) IsEip2384(num *big.Int) bool {
|
||||||
|
return isForked(c.EIP2384Block, num)
|
||||||
|
}
|
||||||
|
|
||||||
// IsPetersburg returns whether num is either
|
// IsPetersburg returns whether num is either
|
||||||
// - equal to or greater than the PetersburgBlock fork block,
|
// - equal to or greater than the PetersburgBlock fork block,
|
||||||
// - OR is nil, and Constantinople is active
|
// - OR is nil, and Constantinople is active
|
||||||
|
|
@ -432,6 +437,7 @@ func (c *ChainConfig) CheckConfigForkOrder() error {
|
||||||
{"constantinopleBlock", c.ConstantinopleBlock},
|
{"constantinopleBlock", c.ConstantinopleBlock},
|
||||||
{"petersburgBlock", c.PetersburgBlock},
|
{"petersburgBlock", c.PetersburgBlock},
|
||||||
{"istanbulBlock", c.IstanbulBlock},
|
{"istanbulBlock", c.IstanbulBlock},
|
||||||
|
{"eip2384Block", c.EIP2384Block},
|
||||||
} {
|
} {
|
||||||
if lastFork.name != "" {
|
if lastFork.name != "" {
|
||||||
// Next one must be higher number
|
// Next one must be higher number
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue