github.com/Blockdaemon/celo-blockchain@v0.0.0-20200129231733-e667f6b08419/cmd/puppeth/genesis.go (about) 1 // Copyright 2017 The go-ethereum Authors 2 // This file is part of go-ethereum. 3 // 4 // go-ethereum is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU 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 // go-ethereum 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 General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. 16 17 package main 18 19 import ( 20 "encoding/binary" 21 "errors" 22 "math" 23 "math/big" 24 "strings" 25 26 "github.com/ethereum/go-ethereum/common" 27 "github.com/ethereum/go-ethereum/common/hexutil" 28 math2 "github.com/ethereum/go-ethereum/common/math" 29 "github.com/ethereum/go-ethereum/consensus/ethash" 30 "github.com/ethereum/go-ethereum/core" 31 "github.com/ethereum/go-ethereum/params" 32 ) 33 34 // alethGenesisSpec represents the genesis specification format used by the 35 // C++ Ethereum implementation. 36 type alethGenesisSpec struct { 37 SealEngine string `json:"sealEngine"` 38 Params struct { 39 AccountStartNonce math2.HexOrDecimal64 `json:"accountStartNonce"` 40 MaximumExtraDataSize hexutil.Uint64 `json:"maximumExtraDataSize"` 41 HomesteadForkBlock hexutil.Uint64 `json:"homesteadForkBlock"` 42 DaoHardforkBlock math2.HexOrDecimal64 `json:"daoHardforkBlock"` 43 EIP150ForkBlock hexutil.Uint64 `json:"EIP150ForkBlock"` 44 EIP158ForkBlock hexutil.Uint64 `json:"EIP158ForkBlock"` 45 ByzantiumForkBlock hexutil.Uint64 `json:"byzantiumForkBlock"` 46 ConstantinopleForkBlock hexutil.Uint64 `json:"constantinopleForkBlock"` 47 MaxGasLimit hexutil.Uint64 `json:"maxGasLimit"` 48 TieBreakingGas bool `json:"tieBreakingGas"` 49 MinimumDifficulty *hexutil.Big `json:"minimumDifficulty"` 50 DifficultyBoundDivisor *math2.HexOrDecimal256 `json:"difficultyBoundDivisor"` 51 DurationLimit *math2.HexOrDecimal256 `json:"durationLimit"` 52 BlockReward *hexutil.Big `json:"blockReward"` 53 NetworkID hexutil.Uint64 `json:"networkID"` 54 ChainID hexutil.Uint64 `json:"chainID"` 55 AllowFutureBlocks bool `json:"allowFutureBlocks"` 56 } `json:"params"` 57 58 Genesis struct { 59 Nonce hexutil.Bytes `json:"nonce"` 60 Difficulty *hexutil.Big `json:"difficulty"` 61 MixHash common.Hash `json:"mixHash"` 62 Author common.Address `json:"author"` 63 Timestamp hexutil.Uint64 `json:"timestamp"` 64 ParentHash common.Hash `json:"parentHash"` 65 ExtraData hexutil.Bytes `json:"extraData"` 66 GasLimit hexutil.Uint64 `json:"gasLimit"` 67 } `json:"genesis"` 68 69 Accounts map[common.UnprefixedAddress]*alethGenesisSpecAccount `json:"accounts"` 70 } 71 72 // alethGenesisSpecAccount is the prefunded genesis account and/or precompiled 73 // contract definition. 74 type alethGenesisSpecAccount struct { 75 Balance *math2.HexOrDecimal256 `json:"balance"` 76 Nonce uint64 `json:"nonce,omitempty"` 77 Precompiled *alethGenesisSpecBuiltin `json:"precompiled,omitempty"` 78 } 79 80 // alethGenesisSpecBuiltin is the precompiled contract definition. 81 type alethGenesisSpecBuiltin struct { 82 Name string `json:"name,omitempty"` 83 StartingBlock hexutil.Uint64 `json:"startingBlock,omitempty"` 84 Linear *alethGenesisSpecLinearPricing `json:"linear,omitempty"` 85 } 86 87 type alethGenesisSpecLinearPricing struct { 88 Base uint64 `json:"base"` 89 Word uint64 `json:"word"` 90 } 91 92 // newAlethGenesisSpec converts a go-ethereum genesis block into a Aleth-specific 93 // chain specification format. 94 func newAlethGenesisSpec(network string, genesis *core.Genesis) (*alethGenesisSpec, error) { 95 // Only ethash is currently supported between go-ethereum and aleth 96 if genesis.Config.Ethash == nil { 97 return nil, errors.New("unsupported consensus engine") 98 } 99 // Reconstruct the chain spec in Aleth format 100 spec := &alethGenesisSpec{ 101 SealEngine: "Ethash", 102 } 103 // Some defaults 104 spec.Params.AccountStartNonce = 0 105 spec.Params.TieBreakingGas = false 106 spec.Params.AllowFutureBlocks = false 107 spec.Params.DaoHardforkBlock = 0 108 109 spec.Params.HomesteadForkBlock = (hexutil.Uint64)(genesis.Config.HomesteadBlock.Uint64()) 110 spec.Params.EIP150ForkBlock = (hexutil.Uint64)(genesis.Config.EIP150Block.Uint64()) 111 spec.Params.EIP158ForkBlock = (hexutil.Uint64)(genesis.Config.EIP158Block.Uint64()) 112 113 // Byzantium 114 if num := genesis.Config.ByzantiumBlock; num != nil { 115 spec.setByzantium(num) 116 } 117 // Constantinople 118 if num := genesis.Config.ConstantinopleBlock; num != nil { 119 spec.setConstantinople(num) 120 } 121 122 spec.Params.NetworkID = (hexutil.Uint64)(genesis.Config.ChainID.Uint64()) 123 spec.Params.ChainID = (hexutil.Uint64)(genesis.Config.ChainID.Uint64()) 124 spec.Params.MaximumExtraDataSize = (hexutil.Uint64)(params.MaximumExtraDataSize) 125 spec.Params.MaxGasLimit = (hexutil.Uint64)(math.MaxInt64) 126 spec.Params.MinimumDifficulty = (*hexutil.Big)(params.MinimumDifficulty) 127 spec.Params.DifficultyBoundDivisor = (*math2.HexOrDecimal256)(params.DifficultyBoundDivisor) 128 spec.Params.DurationLimit = (*math2.HexOrDecimal256)(params.DurationLimit) 129 spec.Params.BlockReward = (*hexutil.Big)(ethash.FrontierBlockReward) 130 131 spec.Genesis.Nonce = (hexutil.Bytes)(make([]byte, 8)) 132 binary.LittleEndian.PutUint64(spec.Genesis.Nonce[:], genesis.Nonce) 133 134 spec.Genesis.MixHash = genesis.Mixhash 135 spec.Genesis.Difficulty = (*hexutil.Big)(genesis.Difficulty) 136 spec.Genesis.Author = genesis.Coinbase 137 spec.Genesis.Timestamp = (hexutil.Uint64)(genesis.Timestamp) 138 spec.Genesis.ParentHash = genesis.ParentHash 139 spec.Genesis.ExtraData = (hexutil.Bytes)(genesis.ExtraData) 140 spec.Genesis.GasLimit = (hexutil.Uint64)(genesis.GasLimit) 141 142 for address, account := range genesis.Alloc { 143 spec.setAccount(address, account) 144 } 145 146 spec.setPrecompile(1, &alethGenesisSpecBuiltin{Name: "ecrecover", 147 Linear: &alethGenesisSpecLinearPricing{Base: 3000}}) 148 spec.setPrecompile(2, &alethGenesisSpecBuiltin{Name: "sha256", 149 Linear: &alethGenesisSpecLinearPricing{Base: 60, Word: 12}}) 150 spec.setPrecompile(3, &alethGenesisSpecBuiltin{Name: "ripemd160", 151 Linear: &alethGenesisSpecLinearPricing{Base: 600, Word: 120}}) 152 spec.setPrecompile(4, &alethGenesisSpecBuiltin{Name: "identity", 153 Linear: &alethGenesisSpecLinearPricing{Base: 15, Word: 3}}) 154 if genesis.Config.ByzantiumBlock != nil { 155 spec.setPrecompile(5, &alethGenesisSpecBuiltin{Name: "modexp", 156 StartingBlock: (hexutil.Uint64)(genesis.Config.ByzantiumBlock.Uint64())}) 157 spec.setPrecompile(6, &alethGenesisSpecBuiltin{Name: "alt_bn128_G1_add", 158 StartingBlock: (hexutil.Uint64)(genesis.Config.ByzantiumBlock.Uint64()), 159 Linear: &alethGenesisSpecLinearPricing{Base: 500}}) 160 spec.setPrecompile(7, &alethGenesisSpecBuiltin{Name: "alt_bn128_G1_mul", 161 StartingBlock: (hexutil.Uint64)(genesis.Config.ByzantiumBlock.Uint64()), 162 Linear: &alethGenesisSpecLinearPricing{Base: 40000}}) 163 spec.setPrecompile(8, &alethGenesisSpecBuiltin{Name: "alt_bn128_pairing_product", 164 StartingBlock: (hexutil.Uint64)(genesis.Config.ByzantiumBlock.Uint64())}) 165 } 166 return spec, nil 167 } 168 169 func (spec *alethGenesisSpec) setPrecompile(address byte, data *alethGenesisSpecBuiltin) { 170 if spec.Accounts == nil { 171 spec.Accounts = make(map[common.UnprefixedAddress]*alethGenesisSpecAccount) 172 } 173 addr := common.UnprefixedAddress(common.BytesToAddress([]byte{address})) 174 if _, exist := spec.Accounts[addr]; !exist { 175 spec.Accounts[addr] = &alethGenesisSpecAccount{} 176 } 177 spec.Accounts[addr].Precompiled = data 178 } 179 180 func (spec *alethGenesisSpec) setAccount(address common.Address, account core.GenesisAccount) { 181 if spec.Accounts == nil { 182 spec.Accounts = make(map[common.UnprefixedAddress]*alethGenesisSpecAccount) 183 } 184 185 a, exist := spec.Accounts[common.UnprefixedAddress(address)] 186 if !exist { 187 a = &alethGenesisSpecAccount{} 188 spec.Accounts[common.UnprefixedAddress(address)] = a 189 } 190 a.Balance = (*math2.HexOrDecimal256)(account.Balance) 191 a.Nonce = account.Nonce 192 193 } 194 195 func (spec *alethGenesisSpec) setByzantium(num *big.Int) { 196 spec.Params.ByzantiumForkBlock = hexutil.Uint64(num.Uint64()) 197 } 198 199 func (spec *alethGenesisSpec) setConstantinople(num *big.Int) { 200 spec.Params.ConstantinopleForkBlock = hexutil.Uint64(num.Uint64()) 201 } 202 203 // parityChainSpec is the chain specification format used by Parity. 204 type parityChainSpec struct { 205 Name string `json:"name"` 206 Datadir string `json:"dataDir"` 207 Engine struct { 208 Ethash struct { 209 Params struct { 210 MinimumDifficulty *hexutil.Big `json:"minimumDifficulty"` 211 DifficultyBoundDivisor *hexutil.Big `json:"difficultyBoundDivisor"` 212 DurationLimit *hexutil.Big `json:"durationLimit"` 213 BlockReward map[string]string `json:"blockReward"` 214 DifficultyBombDelays map[string]string `json:"difficultyBombDelays"` 215 HomesteadTransition hexutil.Uint64 `json:"homesteadTransition"` 216 EIP100bTransition hexutil.Uint64 `json:"eip100bTransition"` 217 } `json:"params"` 218 } `json:"Ethash"` 219 } `json:"engine"` 220 221 Params struct { 222 AccountStartNonce hexutil.Uint64 `json:"accountStartNonce"` 223 MaximumExtraDataSize hexutil.Uint64 `json:"maximumExtraDataSize"` 224 NetworkID hexutil.Uint64 `json:"networkID"` 225 ChainID hexutil.Uint64 `json:"chainID"` 226 MaxCodeSize hexutil.Uint64 `json:"maxCodeSize"` 227 MaxCodeSizeTransition hexutil.Uint64 `json:"maxCodeSizeTransition"` 228 EIP98Transition hexutil.Uint64 `json:"eip98Transition"` 229 EIP150Transition hexutil.Uint64 `json:"eip150Transition"` 230 EIP160Transition hexutil.Uint64 `json:"eip160Transition"` 231 EIP161abcTransition hexutil.Uint64 `json:"eip161abcTransition"` 232 EIP161dTransition hexutil.Uint64 `json:"eip161dTransition"` 233 EIP155Transition hexutil.Uint64 `json:"eip155Transition"` 234 EIP140Transition hexutil.Uint64 `json:"eip140Transition"` 235 EIP211Transition hexutil.Uint64 `json:"eip211Transition"` 236 EIP214Transition hexutil.Uint64 `json:"eip214Transition"` 237 EIP658Transition hexutil.Uint64 `json:"eip658Transition"` 238 EIP145Transition hexutil.Uint64 `json:"eip145Transition"` 239 EIP1014Transition hexutil.Uint64 `json:"eip1014Transition"` 240 EIP1052Transition hexutil.Uint64 `json:"eip1052Transition"` 241 EIP1283Transition hexutil.Uint64 `json:"eip1283Transition"` 242 EIP1283DisableTransition hexutil.Uint64 `json:"eip1283DisableTransition"` 243 } `json:"params"` 244 245 Genesis struct { 246 Seal struct { 247 Ethereum struct { 248 Nonce hexutil.Bytes `json:"nonce"` 249 MixHash hexutil.Bytes `json:"mixHash"` 250 } `json:"ethereum"` 251 } `json:"seal"` 252 253 Difficulty *hexutil.Big `json:"difficulty"` 254 Author common.Address `json:"author"` 255 Timestamp hexutil.Uint64 `json:"timestamp"` 256 ParentHash common.Hash `json:"parentHash"` 257 ExtraData hexutil.Bytes `json:"extraData"` 258 GasLimit hexutil.Uint64 `json:"gasLimit"` 259 } `json:"genesis"` 260 261 Nodes []string `json:"nodes"` 262 Accounts map[common.UnprefixedAddress]*parityChainSpecAccount `json:"accounts"` 263 } 264 265 // parityChainSpecAccount is the prefunded genesis account and/or precompiled 266 // contract definition. 267 type parityChainSpecAccount struct { 268 Balance math2.HexOrDecimal256 `json:"balance"` 269 Nonce math2.HexOrDecimal64 `json:"nonce,omitempty"` 270 Builtin *parityChainSpecBuiltin `json:"builtin,omitempty"` 271 } 272 273 // parityChainSpecBuiltin is the precompiled contract definition. 274 type parityChainSpecBuiltin struct { 275 Name string `json:"name,omitempty"` 276 ActivateAt math2.HexOrDecimal64 `json:"activate_at,omitempty"` 277 Pricing *parityChainSpecPricing `json:"pricing,omitempty"` 278 } 279 280 // parityChainSpecPricing represents the different pricing models that builtin 281 // contracts might advertise using. 282 type parityChainSpecPricing struct { 283 Linear *parityChainSpecLinearPricing `json:"linear,omitempty"` 284 ModExp *parityChainSpecModExpPricing `json:"modexp,omitempty"` 285 AltBnPairing *parityChainSpecAltBnPairingPricing `json:"alt_bn128_pairing,omitempty"` 286 } 287 288 type parityChainSpecLinearPricing struct { 289 Base uint64 `json:"base"` 290 Word uint64 `json:"word"` 291 } 292 293 type parityChainSpecModExpPricing struct { 294 Divisor uint64 `json:"divisor"` 295 } 296 297 type parityChainSpecAltBnPairingPricing struct { 298 Base uint64 `json:"base"` 299 Pair uint64 `json:"pair"` 300 } 301 302 // newParityChainSpec converts a go-ethereum genesis block into a Parity specific 303 // chain specification format. 304 func newParityChainSpec(network string, genesis *core.Genesis, bootnodes []string) (*parityChainSpec, error) { 305 // Only ethash is currently supported between go-ethereum and Parity 306 if genesis.Config.Ethash == nil { 307 return nil, errors.New("unsupported consensus engine") 308 } 309 // Reconstruct the chain spec in Parity's format 310 spec := &parityChainSpec{ 311 Name: network, 312 Nodes: bootnodes, 313 Datadir: strings.ToLower(network), 314 } 315 spec.Engine.Ethash.Params.BlockReward = make(map[string]string) 316 spec.Engine.Ethash.Params.DifficultyBombDelays = make(map[string]string) 317 // Frontier 318 spec.Engine.Ethash.Params.MinimumDifficulty = (*hexutil.Big)(params.MinimumDifficulty) 319 spec.Engine.Ethash.Params.DifficultyBoundDivisor = (*hexutil.Big)(params.DifficultyBoundDivisor) 320 spec.Engine.Ethash.Params.DurationLimit = (*hexutil.Big)(params.DurationLimit) 321 spec.Engine.Ethash.Params.BlockReward["0x0"] = hexutil.EncodeBig(ethash.FrontierBlockReward) 322 323 // Homestead 324 spec.Engine.Ethash.Params.HomesteadTransition = hexutil.Uint64(genesis.Config.HomesteadBlock.Uint64()) 325 326 // Tangerine Whistle : 150 327 // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-608.md 328 spec.Params.EIP150Transition = hexutil.Uint64(genesis.Config.EIP150Block.Uint64()) 329 330 // Spurious Dragon: 155, 160, 161, 170 331 // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-607.md 332 spec.Params.EIP155Transition = hexutil.Uint64(genesis.Config.EIP155Block.Uint64()) 333 spec.Params.EIP160Transition = hexutil.Uint64(genesis.Config.EIP155Block.Uint64()) 334 spec.Params.EIP161abcTransition = hexutil.Uint64(genesis.Config.EIP158Block.Uint64()) 335 spec.Params.EIP161dTransition = hexutil.Uint64(genesis.Config.EIP158Block.Uint64()) 336 337 // Byzantium 338 if num := genesis.Config.ByzantiumBlock; num != nil { 339 spec.setByzantium(num) 340 } 341 // Constantinople 342 if num := genesis.Config.ConstantinopleBlock; num != nil { 343 spec.setConstantinople(num) 344 } 345 // ConstantinopleFix (remove eip-1283) 346 if num := genesis.Config.PetersburgBlock; num != nil { 347 spec.setConstantinopleFix(num) 348 } 349 350 spec.Params.MaximumExtraDataSize = (hexutil.Uint64)(params.MaximumExtraDataSize) 351 spec.Params.NetworkID = (hexutil.Uint64)(genesis.Config.ChainID.Uint64()) 352 spec.Params.ChainID = (hexutil.Uint64)(genesis.Config.ChainID.Uint64()) 353 spec.Params.MaxCodeSize = params.MaxCodeSize 354 // geth has it set from zero 355 spec.Params.MaxCodeSizeTransition = 0 356 357 // Disable this one 358 spec.Params.EIP98Transition = math.MaxInt64 359 360 spec.Genesis.Seal.Ethereum.Nonce = (hexutil.Bytes)(make([]byte, 8)) 361 binary.LittleEndian.PutUint64(spec.Genesis.Seal.Ethereum.Nonce[:], genesis.Nonce) 362 363 spec.Genesis.Seal.Ethereum.MixHash = (hexutil.Bytes)(genesis.Mixhash[:]) 364 spec.Genesis.Difficulty = (*hexutil.Big)(genesis.Difficulty) 365 spec.Genesis.Author = genesis.Coinbase 366 spec.Genesis.Timestamp = (hexutil.Uint64)(genesis.Timestamp) 367 spec.Genesis.ParentHash = genesis.ParentHash 368 spec.Genesis.ExtraData = (hexutil.Bytes)(genesis.ExtraData) 369 spec.Genesis.GasLimit = (hexutil.Uint64)(genesis.GasLimit) 370 371 spec.Accounts = make(map[common.UnprefixedAddress]*parityChainSpecAccount) 372 for address, account := range genesis.Alloc { 373 bal := math2.HexOrDecimal256(*account.Balance) 374 375 spec.Accounts[common.UnprefixedAddress(address)] = &parityChainSpecAccount{ 376 Balance: bal, 377 Nonce: math2.HexOrDecimal64(account.Nonce), 378 } 379 } 380 spec.setPrecompile(1, &parityChainSpecBuiltin{Name: "ecrecover", 381 Pricing: &parityChainSpecPricing{Linear: &parityChainSpecLinearPricing{Base: 3000}}}) 382 383 spec.setPrecompile(2, &parityChainSpecBuiltin{ 384 Name: "sha256", Pricing: &parityChainSpecPricing{Linear: &parityChainSpecLinearPricing{Base: 60, Word: 12}}, 385 }) 386 spec.setPrecompile(3, &parityChainSpecBuiltin{ 387 Name: "ripemd160", Pricing: &parityChainSpecPricing{Linear: &parityChainSpecLinearPricing{Base: 600, Word: 120}}, 388 }) 389 spec.setPrecompile(4, &parityChainSpecBuiltin{ 390 Name: "identity", Pricing: &parityChainSpecPricing{Linear: &parityChainSpecLinearPricing{Base: 15, Word: 3}}, 391 }) 392 if genesis.Config.ByzantiumBlock != nil { 393 blnum := math2.HexOrDecimal64(genesis.Config.ByzantiumBlock.Uint64()) 394 spec.setPrecompile(5, &parityChainSpecBuiltin{ 395 Name: "modexp", ActivateAt: blnum, Pricing: &parityChainSpecPricing{ModExp: &parityChainSpecModExpPricing{Divisor: 20}}, 396 }) 397 spec.setPrecompile(6, &parityChainSpecBuiltin{ 398 Name: "alt_bn128_add", ActivateAt: blnum, Pricing: &parityChainSpecPricing{Linear: &parityChainSpecLinearPricing{Base: 500}}, 399 }) 400 spec.setPrecompile(7, &parityChainSpecBuiltin{ 401 Name: "alt_bn128_mul", ActivateAt: blnum, Pricing: &parityChainSpecPricing{Linear: &parityChainSpecLinearPricing{Base: 40000}}, 402 }) 403 spec.setPrecompile(8, &parityChainSpecBuiltin{ 404 Name: "alt_bn128_pairing", ActivateAt: blnum, Pricing: &parityChainSpecPricing{AltBnPairing: &parityChainSpecAltBnPairingPricing{Base: 100000, Pair: 80000}}, 405 }) 406 } 407 return spec, nil 408 } 409 410 func (spec *parityChainSpec) setPrecompile(address byte, data *parityChainSpecBuiltin) { 411 if spec.Accounts == nil { 412 spec.Accounts = make(map[common.UnprefixedAddress]*parityChainSpecAccount) 413 } 414 a := common.UnprefixedAddress(common.BytesToAddress([]byte{address})) 415 if _, exist := spec.Accounts[a]; !exist { 416 spec.Accounts[a] = &parityChainSpecAccount{} 417 } 418 spec.Accounts[a].Builtin = data 419 } 420 421 func (spec *parityChainSpec) setByzantium(num *big.Int) { 422 spec.Engine.Ethash.Params.BlockReward[hexutil.EncodeBig(num)] = hexutil.EncodeBig(ethash.ByzantiumBlockReward) 423 spec.Engine.Ethash.Params.DifficultyBombDelays[hexutil.EncodeBig(num)] = hexutil.EncodeUint64(3000000) 424 n := hexutil.Uint64(num.Uint64()) 425 spec.Engine.Ethash.Params.EIP100bTransition = n 426 spec.Params.EIP140Transition = n 427 spec.Params.EIP211Transition = n 428 spec.Params.EIP214Transition = n 429 spec.Params.EIP658Transition = n 430 } 431 432 func (spec *parityChainSpec) setConstantinople(num *big.Int) { 433 spec.Engine.Ethash.Params.BlockReward[hexutil.EncodeBig(num)] = hexutil.EncodeBig(ethash.ConstantinopleBlockReward) 434 spec.Engine.Ethash.Params.DifficultyBombDelays[hexutil.EncodeBig(num)] = hexutil.EncodeUint64(2000000) 435 n := hexutil.Uint64(num.Uint64()) 436 spec.Params.EIP145Transition = n 437 spec.Params.EIP1014Transition = n 438 spec.Params.EIP1052Transition = n 439 spec.Params.EIP1283Transition = n 440 } 441 442 func (spec *parityChainSpec) setConstantinopleFix(num *big.Int) { 443 spec.Params.EIP1283DisableTransition = hexutil.Uint64(num.Uint64()) 444 } 445 446 // pyEthereumGenesisSpec represents the genesis specification format used by the 447 // Python Ethereum implementation. 448 type pyEthereumGenesisSpec struct { 449 Nonce hexutil.Bytes `json:"nonce"` 450 Timestamp hexutil.Uint64 `json:"timestamp"` 451 ExtraData hexutil.Bytes `json:"extraData"` 452 GasLimit hexutil.Uint64 `json:"gasLimit"` 453 Difficulty *hexutil.Big `json:"difficulty"` 454 Mixhash common.Hash `json:"mixhash"` 455 Coinbase common.Address `json:"coinbase"` 456 Alloc core.GenesisAlloc `json:"alloc"` 457 ParentHash common.Hash `json:"parentHash"` 458 } 459 460 // newPyEthereumGenesisSpec converts a go-ethereum genesis block into a Parity specific 461 // chain specification format. 462 func newPyEthereumGenesisSpec(network string, genesis *core.Genesis) (*pyEthereumGenesisSpec, error) { 463 // Only ethash is currently supported between go-ethereum and pyethereum 464 if genesis.Config.Ethash == nil { 465 return nil, errors.New("unsupported consensus engine") 466 } 467 spec := &pyEthereumGenesisSpec{ 468 Timestamp: (hexutil.Uint64)(genesis.Timestamp), 469 ExtraData: genesis.ExtraData, 470 GasLimit: (hexutil.Uint64)(genesis.GasLimit), 471 Difficulty: (*hexutil.Big)(genesis.Difficulty), 472 Mixhash: genesis.Mixhash, 473 Coinbase: genesis.Coinbase, 474 Alloc: genesis.Alloc, 475 ParentHash: genesis.ParentHash, 476 } 477 spec.Nonce = (hexutil.Bytes)(make([]byte, 8)) 478 binary.LittleEndian.PutUint64(spec.Nonce[:], genesis.Nonce) 479 480 return spec, nil 481 }