Skip to content

Commit 0928562

Browse files
committed
all: define Berlin hard fork spec
1 parent dc109cc commit 0928562

File tree

22 files changed

+132
-93
lines changed

22 files changed

+132
-93
lines changed

cmd/geth/config.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"bufio"
2121
"errors"
2222
"fmt"
23+
"math/big"
2324
"os"
2425
"reflect"
2526
"unicode"
@@ -165,7 +166,9 @@ func checkWhisper(ctx *cli.Context) {
165166
// makeFullNode loads geth configuration and creates the Ethereum backend.
166167
func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
167168
stack, cfg := makeConfigNode(ctx)
168-
169+
if ctx.GlobalIsSet(utils.OverrideBerlinFlag.Name) {
170+
cfg.Eth.OverrideBerlin = new(big.Int).SetUint64(ctx.GlobalUint64(utils.OverrideBerlinFlag.Name))
171+
}
169172
backend := utils.RegisterEthService(stack, &cfg.Eth)
170173

171174
checkWhisper(ctx)

cmd/geth/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ var (
6969
utils.NoUSBFlag,
7070
utils.USBFlag,
7171
utils.SmartCardDaemonPathFlag,
72+
utils.OverrideBerlinFlag,
7273
utils.EthashCacheDirFlag,
7374
utils.EthashCachesInMemoryFlag,
7475
utils.EthashCachesOnDiskFlag,

cmd/puppeth/wizard_genesis.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ func (w *wizard) manageGenesis() {
235235
fmt.Printf("Which block should Istanbul come into effect? (default = %v)\n", w.conf.Genesis.Config.IstanbulBlock)
236236
w.conf.Genesis.Config.IstanbulBlock = w.readDefaultBigInt(w.conf.Genesis.Config.IstanbulBlock)
237237

238+
fmt.Println()
239+
fmt.Printf("Which block should Berlin come into effect? (default = %v)\n", w.conf.Genesis.Config.BerlinBlock)
240+
w.conf.Genesis.Config.BerlinBlock = w.readDefaultBigInt(w.conf.Genesis.Config.BerlinBlock)
241+
238242
fmt.Println()
239243
fmt.Printf("Which block should YOLOv3 come into effect? (default = %v)\n", w.conf.Genesis.Config.YoloV3Block)
240244
w.conf.Genesis.Config.YoloV3Block = w.readDefaultBigInt(w.conf.Genesis.Config.YoloV3Block)

cmd/utils/flags.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ var (
230230
Usage: "Megabytes of memory allocated to bloom-filter for pruning",
231231
Value: 2048,
232232
}
233+
OverrideBerlinFlag = cli.Uint64Flag{
234+
Name: "override.berlin",
235+
Usage: "Manually specify Berlin fork-block, overriding the bundled setting",
236+
}
233237
// Light server and client settings
234238
LightServeFlag = cli.IntFlag{
235239
Name: "light.serve",

core/forkid/forkid_test.go

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,26 @@ func TestCreation(t *testing.T) {
4343
params.MainnetChainConfig,
4444
params.MainnetGenesisHash,
4545
[]testcase{
46-
{0, ID{Hash: checksumToBytes(0xfc64ec04), Next: 1150000}}, // Unsynced
47-
{1149999, ID{Hash: checksumToBytes(0xfc64ec04), Next: 1150000}}, // Last Frontier block
48-
{1150000, ID{Hash: checksumToBytes(0x97c2c34c), Next: 1920000}}, // First Homestead block
49-
{1919999, ID{Hash: checksumToBytes(0x97c2c34c), Next: 1920000}}, // Last Homestead block
50-
{1920000, ID{Hash: checksumToBytes(0x91d1f948), Next: 2463000}}, // First DAO block
51-
{2462999, ID{Hash: checksumToBytes(0x91d1f948), Next: 2463000}}, // Last DAO block
52-
{2463000, ID{Hash: checksumToBytes(0x7a64da13), Next: 2675000}}, // First Tangerine block
53-
{2674999, ID{Hash: checksumToBytes(0x7a64da13), Next: 2675000}}, // Last Tangerine block
54-
{2675000, ID{Hash: checksumToBytes(0x3edd5b10), Next: 4370000}}, // First Spurious block
55-
{4369999, ID{Hash: checksumToBytes(0x3edd5b10), Next: 4370000}}, // Last Spurious block
56-
{4370000, ID{Hash: checksumToBytes(0xa00bc324), Next: 7280000}}, // First Byzantium block
57-
{7279999, ID{Hash: checksumToBytes(0xa00bc324), Next: 7280000}}, // Last Byzantium block
58-
{7280000, ID{Hash: checksumToBytes(0x668db0af), Next: 9069000}}, // First and last Constantinople, first Petersburg block
59-
{9068999, ID{Hash: checksumToBytes(0x668db0af), Next: 9069000}}, // Last Petersburg block
60-
{9069000, ID{Hash: checksumToBytes(0x879d6e30), Next: 9200000}}, // First Istanbul and first Muir Glacier block
61-
{9199999, ID{Hash: checksumToBytes(0x879d6e30), Next: 9200000}}, // Last Istanbul and first Muir Glacier block
62-
{9200000, ID{Hash: checksumToBytes(0xe029e991), Next: 0}}, // First Muir Glacier block
63-
{10000000, ID{Hash: checksumToBytes(0xe029e991), Next: 0}}, // Future Muir Glacier block
46+
{0, ID{Hash: checksumToBytes(0xfc64ec04), Next: 1150000}}, // Unsynced
47+
{1149999, ID{Hash: checksumToBytes(0xfc64ec04), Next: 1150000}}, // Last Frontier block
48+
{1150000, ID{Hash: checksumToBytes(0x97c2c34c), Next: 1920000}}, // First Homestead block
49+
{1919999, ID{Hash: checksumToBytes(0x97c2c34c), Next: 1920000}}, // Last Homestead block
50+
{1920000, ID{Hash: checksumToBytes(0x91d1f948), Next: 2463000}}, // First DAO block
51+
{2462999, ID{Hash: checksumToBytes(0x91d1f948), Next: 2463000}}, // Last DAO block
52+
{2463000, ID{Hash: checksumToBytes(0x7a64da13), Next: 2675000}}, // First Tangerine block
53+
{2674999, ID{Hash: checksumToBytes(0x7a64da13), Next: 2675000}}, // Last Tangerine block
54+
{2675000, ID{Hash: checksumToBytes(0x3edd5b10), Next: 4370000}}, // First Spurious block
55+
{4369999, ID{Hash: checksumToBytes(0x3edd5b10), Next: 4370000}}, // Last Spurious block
56+
{4370000, ID{Hash: checksumToBytes(0xa00bc324), Next: 7280000}}, // First Byzantium block
57+
{7279999, ID{Hash: checksumToBytes(0xa00bc324), Next: 7280000}}, // Last Byzantium block
58+
{7280000, ID{Hash: checksumToBytes(0x668db0af), Next: 9069000}}, // First and last Constantinople, first Petersburg block
59+
{9068999, ID{Hash: checksumToBytes(0x668db0af), Next: 9069000}}, // Last Petersburg block
60+
{9069000, ID{Hash: checksumToBytes(0x879d6e30), Next: 9200000}}, // First Istanbul and first Muir Glacier block
61+
{9199999, ID{Hash: checksumToBytes(0x879d6e30), Next: 9200000}}, // Last Istanbul and first Muir Glacier block
62+
{9200000, ID{Hash: checksumToBytes(0xe029e991), Next: 12244000}}, // First Muir Glacier block
63+
{12243999, ID{Hash: checksumToBytes(0xe029e991), Next: 12244000}}, // Last Muir Glacier block
64+
{12244000, ID{Hash: checksumToBytes(0x0eb440f6), Next: 0}}, // First Berlin block
65+
{20000000, ID{Hash: checksumToBytes(0x0eb440f6), Next: 0}}, // Future Berlin block
6466
},
6567
},
6668
// Ropsten test cases
@@ -80,8 +82,10 @@ func TestCreation(t *testing.T) {
8082
{6485845, ID{Hash: checksumToBytes(0xd6e2149b), Next: 6485846}}, // Last Petersburg block
8183
{6485846, ID{Hash: checksumToBytes(0x4bc66396), Next: 7117117}}, // First Istanbul block
8284
{7117116, ID{Hash: checksumToBytes(0x4bc66396), Next: 7117117}}, // Last Istanbul block
83-
{7117117, ID{Hash: checksumToBytes(0x6727ef90), Next: 0}}, // First Muir Glacier block
84-
{7500000, ID{Hash: checksumToBytes(0x6727ef90), Next: 0}}, // Future
85+
{7117117, ID{Hash: checksumToBytes(0x6727ef90), Next: 9812189}}, // First Muir Glacier block
86+
{9812188, ID{Hash: checksumToBytes(0x6727ef90), Next: 9812189}}, // Last Muir Glacier block
87+
{9812189, ID{Hash: checksumToBytes(0xa157d377), Next: 0}}, // First Berlin block
88+
{10000000, ID{Hash: checksumToBytes(0xa157d377), Next: 0}}, // Future Berlin block
8589
},
8690
},
8791
// Rinkeby test cases
@@ -100,8 +104,10 @@ func TestCreation(t *testing.T) {
100104
{4321233, ID{Hash: checksumToBytes(0xe49cab14), Next: 4321234}}, // Last Constantinople block
101105
{4321234, ID{Hash: checksumToBytes(0xafec6b27), Next: 5435345}}, // First Petersburg block
102106
{5435344, ID{Hash: checksumToBytes(0xafec6b27), Next: 5435345}}, // Last Petersburg block
103-
{5435345, ID{Hash: checksumToBytes(0xcbdb8838), Next: 0}}, // First Istanbul block
104-
{6000000, ID{Hash: checksumToBytes(0xcbdb8838), Next: 0}}, // Future Istanbul block
107+
{5435345, ID{Hash: checksumToBytes(0xcbdb8838), Next: 8290928}}, // First Istanbul block
108+
{8290927, ID{Hash: checksumToBytes(0xcbdb8838), Next: 8290928}}, // Last Istanbul block
109+
{8290928, ID{Hash: checksumToBytes(0x6910c8bd), Next: 0}}, // First Berlin block
110+
{10000000, ID{Hash: checksumToBytes(0x6910c8bd), Next: 0}}, // Future Berlin block
105111
},
106112
},
107113
// Goerli test cases
@@ -111,8 +117,10 @@ func TestCreation(t *testing.T) {
111117
[]testcase{
112118
{0, ID{Hash: checksumToBytes(0xa3f5ab08), Next: 1561651}}, // Unsynced, last Frontier, Homestead, Tangerine, Spurious, Byzantium, Constantinople and first Petersburg block
113119
{1561650, ID{Hash: checksumToBytes(0xa3f5ab08), Next: 1561651}}, // Last Petersburg block
114-
{1561651, ID{Hash: checksumToBytes(0xc25efa5c), Next: 0}}, // First Istanbul block
115-
{2000000, ID{Hash: checksumToBytes(0xc25efa5c), Next: 0}}, // Future Istanbul block
120+
{1561651, ID{Hash: checksumToBytes(0xc25efa5c), Next: 4460644}}, // First Istanbul block
121+
{4460643, ID{Hash: checksumToBytes(0xc25efa5c), Next: 4460644}}, // Last Istanbul block
122+
{4460644, ID{Hash: checksumToBytes(0x757a1c47), Next: 0}}, // First Berlin block
123+
{5000000, ID{Hash: checksumToBytes(0x757a1c47), Next: 0}}, // Future Berlin block
116124
},
117125
},
118126
}
@@ -185,11 +193,11 @@ func TestValidation(t *testing.T) {
185193
// Local is mainnet Petersburg, remote is Rinkeby Petersburg.
186194
{7987396, ID{Hash: checksumToBytes(0xafec6b27), Next: 0}, ErrLocalIncompatibleOrStale},
187195

188-
// Local is mainnet Muir Glacier, far in the future. Remote announces Gopherium (non existing fork)
196+
// Local is mainnet Berlin, far in the future. Remote announces Gopherium (non existing fork)
189197
// at some future block 88888888, for itself, but past block for local. Local is incompatible.
190198
//
191199
// This case detects non-upgraded nodes with majority hash power (typical Ropsten mess).
192-
{88888888, ID{Hash: checksumToBytes(0xe029e991), Next: 88888888}, ErrLocalIncompatibleOrStale},
200+
{88888888, ID{Hash: checksumToBytes(0x0eb440f6), Next: 88888888}, ErrLocalIncompatibleOrStale},
193201

194202
// Local is mainnet Byzantium. Remote is also in Byzantium, but announces Gopherium (non existing
195203
// fork) at block 7279999, before Petersburg. Local is incompatible.

core/genesis.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ func (e *GenesisMismatchError) Error() string {
153153
//
154154
// The returned chain configuration is never nil.
155155
func SetupGenesisBlock(db ethdb.Database, genesis *Genesis) (*params.ChainConfig, common.Hash, error) {
156+
return SetupGenesisBlockWithOverride(db, genesis, nil)
157+
}
158+
159+
func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, overrideBerlin *big.Int) (*params.ChainConfig, common.Hash, error) {
156160
if genesis != nil && genesis.Config == nil {
157161
return params.AllEthashProtocolChanges, common.Hash{}, errGenesisNoConfig
158162
}
@@ -198,6 +202,9 @@ func SetupGenesisBlock(db ethdb.Database, genesis *Genesis) (*params.ChainConfig
198202
}
199203
// Get the existing chain configuration.
200204
newcfg := genesis.configOrDefault(stored)
205+
if overrideBerlin != nil {
206+
newcfg.BerlinBlock = overrideBerlin
207+
}
201208
if err := newcfg.CheckConfigForkOrder(); err != nil {
202209
return newcfg, common.Hash{}, err
203210
}

core/state_transition.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
259259
}
260260

261261
// Set up the initial access list.
262-
if st.evm.ChainConfig().IsYoloV3(st.evm.Context.BlockNumber) {
262+
if st.evm.ChainConfig().IsBerlin(st.evm.Context.BlockNumber) {
263263
st.state.PrepareAccessList(msg.From(), msg.To(), st.evm.ActivePrecompiles(), msg.AccessList())
264264
}
265265

core/tx_pool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,7 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) {
12041204
// Update all fork indicator by next pending block number.
12051205
next := new(big.Int).Add(newHead.Number, big.NewInt(1))
12061206
pool.istanbul = pool.chainconfig.IsIstanbul(next)
1207-
pool.eip2718 = pool.chainconfig.IsYoloV3(next)
1207+
pool.eip2718 = pool.chainconfig.IsBerlin(next)
12081208
}
12091209

12101210
// promoteExecutables moves transactions that have become processable from the

core/types/transaction_signing.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type sigCache struct {
4040
func MakeSigner(config *params.ChainConfig, blockNumber *big.Int) Signer {
4141
var signer Signer
4242
switch {
43-
case config.IsYoloV3(blockNumber):
43+
case config.IsBerlin(blockNumber):
4444
signer = NewEIP2930Signer(config.ChainID)
4545
case config.IsEIP155(blockNumber):
4646
signer = NewEIP155Signer(config.ChainID)
@@ -61,7 +61,7 @@ func MakeSigner(config *params.ChainConfig, blockNumber *big.Int) Signer {
6161
// have the current block number available, use MakeSigner instead.
6262
func LatestSigner(config *params.ChainConfig) Signer {
6363
if config.ChainID != nil {
64-
if config.YoloV3Block != nil {
64+
if config.BerlinBlock != nil || config.YoloV3Block != nil {
6565
return NewEIP2930Signer(config.ChainID)
6666
}
6767
if config.EIP155Block != nil {

core/vm/contracts.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ var PrecompiledContractsIstanbul = map[common.Address]PrecompiledContract{
7878
common.BytesToAddress([]byte{9}): &blake2F{},
7979
}
8080

81-
// PrecompiledContractsYoloV3 contains the default set of pre-compiled Ethereum
82-
// contracts used in the Yolo v3 test release.
83-
var PrecompiledContractsYoloV3 = map[common.Address]PrecompiledContract{
81+
// PrecompiledContractsBerlin contains the default set of pre-compiled Ethereum
82+
// contracts used in the Berlin release.
83+
var PrecompiledContractsBerlin = map[common.Address]PrecompiledContract{
8484
common.BytesToAddress([]byte{1}): &ecrecover{},
8585
common.BytesToAddress([]byte{2}): &sha256hash{},
8686
common.BytesToAddress([]byte{3}): &ripemd160hash{},
@@ -107,7 +107,7 @@ var PrecompiledContractsBLS = map[common.Address]PrecompiledContract{
107107
}
108108

109109
var (
110-
PrecompiledAddressesYoloV3 []common.Address
110+
PrecompiledAddressesBerlin []common.Address
111111
PrecompiledAddressesIstanbul []common.Address
112112
PrecompiledAddressesByzantium []common.Address
113113
PrecompiledAddressesHomestead []common.Address
@@ -123,8 +123,8 @@ func init() {
123123
for k := range PrecompiledContractsIstanbul {
124124
PrecompiledAddressesIstanbul = append(PrecompiledAddressesIstanbul, k)
125125
}
126-
for k := range PrecompiledContractsYoloV3 {
127-
PrecompiledAddressesYoloV3 = append(PrecompiledAddressesYoloV3, k)
126+
for k := range PrecompiledContractsBerlin {
127+
PrecompiledAddressesBerlin = append(PrecompiledAddressesBerlin, k)
128128
}
129129
}
130130

0 commit comments

Comments
 (0)