consensus, core, params: rebrand Metro to Byzantium

This commit is contained in:
Péter Szilágyi 2017-09-14 10:07:31 +03:00
parent 79b11121a7
commit 5bbd7fb390
No known key found for this signature in database
GPG Key ID: E9AE538CEDF8293D
12 changed files with 86 additions and 86 deletions

View File

@ -36,9 +36,9 @@ import (
// Ethash proof-of-work protocol constants. // Ethash proof-of-work protocol constants.
var ( var (
frontierBlockReward *big.Int = big.NewInt(5e+18) // Block reward in wei for successfully mining a block frontierBlockReward *big.Int = big.NewInt(5e+18) // Block reward in wei for successfully mining a block
metropolisBlockReward *big.Int = big.NewInt(3e+18) // Block reward in wei for successfully mining a block upward from Metropolis byzantiumBlockReward *big.Int = big.NewInt(3e+18) // Block reward in wei for successfully mining a block upward from Byzantium
maxUncles = 2 // Maximum number of uncles allowed in a single block maxUncles = 2 // Maximum number of uncles allowed in a single block
) )
// Various error messages to mark blocks invalid. These should be private to // Various error messages to mark blocks invalid. These should be private to
@ -290,8 +290,8 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainReader, header, parent *
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.IsMetropolis(next): case config.IsByzantium(next):
return calcDifficultyMetropolis(time, parent) return calcDifficultyByzantium(time, parent)
case config.IsHomestead(next): case config.IsHomestead(next):
return calcDifficultyHomestead(time, parent) return calcDifficultyHomestead(time, parent)
default: default:
@ -310,10 +310,10 @@ var (
big2999999 = big.NewInt(2999999) big2999999 = big.NewInt(2999999)
) )
// calcDifficultyMetropolis is the difficulty adjustment algorithm. It returns // calcDifficultyByzantium is the difficulty adjustment algorithm. It returns
// the difficulty that a new block should have when created at time given the // the difficulty that a new block should have when created at time given the
// parent block's time and difficulty. The calculation uses the Metropolis rules. // parent block's time and difficulty. The calculation uses the Byzantium rules.
func calcDifficultyMetropolis(time uint64, parent *types.Header) *big.Int { func calcDifficultyByzantium(time uint64, parent *types.Header) *big.Int {
// https://github.com/ethereum/EIPs/issues/100. // https://github.com/ethereum/EIPs/issues/100.
// algorithm: // algorithm:
// diff = (parent_diff + // diff = (parent_diff +
@ -530,8 +530,8 @@ var (
func AccumulateRewards(config *params.ChainConfig, state *state.StateDB, header *types.Header, uncles []*types.Header) { func AccumulateRewards(config *params.ChainConfig, state *state.StateDB, header *types.Header, uncles []*types.Header) {
// Select the correct block reward based on chain progression // Select the correct block reward based on chain progression
blockReward := frontierBlockReward blockReward := frontierBlockReward
if config.IsMetropolis(header.Number) { if config.IsByzantium(header.Number) {
blockReward = metropolisBlockReward blockReward = byzantiumBlockReward
} }
// Accumulate the rewards for the miner and any included uncles // Accumulate the rewards for the miner and any included uncles
reward := new(big.Int).Set(blockReward) reward := new(big.Int).Set(blockReward)

View File

@ -105,7 +105,7 @@ func ApplyTransaction(config *params.ChainConfig, bc *BlockChain, author *common
// Update the state with pending changes // Update the state with pending changes
var root []byte var root []byte
if config.IsMetropolis(header.Number) { if config.IsByzantium(header.Number) {
statedb.Finalise(true) statedb.Finalise(true)
} else { } else {
root = statedb.IntermediateRoot(config.IsEIP158(header.Number)).Bytes() root = statedb.IntermediateRoot(config.IsEIP158(header.Number)).Bytes()

View File

@ -79,7 +79,7 @@ func NewReceipt(root []byte, failed bool, cumulativeGasUsed *big.Int) *Receipt {
} }
// EncodeRLP implements rlp.Encoder, and flattens the consensus fields of a receipt // EncodeRLP implements rlp.Encoder, and flattens the consensus fields of a receipt
// into an RLP stream. If no post state is present, metropolis fork is assumed. // into an RLP stream. If no post state is present, byzantium fork is assumed.
func (r *Receipt) EncodeRLP(w io.Writer) error { func (r *Receipt) EncodeRLP(w io.Writer) error {
return rlp.Encode(w, &receiptRLP{r.statusEncoding(), r.CumulativeGasUsed, r.Bloom, r.Logs}) return rlp.Encode(w, &receiptRLP{r.statusEncoding(), r.CumulativeGasUsed, r.Bloom, r.Logs})
} }

View File

@ -46,9 +46,9 @@ var PrecompiledContractsHomestead = map[common.Address]PrecompiledContract{
common.BytesToAddress([]byte{4}): &dataCopy{}, common.BytesToAddress([]byte{4}): &dataCopy{},
} }
// PrecompiledContractsMetropolis contains the default set of pre-compiled Ethereum // PrecompiledContractsByzantium contains the default set of pre-compiled Ethereum
// contracts used in the Metropolis release. // contracts used in the Byzantium release.
var PrecompiledContractsMetropolis = map[common.Address]PrecompiledContract{ var PrecompiledContractsByzantium = map[common.Address]PrecompiledContract{
common.BytesToAddress([]byte{1}): &ecrecover{}, common.BytesToAddress([]byte{1}): &ecrecover{},
common.BytesToAddress([]byte{2}): &sha256hash{}, common.BytesToAddress([]byte{2}): &sha256hash{},
common.BytesToAddress([]byte{3}): &ripemd160hash{}, common.BytesToAddress([]byte{3}): &ripemd160hash{},

View File

@ -321,7 +321,7 @@ var bn256PairingTests = []precompiledTest{
} }
func testPrecompiled(addr string, test precompiledTest, t *testing.T) { func testPrecompiled(addr string, test precompiledTest, t *testing.T) {
p := PrecompiledContractsMetropolis[common.HexToAddress(addr)] p := PrecompiledContractsByzantium[common.HexToAddress(addr)]
in := common.Hex2Bytes(test.input) in := common.Hex2Bytes(test.input)
contract := NewContract(AccountRef(common.HexToAddress("1337")), contract := NewContract(AccountRef(common.HexToAddress("1337")),
nil, new(big.Int), p.RequiredGas(in)) nil, new(big.Int), p.RequiredGas(in))
@ -338,7 +338,7 @@ func benchmarkPrecompiled(addr string, test precompiledTest, bench *testing.B) {
if test.noBenchmark { if test.noBenchmark {
return return
} }
p := PrecompiledContractsMetropolis[common.HexToAddress(addr)] p := PrecompiledContractsByzantium[common.HexToAddress(addr)]
in := common.Hex2Bytes(test.input) in := common.Hex2Bytes(test.input)
reqGas := p.RequiredGas(in) reqGas := p.RequiredGas(in)
contract := NewContract(AccountRef(common.HexToAddress("1337")), contract := NewContract(AccountRef(common.HexToAddress("1337")),

View File

@ -41,8 +41,8 @@ type (
func run(evm *EVM, snapshot int, contract *Contract, input []byte) ([]byte, error) { func run(evm *EVM, snapshot int, contract *Contract, input []byte) ([]byte, error) {
if contract.CodeAddr != nil { if contract.CodeAddr != nil {
precompiles := PrecompiledContractsHomestead precompiles := PrecompiledContractsHomestead
if evm.ChainConfig().IsMetropolis(evm.BlockNumber) { if evm.ChainConfig().IsByzantium(evm.BlockNumber) {
precompiles = PrecompiledContractsMetropolis precompiles = PrecompiledContractsByzantium
} }
if p := precompiles[*contract.CodeAddr]; p != nil { if p := precompiles[*contract.CodeAddr]; p != nil {
return RunPrecompiledContract(p, input, contract) return RunPrecompiledContract(p, input, contract)
@ -151,8 +151,8 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
) )
if !evm.StateDB.Exist(addr) { if !evm.StateDB.Exist(addr) {
precompiles := PrecompiledContractsHomestead precompiles := PrecompiledContractsHomestead
if evm.ChainConfig().IsMetropolis(evm.BlockNumber) { if evm.ChainConfig().IsByzantium(evm.BlockNumber) {
precompiles = PrecompiledContractsMetropolis precompiles = PrecompiledContractsByzantium
} }
if precompiles[addr] == nil && evm.ChainConfig().IsEIP158(evm.BlockNumber) && value.Sign() == 0 { if precompiles[addr] == nil && evm.ChainConfig().IsEIP158(evm.BlockNumber) && value.Sign() == 0 {
return nil, gas, nil return nil, gas, nil

View File

@ -324,7 +324,7 @@ func gasCall(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem
eip158 = evm.ChainConfig().IsEIP158(evm.BlockNumber) eip158 = evm.ChainConfig().IsEIP158(evm.BlockNumber)
) )
if eip158 { if eip158 {
if transfersValue && evm.StateDB.Empty(address) { if transfersValue && evm.StateDB.Empty(address) {
gas += params.CallNewAccountGas gas += params.CallNewAccountGas
} }
} else if !evm.StateDB.Exist(address) { } else if !evm.StateDB.Exist(address) {

View File

@ -70,8 +70,8 @@ func NewInterpreter(evm *EVM, cfg Config) *Interpreter {
// we'll set the default jump table. // we'll set the default jump table.
if !cfg.JumpTable[STOP].valid { if !cfg.JumpTable[STOP].valid {
switch { switch {
case evm.ChainConfig().IsMetropolis(evm.BlockNumber): case evm.ChainConfig().IsByzantium(evm.BlockNumber):
cfg.JumpTable = metropolisInstructionSet cfg.JumpTable = byzantiumInstructionSet
case evm.ChainConfig().IsHomestead(evm.BlockNumber): case evm.ChainConfig().IsHomestead(evm.BlockNumber):
cfg.JumpTable = homesteadInstructionSet cfg.JumpTable = homesteadInstructionSet
default: default:
@ -88,7 +88,7 @@ func NewInterpreter(evm *EVM, cfg Config) *Interpreter {
} }
func (in *Interpreter) enforceRestrictions(op OpCode, operation operation, stack *Stack) error { func (in *Interpreter) enforceRestrictions(op OpCode, operation operation, stack *Stack) error {
if in.evm.chainRules.IsMetropolis { if in.evm.chainRules.IsByzantium {
if in.readOnly { if in.readOnly {
// If the interpreter is operating in readonly mode, make sure no // If the interpreter is operating in readonly mode, make sure no
// state-modifying operation is performed. The 3rd stack item // state-modifying operation is performed. The 3rd stack item

View File

@ -51,14 +51,14 @@ type operation struct {
} }
var ( var (
frontierInstructionSet = NewFrontierInstructionSet() frontierInstructionSet = NewFrontierInstructionSet()
homesteadInstructionSet = NewHomesteadInstructionSet() homesteadInstructionSet = NewHomesteadInstructionSet()
metropolisInstructionSet = NewMetropolisInstructionSet() byzantiumInstructionSet = NewByzantiumInstructionSet()
) )
// NewMetropolisInstructionSet returns the frontier, homestead and // NewByzantiumInstructionSet returns the frontier, homestead and
// metropolis instructions. // byzantium instructions.
func NewMetropolisInstructionSet() [256]operation { func NewByzantiumInstructionSet() [256]operation {
// instructions that can be executed during the homestead phase. // instructions that can be executed during the homestead phase.
instructionSet := NewHomesteadInstructionSet() instructionSet := NewHomesteadInstructionSet()
instructionSet[STATICCALL] = operation{ instructionSet[STATICCALL] = operation{

View File

@ -32,45 +32,45 @@ var (
var ( var (
// MainnetChainConfig is the chain parameters to run a node on the main network. // MainnetChainConfig is the chain parameters to run a node on the main network.
MainnetChainConfig = &ChainConfig{ MainnetChainConfig = &ChainConfig{
ChainId: big.NewInt(1), ChainId: big.NewInt(1),
HomesteadBlock: big.NewInt(1150000), HomesteadBlock: big.NewInt(1150000),
DAOForkBlock: big.NewInt(1920000), DAOForkBlock: big.NewInt(1920000),
DAOForkSupport: true, DAOForkSupport: true,
EIP150Block: big.NewInt(2463000), EIP150Block: big.NewInt(2463000),
EIP150Hash: common.HexToHash("0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0"), EIP150Hash: common.HexToHash("0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0"),
EIP155Block: big.NewInt(2675000), EIP155Block: big.NewInt(2675000),
EIP158Block: big.NewInt(2675000), EIP158Block: big.NewInt(2675000),
MetropolisBlock: big.NewInt(math.MaxInt64), // Don't enable yet ByzantiumBlock: big.NewInt(math.MaxInt64), // Don't enable yet
Ethash: new(EthashConfig), Ethash: new(EthashConfig),
} }
// TestnetChainConfig contains the chain parameters to run a node on the Ropsten test network. // TestnetChainConfig contains the chain parameters to run a node on the Ropsten test network.
TestnetChainConfig = &ChainConfig{ TestnetChainConfig = &ChainConfig{
ChainId: big.NewInt(3), ChainId: big.NewInt(3),
HomesteadBlock: big.NewInt(0), HomesteadBlock: big.NewInt(0),
DAOForkBlock: nil, DAOForkBlock: nil,
DAOForkSupport: true, DAOForkSupport: true,
EIP150Block: big.NewInt(0), EIP150Block: big.NewInt(0),
EIP150Hash: common.HexToHash("0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d"), EIP150Hash: common.HexToHash("0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d"),
EIP155Block: big.NewInt(10), EIP155Block: big.NewInt(10),
EIP158Block: big.NewInt(10), EIP158Block: big.NewInt(10),
MetropolisBlock: big.NewInt(math.MaxInt64), // Don't enable yet ByzantiumBlock: big.NewInt(math.MaxInt64), // Don't enable yet
Ethash: new(EthashConfig), Ethash: new(EthashConfig),
} }
// RinkebyChainConfig contains the chain parameters to run a node on the Rinkeby test network. // RinkebyChainConfig contains the chain parameters to run a node on the Rinkeby test network.
RinkebyChainConfig = &ChainConfig{ RinkebyChainConfig = &ChainConfig{
ChainId: big.NewInt(4), ChainId: big.NewInt(4),
HomesteadBlock: big.NewInt(1), HomesteadBlock: big.NewInt(1),
DAOForkBlock: nil, DAOForkBlock: nil,
DAOForkSupport: true, DAOForkSupport: true,
EIP150Block: big.NewInt(2), EIP150Block: big.NewInt(2),
EIP150Hash: common.HexToHash("0x9b095b36c15eaf13044373aef8ee0bd3a382a5abb92e402afa44b8249c3a90e9"), EIP150Hash: common.HexToHash("0x9b095b36c15eaf13044373aef8ee0bd3a382a5abb92e402afa44b8249c3a90e9"),
EIP155Block: big.NewInt(3), EIP155Block: big.NewInt(3),
EIP158Block: big.NewInt(3), EIP158Block: big.NewInt(3),
MetropolisBlock: big.NewInt(math.MaxInt64), // Don't enable yet ByzantiumBlock: big.NewInt(math.MaxInt64), // Don't enable yet
Clique: &CliqueConfig{ Clique: &CliqueConfig{
Period: 15, Period: 15,
@ -110,7 +110,7 @@ type ChainConfig struct {
EIP155Block *big.Int `json:"eip155Block,omitempty"` // EIP155 HF block EIP155Block *big.Int `json:"eip155Block,omitempty"` // EIP155 HF block
EIP158Block *big.Int `json:"eip158Block,omitempty"` // EIP158 HF block EIP158Block *big.Int `json:"eip158Block,omitempty"` // EIP158 HF block
MetropolisBlock *big.Int `json:"metropolisBlock,omitempty"` // Metropolis switch block (nil = no fork, 0 = alraedy on homestead) ByzantiumBlock *big.Int `json:"byzantiumBlock,omitempty"` // Byzantium switch block (nil = no fork, 0 = alraedy on homestead)
// Various consensus engines // Various consensus engines
Ethash *EthashConfig `json:"ethash,omitempty"` Ethash *EthashConfig `json:"ethash,omitempty"`
@ -147,7 +147,7 @@ func (c *ChainConfig) String() string {
default: default:
engine = "unknown" engine = "unknown"
} }
return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Metropolis: %v Engine: %v}", return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Engine: %v}",
c.ChainId, c.ChainId,
c.HomesteadBlock, c.HomesteadBlock,
c.DAOForkBlock, c.DAOForkBlock,
@ -155,7 +155,7 @@ func (c *ChainConfig) String() string {
c.EIP150Block, c.EIP150Block,
c.EIP155Block, c.EIP155Block,
c.EIP158Block, c.EIP158Block,
c.MetropolisBlock, c.ByzantiumBlock,
engine, engine,
) )
} }
@ -182,8 +182,8 @@ func (c *ChainConfig) IsEIP158(num *big.Int) bool {
return isForked(c.EIP158Block, num) return isForked(c.EIP158Block, num)
} }
func (c *ChainConfig) IsMetropolis(num *big.Int) bool { func (c *ChainConfig) IsByzantium(num *big.Int) bool {
return isForked(c.MetropolisBlock, num) return isForked(c.ByzantiumBlock, num)
} }
// GasTable returns the gas table corresponding to the current phase (homestead or homestead reprice). // GasTable returns the gas table corresponding to the current phase (homestead or homestead reprice).
@ -243,8 +243,8 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, head *big.Int) *Confi
if c.IsEIP158(head) && !configNumEqual(c.ChainId, newcfg.ChainId) { if c.IsEIP158(head) && !configNumEqual(c.ChainId, newcfg.ChainId) {
return newCompatError("EIP158 chain ID", c.EIP158Block, newcfg.EIP158Block) return newCompatError("EIP158 chain ID", c.EIP158Block, newcfg.EIP158Block)
} }
if isForkIncompatible(c.MetropolisBlock, newcfg.MetropolisBlock, head) { if isForkIncompatible(c.ByzantiumBlock, newcfg.ByzantiumBlock, head) {
return newCompatError("Metropolis fork block", c.MetropolisBlock, newcfg.MetropolisBlock) return newCompatError("Byzantium fork block", c.ByzantiumBlock, newcfg.ByzantiumBlock)
} }
return nil return nil
} }
@ -312,7 +312,7 @@ func (err *ConfigCompatError) Error() string {
type Rules struct { type Rules struct {
ChainId *big.Int ChainId *big.Int
IsHomestead, IsEIP150, IsEIP155, IsEIP158 bool IsHomestead, IsEIP150, IsEIP155, IsEIP158 bool
IsMetropolis bool IsByzantium bool
} }
func (c *ChainConfig) Rules(num *big.Int) Rules { func (c *ChainConfig) Rules(num *big.Int) Rules {
@ -320,5 +320,5 @@ func (c *ChainConfig) Rules(num *big.Int) Rules {
if chainId == nil { if chainId == nil {
chainId = new(big.Int) chainId = new(big.Int)
} }
return Rules{ChainId: new(big.Int).Set(chainId), IsHomestead: c.IsHomestead(num), IsEIP150: c.IsEIP150(num), IsEIP155: c.IsEIP155(num), IsEIP158: c.IsEIP158(num), IsMetropolis: c.IsMetropolis(num)} return Rules{ChainId: new(big.Int).Set(chainId), IsHomestead: c.IsHomestead(num), IsEIP150: c.IsEIP150(num), IsEIP155: c.IsEIP155(num), IsEIP158: c.IsEIP158(num), IsByzantium: c.IsByzantium(num)}
} }

View File

@ -45,13 +45,13 @@ var Forks = map[string]*params.ChainConfig{
EIP158Block: big.NewInt(0), EIP158Block: big.NewInt(0),
}, },
"Byzantium": &params.ChainConfig{ "Byzantium": &params.ChainConfig{
ChainId: big.NewInt(1), ChainId: big.NewInt(1),
HomesteadBlock: big.NewInt(0), HomesteadBlock: big.NewInt(0),
EIP150Block: big.NewInt(0), EIP150Block: big.NewInt(0),
EIP155Block: big.NewInt(0), EIP155Block: big.NewInt(0),
EIP158Block: big.NewInt(0), EIP158Block: big.NewInt(0),
DAOForkBlock: big.NewInt(0), DAOForkBlock: big.NewInt(0),
MetropolisBlock: big.NewInt(0), ByzantiumBlock: big.NewInt(0),
}, },
"FrontierToHomesteadAt5": &params.ChainConfig{ "FrontierToHomesteadAt5": &params.ChainConfig{
ChainId: big.NewInt(1), ChainId: big.NewInt(1),
@ -69,12 +69,12 @@ var Forks = map[string]*params.ChainConfig{
DAOForkSupport: true, DAOForkSupport: true,
}, },
"EIP158ToByzantiumAt5": &params.ChainConfig{ "EIP158ToByzantiumAt5": &params.ChainConfig{
ChainId: big.NewInt(1), ChainId: big.NewInt(1),
HomesteadBlock: big.NewInt(0), HomesteadBlock: big.NewInt(0),
EIP150Block: big.NewInt(0), EIP150Block: big.NewInt(0),
EIP155Block: big.NewInt(0), EIP155Block: big.NewInt(0),
EIP158Block: big.NewInt(0), EIP158Block: big.NewInt(0),
MetropolisBlock: big.NewInt(5), ByzantiumBlock: big.NewInt(5),
}, },
} }

View File

@ -37,12 +37,12 @@ func TestTransaction(t *testing.T) {
EIP158Block: big.NewInt(0), EIP158Block: big.NewInt(0),
ChainId: big.NewInt(1), ChainId: big.NewInt(1),
}) })
txt.config(`^Metropolis/`, params.ChainConfig{ txt.config(`^Byzantium/`, params.ChainConfig{
HomesteadBlock: big.NewInt(0), HomesteadBlock: big.NewInt(0),
EIP150Block: big.NewInt(0), EIP150Block: big.NewInt(0),
EIP155Block: big.NewInt(0), EIP155Block: big.NewInt(0),
EIP158Block: big.NewInt(0), EIP158Block: big.NewInt(0),
MetropolisBlock: big.NewInt(0), ByzantiumBlock: big.NewInt(0),
}) })
txt.walk(t, transactionTestDir, func(t *testing.T, name string, test *TransactionTest) { txt.walk(t, transactionTestDir, func(t *testing.T, name string, test *TransactionTest) {