Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/ezdev #26

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e8e428e
init dev config files
whilei Nov 21, 2018
3f98091
Fork blocks -> 0, set dev_ file names in config files
whilei Nov 21, 2018
5646f08
init basic feature functionality
whilei Nov 21, 2018
1613926
setup and parse genesis alloc acc:bals
whilei Nov 21, 2018
9e62337
rm keys/ from testing
whilei Nov 21, 2018
086879f
init basic functionality miner.automine (without nonce pow validation)
whilei Nov 21, 2018
ad21687
instructions and notes
whilei Nov 21, 2018
317f036
include instructions for test js
whilei Nov 21, 2018
ecaf620
only write main config file when not present
whilei Nov 21, 2018
1f22472
problem: ezdev overwrites config each run
whilei Nov 21, 2018
afdb01d
add link for test js to make obvious
whilei Nov 21, 2018
979bad2
shane wants no passwords
whilei Nov 21, 2018
97959ba
make chainid 69 2
whilei Nov 21, 2018
56406bc
make readme more legible
whilei Nov 21, 2018
94b2e4b
remove very verbose block logger
whilei Nov 21, 2018
687bd2c
fix maybe it wasn't automining... adjusting test.js to send moar txs'
whilei Nov 22, 2018
56281fc
problem: nil pointer on worker work and blockWithMiningREsult
whilei Nov 22, 2018
2a5be9c
remove scrap file
whilei Nov 26, 2018
dab83cf
add block write stat to NewMinedBlockEvent
whilei Nov 26, 2018
544eadb
test.js: add loggers and time meters
whilei Nov 26, 2018
506b8fd
problem: tx/block creation stalls for 5 seconds
whilei Nov 26, 2018
1f1605f
problem: decoding genesis address fails occasionally
whilei Nov 26, 2018
adf0b2c
problem@txpool: current state getting errors should log to error logs
whilei Nov 26, 2018
7f597bb
unnecessarily random nonces; use plain time
whilei Nov 26, 2018
406f8e7
ensure no nil work by using mutex, ...
whilei Nov 26, 2018
3acff68
readem updates
whilei Nov 26, 2018
7bdb94f
remove dead code, fix comments
whilei Nov 26, 2018
580c8a0
core/types: minor refactoring for tx helpers
whilei Nov 28, 2018
1fba1ed
problem@cmd/geth: messy code, mining not set with ezdev
whilei Nov 28, 2018
97a890f
miner: minor refactoring and logging
whilei Nov 28, 2018
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
343 changes: 15 additions & 328 deletions README.md

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions cmd/geth/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
"syscall"
"time"

"math"

"github.com/ethereumproject/ethash"
"github.com/ethereumproject/go-ethereum/common"
"github.com/ethereumproject/go-ethereum/core"
Expand All @@ -44,7 +46,6 @@ import (
"github.com/ethereumproject/go-ethereum/pow"
"github.com/ethereumproject/go-ethereum/rlp"
"gopkg.in/urfave/cli.v1"
"math"
)

