Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ var (
utils.EthProtocolsFlag,
utils.DeveloperFlag,
utils.DeveloperPeriodFlag,
utils.DeveloperPoWFlag,
utils.ClassicFlag,
utils.MordorFlag,
utils.SocialFlag,
Expand Down Expand Up @@ -510,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) {
Comment thread
ziogaschr marked this conversation as resolved.
Outdated
threads = 1
}
if err := ethBackend.StartMining(threads); err != nil {
utils.Fatalf("Failed to start mining: %v", err)
}
Expand Down
1 change: 1 addition & 0 deletions cmd/geth/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{
Flags: []cli.Flag{
utils.DeveloperFlag,
utils.DeveloperPeriodFlag,
utils.DeveloperPoWFlag,
},
},
{
Expand Down
13 changes: 11 additions & 2 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
}
DeveloperPoWFlag = cli.BoolFlag{
Name: "dev.pow",
Usage: "Ephemeral proof-of-work network with a pre-funded developer account, mining enabled",
Comment thread
ziogaschr marked this conversation as resolved.
}
IdentityFlag = cli.StringFlag{
Name: "identity",
Expand Down Expand Up @@ -1823,8 +1827,13 @@ 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)
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.
Expand Down
2 changes: 1 addition & 1 deletion console/console_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func newTester(t *testing.T, confOverride func(*eth.Config)) *tester {
t.Fatalf("failed to create node: %v", err)
}
ethConf := &eth.Config{
Genesis: params.DeveloperGenesisBlock(15, common.Address{}),
Genesis: params.DeveloperGenesisBlock(15, common.Address{}, false),
Miner: miner.Config{
Etherbase: common.HexToAddress(testAddress),
},
Expand Down
2 changes: 1 addition & 1 deletion miner/miner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 10 additions & 4 deletions params/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Comment thread
ziogaschr marked this conversation as resolved.
Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the AllEthashProtocolChanges config going to be OK to use here? There are some considerations that Clique doesn't have to make for PoW, eg. difficulty (and difficulty bomb), block rewards.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I haven't thought of this. I thought it will work as expected based on initial PoW->Clique change.

Block rewards work fine. I wonder if we should care about difficulty bomb in --dev.pow] mode, or a good use case for it

@meowsbits meowsbits Dec 4, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dev mode shouldn't ever activate the difficulty bomb, in my opinion. And since core-geth has the ECIP available to permanently disable it, I think it should do so. We'll need to double check the difficulty field in the genesis block, too, to make sure it is at the params.MinimumDifficulty (or whatever it is (that's pseudo-code ;)).

The thought I had in mind with the block rewards was in regards to differences available for ETH vs. ETC. For example, AllEthashProtocolChanges will set the reward to the ETH Istanbul (permanently), while ETC might, say, set it to Era 1 of ECIP1017, and would then need to establish some arbitrary value for the Era Rounds length (ie probably not 500000)... maybe math.MaxUint64.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one, thanks for analysing that, it really helps me to grasp the whole system.
I will have a look at it. It will be nice if you can give some tips on it @meowsbits , so as I learn and not spending so much time.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, check out f4530b2

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, very informative. EIPs used for block rewards and difficulty bomb noted. Own you a beer

} 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),
Expand Down