diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go index 693028881..e8e1b733b 100644 --- a/consensus/ethash/consensus.go +++ b/consensus/ethash/consensus.go @@ -47,7 +47,6 @@ var ( ConstantinopleBlockReward = new(big.Int).Mul(big.NewInt(3), big.NewInt(1e+18))// Block reward in wei for successfully mining a block upward from Constantinople maxUncles = 2 // Maximum number of uncles allowed in a single block allowedFutureBlockTimeSeconds = int64(15) // Max seconds from current time allowed for blocks, before they're considered future blocks - halvingBlockStart = int64(3350000) // calcDifficultyEip5133 is the difficulty adjustment algorithm as specified by EIP 5133. // It offsets the bomb a total of 11.4M blocks. // Specification EIP-5133: https://eips.ethereum.org/EIPS/eip-5133 @@ -657,16 +656,11 @@ func accumulateRewards(config *params.ChainConfig, state *state.StateDB, header blockReward := FrontierBlockReward // Reward for the miner (coinbase) minerReward := new(big.Int).Set(blockReward) - - // Convert halvingBlockStart to big.Int - halvingBlock := new(big.Int).SetInt64(halvingBlockStart) - // Apply halving logic if applicable - if header.Number.Cmp(halvingBlock) > 0 { - // Halve the block reward - minerReward.Div(minerReward, big.NewInt(2)) - } + if config.IsAvesHalving(header.Number) { + minerReward.Div(minerReward, big.NewInt(2)) + } // Distribute rewards // 95% goes to the miner reward95 := new(big.Int).Mul(minerReward, big.NewInt(95)) diff --git a/params/config.go b/params/config.go index 0b50a7685..608a3e0f8 100644 --- a/params/config.go +++ b/params/config.go @@ -68,6 +68,7 @@ var ( MuirGlacierBlock: big.NewInt(0), BerlinBlock: big.NewInt(0), LondonBlock: big.NewInt(0), + AvesHalvingBlock: big.NewInt(3350000), DAOForkBlock: nil, DAOForkSupport: false, TerminalTotalDifficulty: nil, @@ -259,17 +260,17 @@ 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), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, nil, false, 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), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0),big.NewInt(0), nil, nil, nil, nil, false, new(EthashConfig), 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), big.NewInt(0), nil, nil, nil, nil, nil, nil, false, 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), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, nil, nil, nil, false, 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), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, nil, false, new(EthashConfig), nil} - NonActivatedConfig = &ChainConfig{big.NewInt(1), nil, nil, false, nil, common.Hash{}, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, false, 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), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, nil, false, new(EthashConfig), nil} + NonActivatedConfig = &ChainConfig{big.NewInt(1), nil, nil, false, nil, common.Hash{}, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,nil, nil, nil, nil, nil, false, new(EthashConfig), nil} TestRules = TestChainConfig.Rules(new(big.Int), false) ) @@ -362,6 +363,7 @@ type ChainConfig struct { MergeNetsplitBlock *big.Int `json:"mergeNetsplitBlock,omitempty"` // Virtual fork after The Merge to use as a network splitter ShanghaiBlock *big.Int `json:"shanghaiBlock,omitempty"` // Shanghai switch block (nil = no fork, 0 = already on shanghai) CancunBlock *big.Int `json:"cancunBlock,omitempty"` // Cancun switch block (nil = no fork, 0 = already on cancun) + AvesHalvingBlock *big.Int `json:"AvesHalvingBlock,omitempty"` // TerminalTotalDifficulty is the amount of total difficulty reached by // the network that triggers the consensus upgrade. @@ -575,6 +577,8 @@ func (c *ChainConfig) CheckConfigForkOrder() error { {name: "mergeNetsplitBlock", block: c.MergeNetsplitBlock, optional: true}, {name: "shanghaiBlock", block: c.ShanghaiBlock, optional: true}, {name: "cancunBlock", block: c.CancunBlock, optional: true}, + {name: "AvesHalvingBlock", block: c.AvesHalvingBlock }, + } { if lastFork.name != "" { // Next one must be higher number @@ -625,6 +629,9 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, head *big.Int) *Confi if isForkIncompatible(c.ConstantinopleBlock, newcfg.ConstantinopleBlock, head) { return newCompatError("Constantinople fork block", c.ConstantinopleBlock, newcfg.ConstantinopleBlock) } + if isForkIncompatible(c.AvesHalvingBlock, newcfg.AvesHalvingBlock, head) { + return newCompatError("AvesHalvingBlock fork block", c.AvesHalvingBlock, newcfg.AvesHalvingBlock) + } if isForkIncompatible(c.PetersburgBlock, newcfg.PetersburgBlock, head) { // the only case where we allow Petersburg to be set in the past is if it is equal to Constantinople // mainly to satisfy fork ordering requirements which state that Petersburg fork be set if Constantinople fork is set @@ -713,6 +720,11 @@ func newCompatError(what string, storedblock, newblock *big.Int) *ConfigCompatEr return err } +func (c *ChainConfig) IsAvesHalving(num *big.Int) bool { + return isForked(c.AvesHalvingBlock, num) +} + + func (err *ConfigCompatError) Error() string { return fmt.Sprintf("mismatching %s in database (have %d, want %d, rewindto %d)", err.What, err.StoredConfig, err.NewConfig, err.RewindTo) } diff --git a/params/version.go b/params/version.go index ebfb6d680..b12b59f28 100644 --- a/params/version.go +++ b/params/version.go @@ -21,7 +21,7 @@ import ( ) const ( - VersionMajor = 1 // Major version component of the current release + VersionMajor = 2 // Major version component of the current release VersionMinor = 1 // Minor version component of the current release VersionPatch = 0 // Patch version component of the current release VersionMeta = "unstable" // Version metadata to append to the version string