const (
Expand Down Expand Up @@ -637,7 +638,7 @@ func rollback(ctx *cli.Context) error {
func dumpChainConfig(ctx *cli.Context) error {

chainIdentity := mustMakeChainIdentity(ctx)
if !(core.ChainIdentitiesMain[chainIdentity] || core.ChainIdentitiesMorden[chainIdentity]) {
if !(core.ChainIdentitiesMain[chainIdentity] || core.ChainIdentitiesMorden[chainIdentity] || chainIdentity == "ezdev") {
glog.Fatal("Dump config should only be used with default chain configurations (mainnet or morden).")
}

Expand Down Expand Up @@ -696,6 +697,10 @@ func dumpChainConfig(ctx *cli.Context) error {
Bootstrap: nodes,
}

if ctx.GlobalBool(EZDevModeFlag.Name) {
currentConfig = core.DefaultConfigEZDev
}

if writeError := currentConfig.WriteToJSONFile(chainConfigFilePath); writeError != nil {
glog.Fatalf("An error occurred while writing chain configuration: %v", writeError)
return writeError
Expand Down
113 changes: 113 additions & 0 deletions cmd/geth/ezdev.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package main

import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"

"github.com/ethereumproject/go-ethereum/core"
"github.com/ethereumproject/go-ethereum/logger"
"github.com/ethereumproject/go-ethereum/logger/glog"
"gopkg.in/urfave/cli.v1"
)

func mustSetCTXDefault(ctx *cli.Context, name, val string) {
if err := ctx.GlobalSet(aliasableName(name, ctx), val); err != nil {
log.Fatal(err)
}
}

func setEZDevFlags(ctx *cli.Context) {
mustSetCTXDefault(ctx, NoDiscoverFlag.Name, "true")
mustSetCTXDefault(ctx, LightKDFFlag.Name, "true")
mustSetCTXDefault(ctx, MiningEnabledFlag.Name, "true")
}

func setupEZDev(ctx *cli.Context, config *core.SufficientChainConfig) error {
// set flag config defaults
// copy dev.json, dev_genesis.json, dev_genesis_allow.csv to datadir/ezdev/{ chain, dev_genesis, dev_genesis_alloc }.json/csv,
// init 10 accounts with password 'foo'
// add these accounts to genesis alloc csv

config.Include = []string{"dev_genesis.json"}

cg := config.Genesis

// Set original genesis to nil so no conflict between GenesisAlloc field and present Genesis obj.
config.Genesis = nil
cg.AllocFile = "dev_genesis_alloc.csv"

// because this cli ctx is weird and accounts seem slower to generate if this isn't here
setEZDevFlags(ctx)

// cc.Genesis = cg
// make some accounts
accman := MakeAccountManager(ctx)
data := []byte{}
bal := "10000000000000000000000000000000"
if len(accman.Accounts()) == 0 {
glog.D(logger.Warn).Infoln("No existing EZDEV accounts found, creating 10")
password := ""
// accounts := []accounts.Account{}
for i := 0; i < 10; i++ {
acc, err := accman.NewAccount(password)
if err != nil {
return err
}
// accounts = append(accounts, acc)
// a := acc.Address.Hex()
a := strings.Replace(acc.Address.Hex(), "0x", "", -1)
d := fmt.Sprintf(`"%s","%v"
`, a, bal)
glog.D(logger.Warn).Infoln(acc.Address.Hex(), acc.File)
// b, ok := new(big.Int).SetString(bal, 10)
// if !ok {
// panic("not ok set string", b, bal)
// }
data = append(data, []byte(d)...)
}
} else {
glog.D(logger.Warn).Infoln("Found existing keyfiles, using: ")
for _, acc := range accman.Accounts() {
d := fmt.Sprintf("%s,%v\n", acc.Address.Hex(), bal)
glog.D(logger.Warn).Infoln(acc.Address.Hex(), acc.File)
data = append(data, []byte(d)...)
}
}

// marshal and write config json IFF it doesn't already exist
if _, err := os.Stat(filepath.Join(MustMakeChainDataDir(ctx), "chain.json")); err != nil && os.IsNotExist(err) {

if err := config.WriteToJSONFile(filepath.Join(MustMakeChainDataDir(ctx), "chain.json")); err != nil {
return err
}
}

// marshal and write dev_genesis.json
genC, err := json.MarshalIndent(struct {
Genesis *core.GenesisDump `json:"genesis"`
}{cg}, "", " ")
if err != nil {
return fmt.Errorf("Could not marshal json from chain config: %v", err)
}
if err := ioutil.WriteFile(filepath.Join(MustMakeChainDataDir(ctx), "dev_genesis.json"), genC, 0644); err != nil {
return err
}

// write alloc file, ALWAYS, because these never change and it's just extra logic, even though it would seem more right to care if the file already exists or not
ioutil.WriteFile(filepath.Join(MustMakeChainDataDir(ctx), "dev_genesis_alloc.csv"), data, os.ModePerm)

// again.. hacky. maybe unnecessary.
cc, err := core.ReadExternalChainConfigFromFile(filepath.Join(MustMakeChainDataDir(ctx), "chain.json"))
if err != nil {
panic(err)
}
config.Genesis = cc.Genesis
config.ChainConfig.Automine = true

return nil
}
17 changes: 17 additions & 0 deletions cmd/geth/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ func mustMakeChainIdentity(ctx *cli.Context) (identity string) {
}
// glog.V(logger.Debug).Infof("No existing file at --%v: '%v'. Using literal chain identity.", aliasableName(ChainIdentityFlag.Name, ctx), chainFlagVal)
identity = chainFlagVal

glog.Error("parse chain identity", identity)

return identity
} else if ctx.GlobalIsSet(aliasableName(ChainIdentityFlag.Name, ctx)) {
glog.Fatalf("%v: %v: chainID empty", ErrInvalidFlag, core.ErrInvalidChainID)
Expand Down Expand Up @@ -478,6 +481,13 @@ func MakeSystemNode(version string, ctx *cli.Context) *node.Node {
miner.HeaderExtra = []byte(s)
}

if ctx.GlobalBool(EZDevModeFlag.Name) {
setEZDevFlags(ctx)
if err := setupEZDev(ctx, core.DefaultConfigEZDev); err != nil {
panic(err)
}
}

// Makes sufficient configuration from JSON file or DB pending flags.
// Delegates flag usage.
config := mustMakeSufficientChainConfig(ctx)
Expand Down Expand Up @@ -691,6 +701,12 @@ func mustMakeSufficientChainConfig(ctx *cli.Context) *core.SufficientChainConfig
state.StartingNonce = state.DefaultTestnetStartingNonce // (2**20)
}
return config
} else if ctx.GlobalBool(EZDevModeFlag.Name) {
c := core.DefaultConfigEZDev
if c.State != nil {
state.StartingNonce = c.State.StartingNonce
}
return c
}

// Returns surely valid suff chain config.
Expand All @@ -707,6 +723,7 @@ func mustMakeSufficientChainConfig(ctx *cli.Context) *core.SufficientChainConfig
`, core.ErrChainConfigNotFound, defaultChainConfigPath,
chainDir, chainIdentity, chainDir, chainDir)
}
glog.D(logger.Warn).Infoln("Reading chain config from", defaultChainConfigPath)
config, err := core.ReadExternalChainConfigFromFile(defaultChainConfigPath)
if err != nil {
glog.Fatalf(`invalid external configuration JSON: '%v': %v
Expand Down
4 changes: 4 additions & 0 deletions cmd/geth/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ var (
Name: "dev",
Usage: "Developer mode: pre-configured private network with several debugging flags",
}
EZDevModeFlag = cli.BoolFlag{
Name: "ezdev",
Usage: "EZ Developer mode: pre-configured private network, automining, default accounts",
}
NodeNameFlag = cli.StringFlag{
Name: "identity,name",
Usage: "Custom node name",
Expand Down
5 changes: 3 additions & 2 deletions cmd/geth/log_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import (
"os"
"path/filepath"

"net"

"github.com/ethereumproject/go-ethereum/logger"
"github.com/ethereumproject/go-ethereum/logger/glog"
"github.com/ethereumproject/go-ethereum/p2p/discover"
"net"
)

const defaultStatusLog = "sync=60s"
Expand Down Expand Up @@ -54,7 +55,7 @@ func setupLogging(ctx *cli.Context) error {
glog.SetToStderr(true)
}
} else {
logDir = filepath.Join(MustMakeChainDataDir(ctx), glog.DefaultLogDirName)
logDir = filepath.Join(mustMakeDataDir(ctx), mustMakeChainIdentity(ctx), glog.DefaultLogDirName)
}

// Allow to-file logging to be disabled
Expand Down
2 changes: 1 addition & 1 deletion cmd/geth/log_display_basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var basicDisplaySystem = displayEventHandlers{
switch d := evData.(type) {
case core.NewMinedBlockEvent:
glog.D(logger.Warn).Infof(basicScanLn,
"Mined",
"Mined "+d.Stat.String(),
formatBlockNumber(d.Block.NumberU64()),
d.Block.Hash().Hex()[2:2+len(xlocalHeadHashD)],
fmt.Sprintf("%3d/%2d", d.Block.Transactions().Len(), new(big.Int).Div(d.Block.GasUsed(), big.NewInt(1000000)).Int64()),
Expand Down
33 changes: 17 additions & 16 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ func makeCLIApp() (app *cli.App) {
PreloadJSFlag,
WhisperEnabledFlag,
DevModeFlag,
EZDevModeFlag,
TestNetFlag,
NetworkIdFlag,
RPCCORSDomainFlag,
Expand Down Expand Up @@ -263,21 +264,6 @@ func makeCLIApp() (app *cli.App) {
if err := handleIfDataDirSchemaMigrations(ctx); err != nil {
return err
}

if err := setupLogRotation(ctx); err != nil {
return err
}

// Handle parsing and applying log verbosity, severities, and default configurations from context.
if err := setupLogging(ctx); err != nil {
return err
}

// Handle parsing and applying log rotation configs from context.
if err := setupLogRotation(ctx); err != nil {
return err
}

if s := ctx.String("metrics"); s != "" {
go metrics.CollectToFile(s)
}
Expand All @@ -292,12 +278,27 @@ func makeCLIApp() (app *cli.App) {
// Set morden chain by default for dev mode.
if ctx.GlobalBool(aliasableName(DevModeFlag.Name, ctx)) {
if !ctx.GlobalIsSet(aliasableName(ChainIdentityFlag.Name, ctx)) {
if e := ctx.Set(aliasableName(ChainIdentityFlag.Name, ctx), "morden"); e != nil {
if e := ctx.GlobalSet(ChainIdentityFlag.Name, "morden"); e != nil {
return fmt.Errorf("failed to set chain value: %v", e)
}
}
}

if ctx.GlobalBool(aliasableName(EZDevModeFlag.Name, ctx)) {
log.Println("Turning on EZDEV...")
core.SetCacheChainIdentity("ezdev")
}

// Handle parsing and applying log verbosity, severities, and default configurations from context.
if err := setupLogging(ctx); err != nil {
return err
}

// Handle parsing and applying log rotation configs from context.
if err := setupLogRotation(ctx); err != nil {
return err
}

if port := ctx.GlobalInt(PprofFlag.Name); port != 0 {
interval := 5 * time.Second
if i := ctx.GlobalInt(PprofIntervalFlag.Name); i > 0 {
Expand Down
Loading