Skip to content

Commit

Permalink
Aves FORK halving
Browse files Browse the repository at this point in the history
  • Loading branch information
Toni-d-e-v committed Apr 15, 2024
1 parent af9c220 commit 1316a4d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
12 changes: 3 additions & 9 deletions consensus/ethash/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
20 changes: 16 additions & 4 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
)

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion params/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1316a4d

Please sign in to comment.