forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extraction of chain configuration (ethereum#92)
Extraction of chain configuration
- Loading branch information
Showing
37 changed files
with
1,096 additions
and
456 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright 2019 The multi-geth Authors | ||
// This file is part of the multi-geth library. | ||
// | ||
// The multi-geth library is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// The multi-geth library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the multi-geth library. If not, see <http://www.gnu.org/licenses/>. | ||
package ethash | ||
|
||
import ( | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/core/state" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethereum/go-ethereum/params" | ||
) | ||
|
||
func ecip1017BlockReward(config *params.ChainConfig, state *state.StateDB, header *types.Header, uncles []*types.Header) { | ||
blockReward := FrontierBlockReward | ||
|
||
// Ensure value 'era' is configured. | ||
eraLen := config.ECIP1017EraRounds | ||
era := GetBlockEra(header.Number, eraLen) | ||
wr := GetBlockWinnerRewardByEra(era, blockReward) // wr "winner reward". 5, 4, 3.2, 2.56, ... | ||
wurs := GetBlockWinnerRewardForUnclesByEra(era, uncles, blockReward) // wurs "winner uncle rewards" | ||
wr.Add(wr, wurs) | ||
state.AddBalance(header.Coinbase, wr) // $$ | ||
|
||
// Reward uncle miners. | ||
for _, uncle := range uncles { | ||
ur := GetBlockUncleRewardByEra(era, header, uncle, blockReward) | ||
state.AddBalance(uncle.Coinbase, ur) // $$ | ||
} | ||
} | ||
|
||
func ecip1010Explosion(config *params.ChainConfig, next *big.Int, exPeriodRef *big.Int) { | ||
// https://github.com/ethereumproject/ECIPs/blob/master/ECIPs/ECIP-1010.md | ||
|
||
explosionBlock := new(big.Int).Add(config.ECIP1010PauseBlock, config.ECIP1010Length) | ||
if next.Cmp(explosionBlock) < 0 { | ||
exPeriodRef.Set(config.ECIP1010PauseBlock) | ||
} else { | ||
exPeriodRef.Sub(exPeriodRef, config.ECIP1010Length) | ||
} | ||
} | ||
|
||
// GetBlockEra gets which "Era" a given block is within, given an era length (ecip-1017 has era=5,000,000 blocks) | ||
// Returns a zero-index era number, so "Era 1": 0, "Era 2": 1, "Era 3": 2 ... | ||
func GetBlockEra(blockNum, eraLength *big.Int) *big.Int { | ||
// If genesis block or impossible negative-numbered block, return zero-val. | ||
if blockNum.Sign() < 1 { | ||
return new(big.Int) | ||
} | ||
|
||
remainder := big.NewInt(0).Mod(big.NewInt(0).Sub(blockNum, big.NewInt(1)), eraLength) | ||
base := big.NewInt(0).Sub(blockNum, remainder) | ||
|
||
d := big.NewInt(0).Div(base, eraLength) | ||
dremainder := big.NewInt(0).Mod(d, big.NewInt(1)) | ||
|
||
return new(big.Int).Sub(d, dremainder) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2019 The multi-geth Authors | ||
// This file is part of the multi-geth library. | ||
// | ||
// The multi-geth library is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// The multi-geth library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the multi-geth library. If not, see <http://www.gnu.org/licenses/>. | ||
package ethash | ||
|
||
import ( | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core/state" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethereum/go-ethereum/params" | ||
) | ||
|
||
func musicoinBlockReward(config *params.ChainConfig, state *state.StateDB, header *types.Header, uncles []*types.Header) { | ||
// Select the correct block reward based on chain progression | ||
blockReward := params.Mcip0BlockReward | ||
mcip3Reward := params.Mcip3BlockReward | ||
mcip8Reward := params.Mcip8BlockReward | ||
ubiReservoir := params.MusicoinUbiBlockReward | ||
devReservoir := params.MusicoinDevBlockReward | ||
|
||
reward := new(big.Int).Set(blockReward) | ||
|
||
if config.IsMCIP8(header.Number) { | ||
state.AddBalance(header.Coinbase, mcip8Reward) | ||
state.AddBalance(common.HexToAddress("0x00eFdd5883eC628983E9063c7d969fE268BBf310"), ubiReservoir) | ||
state.AddBalance(common.HexToAddress("0x00756cF8159095948496617F5FB17ED95059f536"), devReservoir) | ||
blockReward := mcip8Reward | ||
reward := new(big.Int).Set(blockReward) | ||
_ = reward | ||
} else if config.IsMCIP3(header.Number) { | ||
state.AddBalance(header.Coinbase, mcip3Reward) | ||
state.AddBalance(common.HexToAddress("0x00eFdd5883eC628983E9063c7d969fE268BBf310"), ubiReservoir) | ||
state.AddBalance(common.HexToAddress("0x00756cF8159095948496617F5FB17ED95059f536"), devReservoir) | ||
// no change to uncle reward during UBI fork, a mistake but now a legacy | ||
} else { | ||
state.AddBalance(header.Coinbase, reward) | ||
} | ||
|
||
// Accumulate the rewards for the miner and any included uncles | ||
r := new(big.Int) | ||
for _, uncle := range uncles { | ||
r.Add(uncle.Number, big8) | ||
r.Sub(r, header.Number) | ||
r.Mul(r, blockReward) | ||
r.Div(r, big8) | ||
state.AddBalance(uncle.Coinbase, r) | ||
|
||
r.Div(blockReward, big32) | ||
reward.Add(reward, r) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.