From ef0844fabbe6b2d34b8e403edea0db8e40f124f0 Mon Sep 17 00:00:00 2001 From: Chris Ziogas Date: Wed, 25 Nov 2020 20:34:00 +0200 Subject: [PATCH 01/11] =?UTF-8?q?cmd/geth,=20miner,=20params:=20add=20an?= =?UTF-8?q?=20Ethash=20Fake=20sealing=20option=20for=20`=E2=80=94dev`=20mo?= =?UTF-8?q?de=20using=20`=E2=80=94dev.ethash`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement requested feature at issue #188 --- cmd/geth/main.go | 1 + cmd/geth/usage.go | 1 + cmd/utils/flags.go | 13 +++++++++++-- console/console_test.go | 2 +- miner/miner_test.go | 2 +- params/genesis.go | 14 ++++++++++---- 6 files changed, 25 insertions(+), 8 deletions(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 3cecd61d11..286f51da04 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -145,6 +145,7 @@ var ( utils.EthProtocolsFlag, utils.DeveloperFlag, utils.DeveloperPeriodFlag, + utils.DeveloperEthashFlag, utils.ClassicFlag, utils.MordorFlag, utils.SocialFlag, diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go index 6506b6e30c..ad0df66eb4 100644 --- a/cmd/geth/usage.go +++ b/cmd/geth/usage.go @@ -81,6 +81,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{ Flags: []cli.Flag{ utils.DeveloperFlag, utils.DeveloperPeriodFlag, + utils.DeveloperEthashFlag, }, }, { diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 98996fd7fe..c44309b0bf 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -192,7 +192,11 @@ var ( } DeveloperPeriodFlag = cli.IntFlag{ Name: "dev.period", - Usage: "Block period to use in developer mode (0 = mine only if transaction pending)", + Usage: "Block period for proof-of-authority network to use in developer mode (0 = mine only if transaction pending)", + } + DeveloperEthashFlag = cli.BoolFlag{ + Name: "dev.ethash", + Usage: "Ephemeral proof-of-work network with a pre-funded developer account, mining enabled", } IdentityFlag = cli.StringFlag{ Name: "identity", @@ -1823,8 +1827,13 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) { } log.Info("Using developer account", "address", developer.Address) + isPoWNetwork := ctx.GlobalBool(DeveloperEthashFlag.Name) + if isPoWNetwork { + cfg.Ethash.PowMode = ethash.ModeFake + } + // Create a new developer genesis block or reuse existing one - cfg.Genesis = params.DeveloperGenesisBlock(uint64(ctx.GlobalInt(DeveloperPeriodFlag.Name)), developer.Address) + cfg.Genesis = params.DeveloperGenesisBlock(uint64(ctx.GlobalInt(DeveloperPeriodFlag.Name)), developer.Address, isPoWNetwork) if ctx.GlobalIsSet(DataDirFlag.Name) { // Check if we have an already initialized chain and fall back to // that if so. Otherwise we need to generate a new genesis spec. diff --git a/console/console_test.go b/console/console_test.go index 7293d2d761..c0515929c2 100644 --- a/console/console_test.go +++ b/console/console_test.go @@ -98,7 +98,7 @@ func newTester(t *testing.T, confOverride func(*eth.Config)) *tester { t.Fatalf("failed to create node: %v", err) } ethConf := ð.Config{ - Genesis: params.DeveloperGenesisBlock(15, common.Address{}), + Genesis: params.DeveloperGenesisBlock(15, common.Address{}, false), Miner: miner.Config{ Etherbase: common.HexToAddress(testAddress), }, diff --git a/miner/miner_test.go b/miner/miner_test.go index aceca7b3e6..76f32220bb 100644 --- a/miner/miner_test.go +++ b/miner/miner_test.go @@ -238,7 +238,7 @@ func createMiner(t *testing.T) (*Miner, *event.TypeMux) { // Create chainConfig memdb := memorydb.New() chainDB := rawdb.NewDatabase(memdb) - genesis := params.DeveloperGenesisBlock(15, common.HexToAddress("12345")) + genesis := params.DeveloperGenesisBlock(15, common.HexToAddress("12345"), false) chainConfig, _, err := core.SetupGenesisBlock(chainDB, genesis) if err != nil { t.Fatalf("can't create new chain config: %v", err) diff --git a/params/genesis.go b/params/genesis.go index 0b6adb6f82..993e6f0386 100644 --- a/params/genesis.go +++ b/params/genesis.go @@ -23,6 +23,7 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/params/types/genesisT" + "github.com/ethereum/go-ethereum/params/types/goethereum" ) // DefaultGenesisBlock returns the Ethereum main net genesis block. @@ -86,14 +87,19 @@ func DefaultYoloV1GenesisBlock() *genesisT.Genesis { // DeveloperGenesisBlock returns the 'geth --dev' genesis block. Note, this must // be seeded with the -func DeveloperGenesisBlock(period uint64, faucet common.Address) *genesisT.Genesis { +func DeveloperGenesisBlock(period uint64, faucet common.Address, useEthash bool) *genesisT.Genesis { // Override the default period to the user requested one - config := *AllCliqueProtocolChanges - config.Clique.Period = period + var config *goethereum.ChainConfig + if useEthash { + config = AllEthashProtocolChanges + } else { + config = AllCliqueProtocolChanges + config.Clique.Period = period + } // Assemble and return the genesis with the precompiles and faucet pre-funded return &genesisT.Genesis{ - Config: &config, + Config: config, ExtraData: append(append(make([]byte, 32), faucet[:]...), make([]byte, crypto.SignatureLength)...), GasLimit: 6283185, Difficulty: big.NewInt(1), From d6788bd545a86889c648f0639232ee9aa8caccde Mon Sep 17 00:00:00 2001 From: Chris Ziogas Date: Wed, 25 Nov 2020 20:57:33 +0200 Subject: [PATCH 02/11] flags: remane `isPoWNetwork` to `useEthash` missed on last commit --- cmd/utils/flags.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index c44309b0bf..487cb4a2e9 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1827,13 +1827,13 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) { } log.Info("Using developer account", "address", developer.Address) - isPoWNetwork := ctx.GlobalBool(DeveloperEthashFlag.Name) - if isPoWNetwork { + useEthash := ctx.GlobalBool(DeveloperEthashFlag.Name) + if useEthash { cfg.Ethash.PowMode = ethash.ModeFake } // Create a new developer genesis block or reuse existing one - cfg.Genesis = params.DeveloperGenesisBlock(uint64(ctx.GlobalInt(DeveloperPeriodFlag.Name)), developer.Address, isPoWNetwork) + cfg.Genesis = params.DeveloperGenesisBlock(uint64(ctx.GlobalInt(DeveloperPeriodFlag.Name)), developer.Address, useEthash) if ctx.GlobalIsSet(DataDirFlag.Name) { // Check if we have an already initialized chain and fall back to // that if so. Otherwise we need to generate a new genesis spec. From bc7ad1b2c1510f8c69d905143e086af137e1f160 Mon Sep 17 00:00:00 2001 From: Chris Ziogas Date: Tue, 1 Dec 2020 22:57:10 +0200 Subject: [PATCH 03/11] =?UTF-8?q?cmd/geth,=20cmd/utils/flags:=20rename=20`?= =?UTF-8?q?=E2=80=94dev.ethash`=20to=20`=E2=80=94dev.pow`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/geth/main.go | 2 +- cmd/geth/usage.go | 2 +- cmd/utils/flags.go | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 286f51da04..fa666639c6 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -145,7 +145,7 @@ var ( utils.EthProtocolsFlag, utils.DeveloperFlag, utils.DeveloperPeriodFlag, - utils.DeveloperEthashFlag, + utils.DeveloperPoWFlag, utils.ClassicFlag, utils.MordorFlag, utils.SocialFlag, diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go index ad0df66eb4..02ee3b0cb6 100644 --- a/cmd/geth/usage.go +++ b/cmd/geth/usage.go @@ -81,7 +81,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{ Flags: []cli.Flag{ utils.DeveloperFlag, utils.DeveloperPeriodFlag, - utils.DeveloperEthashFlag, + utils.DeveloperPoWFlag, }, }, { diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 487cb4a2e9..ea48daeec2 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -194,8 +194,8 @@ var ( Name: "dev.period", Usage: "Block period for proof-of-authority network to use in developer mode (0 = mine only if transaction pending)", } - DeveloperEthashFlag = cli.BoolFlag{ - Name: "dev.ethash", + DeveloperPoWFlag = cli.BoolFlag{ + Name: "dev.pow", Usage: "Ephemeral proof-of-work network with a pre-funded developer account, mining enabled", } IdentityFlag = cli.StringFlag{ @@ -1827,7 +1827,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) { } log.Info("Using developer account", "address", developer.Address) - useEthash := ctx.GlobalBool(DeveloperEthashFlag.Name) + useEthash := ctx.GlobalBool(DeveloperPoWFlag.Name) if useEthash { cfg.Ethash.PowMode = ethash.ModeFake } From 682f14ac3eefedfd469f85390cf0d659d63d52f7 Mon Sep 17 00:00:00 2001 From: Chris Ziogas Date: Tue, 1 Dec 2020 23:23:03 +0200 Subject: [PATCH 04/11] =?UTF-8?q?cmd/geth:=20when=20`=E2=80=94dev`=20and?= =?UTF-8?q?=20no=20`=E2=80=94miner.threads`=20set,=20default=20to=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/geth/main.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index fa666639c6..cd6af1df56 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -511,6 +511,9 @@ func startNode(ctx *cli.Context, stack *node.Node, backend ethapi.Backend) { threads = ctx.GlobalInt(utils.LegacyMinerThreadsFlag.Name) log.Warn("The flag --minerthreads is deprecated and will be removed in the future, please use --miner.threads") } + if threads == 0 && ctx.GlobalBool(utils.DeveloperFlag.Name) { + threads = 1 + } if err := ethBackend.StartMining(threads); err != nil { utils.Fatalf("Failed to start mining: %v", err) } From 9dbbe8df1388777b55f1e01abd913d6a366e51df Mon Sep 17 00:00:00 2001 From: Chris Ziogas Date: Wed, 2 Dec 2020 14:43:30 +0200 Subject: [PATCH 05/11] =?UTF-8?q?cmd/geth,=20cmd/utils:=20make=20`?= =?UTF-8?q?=E2=80=94dev`,=20`=E2=80=94dev.period`=20and=20`=E2=80=94dev.po?= =?UTF-8?q?w`=20exclusively=20selected?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/geth/main.go | 10 +++++++--- cmd/utils/flags.go | 13 +++++++------ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index cd6af1df56..ac6a6d6dd8 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -312,7 +312,10 @@ func checkMainnet(ctx *cli.Context) bool { log.Info("Starting Geth on Görli testnet...") case ctx.GlobalIsSet(utils.DeveloperFlag.Name): - log.Info("Starting Geth in ephemeral dev mode...") + log.Info("Starting Geth in ephemeral proof-of-authority network dev mode...") + + case ctx.GlobalIsSet(utils.DeveloperPoWFlag.Name): + log.Info("Starting Geth in ephemeral proof-of-work network dev mode...") case ctx.GlobalIsSet(utils.ClassicFlag.Name): log.Info("Starting Geth on Ethereum Classic...") @@ -489,7 +492,8 @@ func startNode(ctx *cli.Context, stack *node.Node, backend ethapi.Backend) { } // Start auxiliary services if enabled - if ctx.GlobalBool(utils.MiningEnabledFlag.Name) || ctx.GlobalBool(utils.DeveloperFlag.Name) { + isDeveloperMode := ctx.GlobalBool(utils.DeveloperFlag.Name) || ctx.GlobalBool(utils.DeveloperPoWFlag.Name) + if ctx.GlobalBool(utils.MiningEnabledFlag.Name) || isDeveloperMode { // Mining only makes sense if a full Ethereum node is running if ctx.GlobalString(utils.SyncModeFlag.Name) == "light" { utils.Fatalf("Light clients do not support mining") @@ -511,7 +515,7 @@ func startNode(ctx *cli.Context, stack *node.Node, backend ethapi.Backend) { threads = ctx.GlobalInt(utils.LegacyMinerThreadsFlag.Name) log.Warn("The flag --minerthreads is deprecated and will be removed in the future, please use --miner.threads") } - if threads == 0 && ctx.GlobalBool(utils.DeveloperFlag.Name) { + if isDeveloperMode && threads == 0 { threads = 1 } if err := ethBackend.StartMining(threads); err != nil { diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index ea48daeec2..41471cb597 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1256,7 +1256,7 @@ func SetP2PConfig(ctx *cli.Context, cfg *p2p.Config) { cfg.NetRestrict = list } - if ctx.GlobalBool(DeveloperFlag.Name) { + if ctx.GlobalBool(DeveloperFlag.Name) || ctx.GlobalBool(DeveloperPoWFlag.Name) { // --dev mode can't use p2p networking. cfg.MaxPeers = 0 cfg.ListenAddr = ":0" @@ -1345,7 +1345,7 @@ func setDataDir(ctx *cli.Context, cfg *node.Config) { case ctx.GlobalIsSet(DataDirFlag.Name): cfg.DataDir = ctx.GlobalString(DataDirFlag.Name) - case ctx.GlobalBool(DeveloperFlag.Name): + case ctx.GlobalBool(DeveloperFlag.Name) || ctx.GlobalBool(DeveloperPoWFlag.Name): cfg.DataDir = "" // unless explicitly requested, use memory databases case (ctx.GlobalBool(LegacyTestnetFlag.Name) || ctx.GlobalBool(RopstenFlag.Name)) && cfg.DataDir == node.DefaultDataDir(): @@ -1615,9 +1615,9 @@ func SetShhConfig(ctx *cli.Context, stack *node.Node) { // SetEthConfig applies eth-related command line flags to the config. func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) { // Avoid conflicting network flags - CheckExclusive(ctx, DeveloperFlag, LegacyTestnetFlag, RopstenFlag, RinkebyFlag, GoerliFlag, YoloV1Flag, ClassicFlag, KottiFlag, MordorFlag, EthersocialFlag, SocialFlag) + CheckExclusive(ctx, DeveloperFlag, DeveloperPoWFlag, LegacyTestnetFlag, RopstenFlag, RinkebyFlag, GoerliFlag, YoloV1Flag, ClassicFlag, KottiFlag, MordorFlag, EthersocialFlag, SocialFlag) CheckExclusive(ctx, LegacyLightServFlag, LightServeFlag, SyncModeFlag, "light") - CheckExclusive(ctx, DeveloperFlag, ExternalSignerFlag) // Can't use both ephemeral unlocked and external signer + CheckExclusive(ctx, DeveloperFlag, DeveloperPoWFlag, ExternalSignerFlag) // Can't use both ephemeral unlocked and external signer CheckExclusive(ctx, GCModeFlag, "archive", TxLookupLimitFlag) // todo(rjl493456442) make it available for les server // Ancient tx indices pruning is not available for les server now @@ -1625,6 +1625,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) { CheckExclusive(ctx, LegacyLightServFlag, LightServeFlag, TxLookupLimitFlag) CheckExclusive(ctx, AncientFlag, AncientRPCFlag) + CheckExclusive(ctx, DeveloperPoWFlag, DeveloperPeriodFlag) var ks *keystore.KeyStore if keystores := stack.AccountManager().Backends(keystore.KeyStoreType); len(keystores) > 0 { @@ -1794,7 +1795,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) { } } - if ctx.GlobalBool(DeveloperFlag.Name) { + if ctx.GlobalBool(DeveloperFlag.Name) || ctx.GlobalBool(DeveloperPoWFlag.Name) { if !ctx.GlobalIsSet(NetworkIdFlag.Name) { cfg.NetworkId = 1337 } @@ -2016,7 +2017,7 @@ func genesisForCtxChainConfig(ctx *cli.Context) *genesisT.Genesis { } func MakeGenesis(ctx *cli.Context) *genesisT.Genesis { - if ctx.GlobalBool(DeveloperFlag.Name) { + if ctx.GlobalBool(DeveloperFlag.Name) || ctx.GlobalBool(DeveloperPoWFlag.Name) { Fatalf("Developer chains are ephemeral") } return genesisForCtxChainConfig(ctx) From 325248fb7392e347ef463a4741e4f103dddf716c Mon Sep 17 00:00:00 2001 From: Chris Ziogas Date: Wed, 2 Dec 2020 14:46:23 +0200 Subject: [PATCH 06/11] =?UTF-8?q?cmd/utils:=20allow=20`=E2=80=94fakepow`?= =?UTF-8?q?=20to=20be=20used=20in=20geth=20node=20main=20runtime?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/utils/flags.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 41471cb597..d365a6f8bc 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1482,6 +1482,9 @@ func setEthash(ctx *cli.Context, cfg *eth.Config) { setEthashCacheDir(ctx, cfg) setEthashDatasetDir(ctx, cfg) + if ctx.GlobalBool(FakePoWFlag.Name) { + cfg.Ethash.PowMode = ethash.ModeFake + } if ctx.GlobalIsSet(EthashCachesInMemoryFlag.Name) { cfg.Ethash.CachesInMem = ctx.GlobalInt(EthashCachesInMemoryFlag.Name) } @@ -1828,13 +1831,8 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) { } log.Info("Using developer account", "address", developer.Address) - useEthash := ctx.GlobalBool(DeveloperPoWFlag.Name) - if useEthash { - cfg.Ethash.PowMode = ethash.ModeFake - } - // Create a new developer genesis block or reuse existing one - cfg.Genesis = params.DeveloperGenesisBlock(uint64(ctx.GlobalInt(DeveloperPeriodFlag.Name)), developer.Address, useEthash) + cfg.Genesis = params.DeveloperGenesisBlock(uint64(ctx.GlobalInt(DeveloperPeriodFlag.Name)), developer.Address, ctx.GlobalBool(DeveloperPoWFlag.Name)) if ctx.GlobalIsSet(DataDirFlag.Name) { // Check if we have an already initialized chain and fall back to // that if so. Otherwise we need to generate a new genesis spec. From f59836476e805142522d1222cbb7f5beccdb6976 Mon Sep 17 00:00:00 2001 From: Chris Ziogas Date: Wed, 2 Dec 2020 18:23:03 +0200 Subject: [PATCH 07/11] cmd/geth, cmd/utils, consensus/ethash, eth: add `--fakepow.poisson` --- cmd/geth/chaincmd.go | 1 + cmd/geth/main.go | 1 + cmd/geth/usage.go | 1 + cmd/utils/flags.go | 11 ++++++++++- consensus/ethash/ethash.go | 12 ++++++++++++ eth/backend.go | 3 +++ 6 files changed, 28 insertions(+), 1 deletion(-) diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go index 05b0192c56..2b693e1669 100644 --- a/cmd/geth/chaincmd.go +++ b/cmd/geth/chaincmd.go @@ -166,6 +166,7 @@ The export-preimages command export hash preimages to an RLP encoded stream`, utils.CacheFlag, utils.SyncModeFlag, utils.FakePoWFlag, + utils.FakePoWPoissonFlag, utils.ClassicFlag, utils.MordorFlag, utils.KottiFlag, diff --git a/cmd/geth/main.go b/cmd/geth/main.go index ac6a6d6dd8..3e03a95fa3 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -161,6 +161,7 @@ var ( utils.NetworkIdFlag, utils.EthStatsURLFlag, utils.FakePoWFlag, + utils.FakePoWPoissonFlag, utils.NoCompactionFlag, utils.GpoBlocksFlag, utils.LegacyGpoBlocksFlag, diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go index 02ee3b0cb6..a6cd695736 100644 --- a/cmd/geth/usage.go +++ b/cmd/geth/usage.go @@ -215,6 +215,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{ Name: "LOGGING AND DEBUGGING", Flags: append([]cli.Flag{ utils.FakePoWFlag, + utils.FakePoWPoissonFlag, utils.NoCompactionFlag, }, debug.Flags...), }, diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index d365a6f8bc..c3525e2944 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -521,6 +521,10 @@ var ( Name: "fakepow", Usage: "Disables proof-of-work verification", } + FakePoWPoissonFlag = cli.BoolFlag{ + Name: "fakepow.poisson", + Usage: "Disables proof-of-work verification and adds mining delay (Poisson) based on --miner.threads", + } NoCompactionFlag = cli.BoolFlag{ Name: "nocompaction", Usage: "Disables db compaction after import", @@ -1484,6 +1488,8 @@ func setEthash(ctx *cli.Context, cfg *eth.Config) { if ctx.GlobalBool(FakePoWFlag.Name) { cfg.Ethash.PowMode = ethash.ModeFake + } else if ctx.GlobalBool(FakePoWPoissonFlag.Name) { + cfg.Ethash.PowMode = ethash.ModePoissonFake } if ctx.GlobalIsSet(EthashCachesInMemoryFlag.Name) { cfg.Ethash.CachesInMem = ctx.GlobalInt(EthashCachesInMemoryFlag.Name) @@ -1629,6 +1635,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) { CheckExclusive(ctx, AncientFlag, AncientRPCFlag) CheckExclusive(ctx, DeveloperPoWFlag, DeveloperPeriodFlag) + CheckExclusive(ctx, FakePoWFlag, FakePoWPoissonFlag) var ks *keystore.KeyStore if keystores := stack.AccountManager().Backends(keystore.KeyStoreType); len(keystores) > 0 { @@ -2037,7 +2044,9 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readOnly bool) (chain *core.B }, chainDb) } else { engine = ethash.NewFaker() - if !ctx.GlobalBool(FakePoWFlag.Name) { + if ctx.GlobalBool(FakePoWPoissonFlag.Name) { + engine = ethash.NewPoissonFaker() + } else if !ctx.GlobalBool(FakePoWFlag.Name) { engine = ethash.New(ethash.Config{ CacheDir: stack.ResolvePath(eth.DefaultConfig.Ethash.CacheDir), CachesInMem: eth.DefaultConfig.Ethash.CachesInMem, diff --git a/consensus/ethash/ethash.go b/consensus/ethash/ethash.go index fe0c61d96a..f5e6778237 100644 --- a/consensus/ethash/ethash.go +++ b/consensus/ethash/ethash.go @@ -642,6 +642,18 @@ func NewFakeDelayer(delay time.Duration) *Ethash { } } +// NewPoissonFaker creates a ethash consensus engine with a fake PoW scheme that +// accepts all blocks as valid, but delays mining by some time based on miner.threads, though +// they still have to conform to the Ethereum consensus rules. +func NewPoissonFaker() *Ethash { + return &Ethash{ + config: Config{ + PowMode: ModePoissonFake, + Log: log.Root(), + }, + } +} + // NewFullFaker creates an ethash consensus engine with a full fake scheme that // accepts all blocks as valid, without checking any consensus rules whatsoever. func NewFullFaker() *Ethash { diff --git a/eth/backend.go b/eth/backend.go index 284f938565..e8238137f7 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -270,6 +270,9 @@ func CreateConsensusEngine(stack *node.Node, chainConfig ctypes.ChainConfigurato case ethash.ModeFake: log.Warn("Ethash used in fake mode") return ethash.NewFaker() + case ethash.ModePoissonFake: + log.Warn("Ethash used in fake Poisson mode") + return ethash.NewPoissonFaker() case ethash.ModeTest: log.Warn("Ethash used in test mode") return ethash.NewTester(nil, noverify) From 25969d9ad650d3dad96f547d18fe3823b0bfe19c Mon Sep 17 00:00:00 2001 From: Chris Ziogas Date: Fri, 4 Dec 2020 10:42:45 +0200 Subject: [PATCH 08/11] cmd/geth: set threads=1 on developer chain mode, only when threads not explicitly set from CLI --- cmd/geth/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 3e03a95fa3..8d45cb76eb 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -516,7 +516,7 @@ func startNode(ctx *cli.Context, stack *node.Node, backend ethapi.Backend) { threads = ctx.GlobalInt(utils.LegacyMinerThreadsFlag.Name) log.Warn("The flag --minerthreads is deprecated and will be removed in the future, please use --miner.threads") } - if isDeveloperMode && threads == 0 { + if isDeveloperMode && !ctx.GlobalIsSet(utils.MinerThreadsFlag.Name) && !ctx.GlobalIsSet(utils.LegacyMinerThreadsFlag.Name) { threads = 1 } if err := ethBackend.StartMining(threads); err != nil { From 6eb9ce9e7b0ef097880deb3b65b616959a549077 Mon Sep 17 00:00:00 2001 From: Chris Ziogas Date: Fri, 4 Dec 2020 16:21:33 +0200 Subject: [PATCH 09/11] =?UTF-8?q?cmd/utils:=20disallow=20`=E2=80=94fakepow?= =?UTF-8?q?`=20with=20`=E2=80=94dev.pow`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/utils/flags.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index c3525e2944..c09a2f28e2 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1486,9 +1486,7 @@ func setEthash(ctx *cli.Context, cfg *eth.Config) { setEthashCacheDir(ctx, cfg) setEthashDatasetDir(ctx, cfg) - if ctx.GlobalBool(FakePoWFlag.Name) { - cfg.Ethash.PowMode = ethash.ModeFake - } else if ctx.GlobalBool(FakePoWPoissonFlag.Name) { + if ctx.GlobalBool(FakePoWPoissonFlag.Name) { cfg.Ethash.PowMode = ethash.ModePoissonFake } if ctx.GlobalIsSet(EthashCachesInMemoryFlag.Name) { @@ -1634,7 +1632,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) { CheckExclusive(ctx, LegacyLightServFlag, LightServeFlag, TxLookupLimitFlag) CheckExclusive(ctx, AncientFlag, AncientRPCFlag) - CheckExclusive(ctx, DeveloperPoWFlag, DeveloperPeriodFlag) + CheckExclusive(ctx, DeveloperPoWFlag, DeveloperPeriodFlag, FakePoWFlag) CheckExclusive(ctx, FakePoWFlag, FakePoWPoissonFlag) var ks *keystore.KeyStore From f4530b2c1cab406bc45f35f4429d1573490d1be5 Mon Sep 17 00:00:00 2001 From: meows Date: Fri, 4 Dec 2020 09:04:57 -0600 Subject: [PATCH 10/11] params: use custom genesis&config for dev.pow This installs an ETC-derived genesis and config for dev.pow mode. Block reward disinflation is disabled, so block rewards will always be at their initial rates. Difficulty bomb is defused from genesis, so no need to worry about that, ever, if CPU mining. Date: 2020-12-04 09:04:57-06:00 Signed-off-by: meows --- params/genesis.go | 80 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 73 insertions(+), 7 deletions(-) diff --git a/params/genesis.go b/params/genesis.go index 993e6f0386..8a1c68df71 100644 --- a/params/genesis.go +++ b/params/genesis.go @@ -22,8 +22,11 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/params/types/coregeth" + "github.com/ethereum/go-ethereum/params/types/ctypes" "github.com/ethereum/go-ethereum/params/types/genesisT" "github.com/ethereum/go-ethereum/params/types/goethereum" + "github.com/ethereum/go-ethereum/params/vars" ) // DefaultGenesisBlock returns the Ethereum main net genesis block. @@ -88,13 +91,76 @@ func DefaultYoloV1GenesisBlock() *genesisT.Genesis { // DeveloperGenesisBlock returns the 'geth --dev' genesis block. Note, this must // be seeded with the func DeveloperGenesisBlock(period uint64, faucet common.Address, useEthash bool) *genesisT.Genesis { - // Override the default period to the user requested one - var config *goethereum.ChainConfig - if useEthash { - config = AllEthashProtocolChanges - } else { - config = AllCliqueProtocolChanges + if !useEthash { + // Make a copy to avoid unpredicted contamination. + config := &goethereum.ChainConfig{} + *config = *AllCliqueProtocolChanges + + // Override the default period to the user requested one config.Clique.Period = period + // Assemble and return the genesis with the precompiles and faucet pre-funded + return &genesisT.Genesis{ + Config: config, + ExtraData: append(append(make([]byte, 32), faucet[:]...), make([]byte, crypto.SignatureLength)...), + GasLimit: 6283185, + Difficulty: big.NewInt(1), + Alloc: map[common.Address]genesisT.GenesisAccount{ + common.BytesToAddress([]byte{1}): {Balance: big.NewInt(1)}, // ECRecover + common.BytesToAddress([]byte{2}): {Balance: big.NewInt(1)}, // SHA256 + common.BytesToAddress([]byte{3}): {Balance: big.NewInt(1)}, // RIPEMD + common.BytesToAddress([]byte{4}): {Balance: big.NewInt(1)}, // Identity + common.BytesToAddress([]byte{5}): {Balance: big.NewInt(1)}, // ModExp + common.BytesToAddress([]byte{6}): {Balance: big.NewInt(1)}, // ECAdd + common.BytesToAddress([]byte{7}): {Balance: big.NewInt(1)}, // ECScalarMul + common.BytesToAddress([]byte{8}): {Balance: big.NewInt(1)}, // ECPairing + faucet: {Balance: new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(9))}, + }, + } + } + + // Use an ETC equivalent of AllEthashProtocolChanges. + // This will allow initial permanent disposal of the difficulty bomb, + // and we'll override the monetary policy block reward schedule to be a non-occurring. + // + // This was originally intended to be as follows, but import cycles prevent it. + // Leaving here to show provenance of initial configuration value. + // config := &coregeth.CoreGethChainConfig{} + // *config = *tests.Forks["ETC_Phoenix"].(*coregeth.CoreGethChainConfig) + config := &coregeth.CoreGethChainConfig{ + NetworkID: AllCliqueProtocolChanges.GetChainID().Uint64(), // Use network and chain IDs equivalent to Clique configuration, ie 1337. + Ethash: new(ctypes.EthashConfig), + ChainID: AllCliqueProtocolChanges.GetChainID(), + EIP2FBlock: big.NewInt(0), + EIP7FBlock: big.NewInt(0), + EIP150Block: big.NewInt(0), + EIP155Block: big.NewInt(0), + EIP160FBlock: big.NewInt(0), + EIP161FBlock: big.NewInt(0), + EIP170FBlock: big.NewInt(0), + EIP100FBlock: big.NewInt(0), + EIP140FBlock: big.NewInt(0), + EIP198FBlock: big.NewInt(0), + EIP211FBlock: big.NewInt(0), + EIP212FBlock: big.NewInt(0), + EIP213FBlock: big.NewInt(0), + EIP214FBlock: big.NewInt(0), + EIP658FBlock: big.NewInt(0), + EIP145FBlock: big.NewInt(0), + EIP1014FBlock: big.NewInt(0), + EIP1052FBlock: big.NewInt(0), + EIP1283FBlock: big.NewInt(0), + PetersburgBlock: big.NewInt(0), + EIP152FBlock: big.NewInt(0), + EIP1108FBlock: big.NewInt(0), + EIP1344FBlock: big.NewInt(0), + EIP1884FBlock: big.NewInt(0), + EIP2028FBlock: big.NewInt(0), + EIP2200FBlock: big.NewInt(0), + DisposalBlock: big.NewInt(0), + ECIP1017FBlock: nil, // disable block reward disinflation + ECIP1017EraRounds: nil, // ^ + ECIP1010PauseBlock: nil, // no need for difficulty bomb delay (see disposal block) + ECIP1010Length: nil, // ^ } // Assemble and return the genesis with the precompiles and faucet pre-funded @@ -102,7 +168,7 @@ func DeveloperGenesisBlock(period uint64, faucet common.Address, useEthash bool) Config: config, ExtraData: append(append(make([]byte, 32), faucet[:]...), make([]byte, crypto.SignatureLength)...), GasLimit: 6283185, - Difficulty: big.NewInt(1), + Difficulty: vars.MinimumDifficulty, Alloc: map[common.Address]genesisT.GenesisAccount{ common.BytesToAddress([]byte{1}): {Balance: big.NewInt(1)}, // ECRecover common.BytesToAddress([]byte{2}): {Balance: big.NewInt(1)}, // SHA256 From 190920df8f54d6b2ab8bac3c2c572b4e44486ab6 Mon Sep 17 00:00:00 2001 From: meows Date: Fri, 4 Dec 2020 09:10:42 -0600 Subject: [PATCH 11/11] main: remove fakepow.poisson flag from 'copydb' command Since this flag is only useful for mining (block emission), we don't need it for copydb, which just runs the import of chain data. Fakepow can be used to import more quickly by cutting corners and not doing ethash field verification, eg if you really trust the chaindata that you're copying. Date: 2020-12-04 09:10:42-06:00 Signed-off-by: meows --- cmd/geth/chaincmd.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go index 2b693e1669..05b0192c56 100644 --- a/cmd/geth/chaincmd.go +++ b/cmd/geth/chaincmd.go @@ -166,7 +166,6 @@ The export-preimages command export hash preimages to an RLP encoded stream`, utils.CacheFlag, utils.SyncModeFlag, utils.FakePoWFlag, - utils.FakePoWPoissonFlag, utils.ClassicFlag, utils.MordorFlag, utils.KottiFlag,