diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2016-11-15 20:46:47 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-15 20:46:47 +0800 |
commit | 81d9d7d38555a63602b9da3d07955ad4e5a62f02 (patch) | |
tree | 9ce0d55bfe182f6493867ea5497bf2c8cd9e8523 /params | |
parent | ef9265d0d7abf6614c1d2fb977989ab0d400a590 (diff) | |
parent | 822355f8a6e8826561433392fd94a8bde7e4dbf3 (diff) | |
download | go-tangerine-1.4.19.tar go-tangerine-1.4.19.tar.gz go-tangerine-1.4.19.tar.bz2 go-tangerine-1.4.19.tar.lz go-tangerine-1.4.19.tar.xz go-tangerine-1.4.19.tar.zst go-tangerine-1.4.19.zip |
Merge pull request #3252 from obscuren/release/1.4v1.4.19
1.4 HF
Diffstat (limited to 'params')
-rw-r--r-- | params/config.go | 112 | ||||
-rw-r--r-- | params/gas_table.go | 18 | ||||
-rw-r--r-- | params/util.go | 21 |
3 files changed, 146 insertions, 5 deletions
diff --git a/params/config.go b/params/config.go new file mode 100644 index 000000000..f75c33870 --- /dev/null +++ b/params/config.go @@ -0,0 +1,112 @@ +// Copyright 2016 The go-ethereum Authors +// This file is part of the go-ethereum library. +// +// The go-ethereum 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 go-ethereum 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 go-ethereum library. If not, see <http://www.gnu.org/licenses/>. + +package params + +import ( + "math/big" + + "github.com/ethereum/go-ethereum/common" +) + +// ChainConfig is the core config which determines the blockchain settings. +// +// ChainConfig is stored in the database on a per block basis. This means +// that any network, identified by its genesis block, can have its own +// set of configuration options. +type ChainConfig struct { + ChainId *big.Int `json:"chainId"` // Chain id identifies the current chain and is used for replay protection + + HomesteadBlock *big.Int `json:"homesteadBlock"` // Homestead switch block (nil = no fork, 0 = already homestead) + DAOForkBlock *big.Int `json:"daoForkBlock"` // TheDAO hard-fork switch block (nil = no fork) + DAOForkSupport bool `json:"daoForkSupport"` // Whether the nodes supports or opposes the DAO hard-fork + + // EIP150 implements the Gas price changes (https://github.com/ethereum/EIPs/issues/150) + EIP150Block *big.Int `json:"EIP150Block"` // EIP150 HF block (nil = no fork) + EIP150Hash common.Hash `json:"EIP150Hash"` // EIP150 HF hash (fast sync aid) + + EIP155Block *big.Int `json:"EIP155Block"` // EIP155 HF block + EIP158Block *big.Int `json:"EIP158Block"` // EIP158 HF block +} + +var ( + TestChainConfig = &ChainConfig{big.NewInt(1), new(big.Int), new(big.Int), true, new(big.Int), common.Hash{}, new(big.Int), new(big.Int)} + TestRules = TestChainConfig.Rules(new(big.Int)) +) + +// IsHomestead returns whether num is either equal to the homestead block or greater. +func (c *ChainConfig) IsHomestead(num *big.Int) bool { + if c.HomesteadBlock == nil || num == nil { + return false + } + return num.Cmp(c.HomesteadBlock) >= 0 +} + +// GasTable returns the gas table corresponding to the current phase (homestead or homestead reprice). +// +// The returned GasTable's fields shouldn't, under any circumstances, be changed. +func (c *ChainConfig) GasTable(num *big.Int) GasTable { + if num == nil { + return GasTableHomestead + } + + switch { + case c.EIP158Block != nil && num.Cmp(c.EIP158Block) >= 0: + return GasTableEIP158 + case c.EIP150Block != nil && num.Cmp(c.EIP150Block) >= 0: + return GasTableHomesteadGasRepriceFork + default: + return GasTableHomestead + } +} + +func (c *ChainConfig) IsEIP150(num *big.Int) bool { + if c.EIP150Block == nil || num == nil { + return false + } + return num.Cmp(c.EIP150Block) >= 0 + +} + +func (c *ChainConfig) IsEIP155(num *big.Int) bool { + if c.EIP155Block == nil || num == nil { + return false + } + return num.Cmp(c.EIP155Block) >= 0 + +} + +func (c *ChainConfig) IsEIP158(num *big.Int) bool { + if c.EIP158Block == nil || num == nil { + return false + } + return num.Cmp(c.EIP158Block) >= 0 + +} + +// Rules wraps ChainConfig and is merely syntatic sugar or can be used for functions +// that do not have or require information about the block. +// +// Rules is a one time interface meaning that it shouldn't be used in between transition +// phases. +type Rules struct { + ChainId *big.Int + IsHomestead, IsEIP150, IsEIP155, IsEIP158 bool +} + +func (c *ChainConfig) Rules(num *big.Int) Rules { + return Rules{ChainId: new(big.Int).Set(c.ChainId), IsHomestead: c.IsHomestead(num), IsEIP150: c.IsEIP150(num), IsEIP155: c.IsEIP155(num), IsEIP158: c.IsEIP158(num)} +} diff --git a/params/gas_table.go b/params/gas_table.go index 98f00a7ee..093dacc8b 100644 --- a/params/gas_table.go +++ b/params/gas_table.go @@ -26,6 +26,8 @@ type GasTable struct { Calls *big.Int Suicide *big.Int + ExpByte *big.Int + // CreateBySuicide occurs when the // refunded account is one that does // not exist. This logic is similar @@ -44,6 +46,7 @@ var ( SLoad: big.NewInt(50), Calls: big.NewInt(40), Suicide: big.NewInt(0), + ExpByte: big.NewInt(10), // explicitly set to nil to indicate // this rule does not apply to homestead. @@ -52,6 +55,8 @@ var ( // GasTableHomestead contain the gas re-prices for // the homestead phase. + // + // TODO rename to GasTableEIP150 GasTableHomesteadGasRepriceFork = GasTable{ ExtcodeSize: big.NewInt(700), ExtcodeCopy: big.NewInt(700), @@ -59,6 +64,19 @@ var ( SLoad: big.NewInt(200), Calls: big.NewInt(700), Suicide: big.NewInt(5000), + ExpByte: big.NewInt(10), + + CreateBySuicide: big.NewInt(25000), + } + + GasTableEIP158 = GasTable{ + ExtcodeSize: big.NewInt(700), + ExtcodeCopy: big.NewInt(700), + Balance: big.NewInt(400), + SLoad: big.NewInt(200), + Calls: big.NewInt(700), + Suicide: big.NewInt(5000), + ExpByte: big.NewInt(50), CreateBySuicide: big.NewInt(25000), } diff --git a/params/util.go b/params/util.go index 583cf03bb..c9c0f393c 100644 --- a/params/util.go +++ b/params/util.go @@ -16,11 +16,22 @@ package params -import "math/big" +import ( + "math/big" + + "github.com/ethereum/go-ethereum/common" +) var ( - TestNetHomesteadBlock = big.NewInt(494000) // Testnet homestead block - MainNetHomesteadBlock = big.NewInt(1150000) // Mainnet homestead block - TestNetHomesteadGasRepriceBlock = big.NewInt(1783000) // Test net gas reprice block - MainNetHomesteadGasRepriceBlock = big.NewInt(2463000) // Main net gas reprice block + TestNetHomesteadBlock = big.NewInt(494000) // Testnet homestead block + MainNetHomesteadBlock = big.NewInt(1150000) // Mainnet homestead block + TestNetHomesteadGasRepriceBlock = big.NewInt(1783000) // Test net gas reprice block + MainNetHomesteadGasRepriceBlock = big.NewInt(2463000) // Main net gas reprice block + TestNetHomesteadGasRepriceHash = common.HexToHash("0xf376243aeff1f256d970714c3de9fd78fa4e63cf63e32a51fe1169e375d98145") // Testnet gas reprice block hash (used by fast sync) + MainNetHomesteadGasRepriceHash = common.HexToHash("0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0") // Mainnet gas reprice block hash (used by fast sync) + TestNetChainID = big.NewInt(2) // Testnet default chain ID + MainNetChainID = big.NewInt(1) // Main net default chain ID + + TestNetSpuriousDragon = big.NewInt(1885000) + MainNetSpuriousDragon = big.NewInt(2675000) ) |