github.com/nnlgsakib/mind-dpos@v0.0.0-20230606105614-f3c8ca06f808/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 "fmt" 21 "github.com/TTCECO/gttc/common" 22 "github.com/TTCECO/gttc/rpc" 23 "math/big" 24 ) 25 26 var ( 27 MainnetGenesisHash = common.HexToHash("t0c6f20167950874a396ca06b717df8cd96597bc849b4935003cda98598c5e98be") // Mainnet genesis hash to enforce below configs on 28 TestnetGenesisHash = common.HexToHash("t01fa3701d9164c47b587e335e9d4c2a34360dd77c84859c818ba7ea684bdf6ee1") // Testnet genesis hash to enforce below configs on 29 ) 30 31 var ( 32 // MainnetChainConfig is the chain parameters to run a node on the main network. 33 MainnetChainConfig = &ChainConfig{ 34 ChainId: big.NewInt(8848), 35 HomesteadBlock: big.NewInt(1), 36 EIP150Block: big.NewInt(2), 37 EIP150Hash: common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"), 38 EIP155Block: big.NewInt(3), 39 EIP158Block: big.NewInt(3), 40 ByzantiumBlock: big.NewInt(4), 41 ConstantinopleBlock: nil, 42 Alien: &AlienConfig{ 43 Period: 3, 44 Epoch: 201600, 45 MaxSignerCount: 21, 46 TrantorBlock: new(big.Int).SetUint64(2968888), 47 MinVoterBalance: new(big.Int).Mul(big.NewInt(100), big.NewInt(1e+18)), 48 GenesisTimestamp: 1554004800, 49 SelfVoteSigners: []common.UnprefixedAddress{ 50 common.UnprefixedAddress(common.HexToAddress("t06e83430ca56ee33a26e5ce87239cb251981ccc2b")), 51 common.UnprefixedAddress(common.HexToAddress("t01807efcb4dc252ff6958eaab770c8b3936a5378f")), 52 common.UnprefixedAddress(common.HexToAddress("t0350fccf36124cecd26318e9931414ce872bdb68c")), 53 common.UnprefixedAddress(common.HexToAddress("t009cbad80e089754f610cb8771d9eca05e4e22bdb")), 54 common.UnprefixedAddress(common.HexToAddress("t09d507c10960531c9adc0ffdc9d9c735167275caf")), 55 common.UnprefixedAddress(common.HexToAddress("t0c252c0f4d460554c679532072c8dbecd8d9ee89b")), 56 common.UnprefixedAddress(common.HexToAddress("t0d8f68e2af8a061f0ea5e57ab7aca1b7fa96dab8a")), 57 common.UnprefixedAddress(common.HexToAddress("t00c58019b9c8e293e3be8d3fd50f77af5f2e84bb7")), 58 common.UnprefixedAddress(common.HexToAddress("t065dd958f7433cbe8353401d131c925e0424330b6")), 59 common.UnprefixedAddress(common.HexToAddress("t0076c15f06f36b15544f1e97b4aacbd358d60cdf0")), 60 common.UnprefixedAddress(common.HexToAddress("t0ecfd032885b4b9e69ab732e800c72296733165d7")), 61 common.UnprefixedAddress(common.HexToAddress("t01a7910fe43b49b8bc33c04cb138cb2a8e1842f32")), 62 common.UnprefixedAddress(common.HexToAddress("t0f52fe2e8decbbb3b00ebec7a1a50a41055d784ea")), 63 common.UnprefixedAddress(common.HexToAddress("t035ef874a0f12581fd01fd2b178da7472475e253c")), 64 common.UnprefixedAddress(common.HexToAddress("t090d4a9e77bf64b58f7c07d3bc19f8bb5e9d49031")), 65 common.UnprefixedAddress(common.HexToAddress("t07bd38c427c685fbecbbe0daf49cda466b6475cc6")), 66 common.UnprefixedAddress(common.HexToAddress("t0db1f586092917033e15298663594abb01eb98e39")), 67 common.UnprefixedAddress(common.HexToAddress("t049574ad7832ff9a9214eb462cce2accf35f9118c")), 68 common.UnprefixedAddress(common.HexToAddress("t0c8a7ca612be71d84c82c2c1fefbd035517df6745")), 69 common.UnprefixedAddress(common.HexToAddress("t07e13706bab4bfae1f856d75e96676ab27eeea083")), 70 common.UnprefixedAddress(common.HexToAddress("t0c5981e7fb6726be96345a732de6206bb1d66b963")), 71 common.UnprefixedAddress(common.HexToAddress("t0ba99e0bb3fb9537db76a8ac1e76ebca5177954c9")), 72 common.UnprefixedAddress(common.HexToAddress("t0d039d1feb6b13c3abe5089da9157fd41104c1aee")), 73 common.UnprefixedAddress(common.HexToAddress("t0532c8772925e4b55a6bc99e954aa4cacc7d152b3")), 74 common.UnprefixedAddress(common.HexToAddress("t0b464963fcb52b4666577987538a45e68876dc4e7")), 75 common.UnprefixedAddress(common.HexToAddress("t08967f6d04ce36683ebe08c55caa15a177447f983")), 76 common.UnprefixedAddress(common.HexToAddress("t005f39bfe9588f9297b8f3b019a3ee336efe47c47")), 77 common.UnprefixedAddress(common.HexToAddress("t00c59dd1a15c3d5db4b4297cd79bfe72b60affc3e")), 78 common.UnprefixedAddress(common.HexToAddress("t08f05387c4d637288dd197e26d5bdd3cb7087793c")), 79 common.UnprefixedAddress(common.HexToAddress("t002289f35b60c97e27141c6aeb2691d25b531c755")), 80 common.UnprefixedAddress(common.HexToAddress("t039e18521278e5121fdb0b691e84869bd4c645241")), 81 common.UnprefixedAddress(common.HexToAddress("t04b4a0c8cb17b50d8d22610b307c349b63560ca4b")), 82 common.UnprefixedAddress(common.HexToAddress("t09b25f97fa4e3892d9a86ac035a338b36dace5c4b")), 83 common.UnprefixedAddress(common.HexToAddress("t0c520c15d943603dc333ebf6b5e39eb4d509fc1f8")), 84 common.UnprefixedAddress(common.HexToAddress("t0da863ba260a36a11e3ea953b61de4a0eeffaa6f5")), 85 common.UnprefixedAddress(common.HexToAddress("t03692048ef49479294bcfe9ee7e97508633756f3f")), 86 common.UnprefixedAddress(common.HexToAddress("t027f7fcf7938618dfb0fc3668cd6fe7c1f7315870")), 87 common.UnprefixedAddress(common.HexToAddress("t0f34961e5654a76335e0480bd7c7d370ad41ac74f")), 88 common.UnprefixedAddress(common.HexToAddress("t092918ee96f529fdabab1a1ffda627c3d6b442ad9")), 89 common.UnprefixedAddress(common.HexToAddress("t02024cc8d89f7cbd09a4085fbc729e3b9ee92c1be")), 90 common.UnprefixedAddress(common.HexToAddress("t01b5887157beff2e2eff9ea9b8409f3ca1b6a052f")), 91 common.UnprefixedAddress(common.HexToAddress("t0ad11612be2d9811ffe80f9e9ec1bbdc0ff34067c")), 92 common.UnprefixedAddress(common.HexToAddress("t04e3011ab5b261cff133f4e8fb597dd0980814a94")), 93 common.UnprefixedAddress(common.HexToAddress("t02834dc6b4b054fcf9cb206df4cce17fa0044826b")), 94 common.UnprefixedAddress(common.HexToAddress("t07a2da45fd12d9bd44227ec58a5f0c3085ef18bf1")), 95 common.UnprefixedAddress(common.HexToAddress("t0e8ae4d470fb87381f34a77c992a1de53fc2d2a3c")), 96 common.UnprefixedAddress(common.HexToAddress("t0777689118d95751e1d709d7134adddd387226ac3")), 97 common.UnprefixedAddress(common.HexToAddress("t00d6556b96b2b7cd095bf42aa2c287df99f22fc87")), 98 common.UnprefixedAddress(common.HexToAddress("t0b97b279af3aa97655e6592b320e94505b41631ec")), 99 common.UnprefixedAddress(common.HexToAddress("t0bce13d77339971d1f5f00c38f523ba7ee44c95ed")), 100 }, 101 }, 102 } 103 104 // TestnetChainConfig contains the chain parameters to run a node on the Ropsten test network. 105 TestnetChainConfig = &ChainConfig{ 106 ChainId: big.NewInt(8341), 107 HomesteadBlock: big.NewInt(1), 108 EIP150Block: big.NewInt(2), 109 EIP150Hash: common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"), 110 EIP155Block: big.NewInt(3), 111 EIP158Block: big.NewInt(3), 112 ByzantiumBlock: big.NewInt(4), 113 ConstantinopleBlock: nil, 114 Alien: &AlienConfig{ 115 Period: 3, 116 Epoch: 201600, 117 MaxSignerCount: 21, 118 MinVoterBalance: new(big.Int).Mul(big.NewInt(100), big.NewInt(1e+18)), 119 TrantorBlock: big.NewInt(695000), 120 GenesisTimestamp: 1554004800, 121 SelfVoteSigners: []common.UnprefixedAddress{ 122 common.UnprefixedAddress(common.HexToAddress("t0be6865ffcbbe5f9746bef5c84b912f2ad9e52075")), 123 common.UnprefixedAddress(common.HexToAddress("t04909b4e54395de9e313ad8a2254fe2dcda99e91c")), 124 common.UnprefixedAddress(common.HexToAddress("t0a034350c8e80eb4d15ac62310657b29c711bb3d5")), 125 }, 126 }, 127 } 128 129 // SideChainConfig contains the chain parameters to run a node on the Ropsten test network. 130 SideChainConfig = &ChainConfig{ 131 ChainId: big.NewInt(8123), 132 HomesteadBlock: big.NewInt(1), 133 EIP150Block: big.NewInt(2), 134 EIP150Hash: common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"), 135 EIP155Block: big.NewInt(3), 136 EIP158Block: big.NewInt(3), 137 ByzantiumBlock: big.NewInt(4), 138 ConstantinopleBlock: nil, 139 Alien: &AlienConfig{ 140 Period: 1, 141 Epoch: 201600, 142 MaxSignerCount: 21, 143 TrantorBlock: big.NewInt(5), 144 MinVoterBalance: new(big.Int).Mul(big.NewInt(100), big.NewInt(1e+18)), 145 GenesisTimestamp: 1554004800, 146 SelfVoteSigners: []common.UnprefixedAddress{}, 147 }, 148 } 149 150 // RinkebyChainConfig contains the chain parameters to run a node on the Rinkeby test network. 151 RinkebyChainConfig = &ChainConfig{ 152 ChainId: big.NewInt(4), 153 HomesteadBlock: big.NewInt(1), 154 EIP150Block: big.NewInt(2), 155 EIP150Hash: common.HexToHash("0x9b095b36c15eaf13044373aef8ee0bd3a382a5abb92e402afa44b8249c3a90e9"), 156 EIP155Block: big.NewInt(3), 157 EIP158Block: big.NewInt(3), 158 ByzantiumBlock: big.NewInt(1035301), 159 ConstantinopleBlock: nil, 160 Clique: &CliqueConfig{ 161 Period: 15, 162 Epoch: 30000, 163 }, 164 } 165 166 // AllEthashProtocolChanges contains every protocol change (EIPs) introduced 167 // and accepted by the Ethereum core developers into the Ethash consensus. 168 // 169 // This configuration is intentionally not using keyed fields to force anyone 170 // adding flags to the config to also have to set these fields. 171 AllEthashProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, new(EthashConfig), nil, nil} 172 173 // AllCliqueProtocolChanges contains every protocol change (EIPs) introduced 174 // and accepted by the Ethereum core developers into the Clique consensus. 175 // 176 // This configuration is intentionally not using keyed fields to force anyone 177 // adding flags to the config to also have to set these fields. 178 AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}, nil} 179 180 // AllAlienProtocolChanges contains every protocol change (EIPs) introduced 181 // and accepted by the Ethereum core developers into the Alien consensus. 182 // 183 // This configuration is intentionally not using keyed fields to force anyone 184 // adding flags to the config to also have to set these fields. 185 AllAlienProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, &AlienConfig{Period: 3, Epoch: 30000, MaxSignerCount: 21, MinVoterBalance: new(big.Int).Mul(big.NewInt(10000), big.NewInt(1000000000000000000)), GenesisTimestamp: 0, SelfVoteSigners: []common.UnprefixedAddress{}}} 186 187 TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, new(EthashConfig), nil, nil} 188 TestRules = TestChainConfig.Rules(new(big.Int)) 189 ) 190 191 // ChainConfig is the core config which determines the blockchain settings. 192 // 193 // ChainConfig is stored in the database on a per block basis. This means 194 // that any network, identified by its genesis block, can have its own 195 // set of configuration options. 196 type ChainConfig struct { 197 ChainId *big.Int `json:"chainId"` // Chain id identifies the current chain and is used for replay protection 198 199 HomesteadBlock *big.Int `json:"homesteadBlock,omitempty"` // Homestead switch block (nil = no fork, 0 = already homestead) 200 201 // EIP150 implements the Gas price changes (https://github.com/ethereum/EIPs/issues/150) 202 EIP150Block *big.Int `json:"eip150Block,omitempty"` // EIP150 HF block (nil = no fork) 203 EIP150Hash common.Hash `json:"eip150Hash,omitempty"` // EIP150 HF hash (needed for header only clients as only gas pricing changed) 204 205 EIP155Block *big.Int `json:"eip155Block,omitempty"` // EIP155 HF block 206 EIP158Block *big.Int `json:"eip158Block,omitempty"` // EIP158 HF block 207 208 ByzantiumBlock *big.Int `json:"byzantiumBlock,omitempty"` // Byzantium switch block (nil = no fork, 0 = already on byzantium) 209 ConstantinopleBlock *big.Int `json:"constantinopleBlock,omitempty"` // Constantinople switch block (nil = no fork, 0 = already activated) 210 211 // Various consensus engines 212 Ethash *EthashConfig `json:"ethash,omitempty"` 213 Clique *CliqueConfig `json:"clique,omitempty"` 214 Alien *AlienConfig `json:"alien,omitempty"` 215 } 216 217 // EthashConfig is the consensus engine configs for proof-of-work based sealing. 218 type EthashConfig struct{} 219 220 // String implements the stringer interface, returning the consensus engine details. 221 func (c *EthashConfig) String() string { 222 return "ethash" 223 } 224 225 // CliqueConfig is the consensus engine configs for proof-of-authority based sealing. 226 type CliqueConfig struct { 227 Period uint64 `json:"period"` // Number of seconds between blocks to enforce 228 Epoch uint64 `json:"epoch"` // Epoch length to reset votes and checkpoint 229 } 230 231 // String implements the stringer interface, returning the consensus engine details. 232 func (c *CliqueConfig) String() string { 233 return "clique" 234 } 235 236 type GenesisAccount struct { 237 Balance string `json:"balance"` 238 } 239 240 // AlienLightConfig is the config for light node of alien 241 type AlienLightConfig struct { 242 Alloc map[common.UnprefixedAddress]GenesisAccount `json:"alloc"` 243 } 244 245 // AlienConfig is the consensus engine configs for delegated-proof-of-stake based sealing. 246 type AlienConfig struct { 247 Period uint64 `json:"period"` // Number of seconds between blocks to enforce 248 Epoch uint64 `json:"epoch"` // Epoch length to reset votes and checkpoint 249 MaxSignerCount uint64 `json:"maxSignersCount"` // Max count of signers 250 MinVoterBalance *big.Int `json:"minVoterBalance"` // Min voter balance to valid this vote 251 GenesisTimestamp uint64 `json:"genesisTimestamp"` // The LoopStartTime of first Block 252 SelfVoteSigners []common.UnprefixedAddress `json:"signers"` // Signers vote by themselves to seal the block, make sure the signer accounts are pre-funded 253 SideChain bool `json:"sideChain"` // If side chain or not 254 MCRPCClient *rpc.Client // Main chain rpc client for side chain 255 PBFTEnable bool `json:"pbft"` // 256 257 TrantorBlock *big.Int `json:"trantorBlock,omitempty"` // Trantor switch block (nil = no fork) 258 TerminusBlock *big.Int `json:"terminusBlock,omitempty"` // Terminus switch block (nil = no fork) 259 LightConfig *AlienLightConfig `json:"lightConfig,omitempty"` 260 } 261 262 // String implements the stringer interface, returning the consensus engine details. 263 func (a *AlienConfig) String() string { 264 return "alien" 265 } 266 267 // IsTrantor returns whether num is either equal to the Trantor block or greater. 268 func (a *AlienConfig) IsTrantor(num *big.Int) bool { 269 return isForked(a.TrantorBlock, num) 270 } 271 272 // IsTerminus returns whether num is either equal to the Terminus block or greater. 273 func (a *AlienConfig) IsTerminus(num *big.Int) bool { 274 return isForked(a.TerminusBlock, num) 275 } 276 277 // String implements the fmt.Stringer interface. 278 func (c *ChainConfig) String() string { 279 var engine interface{} 280 switch { 281 case c.Ethash != nil: 282 engine = c.Ethash 283 case c.Clique != nil: 284 engine = c.Clique 285 case c.Alien != nil: 286 engine = c.Alien 287 default: 288 engine = "unknown" 289 } 290 return fmt.Sprintf("{ChainID: %v Homestead: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Engine: %v}", 291 c.ChainId, 292 c.HomesteadBlock, 293 c.EIP150Block, 294 c.EIP155Block, 295 c.EIP158Block, 296 c.ByzantiumBlock, 297 c.ConstantinopleBlock, 298 engine, 299 ) 300 } 301 302 // IsHomestead returns whether num is either equal to the homestead block or greater. 303 func (c *ChainConfig) IsHomestead(num *big.Int) bool { 304 return isForked(c.HomesteadBlock, num) 305 } 306 307 func (c *ChainConfig) IsEIP150(num *big.Int) bool { 308 return isForked(c.EIP150Block, num) 309 } 310 311 func (c *ChainConfig) IsEIP155(num *big.Int) bool { 312 return isForked(c.EIP155Block, num) 313 } 314 315 func (c *ChainConfig) IsEIP158(num *big.Int) bool { 316 return isForked(c.EIP158Block, num) 317 } 318 319 func (c *ChainConfig) IsByzantium(num *big.Int) bool { 320 return isForked(c.ByzantiumBlock, num) 321 } 322 323 func (c *ChainConfig) IsConstantinople(num *big.Int) bool { 324 return isForked(c.ConstantinopleBlock, num) 325 } 326 327 // GasTable returns the gas table corresponding to the current phase (homestead or homestead reprice). 328 // 329 // The returned GasTable's fields shouldn't, under any circumstances, be changed. 330 func (c *ChainConfig) GasTable(num *big.Int) GasTable { 331 if num == nil { 332 return GasTableHomestead 333 } 334 switch { 335 case c.IsEIP158(num): 336 return GasTableEIP158 337 case c.IsEIP150(num): 338 return GasTableEIP150 339 default: 340 return GasTableHomestead 341 } 342 } 343 344 // CheckCompatible checks whether scheduled fork transitions have been imported 345 // with a mismatching chain configuration. 346 func (c *ChainConfig) CheckCompatible(newcfg *ChainConfig, height uint64) *ConfigCompatError { 347 bhead := new(big.Int).SetUint64(height) 348 349 // Iterate checkCompatible to find the lowest conflict. 350 var lasterr *ConfigCompatError 351 for { 352 err := c.checkCompatible(newcfg, bhead) 353 if err == nil || (lasterr != nil && err.RewindTo == lasterr.RewindTo) { 354 break 355 } 356 lasterr = err 357 bhead.SetUint64(err.RewindTo) 358 } 359 return lasterr 360 } 361 362 func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, head *big.Int) *ConfigCompatError { 363 if isForkIncompatible(c.HomesteadBlock, newcfg.HomesteadBlock, head) { 364 return newCompatError("Homestead fork block", c.HomesteadBlock, newcfg.HomesteadBlock) 365 } 366 if isForkIncompatible(c.EIP150Block, newcfg.EIP150Block, head) { 367 return newCompatError("EIP150 fork block", c.EIP150Block, newcfg.EIP150Block) 368 } 369 if isForkIncompatible(c.EIP155Block, newcfg.EIP155Block, head) { 370 return newCompatError("EIP155 fork block", c.EIP155Block, newcfg.EIP155Block) 371 } 372 if isForkIncompatible(c.EIP158Block, newcfg.EIP158Block, head) { 373 return newCompatError("EIP158 fork block", c.EIP158Block, newcfg.EIP158Block) 374 } 375 if c.IsEIP158(head) && !configNumEqual(c.ChainId, newcfg.ChainId) { 376 return newCompatError("EIP158 chain ID", c.EIP158Block, newcfg.EIP158Block) 377 } 378 if isForkIncompatible(c.ByzantiumBlock, newcfg.ByzantiumBlock, head) { 379 return newCompatError("Byzantium fork block", c.ByzantiumBlock, newcfg.ByzantiumBlock) 380 } 381 if isForkIncompatible(c.ConstantinopleBlock, newcfg.ConstantinopleBlock, head) { 382 return newCompatError("Constantinople fork block", c.ConstantinopleBlock, newcfg.ConstantinopleBlock) 383 } 384 return nil 385 } 386 387 // isForkIncompatible returns true if a fork scheduled at s1 cannot be rescheduled to 388 // block s2 because head is already past the fork. 389 func isForkIncompatible(s1, s2, head *big.Int) bool { 390 return (isForked(s1, head) || isForked(s2, head)) && !configNumEqual(s1, s2) 391 } 392 393 // isForked returns whether a fork scheduled at block s is active at the given head block. 394 func isForked(s, head *big.Int) bool { 395 if s == nil || head == nil { 396 return false 397 } 398 return s.Cmp(head) <= 0 399 } 400 401 func configNumEqual(x, y *big.Int) bool { 402 if x == nil { 403 return y == nil 404 } 405 if y == nil { 406 return x == nil 407 } 408 return x.Cmp(y) == 0 409 } 410 411 // ConfigCompatError is raised if the locally-stored blockchain is initialised with a 412 // ChainConfig that would alter the past. 413 type ConfigCompatError struct { 414 What string 415 // block numbers of the stored and new configurations 416 StoredConfig, NewConfig *big.Int 417 // the block number to which the local chain must be rewound to correct the error 418 RewindTo uint64 419 } 420 421 func newCompatError(what string, storedblock, newblock *big.Int) *ConfigCompatError { 422 var rew *big.Int 423 switch { 424 case storedblock == nil: 425 rew = newblock 426 case newblock == nil || storedblock.Cmp(newblock) < 0: 427 rew = storedblock 428 default: 429 rew = newblock 430 } 431 err := &ConfigCompatError{what, storedblock, newblock, 0} 432 if rew != nil && rew.Sign() > 0 { 433 err.RewindTo = rew.Uint64() - 1 434 } 435 return err 436 } 437 438 func (err *ConfigCompatError) Error() string { 439 return fmt.Sprintf("mismatching %s in database (have %d, want %d, rewindto %d)", err.What, err.StoredConfig, err.NewConfig, err.RewindTo) 440 } 441 442 // Rules wraps ChainConfig and is merely syntatic sugar or can be used for functions 443 // that do not have or require information about the block. 444 // 445 // Rules is a one time interface meaning that it shouldn't be used in between transition 446 // phases. 447 type Rules struct { 448 ChainId *big.Int 449 IsHomestead, IsEIP150, IsEIP155, IsEIP158 bool 450 IsByzantium bool 451 } 452 453 func (c *ChainConfig) Rules(num *big.Int) Rules { 454 chainId := c.ChainId 455 if chainId == nil { 456 chainId = new(big.Int) 457 } 458 return Rules{ChainId: new(big.Int).Set(chainId), IsHomestead: c.IsHomestead(num), IsEIP150: c.IsEIP150(num), IsEIP155: c.IsEIP155(num), IsEIP158: c.IsEIP158(num), IsByzantium: c.IsByzantium(num)} 459 }