github.com/jimmyx0x/go-ethereum@v1.10.28/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/go-ethereum/common" 25 "golang.org/x/crypto/sha3" 26 ) 27 28 // Genesis hashes to enforce below configs on. 29 var ( 30 MainnetGenesisHash = common.HexToHash("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3") 31 RopstenGenesisHash = common.HexToHash("0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d") 32 SepoliaGenesisHash = common.HexToHash("0x25a5cc106eea7138acab33231d7160d69cb777ee0c2c553fcddf5138993e6dd9") 33 RinkebyGenesisHash = common.HexToHash("0x6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177") 34 GoerliGenesisHash = common.HexToHash("0xbf7e331f7f7c1dd2e05159666b3bf8bc7a8a3a9eb1d518969eab529dd9b88c1a") 35 KilnGenesisHash = common.HexToHash("0x51c7fe41be669f69c45c33a56982cbde405313342d9e2b00d7c91a7b284dd4f8") 36 ) 37 38 // TrustedCheckpoints associates each known checkpoint with the genesis hash of 39 // the chain it belongs to. 40 var TrustedCheckpoints = map[common.Hash]*TrustedCheckpoint{ 41 MainnetGenesisHash: MainnetTrustedCheckpoint, 42 RopstenGenesisHash: RopstenTrustedCheckpoint, 43 SepoliaGenesisHash: SepoliaTrustedCheckpoint, 44 RinkebyGenesisHash: RinkebyTrustedCheckpoint, 45 GoerliGenesisHash: GoerliTrustedCheckpoint, 46 } 47 48 // CheckpointOracles associates each known checkpoint oracles with the genesis hash of 49 // the chain it belongs to. 50 var CheckpointOracles = map[common.Hash]*CheckpointOracleConfig{ 51 MainnetGenesisHash: MainnetCheckpointOracle, 52 RopstenGenesisHash: RopstenCheckpointOracle, 53 RinkebyGenesisHash: RinkebyCheckpointOracle, 54 GoerliGenesisHash: GoerliCheckpointOracle, 55 } 56 57 var ( 58 MainnetTerminalTotalDifficulty, _ = new(big.Int).SetString("58_750_000_000_000_000_000_000", 0) 59 60 // MainnetChainConfig is the chain parameters to run a node on the main network. 61 MainnetChainConfig = &ChainConfig{ 62 ChainID: big.NewInt(1), 63 HomesteadBlock: big.NewInt(1_150_000), 64 DAOForkBlock: big.NewInt(1_920_000), 65 DAOForkSupport: true, 66 EIP150Block: big.NewInt(2_463_000), 67 EIP150Hash: common.HexToHash("0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0"), 68 EIP155Block: big.NewInt(2_675_000), 69 EIP158Block: big.NewInt(2_675_000), 70 ByzantiumBlock: big.NewInt(4_370_000), 71 ConstantinopleBlock: big.NewInt(7_280_000), 72 PetersburgBlock: big.NewInt(7_280_000), 73 IstanbulBlock: big.NewInt(9_069_000), 74 MuirGlacierBlock: big.NewInt(9_200_000), 75 BerlinBlock: big.NewInt(12_244_000), 76 LondonBlock: big.NewInt(12_965_000), 77 ArrowGlacierBlock: big.NewInt(13_773_000), 78 GrayGlacierBlock: big.NewInt(15_050_000), 79 TerminalTotalDifficulty: MainnetTerminalTotalDifficulty, // 58_750_000_000_000_000_000_000 80 TerminalTotalDifficultyPassed: true, 81 Ethash: new(EthashConfig), 82 } 83 84 // MainnetTrustedCheckpoint contains the light client trusted checkpoint for the main network. 85 MainnetTrustedCheckpoint = &TrustedCheckpoint{ 86 SectionIndex: 471, 87 SectionHead: common.HexToHash("0xa03d6354f5ca8d33203bb646ac26a964f240ee54728dcb7483faff0204ec4c9b"), 88 CHTRoot: common.HexToHash("0x29efeeea3540b7f499b4214d5262bd1fcd87253de10a878f92e6497d848b186f"), 89 BloomRoot: common.HexToHash("0x2ff6a93ff5e78e823bfc80c6ec856bfe9b20c4ffd0af3cef644a916eabcd3c84"), 90 } 91 92 // MainnetCheckpointOracle contains a set of configs for the main network oracle. 93 MainnetCheckpointOracle = &CheckpointOracleConfig{ 94 Address: common.HexToAddress("0x9a9070028361F7AAbeB3f2F2Dc07F82C4a98A02a"), 95 Signers: []common.Address{ 96 common.HexToAddress("0x1b2C260efc720BE89101890E4Db589b44E950527"), // Peter 97 common.HexToAddress("0x78d1aD571A1A09D60D9BBf25894b44e4C8859595"), // Martin 98 common.HexToAddress("0x286834935f4A8Cfb4FF4C77D5770C2775aE2b0E7"), // Zsolt 99 common.HexToAddress("0xb86e2B0Ab5A4B1373e40c51A7C712c70Ba2f9f8E"), // Gary 100 common.HexToAddress("0x0DF8fa387C602AE62559cC4aFa4972A7045d6707"), // Guillaume 101 }, 102 Threshold: 2, 103 } 104 105 // RopstenChainConfig contains the chain parameters to run a node on the Ropsten test network. 106 RopstenChainConfig = &ChainConfig{ 107 ChainID: big.NewInt(3), 108 HomesteadBlock: big.NewInt(0), 109 DAOForkBlock: nil, 110 DAOForkSupport: true, 111 EIP150Block: big.NewInt(0), 112 EIP150Hash: common.HexToHash("0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d"), 113 EIP155Block: big.NewInt(10), 114 EIP158Block: big.NewInt(10), 115 ByzantiumBlock: big.NewInt(1_700_000), 116 ConstantinopleBlock: big.NewInt(4_230_000), 117 PetersburgBlock: big.NewInt(4_939_394), 118 IstanbulBlock: big.NewInt(6_485_846), 119 MuirGlacierBlock: big.NewInt(7_117_117), 120 BerlinBlock: big.NewInt(9_812_189), 121 LondonBlock: big.NewInt(10_499_401), 122 TerminalTotalDifficulty: new(big.Int).SetUint64(50_000_000_000_000_000), 123 TerminalTotalDifficultyPassed: true, 124 Ethash: new(EthashConfig), 125 } 126 127 // RopstenTrustedCheckpoint contains the light client trusted checkpoint for the Ropsten test network. 128 RopstenTrustedCheckpoint = &TrustedCheckpoint{ 129 SectionIndex: 393, 130 SectionHead: common.HexToHash("0x04479087c89428c6ed0d4ff25642776f0c35747d8ecef90547fa3ce4ebec8606"), 131 CHTRoot: common.HexToHash("0xaa100968cebe48dba3a8f196f044db04113d5a938ff083838ce6f2c588d416ad"), 132 BloomRoot: common.HexToHash("0xb9108d510c4b50b60793feead27620781bc1c2164e072d8022201c4eb7c36ba0"), 133 } 134 135 // RopstenCheckpointOracle contains a set of configs for the Ropsten test network oracle. 136 RopstenCheckpointOracle = &CheckpointOracleConfig{ 137 Address: common.HexToAddress("0xEF79475013f154E6A65b54cB2742867791bf0B84"), 138 Signers: []common.Address{ 139 common.HexToAddress("0x32162F3581E88a5f62e8A61892B42C46E2c18f7b"), // Peter 140 common.HexToAddress("0x78d1aD571A1A09D60D9BBf25894b44e4C8859595"), // Martin 141 common.HexToAddress("0x286834935f4A8Cfb4FF4C77D5770C2775aE2b0E7"), // Zsolt 142 common.HexToAddress("0xb86e2B0Ab5A4B1373e40c51A7C712c70Ba2f9f8E"), // Gary 143 common.HexToAddress("0x0DF8fa387C602AE62559cC4aFa4972A7045d6707"), // Guillaume 144 }, 145 Threshold: 2, 146 } 147 148 // SepoliaChainConfig contains the chain parameters to run a node on the Sepolia test network. 149 SepoliaChainConfig = &ChainConfig{ 150 ChainID: big.NewInt(11155111), 151 HomesteadBlock: big.NewInt(0), 152 DAOForkBlock: nil, 153 DAOForkSupport: true, 154 EIP150Block: big.NewInt(0), 155 EIP155Block: big.NewInt(0), 156 EIP158Block: big.NewInt(0), 157 ByzantiumBlock: big.NewInt(0), 158 ConstantinopleBlock: big.NewInt(0), 159 PetersburgBlock: big.NewInt(0), 160 IstanbulBlock: big.NewInt(0), 161 MuirGlacierBlock: big.NewInt(0), 162 BerlinBlock: big.NewInt(0), 163 LondonBlock: big.NewInt(0), 164 TerminalTotalDifficulty: big.NewInt(17_000_000_000_000_000), 165 TerminalTotalDifficultyPassed: true, 166 MergeNetsplitBlock: big.NewInt(1735371), 167 Ethash: new(EthashConfig), 168 } 169 170 // SepoliaTrustedCheckpoint contains the light client trusted checkpoint for the Sepolia test network. 171 SepoliaTrustedCheckpoint = &TrustedCheckpoint{ 172 SectionIndex: 55, 173 SectionHead: common.HexToHash("0xb70ea113ab4db9d6e015c5b55d486713f60c40bda666121914a71ce3aec53a75"), 174 CHTRoot: common.HexToHash("0x206456d8847b66aaf427ed551f55e24cff90241bdb0a02583c761bf8164f78e4"), 175 BloomRoot: common.HexToHash("0x4369228d59a8fe285fee874c636531091e659b3b1294bb978eb159860a1cede2"), 176 } 177 178 // RinkebyChainConfig contains the chain parameters to run a node on the Rinkeby test network. 179 RinkebyChainConfig = &ChainConfig{ 180 ChainID: big.NewInt(4), 181 HomesteadBlock: big.NewInt(1), 182 DAOForkBlock: nil, 183 DAOForkSupport: true, 184 EIP150Block: big.NewInt(2), 185 EIP150Hash: common.HexToHash("0x9b095b36c15eaf13044373aef8ee0bd3a382a5abb92e402afa44b8249c3a90e9"), 186 EIP155Block: big.NewInt(3), 187 EIP158Block: big.NewInt(3), 188 ByzantiumBlock: big.NewInt(1_035_301), 189 ConstantinopleBlock: big.NewInt(3_660_663), 190 PetersburgBlock: big.NewInt(4_321_234), 191 IstanbulBlock: big.NewInt(5_435_345), 192 MuirGlacierBlock: nil, 193 BerlinBlock: big.NewInt(8_290_928), 194 LondonBlock: big.NewInt(8_897_988), 195 ArrowGlacierBlock: nil, 196 Clique: &CliqueConfig{ 197 Period: 15, 198 Epoch: 30000, 199 }, 200 } 201 202 // RinkebyTrustedCheckpoint contains the light client trusted checkpoint for the Rinkeby test network. 203 RinkebyTrustedCheckpoint = &TrustedCheckpoint{ 204 SectionIndex: 344, 205 SectionHead: common.HexToHash("0x06bb973aecce633df8cda532ff75b9d0b38c16de2545f52eaf745f858d0fe616"), 206 CHTRoot: common.HexToHash("0xf1c80b9270ef9fb7907362bca006f8349f0c38d45b83167b57638f54211c6aca"), 207 BloomRoot: common.HexToHash("0xd72187253f49bce9d471f5e0ddf2b5008ba695d7a1be1192d52fb4d8b01970c6"), 208 } 209 210 // RinkebyCheckpointOracle contains a set of configs for the Rinkeby test network oracle. 211 RinkebyCheckpointOracle = &CheckpointOracleConfig{ 212 Address: common.HexToAddress("0xebe8eFA441B9302A0d7eaECc277c09d20D684540"), 213 Signers: []common.Address{ 214 common.HexToAddress("0xd9c9cd5f6779558b6e0ed4e6acf6b1947e7fa1f3"), // Peter 215 common.HexToAddress("0x78d1aD571A1A09D60D9BBf25894b44e4C8859595"), // Martin 216 common.HexToAddress("0x286834935f4A8Cfb4FF4C77D5770C2775aE2b0E7"), // Zsolt 217 common.HexToAddress("0xb86e2B0Ab5A4B1373e40c51A7C712c70Ba2f9f8E"), // Gary 218 }, 219 Threshold: 2, 220 } 221 222 // GoerliChainConfig contains the chain parameters to run a node on the Görli test network. 223 GoerliChainConfig = &ChainConfig{ 224 ChainID: big.NewInt(5), 225 HomesteadBlock: big.NewInt(0), 226 DAOForkBlock: nil, 227 DAOForkSupport: true, 228 EIP150Block: big.NewInt(0), 229 EIP155Block: big.NewInt(0), 230 EIP158Block: big.NewInt(0), 231 ByzantiumBlock: big.NewInt(0), 232 ConstantinopleBlock: big.NewInt(0), 233 PetersburgBlock: big.NewInt(0), 234 IstanbulBlock: big.NewInt(1_561_651), 235 MuirGlacierBlock: nil, 236 BerlinBlock: big.NewInt(4_460_644), 237 LondonBlock: big.NewInt(5_062_605), 238 ArrowGlacierBlock: nil, 239 TerminalTotalDifficulty: big.NewInt(10_790_000), 240 TerminalTotalDifficultyPassed: true, 241 Clique: &CliqueConfig{ 242 Period: 15, 243 Epoch: 30000, 244 }, 245 } 246 247 // GoerliTrustedCheckpoint contains the light client trusted checkpoint for the Görli test network. 248 GoerliTrustedCheckpoint = &TrustedCheckpoint{ 249 SectionIndex: 229, 250 SectionHead: common.HexToHash("0xc5a7b57cb4af7b3d4cc251ac5f29acaac94e7464365358e7ad26129083b7729a"), 251 CHTRoot: common.HexToHash("0x54c0d5c756d9c48eda26ea13c2a49c2e31f1cb7dfb01514ddc49f3d24272c77e"), 252 BloomRoot: common.HexToHash("0xd681970a496f6187d089f8c8665a3587b5a78212d79b6ceef97c0dabd0188e56"), 253 } 254 255 // GoerliCheckpointOracle contains a set of configs for the Goerli test network oracle. 256 GoerliCheckpointOracle = &CheckpointOracleConfig{ 257 Address: common.HexToAddress("0x18CA0E045F0D772a851BC7e48357Bcaab0a0795D"), 258 Signers: []common.Address{ 259 common.HexToAddress("0x4769bcaD07e3b938B7f43EB7D278Bc7Cb9efFb38"), // Peter 260 common.HexToAddress("0x78d1aD571A1A09D60D9BBf25894b44e4C8859595"), // Martin 261 common.HexToAddress("0x286834935f4A8Cfb4FF4C77D5770C2775aE2b0E7"), // Zsolt 262 common.HexToAddress("0xb86e2B0Ab5A4B1373e40c51A7C712c70Ba2f9f8E"), // Gary 263 common.HexToAddress("0x0DF8fa387C602AE62559cC4aFa4972A7045d6707"), // Guillaume 264 }, 265 Threshold: 2, 266 } 267 268 // AllEthashProtocolChanges contains every protocol change (EIPs) introduced 269 // and accepted by the Ethereum core developers into the Ethash consensus. 270 // 271 // This configuration is intentionally not using keyed fields to force anyone 272 // adding flags to the config to also have to set these fields. 273 AllEthashProtocolChanges = &ChainConfig{big.NewInt(1337), 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), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, nil, false, new(EthashConfig), nil} 274 275 // AllCliqueProtocolChanges contains every protocol change (EIPs) introduced 276 // and accepted by the Ethereum core developers into the Clique consensus. 277 // 278 // This configuration is intentionally not using keyed fields to force anyone 279 // adding flags to the config to also have to set these fields. 280 AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), 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), big.NewInt(0), big.NewInt(0), nil, nil, nil, nil, nil, nil, false, nil, &CliqueConfig{Period: 0, Epoch: 30000}} 281 282 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), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, nil, false, new(EthashConfig), nil} 283 NonActivatedConfig = &ChainConfig{big.NewInt(1), nil, nil, false, nil, common.Hash{}, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, false, new(EthashConfig), nil} 284 TestRules = TestChainConfig.Rules(new(big.Int), false, new(big.Int)) 285 ) 286 287 // NetworkNames are user friendly names to use in the chain spec banner. 288 var NetworkNames = map[string]string{ 289 MainnetChainConfig.ChainID.String(): "mainnet", 290 RopstenChainConfig.ChainID.String(): "ropsten", 291 RinkebyChainConfig.ChainID.String(): "rinkeby", 292 GoerliChainConfig.ChainID.String(): "goerli", 293 SepoliaChainConfig.ChainID.String(): "sepolia", 294 } 295 296 // TrustedCheckpoint represents a set of post-processed trie roots (CHT and 297 // BloomTrie) associated with the appropriate section index and head hash. It is 298 // used to start light syncing from this checkpoint and avoid downloading the 299 // entire header chain while still being able to securely access old headers/logs. 300 type TrustedCheckpoint struct { 301 SectionIndex uint64 `json:"sectionIndex"` 302 SectionHead common.Hash `json:"sectionHead"` 303 CHTRoot common.Hash `json:"chtRoot"` 304 BloomRoot common.Hash `json:"bloomRoot"` 305 } 306 307 // HashEqual returns an indicator comparing the itself hash with given one. 308 func (c *TrustedCheckpoint) HashEqual(hash common.Hash) bool { 309 if c.Empty() { 310 return hash == common.Hash{} 311 } 312 return c.Hash() == hash 313 } 314 315 // Hash returns the hash of checkpoint's four key fields(index, sectionHead, chtRoot and bloomTrieRoot). 316 func (c *TrustedCheckpoint) Hash() common.Hash { 317 var sectionIndex [8]byte 318 binary.BigEndian.PutUint64(sectionIndex[:], c.SectionIndex) 319 320 w := sha3.NewLegacyKeccak256() 321 w.Write(sectionIndex[:]) 322 w.Write(c.SectionHead[:]) 323 w.Write(c.CHTRoot[:]) 324 w.Write(c.BloomRoot[:]) 325 326 var h common.Hash 327 w.Sum(h[:0]) 328 return h 329 } 330 331 // Empty returns an indicator whether the checkpoint is regarded as empty. 332 func (c *TrustedCheckpoint) Empty() bool { 333 return c.SectionHead == (common.Hash{}) || c.CHTRoot == (common.Hash{}) || c.BloomRoot == (common.Hash{}) 334 } 335 336 // CheckpointOracleConfig represents a set of checkpoint contract(which acts as an oracle) 337 // config which used for light client checkpoint syncing. 338 type CheckpointOracleConfig struct { 339 Address common.Address `json:"address"` 340 Signers []common.Address `json:"signers"` 341 Threshold uint64 `json:"threshold"` 342 } 343 344 // ChainConfig is the core config which determines the blockchain settings. 345 // 346 // ChainConfig is stored in the database on a per block basis. This means 347 // that any network, identified by its genesis block, can have its own 348 // set of configuration options. 349 type ChainConfig struct { 350 ChainID *big.Int `json:"chainId"` // chainId identifies the current chain and is used for replay protection 351 352 HomesteadBlock *big.Int `json:"homesteadBlock,omitempty"` // Homestead switch block (nil = no fork, 0 = already homestead) 353 354 DAOForkBlock *big.Int `json:"daoForkBlock,omitempty"` // TheDAO hard-fork switch block (nil = no fork) 355 DAOForkSupport bool `json:"daoForkSupport,omitempty"` // Whether the nodes supports or opposes the DAO hard-fork 356 357 // EIP150 implements the Gas price changes (https://github.com/ethereum/EIPs/issues/150) 358 EIP150Block *big.Int `json:"eip150Block,omitempty"` // EIP150 HF block (nil = no fork) 359 EIP150Hash common.Hash `json:"eip150Hash,omitempty"` // EIP150 HF hash (needed for header only clients as only gas pricing changed) 360 361 EIP155Block *big.Int `json:"eip155Block,omitempty"` // EIP155 HF block 362 EIP158Block *big.Int `json:"eip158Block,omitempty"` // EIP158 HF block 363 364 ByzantiumBlock *big.Int `json:"byzantiumBlock,omitempty"` // Byzantium switch block (nil = no fork, 0 = already on byzantium) 365 ConstantinopleBlock *big.Int `json:"constantinopleBlock,omitempty"` // Constantinople switch block (nil = no fork, 0 = already activated) 366 PetersburgBlock *big.Int `json:"petersburgBlock,omitempty"` // Petersburg switch block (nil = same as Constantinople) 367 IstanbulBlock *big.Int `json:"istanbulBlock,omitempty"` // Istanbul switch block (nil = no fork, 0 = already on istanbul) 368 MuirGlacierBlock *big.Int `json:"muirGlacierBlock,omitempty"` // Eip-2384 (bomb delay) switch block (nil = no fork, 0 = already activated) 369 BerlinBlock *big.Int `json:"berlinBlock,omitempty"` // Berlin switch block (nil = no fork, 0 = already on berlin) 370 LondonBlock *big.Int `json:"londonBlock,omitempty"` // London switch block (nil = no fork, 0 = already on london) 371 ArrowGlacierBlock *big.Int `json:"arrowGlacierBlock,omitempty"` // Eip-4345 (bomb delay) switch block (nil = no fork, 0 = already activated) 372 GrayGlacierBlock *big.Int `json:"grayGlacierBlock,omitempty"` // Eip-5133 (bomb delay) switch block (nil = no fork, 0 = already activated) 373 MergeNetsplitBlock *big.Int `json:"mergeNetsplitBlock,omitempty"` // Virtual fork after The Merge to use as a network splitter 374 CancunBlock *big.Int `json:"cancunBlock,omitempty"` // Cancun switch block (nil = no fork, 0 = already on cancun) 375 376 // Fork scheduling was switched from blocks to timestamps here 377 378 ShanghaiTime *big.Int `json:"shanghaiTime,omitempty"` // Shanghai switch time (nil = no fork, 0 = already on shanghai) 379 380 // TerminalTotalDifficulty is the amount of total difficulty reached by 381 // the network that triggers the consensus upgrade. 382 TerminalTotalDifficulty *big.Int `json:"terminalTotalDifficulty,omitempty"` 383 384 // TerminalTotalDifficultyPassed is a flag specifying that the network already 385 // passed the terminal total difficulty. Its purpose is to disable legacy sync 386 // even without having seen the TTD locally (safer long term). 387 TerminalTotalDifficultyPassed bool `json:"terminalTotalDifficultyPassed,omitempty"` 388 389 // Various consensus engines 390 Ethash *EthashConfig `json:"ethash,omitempty"` 391 Clique *CliqueConfig `json:"clique,omitempty"` 392 } 393 394 // EthashConfig is the consensus engine configs for proof-of-work based sealing. 395 type EthashConfig struct{} 396 397 // String implements the stringer interface, returning the consensus engine details. 398 func (c *EthashConfig) String() string { 399 return "ethash" 400 } 401 402 // CliqueConfig is the consensus engine configs for proof-of-authority based sealing. 403 type CliqueConfig struct { 404 Period uint64 `json:"period"` // Number of seconds between blocks to enforce 405 Epoch uint64 `json:"epoch"` // Epoch length to reset votes and checkpoint 406 } 407 408 // String implements the stringer interface, returning the consensus engine details. 409 func (c *CliqueConfig) String() string { 410 return "clique" 411 } 412 413 // Description returns a human-readable description of ChainConfig. 414 func (c *ChainConfig) Description() string { 415 var banner string 416 417 // Create some basinc network config output 418 network := NetworkNames[c.ChainID.String()] 419 if network == "" { 420 network = "unknown" 421 } 422 banner += fmt.Sprintf("Chain ID: %v (%s)\n", c.ChainID, network) 423 switch { 424 case c.Ethash != nil: 425 if c.TerminalTotalDifficulty == nil { 426 banner += "Consensus: Ethash (proof-of-work)\n" 427 } else if !c.TerminalTotalDifficultyPassed { 428 banner += "Consensus: Beacon (proof-of-stake), merging from Ethash (proof-of-work)\n" 429 } else { 430 banner += "Consensus: Beacon (proof-of-stake), merged from Ethash (proof-of-work)\n" 431 } 432 case c.Clique != nil: 433 if c.TerminalTotalDifficulty == nil { 434 banner += "Consensus: Clique (proof-of-authority)\n" 435 } else if !c.TerminalTotalDifficultyPassed { 436 banner += "Consensus: Beacon (proof-of-stake), merging from Clique (proof-of-authority)\n" 437 } else { 438 banner += "Consensus: Beacon (proof-of-stake), merged from Clique (proof-of-authority)\n" 439 } 440 default: 441 banner += "Consensus: unknown\n" 442 } 443 banner += "\n" 444 445 // Create a list of forks with a short description of them. Forks that only 446 // makes sense for mainnet should be optional at printing to avoid bloating 447 // the output for testnets and private networks. 448 banner += "Pre-Merge hard forks (block based):\n" 449 banner += fmt.Sprintf(" - Homestead: #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/homestead.md)\n", c.HomesteadBlock) 450 if c.DAOForkBlock != nil { 451 banner += fmt.Sprintf(" - DAO Fork: #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/dao-fork.md)\n", c.DAOForkBlock) 452 } 453 banner += fmt.Sprintf(" - Tangerine Whistle (EIP 150): #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/tangerine-whistle.md)\n", c.EIP150Block) 454 banner += fmt.Sprintf(" - Spurious Dragon/1 (EIP 155): #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/spurious-dragon.md)\n", c.EIP155Block) 455 banner += fmt.Sprintf(" - Spurious Dragon/2 (EIP 158): #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/spurious-dragon.md)\n", c.EIP155Block) 456 banner += fmt.Sprintf(" - Byzantium: #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/byzantium.md)\n", c.ByzantiumBlock) 457 banner += fmt.Sprintf(" - Constantinople: #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/constantinople.md)\n", c.ConstantinopleBlock) 458 banner += fmt.Sprintf(" - Petersburg: #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/petersburg.md)\n", c.PetersburgBlock) 459 banner += fmt.Sprintf(" - Istanbul: #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/istanbul.md)\n", c.IstanbulBlock) 460 if c.MuirGlacierBlock != nil { 461 banner += fmt.Sprintf(" - Muir Glacier: #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/muir-glacier.md)\n", c.MuirGlacierBlock) 462 } 463 banner += fmt.Sprintf(" - Berlin: #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/berlin.md)\n", c.BerlinBlock) 464 banner += fmt.Sprintf(" - London: #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/london.md)\n", c.LondonBlock) 465 if c.ArrowGlacierBlock != nil { 466 banner += fmt.Sprintf(" - Arrow Glacier: #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/arrow-glacier.md)\n", c.ArrowGlacierBlock) 467 } 468 if c.GrayGlacierBlock != nil { 469 banner += fmt.Sprintf(" - Gray Glacier: #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/gray-glacier.md)\n", c.GrayGlacierBlock) 470 } 471 banner += "\n" 472 473 // Add a special section for the merge as it's non-obvious 474 if c.TerminalTotalDifficulty == nil { 475 banner += "The Merge is not yet available for this network!\n" 476 banner += " - Hard-fork specification: https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/paris.md\n" 477 } else { 478 banner += "Merge configured:\n" 479 banner += " - Hard-fork specification: https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/paris.md\n" 480 banner += fmt.Sprintf(" - Network known to be merged: %v\n", c.TerminalTotalDifficultyPassed) 481 banner += fmt.Sprintf(" - Total terminal difficulty: %v\n", c.TerminalTotalDifficulty) 482 if c.MergeNetsplitBlock != nil { 483 banner += fmt.Sprintf(" - Merge netsplit block: #%-8v\n", c.MergeNetsplitBlock) 484 } 485 } 486 banner += "\n" 487 488 // Create a list of forks post-merge 489 banner += "Post-Merge hard forks (timestamp based):\n" 490 if c.ShanghaiTime != nil { 491 banner += fmt.Sprintf(" - Shanghai: @%-10v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/shanghai.md)\n", c.ShanghaiTime) 492 } 493 if c.CancunBlock != nil { 494 banner += fmt.Sprintf(" - Cancun: @%-10v\n", c.CancunBlock) 495 } 496 return banner 497 } 498 499 // IsHomestead returns whether num is either equal to the homestead block or greater. 500 func (c *ChainConfig) IsHomestead(num *big.Int) bool { 501 return isBlockForked(c.HomesteadBlock, num) 502 } 503 504 // IsDAOFork returns whether num is either equal to the DAO fork block or greater. 505 func (c *ChainConfig) IsDAOFork(num *big.Int) bool { 506 return isBlockForked(c.DAOForkBlock, num) 507 } 508 509 // IsEIP150 returns whether num is either equal to the EIP150 fork block or greater. 510 func (c *ChainConfig) IsEIP150(num *big.Int) bool { 511 return isBlockForked(c.EIP150Block, num) 512 } 513 514 // IsEIP155 returns whether num is either equal to the EIP155 fork block or greater. 515 func (c *ChainConfig) IsEIP155(num *big.Int) bool { 516 return isBlockForked(c.EIP155Block, num) 517 } 518 519 // IsEIP158 returns whether num is either equal to the EIP158 fork block or greater. 520 func (c *ChainConfig) IsEIP158(num *big.Int) bool { 521 return isBlockForked(c.EIP158Block, num) 522 } 523 524 // IsByzantium returns whether num is either equal to the Byzantium fork block or greater. 525 func (c *ChainConfig) IsByzantium(num *big.Int) bool { 526 return isBlockForked(c.ByzantiumBlock, num) 527 } 528 529 // IsConstantinople returns whether num is either equal to the Constantinople fork block or greater. 530 func (c *ChainConfig) IsConstantinople(num *big.Int) bool { 531 return isBlockForked(c.ConstantinopleBlock, num) 532 } 533 534 // IsMuirGlacier returns whether num is either equal to the Muir Glacier (EIP-2384) fork block or greater. 535 func (c *ChainConfig) IsMuirGlacier(num *big.Int) bool { 536 return isBlockForked(c.MuirGlacierBlock, num) 537 } 538 539 // IsPetersburg returns whether num is either 540 // - equal to or greater than the PetersburgBlock fork block, 541 // - OR is nil, and Constantinople is active 542 func (c *ChainConfig) IsPetersburg(num *big.Int) bool { 543 return isBlockForked(c.PetersburgBlock, num) || c.PetersburgBlock == nil && isBlockForked(c.ConstantinopleBlock, num) 544 } 545 546 // IsIstanbul returns whether num is either equal to the Istanbul fork block or greater. 547 func (c *ChainConfig) IsIstanbul(num *big.Int) bool { 548 return isBlockForked(c.IstanbulBlock, num) 549 } 550 551 // IsBerlin returns whether num is either equal to the Berlin fork block or greater. 552 func (c *ChainConfig) IsBerlin(num *big.Int) bool { 553 return isBlockForked(c.BerlinBlock, num) 554 } 555 556 // IsLondon returns whether num is either equal to the London fork block or greater. 557 func (c *ChainConfig) IsLondon(num *big.Int) bool { 558 return isBlockForked(c.LondonBlock, num) 559 } 560 561 // IsArrowGlacier returns whether num is either equal to the Arrow Glacier (EIP-4345) fork block or greater. 562 func (c *ChainConfig) IsArrowGlacier(num *big.Int) bool { 563 return isBlockForked(c.ArrowGlacierBlock, num) 564 } 565 566 // IsGrayGlacier returns whether num is either equal to the Gray Glacier (EIP-5133) fork block or greater. 567 func (c *ChainConfig) IsGrayGlacier(num *big.Int) bool { 568 return isBlockForked(c.GrayGlacierBlock, num) 569 } 570 571 // IsTerminalPoWBlock returns whether the given block is the last block of PoW stage. 572 func (c *ChainConfig) IsTerminalPoWBlock(parentTotalDiff *big.Int, totalDiff *big.Int) bool { 573 if c.TerminalTotalDifficulty == nil { 574 return false 575 } 576 return parentTotalDiff.Cmp(c.TerminalTotalDifficulty) < 0 && totalDiff.Cmp(c.TerminalTotalDifficulty) >= 0 577 } 578 579 // IsCancun returns whether num is either equal to the Cancun fork block or greater. 580 func (c *ChainConfig) IsCancun(num *big.Int) bool { 581 return isBlockForked(c.CancunBlock, num) 582 } 583 584 // IsShanghai returns whether time is either equal to the Shanghai fork time or greater. 585 func (c *ChainConfig) IsShanghai(time *big.Int) bool { 586 return isTimestampForked(c.ShanghaiTime, time) 587 } 588 589 // CheckCompatible checks whether scheduled fork transitions have been imported 590 // with a mismatching chain configuration. 591 func (c *ChainConfig) CheckCompatible(newcfg *ChainConfig, height uint64, time uint64) *ConfigCompatError { 592 var ( 593 bhead = new(big.Int).SetUint64(height) 594 btime = new(big.Int).SetUint64(time) 595 ) 596 // Iterate checkCompatible to find the lowest conflict. 597 var lasterr *ConfigCompatError 598 for { 599 err := c.checkCompatible(newcfg, bhead, btime) 600 if err == nil || (lasterr != nil && err.RewindToBlock == lasterr.RewindToBlock && err.RewindToTime == lasterr.RewindToTime) { 601 break 602 } 603 lasterr = err 604 605 if err.RewindToTime > 0 { 606 btime.SetUint64(err.RewindToTime) 607 } else { 608 bhead.SetUint64(err.RewindToBlock) 609 } 610 } 611 return lasterr 612 } 613 614 // CheckConfigForkOrder checks that we don't "skip" any forks, geth isn't pluggable enough 615 // to guarantee that forks can be implemented in a different order than on official networks 616 func (c *ChainConfig) CheckConfigForkOrder() error { 617 type fork struct { 618 name string 619 block *big.Int // forks up to - and including the merge - were defined with block numbers 620 timestamp *big.Int // forks after the merge are scheduled using timestamps 621 optional bool // if true, the fork may be nil and next fork is still allowed 622 } 623 var lastFork fork 624 for _, cur := range []fork{ 625 {name: "homesteadBlock", block: c.HomesteadBlock}, 626 {name: "daoForkBlock", block: c.DAOForkBlock, optional: true}, 627 {name: "eip150Block", block: c.EIP150Block}, 628 {name: "eip155Block", block: c.EIP155Block}, 629 {name: "eip158Block", block: c.EIP158Block}, 630 {name: "byzantiumBlock", block: c.ByzantiumBlock}, 631 {name: "constantinopleBlock", block: c.ConstantinopleBlock}, 632 {name: "petersburgBlock", block: c.PetersburgBlock}, 633 {name: "istanbulBlock", block: c.IstanbulBlock}, 634 {name: "muirGlacierBlock", block: c.MuirGlacierBlock, optional: true}, 635 {name: "berlinBlock", block: c.BerlinBlock}, 636 {name: "londonBlock", block: c.LondonBlock}, 637 {name: "arrowGlacierBlock", block: c.ArrowGlacierBlock, optional: true}, 638 {name: "grayGlacierBlock", block: c.GrayGlacierBlock, optional: true}, 639 {name: "mergeNetsplitBlock", block: c.MergeNetsplitBlock, optional: true}, 640 {name: "cancunBlock", block: c.CancunBlock, optional: true}, 641 {name: "shanghaiTime", timestamp: c.ShanghaiTime}, 642 } { 643 if lastFork.name != "" { 644 switch { 645 // Non-optional forks must all be present in the chain config up to the last defined fork 646 case lastFork.block == nil && lastFork.timestamp == nil && (cur.block != nil || cur.timestamp != nil): 647 if cur.block != nil { 648 return fmt.Errorf("unsupported fork ordering: %v not enabled, but %v enabled at block %v", 649 lastFork.name, cur.name, cur.block) 650 } else { 651 return fmt.Errorf("unsupported fork ordering: %v not enabled, but %v enabled at timestamp %v", 652 lastFork.name, cur.name, cur.timestamp) 653 } 654 655 // Fork (whether defined by block or timestamp) must follow the fork definition sequence 656 case (lastFork.block != nil && cur.block != nil) || (lastFork.timestamp != nil && cur.timestamp != nil): 657 if lastFork.block != nil && lastFork.block.Cmp(cur.block) > 0 { 658 return fmt.Errorf("unsupported fork ordering: %v enabled at block %v, but %v enabled at block %v", 659 lastFork.name, lastFork.block, cur.name, cur.block) 660 } else if lastFork.timestamp != nil && lastFork.timestamp.Cmp(cur.timestamp) > 0 { 661 return fmt.Errorf("unsupported fork ordering: %v enabled at timestamp %v, but %v enabled at timestamp %v", 662 lastFork.name, lastFork.timestamp, cur.name, cur.timestamp) 663 } 664 665 // Timestamp based forks can follow block based ones, but not the other way around 666 if lastFork.timestamp != nil && cur.block != nil { 667 return fmt.Errorf("unsupported fork ordering: %v used timestamp ordering, but %v reverted to block ordering", 668 lastFork.name, cur.name) 669 } 670 } 671 } 672 // If it was optional and not set, then ignore it 673 if !cur.optional || (cur.block != nil || cur.timestamp != nil) { 674 lastFork = cur 675 } 676 } 677 return nil 678 } 679 680 func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, headNumber *big.Int, headTimestamp *big.Int) *ConfigCompatError { 681 if isForkBlockIncompatible(c.HomesteadBlock, newcfg.HomesteadBlock, headNumber) { 682 return newBlockCompatError("Homestead fork block", c.HomesteadBlock, newcfg.HomesteadBlock) 683 } 684 if isForkBlockIncompatible(c.DAOForkBlock, newcfg.DAOForkBlock, headNumber) { 685 return newBlockCompatError("DAO fork block", c.DAOForkBlock, newcfg.DAOForkBlock) 686 } 687 if c.IsDAOFork(headNumber) && c.DAOForkSupport != newcfg.DAOForkSupport { 688 return newBlockCompatError("DAO fork support flag", c.DAOForkBlock, newcfg.DAOForkBlock) 689 } 690 if isForkBlockIncompatible(c.EIP150Block, newcfg.EIP150Block, headNumber) { 691 return newBlockCompatError("EIP150 fork block", c.EIP150Block, newcfg.EIP150Block) 692 } 693 if isForkBlockIncompatible(c.EIP155Block, newcfg.EIP155Block, headNumber) { 694 return newBlockCompatError("EIP155 fork block", c.EIP155Block, newcfg.EIP155Block) 695 } 696 if isForkBlockIncompatible(c.EIP158Block, newcfg.EIP158Block, headNumber) { 697 return newBlockCompatError("EIP158 fork block", c.EIP158Block, newcfg.EIP158Block) 698 } 699 if c.IsEIP158(headNumber) && !configBlockEqual(c.ChainID, newcfg.ChainID) { 700 return newBlockCompatError("EIP158 chain ID", c.EIP158Block, newcfg.EIP158Block) 701 } 702 if isForkBlockIncompatible(c.ByzantiumBlock, newcfg.ByzantiumBlock, headNumber) { 703 return newBlockCompatError("Byzantium fork block", c.ByzantiumBlock, newcfg.ByzantiumBlock) 704 } 705 if isForkBlockIncompatible(c.ConstantinopleBlock, newcfg.ConstantinopleBlock, headNumber) { 706 return newBlockCompatError("Constantinople fork block", c.ConstantinopleBlock, newcfg.ConstantinopleBlock) 707 } 708 if isForkBlockIncompatible(c.PetersburgBlock, newcfg.PetersburgBlock, headNumber) { 709 // the only case where we allow Petersburg to be set in the past is if it is equal to Constantinople 710 // mainly to satisfy fork ordering requirements which state that Petersburg fork be set if Constantinople fork is set 711 if isForkBlockIncompatible(c.ConstantinopleBlock, newcfg.PetersburgBlock, headNumber) { 712 return newBlockCompatError("Petersburg fork block", c.PetersburgBlock, newcfg.PetersburgBlock) 713 } 714 } 715 if isForkBlockIncompatible(c.IstanbulBlock, newcfg.IstanbulBlock, headNumber) { 716 return newBlockCompatError("Istanbul fork block", c.IstanbulBlock, newcfg.IstanbulBlock) 717 } 718 if isForkBlockIncompatible(c.MuirGlacierBlock, newcfg.MuirGlacierBlock, headNumber) { 719 return newBlockCompatError("Muir Glacier fork block", c.MuirGlacierBlock, newcfg.MuirGlacierBlock) 720 } 721 if isForkBlockIncompatible(c.BerlinBlock, newcfg.BerlinBlock, headNumber) { 722 return newBlockCompatError("Berlin fork block", c.BerlinBlock, newcfg.BerlinBlock) 723 } 724 if isForkBlockIncompatible(c.LondonBlock, newcfg.LondonBlock, headNumber) { 725 return newBlockCompatError("London fork block", c.LondonBlock, newcfg.LondonBlock) 726 } 727 if isForkBlockIncompatible(c.ArrowGlacierBlock, newcfg.ArrowGlacierBlock, headNumber) { 728 return newBlockCompatError("Arrow Glacier fork block", c.ArrowGlacierBlock, newcfg.ArrowGlacierBlock) 729 } 730 if isForkBlockIncompatible(c.GrayGlacierBlock, newcfg.GrayGlacierBlock, headNumber) { 731 return newBlockCompatError("Gray Glacier fork block", c.GrayGlacierBlock, newcfg.GrayGlacierBlock) 732 } 733 if isForkBlockIncompatible(c.MergeNetsplitBlock, newcfg.MergeNetsplitBlock, headNumber) { 734 return newBlockCompatError("Merge netsplit fork block", c.MergeNetsplitBlock, newcfg.MergeNetsplitBlock) 735 } 736 if isForkBlockIncompatible(c.CancunBlock, newcfg.CancunBlock, headNumber) { 737 return newBlockCompatError("Cancun fork block", c.CancunBlock, newcfg.CancunBlock) 738 } 739 if isForkTimestampIncompatible(c.ShanghaiTime, newcfg.ShanghaiTime, headTimestamp) { 740 return newTimestampCompatError("Shanghai fork timestamp", c.ShanghaiTime, newcfg.ShanghaiTime) 741 } 742 return nil 743 } 744 745 // BaseFeeChangeDenominator bounds the amount the base fee can change between blocks. 746 func (c *ChainConfig) BaseFeeChangeDenominator() uint64 { 747 return DefaultBaseFeeChangeDenominator 748 } 749 750 // ElasticityMultiplier bounds the maximum gas limit an EIP-1559 block may have. 751 func (c *ChainConfig) ElasticityMultiplier() uint64 { 752 return DefaultElasticityMultiplier 753 } 754 755 // isForkBlockIncompatible returns true if a fork scheduled at block s1 cannot be 756 // rescheduled to block s2 because head is already past the fork. 757 func isForkBlockIncompatible(s1, s2, head *big.Int) bool { 758 return (isBlockForked(s1, head) || isBlockForked(s2, head)) && !configBlockEqual(s1, s2) 759 } 760 761 // isBlockForked returns whether a fork scheduled at block s is active at the 762 // given head block. Whilst this method is the same as isTimestampForked, they 763 // are explicitly separate for clearer reading. 764 func isBlockForked(s, head *big.Int) bool { 765 if s == nil || head == nil { 766 return false 767 } 768 return s.Cmp(head) <= 0 769 } 770 771 func configBlockEqual(x, y *big.Int) bool { 772 if x == nil { 773 return y == nil 774 } 775 if y == nil { 776 return x == nil 777 } 778 return x.Cmp(y) == 0 779 } 780 781 // isForkTimestampIncompatible returns true if a fork scheduled at timestamp s1 782 // cannot be rescheduled to timestamp s2 because head is already past the fork. 783 func isForkTimestampIncompatible(s1, s2, head *big.Int) bool { 784 return (isTimestampForked(s1, head) || isTimestampForked(s2, head)) && !configTimestampEqual(s1, s2) 785 } 786 787 // isTimestampForked returns whether a fork scheduled at timestamp s is active 788 // at the given head timestamp. Whilst this method is the same as isBlockForked, 789 // they are explicitly separate for clearer reading. 790 func isTimestampForked(s, head *big.Int) bool { 791 if s == nil || head == nil { 792 return false 793 } 794 return s.Cmp(head) <= 0 795 } 796 797 func configTimestampEqual(x, y *big.Int) bool { 798 if x == nil { 799 return y == nil 800 } 801 if y == nil { 802 return x == nil 803 } 804 return x.Cmp(y) == 0 805 } 806 807 // ConfigCompatError is raised if the locally-stored blockchain is initialised with a 808 // ChainConfig that would alter the past. 809 type ConfigCompatError struct { 810 What string 811 812 // block numbers of the stored and new configurations if block based forking 813 StoredBlock, NewBlock *big.Int 814 815 // timestamps of the stored and new configurations if time based forking 816 StoredTime, NewTime *big.Int 817 818 // the block number to which the local chain must be rewound to correct the error 819 RewindToBlock uint64 820 821 // the timestamp to which the local chain must be rewound to correct the error 822 RewindToTime uint64 823 } 824 825 func newBlockCompatError(what string, storedblock, newblock *big.Int) *ConfigCompatError { 826 var rew *big.Int 827 switch { 828 case storedblock == nil: 829 rew = newblock 830 case newblock == nil || storedblock.Cmp(newblock) < 0: 831 rew = storedblock 832 default: 833 rew = newblock 834 } 835 err := &ConfigCompatError{ 836 What: what, 837 StoredBlock: storedblock, 838 NewBlock: newblock, 839 RewindToBlock: 0, 840 } 841 if rew != nil && rew.Sign() > 0 { 842 err.RewindToBlock = rew.Uint64() - 1 843 } 844 return err 845 } 846 847 func newTimestampCompatError(what string, storedtime, newtime *big.Int) *ConfigCompatError { 848 var rew *big.Int 849 switch { 850 case storedtime == nil: 851 rew = newtime 852 case newtime == nil || storedtime.Cmp(newtime) < 0: 853 rew = storedtime 854 default: 855 rew = newtime 856 } 857 err := &ConfigCompatError{ 858 What: what, 859 StoredTime: storedtime, 860 NewTime: newtime, 861 RewindToTime: 0, 862 } 863 if rew != nil && rew.Sign() > 0 { 864 err.RewindToTime = rew.Uint64() - 1 865 } 866 return err 867 } 868 869 func (err *ConfigCompatError) Error() string { 870 if err.StoredBlock != nil { 871 return fmt.Sprintf("mismatching %s in database (have block %d, want block %d, rewindto block %d)", err.What, err.StoredBlock, err.NewBlock, err.RewindToBlock) 872 } 873 return fmt.Sprintf("mismatching %s in database (have timestamp %d, want timestamp %d, rewindto timestamp %d)", err.What, err.StoredTime, err.NewTime, err.RewindToTime) 874 } 875 876 // Rules wraps ChainConfig and is merely syntactic sugar or can be used for functions 877 // that do not have or require information about the block. 878 // 879 // Rules is a one time interface meaning that it shouldn't be used in between transition 880 // phases. 881 type Rules struct { 882 ChainID *big.Int 883 IsHomestead, IsEIP150, IsEIP155, IsEIP158 bool 884 IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool 885 IsBerlin, IsLondon bool 886 IsMerge, IsShanghai, isCancun bool 887 } 888 889 // Rules ensures c's ChainID is not nil. 890 func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp *big.Int) Rules { 891 chainID := c.ChainID 892 if chainID == nil { 893 chainID = new(big.Int) 894 } 895 return Rules{ 896 ChainID: new(big.Int).Set(chainID), 897 IsHomestead: c.IsHomestead(num), 898 IsEIP150: c.IsEIP150(num), 899 IsEIP155: c.IsEIP155(num), 900 IsEIP158: c.IsEIP158(num), 901 IsByzantium: c.IsByzantium(num), 902 IsConstantinople: c.IsConstantinople(num), 903 IsPetersburg: c.IsPetersburg(num), 904 IsIstanbul: c.IsIstanbul(num), 905 IsBerlin: c.IsBerlin(num), 906 IsLondon: c.IsLondon(num), 907 IsMerge: isMerge, 908 IsShanghai: c.IsShanghai(timestamp), 909 isCancun: c.IsCancun(num), 910 } 911 }