github.com/ethereum-optimism/optimism/l2geth@v0.0.0-20230612200230-50b04ade19e3/params/config.go (about) 1 // Copyright 2016 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package params 18 19 import ( 20 "encoding/binary" 21 "fmt" 22 "math/big" 23 24 "github.com/ethereum-optimism/optimism/l2geth/common" 25 "github.com/ethereum-optimism/optimism/l2geth/crypto" 26 ) 27 28 // Genesis hashes to enforce below configs on. 29 var ( 30 MainnetGenesisHash = common.HexToHash("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3") 31 TestnetGenesisHash = common.HexToHash("0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d") 32 RinkebyGenesisHash = common.HexToHash("0x6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177") 33 GoerliGenesisHash = common.HexToHash("0xbf7e331f7f7c1dd2e05159666b3bf8bc7a8a3a9eb1d518969eab529dd9b88c1a") 34 ) 35 36 // TrustedCheckpoints associates each known checkpoint with the genesis hash of 37 // the chain it belongs to. 38 var TrustedCheckpoints = map[common.Hash]*TrustedCheckpoint{ 39 MainnetGenesisHash: MainnetTrustedCheckpoint, 40 TestnetGenesisHash: TestnetTrustedCheckpoint, 41 RinkebyGenesisHash: RinkebyTrustedCheckpoint, 42 GoerliGenesisHash: GoerliTrustedCheckpoint, 43 } 44 45 // CheckpointOracles associates each known checkpoint oracles with the genesis hash of 46 // the chain it belongs to. 47 var CheckpointOracles = map[common.Hash]*CheckpointOracleConfig{ 48 MainnetGenesisHash: MainnetCheckpointOracle, 49 TestnetGenesisHash: TestnetCheckpointOracle, 50 RinkebyGenesisHash: RinkebyCheckpointOracle, 51 GoerliGenesisHash: GoerliCheckpointOracle, 52 } 53 54 var ( 55 // MainnetChainConfig is the chain parameters to run a node on the main network. 56 MainnetChainConfig = &ChainConfig{ 57 ChainID: big.NewInt(1), 58 HomesteadBlock: big.NewInt(1150000), 59 DAOForkBlock: big.NewInt(1920000), 60 DAOForkSupport: true, 61 EIP150Block: big.NewInt(2463000), 62 EIP150Hash: common.HexToHash("0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0"), 63 EIP155Block: big.NewInt(2675000), 64 EIP158Block: big.NewInt(2675000), 65 ByzantiumBlock: big.NewInt(4370000), 66 ConstantinopleBlock: big.NewInt(7280000), 67 PetersburgBlock: big.NewInt(7280000), 68 IstanbulBlock: big.NewInt(9069000), 69 MuirGlacierBlock: big.NewInt(9200000), 70 Ethash: new(EthashConfig), 71 } 72 73 // MainnetTrustedCheckpoint contains the light client trusted checkpoint for the main network. 74 MainnetTrustedCheckpoint = &TrustedCheckpoint{ 75 SectionIndex: 283, 76 SectionHead: common.HexToHash("0x7da9639e5b378421f2cabd1d3bdae02dbf6d4ba79fc9b3c3916c66412ef7d0b6"), 77 CHTRoot: common.HexToHash("0xb8c6f06e1d5a4fddf593d1ff787e6b89eff4183d0b40d276f19e7d41178a53cf"), 78 BloomRoot: common.HexToHash("0xc47d7d6924ba46090d568296bb667a3ea4b6a00dd69bd5fb4f4f78be2fe05ec2"), 79 } 80 81 // MainnetCheckpointOracle contains a set of configs for the main network oracle. 82 MainnetCheckpointOracle = &CheckpointOracleConfig{ 83 Address: common.HexToAddress("0x9a9070028361F7AAbeB3f2F2Dc07F82C4a98A02a"), 84 Signers: []common.Address{ 85 common.HexToAddress("0x1b2C260efc720BE89101890E4Db589b44E950527"), // Peter 86 common.HexToAddress("0x78d1aD571A1A09D60D9BBf25894b44e4C8859595"), // Martin 87 common.HexToAddress("0x286834935f4A8Cfb4FF4C77D5770C2775aE2b0E7"), // Zsolt 88 common.HexToAddress("0xb86e2B0Ab5A4B1373e40c51A7C712c70Ba2f9f8E"), // Gary 89 common.HexToAddress("0x0DF8fa387C602AE62559cC4aFa4972A7045d6707"), // Guillaume 90 }, 91 Threshold: 2, 92 } 93 94 // TestnetChainConfig contains the chain parameters to run a node on the Ropsten test network. 95 TestnetChainConfig = &ChainConfig{ 96 ChainID: big.NewInt(3), 97 HomesteadBlock: big.NewInt(0), 98 DAOForkBlock: nil, 99 DAOForkSupport: true, 100 EIP150Block: big.NewInt(0), 101 EIP150Hash: common.HexToHash("0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d"), 102 EIP155Block: big.NewInt(10), 103 EIP158Block: big.NewInt(10), 104 ByzantiumBlock: big.NewInt(1700000), 105 ConstantinopleBlock: big.NewInt(4230000), 106 PetersburgBlock: big.NewInt(4939394), 107 IstanbulBlock: big.NewInt(6485846), 108 MuirGlacierBlock: big.NewInt(7117117), 109 Ethash: new(EthashConfig), 110 } 111 112 // TestnetTrustedCheckpoint contains the light client trusted checkpoint for the Ropsten test network. 113 TestnetTrustedCheckpoint = &TrustedCheckpoint{ 114 SectionIndex: 217, 115 SectionHead: common.HexToHash("0x1895e3cceb6fb201044679db2b9f4f9df4233b52e8d3c5ec4b75ae0ae75c90fa"), 116 CHTRoot: common.HexToHash("0x8f2016fb336b64bd8ef4e9a73659a0a99476ea8789aacad695d65295a50fdb8d"), 117 BloomRoot: common.HexToHash("0x57f5b8ecfa10ada7509a45f7e0f2283c6b2dc08d8771163ffbb4ff0e3e6bca1c"), 118 } 119 120 // TestnetCheckpointOracle contains a set of configs for the Ropsten test network oracle. 121 TestnetCheckpointOracle = &CheckpointOracleConfig{ 122 Address: common.HexToAddress("0xEF79475013f154E6A65b54cB2742867791bf0B84"), 123 Signers: []common.Address{ 124 common.HexToAddress("0x32162F3581E88a5f62e8A61892B42C46E2c18f7b"), // Peter 125 common.HexToAddress("0x78d1aD571A1A09D60D9BBf25894b44e4C8859595"), // Martin 126 common.HexToAddress("0x286834935f4A8Cfb4FF4C77D5770C2775aE2b0E7"), // Zsolt 127 common.HexToAddress("0xb86e2B0Ab5A4B1373e40c51A7C712c70Ba2f9f8E"), // Gary 128 common.HexToAddress("0x0DF8fa387C602AE62559cC4aFa4972A7045d6707"), // Guillaume 129 }, 130 Threshold: 2, 131 } 132 133 // RinkebyChainConfig contains the chain parameters to run a node on the Rinkeby test network. 134 RinkebyChainConfig = &ChainConfig{ 135 ChainID: big.NewInt(4), 136 HomesteadBlock: big.NewInt(1), 137 DAOForkBlock: nil, 138 DAOForkSupport: true, 139 EIP150Block: big.NewInt(2), 140 EIP150Hash: common.HexToHash("0x9b095b36c15eaf13044373aef8ee0bd3a382a5abb92e402afa44b8249c3a90e9"), 141 EIP155Block: big.NewInt(3), 142 EIP158Block: big.NewInt(3), 143 ByzantiumBlock: big.NewInt(1035301), 144 ConstantinopleBlock: big.NewInt(3660663), 145 PetersburgBlock: big.NewInt(4321234), 146 IstanbulBlock: big.NewInt(5435345), 147 Clique: &CliqueConfig{ 148 Period: 15, 149 Epoch: 30000, 150 }, 151 } 152 153 // RinkebyTrustedCheckpoint contains the light client trusted checkpoint for the Rinkeby test network. 154 RinkebyTrustedCheckpoint = &TrustedCheckpoint{ 155 SectionIndex: 176, 156 SectionHead: common.HexToHash("0xb2cbd3396f25647fd80598fc4f7b015fb4131c0831630d878742b33dd286b641"), 157 CHTRoot: common.HexToHash("0xd81776495227babd75d8a519cb55e506e7b24265de5aa1847d38cb8f216ac09e"), 158 BloomRoot: common.HexToHash("0x0ea52b610139fcd6b1bc75351787e21c72922b18ea8a27091a51eb29b6723cd6"), 159 } 160 161 // RinkebyCheckpointOracle contains a set of configs for the Rinkeby test network oracle. 162 RinkebyCheckpointOracle = &CheckpointOracleConfig{ 163 Address: common.HexToAddress("0xebe8eFA441B9302A0d7eaECc277c09d20D684540"), 164 Signers: []common.Address{ 165 common.HexToAddress("0xd9c9cd5f6779558b6e0ed4e6acf6b1947e7fa1f3"), // Peter 166 common.HexToAddress("0x78d1aD571A1A09D60D9BBf25894b44e4C8859595"), // Martin 167 common.HexToAddress("0x286834935f4A8Cfb4FF4C77D5770C2775aE2b0E7"), // Zsolt 168 common.HexToAddress("0xb86e2B0Ab5A4B1373e40c51A7C712c70Ba2f9f8E"), // Gary 169 }, 170 Threshold: 2, 171 } 172 173 // GoerliChainConfig contains the chain parameters to run a node on the Görli test network. 174 GoerliChainConfig = &ChainConfig{ 175 ChainID: big.NewInt(5), 176 HomesteadBlock: big.NewInt(0), 177 DAOForkBlock: nil, 178 DAOForkSupport: true, 179 EIP150Block: big.NewInt(0), 180 EIP155Block: big.NewInt(0), 181 EIP158Block: big.NewInt(0), 182 ByzantiumBlock: big.NewInt(0), 183 ConstantinopleBlock: big.NewInt(0), 184 PetersburgBlock: big.NewInt(0), 185 IstanbulBlock: big.NewInt(1561651), 186 Clique: &CliqueConfig{ 187 Period: 15, 188 Epoch: 30000, 189 }, 190 } 191 192 // GoerliTrustedCheckpoint contains the light client trusted checkpoint for the Görli test network. 193 GoerliTrustedCheckpoint = &TrustedCheckpoint{ 194 SectionIndex: 60, 195 SectionHead: common.HexToHash("0x9bc784b6ad0c944f6aebf930fb5e811497059788b616e211db655a885e65f1cb"), 196 CHTRoot: common.HexToHash("0x961a811e2843f6196903edc1d04adbf13dee92627a89c21b3e0cdf69e0100638"), 197 BloomRoot: common.HexToHash("0x1564889bbe8c68011d29d3966439956303283c0fb8b08daa8376028e82dcd763"), 198 } 199 200 // GoerliCheckpointOracle contains a set of configs for the Goerli test network oracle. 201 GoerliCheckpointOracle = &CheckpointOracleConfig{ 202 Address: common.HexToAddress("0x18CA0E045F0D772a851BC7e48357Bcaab0a0795D"), 203 Signers: []common.Address{ 204 common.HexToAddress("0x4769bcaD07e3b938B7f43EB7D278Bc7Cb9efFb38"), // Peter 205 common.HexToAddress("0x78d1aD571A1A09D60D9BBf25894b44e4C8859595"), // Martin 206 common.HexToAddress("0x286834935f4A8Cfb4FF4C77D5770C2775aE2b0E7"), // Zsolt 207 common.HexToAddress("0xb86e2B0Ab5A4B1373e40c51A7C712c70Ba2f9f8E"), // Gary 208 common.HexToAddress("0x0DF8fa387C602AE62559cC4aFa4972A7045d6707"), // Guillaume 209 }, 210 Threshold: 2, 211 } 212 213 // AllEthashProtocolChanges contains every protocol change (EIPs) introduced 214 // and accepted by the Ethereum core developers into the Ethash consensus. 215 // 216 // This configuration is intentionally not using keyed fields to force anyone 217 // adding flags to the config to also have to set these fields. 218 AllEthashProtocolChanges = &ChainConfig{big.NewInt(108), 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), nil, nil, new(EthashConfig), nil} 219 220 // AllCliqueProtocolChanges contains every protocol change (EIPs) introduced 221 // and accepted by the Ethereum core developers into the Clique consensus. 222 // 223 // This configuration is intentionally not using keyed fields to force anyone 224 // adding flags to the config to also have to set these fields. 225 AllCliqueProtocolChanges = &ChainConfig{big.NewInt(420), 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), nil, nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}} 226 227 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), nil, nil, new(EthashConfig), nil} 228 TestRules = TestChainConfig.Rules(new(big.Int)) 229 230 // OpMainnetChainID is the ID of Optimism's mainnet chain. 231 OpMainnetChainID = big.NewInt(10) 232 233 // OpKovanChainID is the ID of Optimism's Kovan testnet chain. 234 OpKovanChainID = big.NewInt(69) 235 236 // OpMainnetSDUpdateForkNum is the height at which the SD update fork activates on Mainnet. 237 OpMainnetSDUpdateForkNum = big.NewInt(3135900) 238 239 // OpKovanSDUpdateForkNum is the height at which the SD update fork activates on Kovan. 240 OpKovanSDUpdateForkNum = big.NewInt(1094820) 241 ) 242 243 // TrustedCheckpoint represents a set of post-processed trie roots (CHT and 244 // BloomTrie) associated with the appropriate section index and head hash. It is 245 // used to start light syncing from this checkpoint and avoid downloading the 246 // entire header chain while still being able to securely access old headers/logs. 247 type TrustedCheckpoint struct { 248 SectionIndex uint64 `json:"sectionIndex"` 249 SectionHead common.Hash `json:"sectionHead"` 250 CHTRoot common.Hash `json:"chtRoot"` 251 BloomRoot common.Hash `json:"bloomRoot"` 252 } 253 254 // HashEqual returns an indicator comparing the itself hash with given one. 255 func (c *TrustedCheckpoint) HashEqual(hash common.Hash) bool { 256 if c.Empty() { 257 return hash == common.Hash{} 258 } 259 return c.Hash() == hash 260 } 261 262 // Hash returns the hash of checkpoint's four key fields(index, sectionHead, chtRoot and bloomTrieRoot). 263 func (c *TrustedCheckpoint) Hash() common.Hash { 264 buf := make([]byte, 8+3*common.HashLength) 265 binary.BigEndian.PutUint64(buf, c.SectionIndex) 266 copy(buf[8:], c.SectionHead.Bytes()) 267 copy(buf[8+common.HashLength:], c.CHTRoot.Bytes()) 268 copy(buf[8+2*common.HashLength:], c.BloomRoot.Bytes()) 269 return crypto.Keccak256Hash(buf) 270 } 271 272 // Empty returns an indicator whether the checkpoint is regarded as empty. 273 func (c *TrustedCheckpoint) Empty() bool { 274 return c.SectionHead == (common.Hash{}) || c.CHTRoot == (common.Hash{}) || c.BloomRoot == (common.Hash{}) 275 } 276 277 // CheckpointOracleConfig represents a set of checkpoint contract(which acts as an oracle) 278 // config which used for light client checkpoint syncing. 279 type CheckpointOracleConfig struct { 280 Address common.Address `json:"address"` 281 Signers []common.Address `json:"signers"` 282 Threshold uint64 `json:"threshold"` 283 } 284 285 // ChainConfig is the core config which determines the blockchain settings. 286 // 287 // ChainConfig is stored in the database on a per block basis. This means 288 // that any network, identified by its genesis block, can have its own 289 // set of configuration options. 290 type ChainConfig struct { 291 ChainID *big.Int `json:"chainId"` // chainId identifies the current chain and is used for replay protection 292 293 HomesteadBlock *big.Int `json:"homesteadBlock,omitempty"` // Homestead switch block (nil = no fork, 0 = already homestead) 294 295 DAOForkBlock *big.Int `json:"daoForkBlock,omitempty"` // TheDAO hard-fork switch block (nil = no fork) 296 DAOForkSupport bool `json:"daoForkSupport,omitempty"` // Whether the nodes supports or opposes the DAO hard-fork 297 298 // EIP150 implements the Gas price changes (https://github.com/ethereum/EIPs/issues/150) 299 EIP150Block *big.Int `json:"eip150Block,omitempty"` // EIP150 HF block (nil = no fork) 300 EIP150Hash common.Hash `json:"eip150Hash,omitempty"` // EIP150 HF hash (needed for header only clients as only gas pricing changed) 301 302 EIP155Block *big.Int `json:"eip155Block,omitempty"` // EIP155 HF block 303 EIP158Block *big.Int `json:"eip158Block,omitempty"` // EIP158 HF block 304 305 ByzantiumBlock *big.Int `json:"byzantiumBlock,omitempty"` // Byzantium switch block (nil = no fork, 0 = already on byzantium) 306 ConstantinopleBlock *big.Int `json:"constantinopleBlock,omitempty"` // Constantinople switch block (nil = no fork, 0 = already activated) 307 PetersburgBlock *big.Int `json:"petersburgBlock,omitempty"` // Petersburg switch block (nil = same as Constantinople) 308 IstanbulBlock *big.Int `json:"istanbulBlock,omitempty"` // Istanbul switch block (nil = no fork, 0 = already on istanbul) 309 MuirGlacierBlock *big.Int `json:"muirGlacierBlock,omitempty"` // Eip-2384 (bomb delay) switch block (nil = no fork, 0 = already activated) 310 BerlinBlock *big.Int `json:"berlinBlock,omitempty"` // Berlin switch block (nil = no fork, 0 = already on berlin) 311 312 EWASMBlock *big.Int `json:"ewasmBlock,omitempty"` // EWASM switch block (nil = no fork, 0 = already activated) 313 314 // Various consensus engines 315 Ethash *EthashConfig `json:"ethash,omitempty"` 316 Clique *CliqueConfig `json:"clique,omitempty"` 317 } 318 319 // EthashConfig is the consensus engine configs for proof-of-work based sealing. 320 type EthashConfig struct{} 321 322 // String implements the stringer interface, returning the consensus engine details. 323 func (c *EthashConfig) String() string { 324 return "ethash" 325 } 326 327 // CliqueConfig is the consensus engine configs for proof-of-authority based sealing. 328 type CliqueConfig struct { 329 Period uint64 `json:"period"` // Number of seconds between blocks to enforce 330 Epoch uint64 `json:"epoch"` // Epoch length to reset votes and checkpoint 331 } 332 333 // String implements the stringer interface, returning the consensus engine details. 334 func (c *CliqueConfig) String() string { 335 return "clique" 336 } 337 338 // String implements the fmt.Stringer interface. 339 func (c *ChainConfig) String() string { 340 var engine interface{} 341 switch { 342 case c.Ethash != nil: 343 engine = c.Ethash 344 case c.Clique != nil: 345 engine = c.Clique 346 default: 347 engine = "unknown" 348 } 349 return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Petersburg: %v Istanbul: %v, Muir Glacier: %v, Berlin: %v, Engine: %v}", 350 c.ChainID, 351 c.HomesteadBlock, 352 c.DAOForkBlock, 353 c.DAOForkSupport, 354 c.EIP150Block, 355 c.EIP155Block, 356 c.EIP158Block, 357 c.ByzantiumBlock, 358 c.ConstantinopleBlock, 359 c.PetersburgBlock, 360 c.IstanbulBlock, 361 c.MuirGlacierBlock, 362 c.BerlinBlock, 363 engine, 364 ) 365 } 366 367 // IsHomestead returns whether num is either equal to the homestead block or greater. 368 func (c *ChainConfig) IsHomestead(num *big.Int) bool { 369 return isForked(c.HomesteadBlock, num) 370 } 371 372 // IsDAOFork returns whether num is either equal to the DAO fork block or greater. 373 func (c *ChainConfig) IsDAOFork(num *big.Int) bool { 374 return isForked(c.DAOForkBlock, num) 375 } 376 377 // IsEIP150 returns whether num is either equal to the EIP150 fork block or greater. 378 func (c *ChainConfig) IsEIP150(num *big.Int) bool { 379 return isForked(c.EIP150Block, num) 380 } 381 382 // IsEIP155 returns whether num is either equal to the EIP155 fork block or greater. 383 func (c *ChainConfig) IsEIP155(num *big.Int) bool { 384 return isForked(c.EIP155Block, num) 385 } 386 387 // IsEIP158 returns whether num is either equal to the EIP158 fork block or greater. 388 func (c *ChainConfig) IsEIP158(num *big.Int) bool { 389 return isForked(c.EIP158Block, num) 390 } 391 392 // IsByzantium returns whether num is either equal to the Byzantium fork block or greater. 393 func (c *ChainConfig) IsByzantium(num *big.Int) bool { 394 return isForked(c.ByzantiumBlock, num) 395 } 396 397 // IsConstantinople returns whether num is either equal to the Constantinople fork block or greater. 398 func (c *ChainConfig) IsConstantinople(num *big.Int) bool { 399 return isForked(c.ConstantinopleBlock, num) 400 } 401 402 // IsMuirGlacier returns whether num is either equal to the Muir Glacier (EIP-2384) fork block or greater. 403 func (c *ChainConfig) IsMuirGlacier(num *big.Int) bool { 404 return isForked(c.MuirGlacierBlock, num) 405 } 406 407 // IsPetersburg returns whether num is either 408 // - equal to or greater than the PetersburgBlock fork block, 409 // - OR is nil, and Constantinople is active 410 func (c *ChainConfig) IsPetersburg(num *big.Int) bool { 411 return isForked(c.PetersburgBlock, num) || c.PetersburgBlock == nil && isForked(c.ConstantinopleBlock, num) 412 } 413 414 // IsIstanbul returns whether num is either equal to the Istanbul fork block or greater. 415 func (c *ChainConfig) IsIstanbul(num *big.Int) bool { 416 return isForked(c.IstanbulBlock, num) 417 } 418 419 // IsBerlin returns whether num is either equal to the Berlin fork block or greater. 420 func (c *ChainConfig) IsBerlin(num *big.Int) bool { 421 return isForked(c.BerlinBlock, num) 422 } 423 424 // IsEWASM returns whether num represents a block number after the EWASM fork 425 func (c *ChainConfig) IsEWASM(num *big.Int) bool { 426 return isForked(c.EWASMBlock, num) 427 } 428 429 // IsSDUpdate returns whether num represents a block number after the SD update fork 430 func (c *ChainConfig) IsSDUpdate(num *big.Int) bool { 431 if c.ChainID.Cmp(OpMainnetChainID) == 0 { 432 return isForked(OpMainnetSDUpdateForkNum, num) 433 } 434 if c.ChainID.Cmp(OpKovanChainID) == 0 { 435 return isForked(OpKovanSDUpdateForkNum, num) 436 } 437 return true 438 } 439 440 // CheckCompatible checks whether scheduled fork transitions have been imported 441 // with a mismatching chain configuration. 442 func (c *ChainConfig) CheckCompatible(newcfg *ChainConfig, height uint64) *ConfigCompatError { 443 bhead := new(big.Int).SetUint64(height) 444 445 // Iterate checkCompatible to find the lowest conflict. 446 var lasterr *ConfigCompatError 447 for { 448 err := c.checkCompatible(newcfg, bhead) 449 if err == nil || (lasterr != nil && err.RewindTo == lasterr.RewindTo) { 450 break 451 } 452 lasterr = err 453 bhead.SetUint64(err.RewindTo) 454 } 455 return lasterr 456 } 457 458 // CheckConfigForkOrder checks that we don't "skip" any forks, geth isn't pluggable enough 459 // to guarantee that forks can be implemented in a different order than on official networks 460 func (c *ChainConfig) CheckConfigForkOrder() error { 461 type fork struct { 462 name string 463 block *big.Int 464 } 465 var lastFork fork 466 for _, cur := range []fork{ 467 {"homesteadBlock", c.HomesteadBlock}, 468 {"eip150Block", c.EIP150Block}, 469 {"eip155Block", c.EIP155Block}, 470 {"eip158Block", c.EIP158Block}, 471 {"byzantiumBlock", c.ByzantiumBlock}, 472 {"constantinopleBlock", c.ConstantinopleBlock}, 473 {"petersburgBlock", c.PetersburgBlock}, 474 {"istanbulBlock", c.IstanbulBlock}, 475 {"muirGlacierBlock", c.MuirGlacierBlock}, 476 {name: "berlinBlock", block: c.BerlinBlock}, 477 } { 478 if lastFork.name != "" { 479 // Next one must be higher number 480 if lastFork.block == nil && cur.block != nil { 481 return fmt.Errorf("unsupported fork ordering: %v not enabled, but %v enabled at %v", 482 lastFork.name, cur.name, cur.block) 483 } 484 if lastFork.block != nil && cur.block != nil { 485 if lastFork.block.Cmp(cur.block) > 0 { 486 return fmt.Errorf("unsupported fork ordering: %v enabled at %v, but %v enabled at %v", 487 lastFork.name, lastFork.block, cur.name, cur.block) 488 } 489 } 490 } 491 lastFork = cur 492 } 493 return nil 494 } 495 496 func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, head *big.Int) *ConfigCompatError { 497 if isForkIncompatible(c.HomesteadBlock, newcfg.HomesteadBlock, head) { 498 return newCompatError("Homestead fork block", c.HomesteadBlock, newcfg.HomesteadBlock) 499 } 500 if isForkIncompatible(c.DAOForkBlock, newcfg.DAOForkBlock, head) { 501 return newCompatError("DAO fork block", c.DAOForkBlock, newcfg.DAOForkBlock) 502 } 503 if c.IsDAOFork(head) && c.DAOForkSupport != newcfg.DAOForkSupport { 504 return newCompatError("DAO fork support flag", c.DAOForkBlock, newcfg.DAOForkBlock) 505 } 506 if isForkIncompatible(c.EIP150Block, newcfg.EIP150Block, head) { 507 return newCompatError("EIP150 fork block", c.EIP150Block, newcfg.EIP150Block) 508 } 509 if isForkIncompatible(c.EIP155Block, newcfg.EIP155Block, head) { 510 return newCompatError("EIP155 fork block", c.EIP155Block, newcfg.EIP155Block) 511 } 512 if isForkIncompatible(c.EIP158Block, newcfg.EIP158Block, head) { 513 return newCompatError("EIP158 fork block", c.EIP158Block, newcfg.EIP158Block) 514 } 515 if c.IsEIP158(head) && !configNumEqual(c.ChainID, newcfg.ChainID) { 516 return newCompatError("EIP158 chain ID", c.EIP158Block, newcfg.EIP158Block) 517 } 518 if isForkIncompatible(c.ByzantiumBlock, newcfg.ByzantiumBlock, head) { 519 return newCompatError("Byzantium fork block", c.ByzantiumBlock, newcfg.ByzantiumBlock) 520 } 521 if isForkIncompatible(c.ConstantinopleBlock, newcfg.ConstantinopleBlock, head) { 522 return newCompatError("Constantinople fork block", c.ConstantinopleBlock, newcfg.ConstantinopleBlock) 523 } 524 if isForkIncompatible(c.PetersburgBlock, newcfg.PetersburgBlock, head) { 525 return newCompatError("Petersburg fork block", c.PetersburgBlock, newcfg.PetersburgBlock) 526 } 527 if isForkIncompatible(c.IstanbulBlock, newcfg.IstanbulBlock, head) { 528 return newCompatError("Istanbul fork block", c.IstanbulBlock, newcfg.IstanbulBlock) 529 } 530 if isForkIncompatible(c.MuirGlacierBlock, newcfg.MuirGlacierBlock, head) { 531 return newCompatError("Muir Glacier fork block", c.MuirGlacierBlock, newcfg.MuirGlacierBlock) 532 } 533 if isForkIncompatible(c.BerlinBlock, newcfg.BerlinBlock, head) { 534 return newCompatError("Berlin fork block", c.BerlinBlock, newcfg.BerlinBlock) 535 } 536 if isForkIncompatible(c.EWASMBlock, newcfg.EWASMBlock, head) { 537 return newCompatError("ewasm fork block", c.EWASMBlock, newcfg.EWASMBlock) 538 } 539 return nil 540 } 541 542 // isForkIncompatible returns true if a fork scheduled at s1 cannot be rescheduled to 543 // block s2 because head is already past the fork. 544 func isForkIncompatible(s1, s2, head *big.Int) bool { 545 return (isForked(s1, head) || isForked(s2, head)) && !configNumEqual(s1, s2) 546 } 547 548 // isForked returns whether a fork scheduled at block s is active at the given head block. 549 func isForked(s, head *big.Int) bool { 550 if s == nil || head == nil { 551 return false 552 } 553 return s.Cmp(head) <= 0 554 } 555 556 func configNumEqual(x, y *big.Int) bool { 557 if x == nil { 558 return y == nil 559 } 560 if y == nil { 561 return x == nil 562 } 563 return x.Cmp(y) == 0 564 } 565 566 // ConfigCompatError is raised if the locally-stored blockchain is initialised with a 567 // ChainConfig that would alter the past. 568 type ConfigCompatError struct { 569 What string 570 // block numbers of the stored and new configurations 571 StoredConfig, NewConfig *big.Int 572 // the block number to which the local chain must be rewound to correct the error 573 RewindTo uint64 574 } 575 576 func newCompatError(what string, storedblock, newblock *big.Int) *ConfigCompatError { 577 var rew *big.Int 578 switch { 579 case storedblock == nil: 580 rew = newblock 581 case newblock == nil || storedblock.Cmp(newblock) < 0: 582 rew = storedblock 583 default: 584 rew = newblock 585 } 586 err := &ConfigCompatError{what, storedblock, newblock, 0} 587 if rew != nil && rew.Sign() > 0 { 588 err.RewindTo = rew.Uint64() - 1 589 } 590 return err 591 } 592 593 func (err *ConfigCompatError) Error() string { 594 return fmt.Sprintf("mismatching %s in database (have %d, want %d, rewindto %d)", err.What, err.StoredConfig, err.NewConfig, err.RewindTo) 595 } 596 597 // Rules wraps ChainConfig and is merely syntactic sugar or can be used for functions 598 // that do not have or require information about the block. 599 // 600 // Rules is a one time interface meaning that it shouldn't be used in between transition 601 // phases. 602 type Rules struct { 603 ChainID *big.Int 604 IsHomestead, IsEIP150, IsEIP155, IsEIP158 bool 605 IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool 606 IsBerlin bool 607 } 608 609 // Rules ensures c's ChainID is not nil. 610 func (c *ChainConfig) Rules(num *big.Int) Rules { 611 chainID := c.ChainID 612 if chainID == nil { 613 chainID = new(big.Int) 614 } 615 return Rules{ 616 ChainID: new(big.Int).Set(chainID), 617 IsHomestead: c.IsHomestead(num), 618 IsEIP150: c.IsEIP150(num), 619 IsEIP155: c.IsEIP155(num), 620 IsEIP158: c.IsEIP158(num), 621 IsByzantium: c.IsByzantium(num), 622 IsConstantinople: c.IsConstantinople(num), 623 IsPetersburg: c.IsPetersburg(num), 624 IsIstanbul: c.IsIstanbul(num), 625 IsBerlin: c.IsBerlin(num), 626 } 627 }