2017-04-10 18:25:53 -05:00
|
|
|
// Copyright 2017 The go-ethereum Authors
|
|
|
|
// This file is part of go-ethereum.
|
|
|
|
//
|
|
|
|
// go-ethereum is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// go-ethereum is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2017-10-04 04:15:58 -05:00
|
|
|
"encoding/json"
|
2017-04-10 18:25:53 -05:00
|
|
|
"fmt"
|
2018-12-03 08:50:59 -06:00
|
|
|
"io"
|
2017-04-10 18:25:53 -05:00
|
|
|
"math/big"
|
|
|
|
"math/rand"
|
2018-12-03 08:50:59 -06:00
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2017-04-10 18:25:53 -05:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
"github.com/ethereum/go-ethereum/core"
|
|
|
|
"github.com/ethereum/go-ethereum/log"
|
|
|
|
"github.com/ethereum/go-ethereum/params"
|
|
|
|
)
|
|
|
|
|
|
|
|
// makeGenesis creates a new genesis struct based on some user input.
|
|
|
|
func (w *wizard) makeGenesis() {
|
|
|
|
// Construct a default genesis block
|
|
|
|
genesis := &core.Genesis{
|
|
|
|
Timestamp: uint64(time.Now().Unix()),
|
|
|
|
GasLimit: 4700000,
|
2017-10-23 04:24:25 -05:00
|
|
|
Difficulty: big.NewInt(524288),
|
2017-04-10 18:25:53 -05:00
|
|
|
Alloc: make(core.GenesisAlloc),
|
|
|
|
Config: ¶ms.ChainConfig{
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 02:34:02 -05:00
|
|
|
HomesteadBlock: big.NewInt(0),
|
|
|
|
EIP150Block: big.NewInt(0),
|
|
|
|
EIP155Block: big.NewInt(0),
|
|
|
|
EIP158Block: big.NewInt(0),
|
|
|
|
ByzantiumBlock: big.NewInt(0),
|
|
|
|
ConstantinopleBlock: big.NewInt(0),
|
|
|
|
PetersburgBlock: big.NewInt(0),
|
2019-11-04 02:41:29 -06:00
|
|
|
IstanbulBlock: big.NewInt(0),
|
2017-04-10 18:25:53 -05:00
|
|
|
},
|
|
|
|
}
|
|
|
|
// Figure out which consensus engine to choose
|
|
|
|
fmt.Println()
|
|
|
|
fmt.Println("Which consensus engine to use? (default = clique)")
|
|
|
|
fmt.Println(" 1. Ethash - proof-of-work")
|
|
|
|
fmt.Println(" 2. Clique - proof-of-authority")
|
|
|
|
|
|
|
|
choice := w.read()
|
|
|
|
switch {
|
|
|
|
case choice == "1":
|
|
|
|
// In case of ethash, we're pretty much done
|
|
|
|
genesis.Config.Ethash = new(params.EthashConfig)
|
|
|
|
genesis.ExtraData = make([]byte, 32)
|
|
|
|
|
|
|
|
case choice == "" || choice == "2":
|
|
|
|
// In the case of clique, configure the consensus parameters
|
|
|
|
genesis.Difficulty = big.NewInt(1)
|
|
|
|
genesis.Config.Clique = ¶ms.CliqueConfig{
|
|
|
|
Period: 15,
|
|
|
|
Epoch: 30000,
|
|
|
|
}
|
|
|
|
fmt.Println()
|
|
|
|
fmt.Println("How many seconds should blocks take? (default = 15)")
|
|
|
|
genesis.Config.Clique.Period = uint64(w.readDefaultInt(15))
|
|
|
|
|
|
|
|
// We also need the initial list of signers
|
|
|
|
fmt.Println()
|
|
|
|
fmt.Println("Which accounts are allowed to seal? (mandatory at least one)")
|
|
|
|
|
|
|
|
var signers []common.Address
|
|
|
|
for {
|
|
|
|
if address := w.readAddress(); address != nil {
|
|
|
|
signers = append(signers, *address)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if len(signers) > 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Sort the signers and embed into the extra-data section
|
|
|
|
for i := 0; i < len(signers); i++ {
|
|
|
|
for j := i + 1; j < len(signers); j++ {
|
|
|
|
if bytes.Compare(signers[i][:], signers[j][:]) > 0 {
|
|
|
|
signers[i], signers[j] = signers[j], signers[i]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
genesis.ExtraData = make([]byte, 32+len(signers)*common.AddressLength+65)
|
|
|
|
for i, signer := range signers {
|
|
|
|
copy(genesis.ExtraData[32+i*common.AddressLength:], signer[:])
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
log.Crit("Invalid consensus engine choice", "choice", choice)
|
|
|
|
}
|
|
|
|
// Consensus all set, just ask for initial funds and go
|
|
|
|
fmt.Println()
|
|
|
|
fmt.Println("Which accounts should be pre-funded? (advisable at least one)")
|
|
|
|
for {
|
|
|
|
// Read the address of the account to fund
|
|
|
|
if address := w.readAddress(); address != nil {
|
|
|
|
genesis.Alloc[*address] = core.GenesisAccount{
|
|
|
|
Balance: new(big.Int).Lsh(big.NewInt(1), 256-7), // 2^256 / 128 (allow many pre-funds without balance overflows)
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
2018-11-24 16:22:25 -06:00
|
|
|
fmt.Println()
|
|
|
|
fmt.Println("Should the precompile-addresses (0x1 .. 0xff) be pre-funded with 1 wei? (advisable yes)")
|
2018-12-03 08:50:59 -06:00
|
|
|
if w.readDefaultYesNo(true) {
|
2018-11-24 16:22:25 -06:00
|
|
|
// Add a batch of precompile balances to avoid them getting deleted
|
|
|
|
for i := int64(0); i < 256; i++ {
|
|
|
|
genesis.Alloc[common.BigToAddress(big.NewInt(i))] = core.GenesisAccount{Balance: big.NewInt(1)}
|
|
|
|
}
|
2017-04-10 18:25:53 -05:00
|
|
|
}
|
|
|
|
// Query the user for some custom extras
|
|
|
|
fmt.Println()
|
|
|
|
fmt.Println("Specify your chain/network ID if you want an explicit one (default = random)")
|
2018-06-05 05:31:34 -05:00
|
|
|
genesis.Config.ChainID = new(big.Int).SetUint64(uint64(w.readDefaultInt(rand.Intn(65536))))
|
2017-04-10 18:25:53 -05:00
|
|
|
|
|
|
|
// All done, store the genesis and flush to disk
|
2017-10-26 04:39:03 -05:00
|
|
|
log.Info("Configured new genesis block")
|
|
|
|
|
|
|
|
w.conf.Genesis = genesis
|
|
|
|
w.conf.flush()
|
2017-04-10 18:25:53 -05:00
|
|
|
}
|
2017-10-04 04:15:58 -05:00
|
|
|
|
2018-12-03 08:50:59 -06:00
|
|
|
// importGenesis imports a Geth genesis spec into puppeth.
|
|
|
|
func (w *wizard) importGenesis() {
|
|
|
|
// Request the genesis JSON spec URL from the user
|
|
|
|
fmt.Println()
|
|
|
|
fmt.Println("Where's the genesis file? (local file or http/https url)")
|
|
|
|
url := w.readURL()
|
|
|
|
|
|
|
|
// Convert the various allowed URLs to a reader stream
|
|
|
|
var reader io.Reader
|
|
|
|
|
|
|
|
switch url.Scheme {
|
|
|
|
case "http", "https":
|
|
|
|
// Remote web URL, retrieve it via an HTTP client
|
|
|
|
res, err := http.Get(url.String())
|
|
|
|
if err != nil {
|
|
|
|
log.Error("Failed to retrieve remote genesis", "err", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer res.Body.Close()
|
|
|
|
reader = res.Body
|
|
|
|
|
|
|
|
case "":
|
|
|
|
// Schemaless URL, interpret as a local file
|
|
|
|
file, err := os.Open(url.String())
|
|
|
|
if err != nil {
|
|
|
|
log.Error("Failed to open local genesis", "err", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
reader = file
|
|
|
|
|
|
|
|
default:
|
|
|
|
log.Error("Unsupported genesis URL scheme", "scheme", url.Scheme)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// Parse the genesis file and inject it successful
|
|
|
|
var genesis core.Genesis
|
|
|
|
if err := json.NewDecoder(reader).Decode(&genesis); err != nil {
|
2020-05-13 10:34:24 -05:00
|
|
|
log.Error("Invalid genesis spec", "err", err)
|
2018-12-03 08:50:59 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
log.Info("Imported genesis block")
|
|
|
|
|
|
|
|
w.conf.Genesis = &genesis
|
|
|
|
w.conf.flush()
|
|
|
|
}
|
|
|
|
|
2017-10-04 04:15:58 -05:00
|
|
|
// manageGenesis permits the modification of chain configuration parameters in
|
|
|
|
// a genesis config and the export of the entire genesis spec.
|
|
|
|
func (w *wizard) manageGenesis() {
|
|
|
|
// Figure out whether to modify or export the genesis
|
|
|
|
fmt.Println()
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 02:34:02 -05:00
|
|
|
fmt.Println(" 1. Modify existing configurations")
|
2018-11-24 16:22:25 -06:00
|
|
|
fmt.Println(" 2. Export genesis configurations")
|
2017-10-26 04:39:03 -05:00
|
|
|
fmt.Println(" 3. Remove genesis configuration")
|
2017-10-04 04:15:58 -05:00
|
|
|
|
|
|
|
choice := w.read()
|
2018-11-24 16:22:25 -06:00
|
|
|
switch choice {
|
|
|
|
case "1":
|
2017-10-04 04:15:58 -05:00
|
|
|
// Fork rule updating requested, iterate over each fork
|
|
|
|
fmt.Println()
|
2017-10-26 04:39:03 -05:00
|
|
|
fmt.Printf("Which block should Homestead come into effect? (default = %v)\n", w.conf.Genesis.Config.HomesteadBlock)
|
|
|
|
w.conf.Genesis.Config.HomesteadBlock = w.readDefaultBigInt(w.conf.Genesis.Config.HomesteadBlock)
|
2017-10-04 04:15:58 -05:00
|
|
|
|
|
|
|
fmt.Println()
|
2018-11-24 16:22:25 -06:00
|
|
|
fmt.Printf("Which block should EIP150 (Tangerine Whistle) come into effect? (default = %v)\n", w.conf.Genesis.Config.EIP150Block)
|
2017-10-26 04:39:03 -05:00
|
|
|
w.conf.Genesis.Config.EIP150Block = w.readDefaultBigInt(w.conf.Genesis.Config.EIP150Block)
|
2017-10-04 04:15:58 -05:00
|
|
|
|
|
|
|
fmt.Println()
|
2018-11-24 16:22:25 -06:00
|
|
|
fmt.Printf("Which block should EIP155 (Spurious Dragon) come into effect? (default = %v)\n", w.conf.Genesis.Config.EIP155Block)
|
2017-10-26 04:39:03 -05:00
|
|
|
w.conf.Genesis.Config.EIP155Block = w.readDefaultBigInt(w.conf.Genesis.Config.EIP155Block)
|
2017-10-04 04:15:58 -05:00
|
|
|
|
|
|
|
fmt.Println()
|
2018-11-24 16:22:25 -06:00
|
|
|
fmt.Printf("Which block should EIP158/161 (also Spurious Dragon) come into effect? (default = %v)\n", w.conf.Genesis.Config.EIP158Block)
|
2017-10-26 04:39:03 -05:00
|
|
|
w.conf.Genesis.Config.EIP158Block = w.readDefaultBigInt(w.conf.Genesis.Config.EIP158Block)
|
2017-10-04 04:15:58 -05:00
|
|
|
|
|
|
|
fmt.Println()
|
2017-10-26 04:39:03 -05:00
|
|
|
fmt.Printf("Which block should Byzantium come into effect? (default = %v)\n", w.conf.Genesis.Config.ByzantiumBlock)
|
|
|
|
w.conf.Genesis.Config.ByzantiumBlock = w.readDefaultBigInt(w.conf.Genesis.Config.ByzantiumBlock)
|
2017-10-04 04:15:58 -05:00
|
|
|
|
2018-11-24 16:22:25 -06:00
|
|
|
fmt.Println()
|
2018-12-03 08:50:59 -06:00
|
|
|
fmt.Printf("Which block should Constantinople come into effect? (default = %v)\n", w.conf.Genesis.Config.ConstantinopleBlock)
|
2018-11-24 16:22:25 -06:00
|
|
|
w.conf.Genesis.Config.ConstantinopleBlock = w.readDefaultBigInt(w.conf.Genesis.Config.ConstantinopleBlock)
|
2019-02-06 06:34:08 -06:00
|
|
|
if w.conf.Genesis.Config.PetersburgBlock == nil {
|
|
|
|
w.conf.Genesis.Config.PetersburgBlock = w.conf.Genesis.Config.ConstantinopleBlock
|
|
|
|
}
|
2019-01-24 04:36:30 -06:00
|
|
|
fmt.Println()
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 02:34:02 -05:00
|
|
|
fmt.Printf("Which block should Petersburg come into effect? (default = %v)\n", w.conf.Genesis.Config.PetersburgBlock)
|
2019-02-06 06:34:08 -06:00
|
|
|
w.conf.Genesis.Config.PetersburgBlock = w.readDefaultBigInt(w.conf.Genesis.Config.PetersburgBlock)
|
2019-01-24 04:36:30 -06:00
|
|
|
|
2019-11-04 02:41:29 -06:00
|
|
|
fmt.Println()
|
|
|
|
fmt.Printf("Which block should Istanbul come into effect? (default = %v)\n", w.conf.Genesis.Config.IstanbulBlock)
|
|
|
|
w.conf.Genesis.Config.IstanbulBlock = w.readDefaultBigInt(w.conf.Genesis.Config.IstanbulBlock)
|
|
|
|
|
2021-02-25 01:10:30 -06:00
|
|
|
fmt.Println()
|
|
|
|
fmt.Printf("Which block should Berlin come into effect? (default = %v)\n", w.conf.Genesis.Config.BerlinBlock)
|
|
|
|
w.conf.Genesis.Config.BerlinBlock = w.readDefaultBigInt(w.conf.Genesis.Config.BerlinBlock)
|
|
|
|
|
2020-06-03 04:05:15 -05:00
|
|
|
fmt.Println()
|
2021-05-06 04:07:42 -05:00
|
|
|
fmt.Printf("Which block should London come into effect? (default = %v)\n", w.conf.Genesis.Config.LondonBlock)
|
|
|
|
w.conf.Genesis.Config.LondonBlock = w.readDefaultBigInt(w.conf.Genesis.Config.LondonBlock)
|
2020-06-03 04:05:15 -05:00
|
|
|
|
2017-10-26 04:39:03 -05:00
|
|
|
out, _ := json.MarshalIndent(w.conf.Genesis.Config, "", " ")
|
2017-10-04 04:15:58 -05:00
|
|
|
fmt.Printf("Chain configuration updated:\n\n%s\n", out)
|
|
|
|
|
2019-02-06 06:34:08 -06:00
|
|
|
w.conf.flush()
|
|
|
|
|
2018-11-24 16:22:25 -06:00
|
|
|
case "2":
|
2017-10-04 04:15:58 -05:00
|
|
|
// Save whatever genesis configuration we currently have
|
|
|
|
fmt.Println()
|
2022-07-22 02:51:01 -05:00
|
|
|
fmt.Printf("Which folder to save the genesis spec into? (default = current)\n")
|
|
|
|
fmt.Printf(" Will create %s.json\n", w.network)
|
2018-12-03 08:50:59 -06:00
|
|
|
|
|
|
|
folder := w.readDefaultString(".")
|
|
|
|
if err := os.MkdirAll(folder, 0755); err != nil {
|
|
|
|
log.Error("Failed to create spec folder", "folder", folder, "err", err)
|
|
|
|
return
|
|
|
|
}
|
2017-10-26 04:39:03 -05:00
|
|
|
out, _ := json.MarshalIndent(w.conf.Genesis, "", " ")
|
2018-11-24 16:22:25 -06:00
|
|
|
|
2018-12-03 08:50:59 -06:00
|
|
|
// Export the native genesis spec used by puppeth and Geth
|
|
|
|
gethJson := filepath.Join(folder, fmt.Sprintf("%s.json", w.network))
|
2022-05-16 04:59:35 -05:00
|
|
|
if err := os.WriteFile(gethJson, out, 0644); err != nil {
|
2017-10-04 04:15:58 -05:00
|
|
|
log.Error("Failed to save genesis file", "err", err)
|
2018-12-03 08:50:59 -06:00
|
|
|
return
|
2017-10-04 04:15:58 -05:00
|
|
|
}
|
2018-12-03 08:50:59 -06:00
|
|
|
log.Info("Saved native genesis chain spec", "path", gethJson)
|
|
|
|
|
2018-11-24 16:22:25 -06:00
|
|
|
case "3":
|
2017-10-26 04:39:03 -05:00
|
|
|
// Make sure we don't have any services running
|
|
|
|
if len(w.conf.servers()) > 0 {
|
|
|
|
log.Error("Genesis reset requires all services and servers torn down")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
log.Info("Genesis block destroyed")
|
|
|
|
|
|
|
|
w.conf.Genesis = nil
|
|
|
|
w.conf.flush()
|
2017-10-04 04:15:58 -05:00
|
|
|
default:
|
|
|
|
log.Error("That's not something I can do")
|
2018-12-03 08:50:59 -06:00
|
|
|
return
|
2017-10-04 04:15:58 -05:00
|
|
|
}
|
|
|
|
}
|