mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 14:16:44 +00:00
rework
This commit is contained in:
parent
38f7849f95
commit
bbdf020448
4 changed files with 53 additions and 55 deletions
|
|
@ -304,7 +304,7 @@ func dumpGenesis(ctx *cli.Context) error {
|
||||||
if utils.IsNetworkPreset(ctx) {
|
if utils.IsNetworkPreset(ctx) {
|
||||||
genesis = utils.MakeGenesis(ctx)
|
genesis = utils.MakeGenesis(ctx)
|
||||||
} else if ctx.IsSet(utils.DeveloperFlag.Name) && !ctx.IsSet(utils.DataDirFlag.Name) {
|
} else if ctx.IsSet(utils.DeveloperFlag.Name) && !ctx.IsSet(utils.DataDirFlag.Name) {
|
||||||
genesis, _, _ = core.DeveloperGenesisBlock(11_500_000, nil)
|
genesis = core.DeveloperGenesisBlock(11_500_000, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
if genesis != nil {
|
if genesis != nil {
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"slices"
|
"slices"
|
||||||
|
|
@ -30,8 +29,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/cmd/utils"
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/console/prompt"
|
"github.com/ethereum/go-ethereum/console/prompt"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
|
||||||
"github.com/ethereum/go-ethereum/eth/downloader"
|
"github.com/ethereum/go-ethereum/eth/downloader"
|
||||||
"github.com/ethereum/go-ethereum/ethclient"
|
"github.com/ethereum/go-ethereum/ethclient"
|
||||||
"github.com/ethereum/go-ethereum/internal/debug"
|
"github.com/ethereum/go-ethereum/internal/debug"
|
||||||
|
|
@ -331,6 +328,7 @@ func prepare(ctx *cli.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// geth is the main entry point into the system if no special subcommand is run.
|
// geth is the main entry point into the system if no special subcommand is run.
|
||||||
// It creates a default node based on the command line arguments and runs it in
|
// It creates a default node based on the command line arguments and runs it in
|
||||||
// blocking mode, waiting for it to be shut down.
|
// blocking mode, waiting for it to be shut down.
|
||||||
|
|
@ -344,18 +342,6 @@ func geth(ctx *cli.Context) error {
|
||||||
defer stack.Close()
|
defer stack.Close()
|
||||||
|
|
||||||
startNode(ctx, stack, false)
|
startNode(ctx, stack, false)
|
||||||
|
|
||||||
if ctx.IsSet(utils.DeveloperFlag.Name) && !ctx.IsSet(utils.DataDirFlag.Name) {
|
|
||||||
_, faucetAddr, faucetKey := core.DeveloperGenesisBlock(0, nil)
|
|
||||||
fmt.Println("Developer Faucet Account")
|
|
||||||
fmt.Println("========================")
|
|
||||||
fmt.Printf("Address: %s\n", faucetAddr.Hex())
|
|
||||||
if faucetKey != nil {
|
|
||||||
fmt.Printf("Private Key: 0x%s\n", hex.EncodeToString(crypto.FromECDSA(faucetKey)))
|
|
||||||
}
|
|
||||||
fmt.Println()
|
|
||||||
}
|
|
||||||
|
|
||||||
stack.Wait()
|
stack.Wait()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -1787,13 +1787,11 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
|
||||||
log.Info("Using developer account", "address", developer.Address)
|
log.Info("Using developer account", "address", developer.Address)
|
||||||
|
|
||||||
// Create a new developer genesis block or reuse existing one
|
// Create a new developer genesis block or reuse existing one
|
||||||
cfg.Genesis, _, _ = core.DeveloperGenesisBlock(ctx.Uint64(DeveloperGasLimitFlag.Name), &developer.Address)
|
|
||||||
if ctx.IsSet(DataDirFlag.Name) {
|
if ctx.IsSet(DataDirFlag.Name) {
|
||||||
chaindb := tryMakeReadOnlyDatabase(ctx, stack)
|
chaindb := tryMakeReadOnlyDatabase(ctx, stack)
|
||||||
if rawdb.ReadCanonicalHash(chaindb, 0) != (common.Hash{}) {
|
if rawdb.ReadCanonicalHash(chaindb, 0) != (common.Hash{}) {
|
||||||
cfg.Genesis = nil // fallback to db content
|
// validate that the stored genesis config compatible with dev-mode:
|
||||||
|
// it must be merged at genesis
|
||||||
//validate genesis has PoS enabled in block 0
|
|
||||||
genesis, err := core.ReadGenesis(chaindb)
|
genesis, err := core.ReadGenesis(chaindb)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Fatalf("Could not read genesis from database: %v", err)
|
Fatalf("Could not read genesis from database: %v", err)
|
||||||
|
|
@ -1808,6 +1806,22 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
chaindb.Close()
|
chaindb.Close()
|
||||||
|
} else {
|
||||||
|
// if no datadir is specified, dev mode runs ephemerally in memory
|
||||||
|
var (
|
||||||
|
devAddr = developer.Address
|
||||||
|
devKey *ecdsa.PrivateKey
|
||||||
|
)
|
||||||
|
if devAddr != (common.Address{}) {
|
||||||
|
devKey, err = crypto.GenerateKey()
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("failed to generate dev mode prefunded account key: %v", err))
|
||||||
|
}
|
||||||
|
devAddr = crypto.PubkeyToAddress(devKey.PublicKey)
|
||||||
|
|
||||||
|
log.Info("running dev mode with prefunded account", "address", devAddr, "private key", crypto.FromECDSA(devKey))
|
||||||
|
}
|
||||||
|
cfg.Genesis = core.DeveloperGenesisBlock(ctx.Uint64(DeveloperGasLimitFlag.Name), &devAddr)
|
||||||
}
|
}
|
||||||
if !ctx.IsSet(MinerGasPriceFlag.Name) {
|
if !ctx.IsSet(MinerGasPriceFlag.Name) {
|
||||||
cfg.Miner.GasPrice = big.NewInt(1)
|
cfg.Miner.GasPrice = big.NewInt(1)
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,6 @@ import (
|
||||||
"math/big"
|
"math/big"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"crypto/ecdsa"
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"github.com/ethereum/go-ethereum/common/math"
|
"github.com/ethereum/go-ethereum/common/math"
|
||||||
|
|
@ -646,47 +644,47 @@ func DefaultHoodiGenesisBlock() *Genesis {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeveloperGenesisBlock returns the 'geth --dev' genesis block, faucet address, and key.
|
// DeveloperGenesisBlock returns the genesis block for dev mode, with initial
|
||||||
func DeveloperGenesisBlock(gasLimit uint64, faucet *common.Address) (*Genesis, common.Address, *ecdsa.PrivateKey) {
|
// gas limit and optional prefunded address
|
||||||
|
func DeveloperGenesisBlock(gasLimit uint64, faucet *common.Address) *Genesis {
|
||||||
|
// Override the default period to the user requested one
|
||||||
config := *params.AllDevChainProtocolChanges
|
config := *params.AllDevChainProtocolChanges
|
||||||
|
|
||||||
alloc := make(map[common.Address]types.Account)
|
// Assemble and return the genesis with the precompiles and faucet pre-funded
|
||||||
|
|
||||||
var faucetAddr common.Address
|
|
||||||
var faucetKey *ecdsa.PrivateKey
|
|
||||||
if faucet == nil {
|
|
||||||
// Generate a new dev account for the faucet
|
|
||||||
key, err := crypto.GenerateKey()
|
|
||||||
if err != nil {
|
|
||||||
panic(fmt.Errorf("failed to generate dev faucet key: %w", err))
|
|
||||||
}
|
|
||||||
faucetAddr = crypto.PubkeyToAddress(key.PublicKey)
|
|
||||||
faucetKey = key
|
|
||||||
} else {
|
|
||||||
faucetAddr = *faucet
|
|
||||||
}
|
|
||||||
alloc[faucetAddr] = types.Account{Balance: new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(9))}
|
|
||||||
|
|
||||||
// Add precompiles and system contracts
|
|
||||||
precompileAddrs := [][]byte{
|
|
||||||
{0x01}, {0x02}, {0x03}, {0x04}, {0x05}, {0x06}, {0x07}, {0x08}, {0x09}, {0x0a}, {0x0b}, {0x0c}, {0x0d}, {0x0e}, {0x0f}, {0x10}, {0x11},
|
|
||||||
}
|
|
||||||
for _, addr := range precompileAddrs {
|
|
||||||
alloc[common.BytesToAddress(addr)] = types.Account{Balance: big.NewInt(1)}
|
|
||||||
}
|
|
||||||
alloc[params.BeaconRootsAddress] = types.Account{Nonce: 1, Code: params.BeaconRootsCode, Balance: common.Big0}
|
|
||||||
alloc[params.HistoryStorageAddress] = types.Account{Nonce: 1, Code: params.HistoryStorageCode, Balance: common.Big0}
|
|
||||||
alloc[params.WithdrawalQueueAddress] = types.Account{Nonce: 1, Code: params.WithdrawalQueueCode, Balance: common.Big0}
|
|
||||||
alloc[params.ConsolidationQueueAddress] = types.Account{Nonce: 1, Code: params.ConsolidationQueueCode, Balance: common.Big0}
|
|
||||||
|
|
||||||
genesis := &Genesis{
|
genesis := &Genesis{
|
||||||
Config: &config,
|
Config: &config,
|
||||||
GasLimit: gasLimit,
|
GasLimit: gasLimit,
|
||||||
BaseFee: big.NewInt(params.InitialBaseFee),
|
BaseFee: big.NewInt(params.InitialBaseFee),
|
||||||
Difficulty: big.NewInt(0),
|
Difficulty: big.NewInt(0),
|
||||||
Alloc: alloc,
|
Alloc: map[common.Address]types.Account{
|
||||||
|
common.BytesToAddress([]byte{0x01}): {Balance: big.NewInt(1)}, // ECRecover
|
||||||
|
common.BytesToAddress([]byte{0x02}): {Balance: big.NewInt(1)}, // SHA256
|
||||||
|
common.BytesToAddress([]byte{0x03}): {Balance: big.NewInt(1)}, // RIPEMD
|
||||||
|
common.BytesToAddress([]byte{0x04}): {Balance: big.NewInt(1)}, // Identity
|
||||||
|
common.BytesToAddress([]byte{0x05}): {Balance: big.NewInt(1)}, // ModExp
|
||||||
|
common.BytesToAddress([]byte{0x06}): {Balance: big.NewInt(1)}, // ECAdd
|
||||||
|
common.BytesToAddress([]byte{0x07}): {Balance: big.NewInt(1)}, // ECScalarMul
|
||||||
|
common.BytesToAddress([]byte{0x08}): {Balance: big.NewInt(1)}, // ECPairing
|
||||||
|
common.BytesToAddress([]byte{0x09}): {Balance: big.NewInt(1)}, // BLAKE2b
|
||||||
|
common.BytesToAddress([]byte{0x0a}): {Balance: big.NewInt(1)}, // KZGPointEval
|
||||||
|
common.BytesToAddress([]byte{0x0b}): {Balance: big.NewInt(1)}, // BLSG1Add
|
||||||
|
common.BytesToAddress([]byte{0x0c}): {Balance: big.NewInt(1)}, // BLSG1MultiExp
|
||||||
|
common.BytesToAddress([]byte{0x0d}): {Balance: big.NewInt(1)}, // BLSG2Add
|
||||||
|
common.BytesToAddress([]byte{0x0e}): {Balance: big.NewInt(1)}, // BLSG2MultiExp
|
||||||
|
common.BytesToAddress([]byte{0x0f}): {Balance: big.NewInt(1)}, // BLSG1Pairing
|
||||||
|
common.BytesToAddress([]byte{0x10}): {Balance: big.NewInt(1)}, // BLSG1MapG1
|
||||||
|
common.BytesToAddress([]byte{0x11}): {Balance: big.NewInt(1)}, // BLSG2MapG2
|
||||||
|
// Pre-deploy system contracts
|
||||||
|
params.BeaconRootsAddress: {Nonce: 1, Code: params.BeaconRootsCode, Balance: common.Big0},
|
||||||
|
params.HistoryStorageAddress: {Nonce: 1, Code: params.HistoryStorageCode, Balance: common.Big0},
|
||||||
|
params.WithdrawalQueueAddress: {Nonce: 1, Code: params.WithdrawalQueueCode, Balance: common.Big0},
|
||||||
|
params.ConsolidationQueueAddress: {Nonce: 1, Code: params.ConsolidationQueueCode, Balance: common.Big0},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
return genesis, faucetAddr, faucetKey
|
if faucet != nil {
|
||||||
|
genesis.Alloc[*faucet] = types.Account{Balance: new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(9))}
|
||||||
|
}
|
||||||
|
return genesis
|
||||||
}
|
}
|
||||||
|
|
||||||
func decodePrealloc(data string) types.GenesisAlloc {
|
func decodePrealloc(data string) types.GenesisAlloc {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue