From 1d7d7f57d0fefa8797fbb269f1de76bca3e73dc3 Mon Sep 17 00:00:00 2001 From: Sorin Neacsu Date: Fri, 15 Dec 2017 13:31:10 -0800 Subject: cmd/geth: add support for geth --rinkeby attach --- cmd/geth/consolecmd.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'cmd') diff --git a/cmd/geth/consolecmd.go b/cmd/geth/consolecmd.go index 2c6b16687..9d5cc38a1 100644 --- a/cmd/geth/consolecmd.go +++ b/cmd/geth/consolecmd.go @@ -120,8 +120,12 @@ func remoteConsole(ctx *cli.Context) error { if ctx.GlobalIsSet(utils.DataDirFlag.Name) { path = ctx.GlobalString(utils.DataDirFlag.Name) } - if path != "" && ctx.GlobalBool(utils.TestnetFlag.Name) { - path = filepath.Join(path, "testnet") + if path != "" { + if ctx.GlobalBool(utils.TestnetFlag.Name) { + path = filepath.Join(path, "testnet") + } else if ctx.GlobalBool(utils.RinkebyFlag.Name) { + path = filepath.Join(path, "rinkeby") + } } endpoint = fmt.Sprintf("%s/geth.ipc", path) } -- cgit v1.2.3 From eeb53bc14301a54aee7cd7e1475e296155ee986d Mon Sep 17 00:00:00 2001 From: Steven Roose Date: Thu, 21 Dec 2017 11:36:05 +0100 Subject: cmd/ethkey: new command line tool for keys (#15438) ethkey is a new tool that serves as a command line interface to the basic key management functionalities of geth. It currently supports: - generating keyfiles - inspecting keyfiles (print public and private key) - signing messages - verifying signed messages --- cmd/ethkey/README.md | 41 ++++++++++++++ cmd/ethkey/generate.go | 117 ++++++++++++++++++++++++++++++++++++++ cmd/ethkey/inspect.go | 74 +++++++++++++++++++++++++ cmd/ethkey/main.go | 70 +++++++++++++++++++++++ cmd/ethkey/message.go | 148 +++++++++++++++++++++++++++++++++++++++++++++++++ cmd/ethkey/utils.go | 83 +++++++++++++++++++++++++++ 6 files changed, 533 insertions(+) create mode 100644 cmd/ethkey/README.md create mode 100644 cmd/ethkey/generate.go create mode 100644 cmd/ethkey/inspect.go create mode 100644 cmd/ethkey/main.go create mode 100644 cmd/ethkey/message.go create mode 100644 cmd/ethkey/utils.go (limited to 'cmd') diff --git a/cmd/ethkey/README.md b/cmd/ethkey/README.md new file mode 100644 index 000000000..cf72ba43d --- /dev/null +++ b/cmd/ethkey/README.md @@ -0,0 +1,41 @@ +ethkey +====== + +ethkey is a simple command-line tool for working with Ethereum keyfiles. + + +# Usage + +### `ethkey generate` + +Generate a new keyfile. +If you want to use an existing private key to use in the keyfile, it can be +specified by setting `--privatekey` with the location of the file containing the +private key. + + +### `ethkey inspect ` + +Print various information about the keyfile. +Private key information can be printed by using the `--private` flag; +make sure to use this feature with great caution! + + +### `ethkey sign ` + +Sign the message with a keyfile. +It is possible to refer to a file containing the message. + + +### `ethkey verify
` + +Verify the signature of the message. +It is possible to refer to a file containing the message. + + +## Passphrases + +For every command that uses a keyfile, you will be prompted to provide the +passphrase for decrypting the keyfile. To avoid this message, it is possible +to pass the passphrase by using the `--passphrase` flag pointing to a file that +contains the passphrase. diff --git a/cmd/ethkey/generate.go b/cmd/ethkey/generate.go new file mode 100644 index 000000000..dee0e9d70 --- /dev/null +++ b/cmd/ethkey/generate.go @@ -0,0 +1,117 @@ +package main + +import ( + "crypto/ecdsa" + "crypto/rand" + "fmt" + "io/ioutil" + "os" + "path/filepath" + + "github.com/ethereum/go-ethereum/accounts/keystore" + "github.com/ethereum/go-ethereum/cmd/utils" + "github.com/ethereum/go-ethereum/crypto" + "github.com/pborman/uuid" + "gopkg.in/urfave/cli.v1" +) + +type outputGenerate struct { + Address string + AddressEIP55 string +} + +var commandGenerate = cli.Command{ + Name: "generate", + Usage: "generate new keyfile", + ArgsUsage: "[ ]", + Description: ` +Generate a new keyfile. +If you want to use an existing private key to use in the keyfile, it can be +specified by setting --privatekey with the location of the file containing the +private key.`, + Flags: []cli.Flag{ + passphraseFlag, + jsonFlag, + cli.StringFlag{ + Name: "privatekey", + Usage: "the file from where to read the private key to " + + "generate a keyfile for", + }, + }, + Action: func(ctx *cli.Context) error { + // Check if keyfile path given and make sure it doesn't already exist. + keyfilepath := ctx.Args().First() + if keyfilepath == "" { + keyfilepath = defaultKeyfileName + } + if _, err := os.Stat(keyfilepath); err == nil { + utils.Fatalf("Keyfile already exists at %s.", keyfilepath) + } else if !os.IsNotExist(err) { + utils.Fatalf("Error checking if keyfile exists: %v", err) + } + + var privateKey *ecdsa.PrivateKey + + // First check if a private key file is provided. + privateKeyFile := ctx.String("privatekey") + if privateKeyFile != "" { + privateKeyBytes, err := ioutil.ReadFile(privateKeyFile) + if err != nil { + utils.Fatalf("Failed to read the private key file '%s': %v", + privateKeyFile, err) + } + + pk, err := crypto.HexToECDSA(string(privateKeyBytes)) + if err != nil { + utils.Fatalf( + "Could not construct ECDSA private key from file content: %v", + err) + } + privateKey = pk + } + + // If not loaded, generate random. + if privateKey == nil { + pk, err := ecdsa.GenerateKey(crypto.S256(), rand.Reader) + if err != nil { + utils.Fatalf("Failed to generate random private key: %v", err) + } + privateKey = pk + } + + // Create the keyfile object with a random UUID. + id := uuid.NewRandom() + key := &keystore.Key{ + Id: id, + Address: crypto.PubkeyToAddress(privateKey.PublicKey), + PrivateKey: privateKey, + } + + // Encrypt key with passphrase. + passphrase := getPassPhrase(ctx, true) + keyjson, err := keystore.EncryptKey(key, passphrase, + keystore.StandardScryptN, keystore.StandardScryptP) + if err != nil { + utils.Fatalf("Error encrypting key: %v", err) + } + + // Store the file to disk. + if err := os.MkdirAll(filepath.Dir(keyfilepath), 0700); err != nil { + utils.Fatalf("Could not create directory %s", filepath.Dir(keyfilepath)) + } + if err := ioutil.WriteFile(keyfilepath, keyjson, 0600); err != nil { + utils.Fatalf("Failed to write keyfile to %s: %v", keyfilepath, err) + } + + // Output some information. + out := outputGenerate{ + Address: key.Address.Hex(), + } + if ctx.Bool(jsonFlag.Name) { + mustPrintJSON(out) + } else { + fmt.Println("Address: ", out.Address) + } + return nil + }, +} diff --git a/cmd/ethkey/inspect.go b/cmd/ethkey/inspect.go new file mode 100644 index 000000000..8a7aeef84 --- /dev/null +++ b/cmd/ethkey/inspect.go @@ -0,0 +1,74 @@ +package main + +import ( + "encoding/hex" + "fmt" + "io/ioutil" + + "github.com/ethereum/go-ethereum/accounts/keystore" + "github.com/ethereum/go-ethereum/cmd/utils" + "github.com/ethereum/go-ethereum/crypto" + "gopkg.in/urfave/cli.v1" +) + +type outputInspect struct { + Address string + PublicKey string + PrivateKey string +} + +var commandInspect = cli.Command{ + Name: "inspect", + Usage: "inspect a keyfile", + ArgsUsage: "", + Description: ` +Print various information about the keyfile. +Private key information can be printed by using the --private flag; +make sure to use this feature with great caution!`, + Flags: []cli.Flag{ + passphraseFlag, + jsonFlag, + cli.BoolFlag{ + Name: "private", + Usage: "include the private key in the output", + }, + }, + Action: func(ctx *cli.Context) error { + keyfilepath := ctx.Args().First() + + // Read key from file. + keyjson, err := ioutil.ReadFile(keyfilepath) + if err != nil { + utils.Fatalf("Failed to read the keyfile at '%s': %v", keyfilepath, err) + } + + // Decrypt key with passphrase. + passphrase := getPassPhrase(ctx, false) + key, err := keystore.DecryptKey(keyjson, passphrase) + if err != nil { + utils.Fatalf("Error decrypting key: %v", err) + } + + // Output all relevant information we can retrieve. + showPrivate := ctx.Bool("private") + out := outputInspect{ + Address: key.Address.Hex(), + PublicKey: hex.EncodeToString( + crypto.FromECDSAPub(&key.PrivateKey.PublicKey)), + } + if showPrivate { + out.PrivateKey = hex.EncodeToString(crypto.FromECDSA(key.PrivateKey)) + } + + if ctx.Bool(jsonFlag.Name) { + mustPrintJSON(out) + } else { + fmt.Println("Address: ", out.Address) + fmt.Println("Public key: ", out.PublicKey) + if showPrivate { + fmt.Println("Private key: ", out.PrivateKey) + } + } + return nil + }, +} diff --git a/cmd/ethkey/main.go b/cmd/ethkey/main.go new file mode 100644 index 000000000..b9b7a18e0 --- /dev/null +++ b/cmd/ethkey/main.go @@ -0,0 +1,70 @@ +// 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 . + +package main + +import ( + "fmt" + "os" + + "github.com/ethereum/go-ethereum/cmd/utils" + "gopkg.in/urfave/cli.v1" +) + +const ( + defaultKeyfileName = "keyfile.json" +) + +var ( + gitCommit = "" // Git SHA1 commit hash of the release (set via linker flags) + + app *cli.App // the main app instance +) + +var ( // Commonly used command line flags. + passphraseFlag = cli.StringFlag{ + Name: "passwordfile", + Usage: "the file that contains the passphrase for the keyfile", + } + + jsonFlag = cli.BoolFlag{ + Name: "json", + Usage: "output JSON instead of human-readable format", + } + + messageFlag = cli.StringFlag{ + Name: "message", + Usage: "the file that contains the message to sign/verify", + } +) + +// Configure the app instance. +func init() { + app = utils.NewApp(gitCommit, "an Ethereum key manager") + app.Commands = []cli.Command{ + commandGenerate, + commandInspect, + commandSignMessage, + commandVerifyMessage, + } +} + +func main() { + if err := app.Run(os.Args); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } +} diff --git a/cmd/ethkey/message.go b/cmd/ethkey/message.go new file mode 100644 index 000000000..ae6b6552d --- /dev/null +++ b/cmd/ethkey/message.go @@ -0,0 +1,148 @@ +package main + +import ( + "encoding/hex" + "fmt" + "io/ioutil" + "os" + "strings" + + "github.com/ethereum/go-ethereum/accounts/keystore" + "github.com/ethereum/go-ethereum/cmd/utils" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" + "gopkg.in/urfave/cli.v1" +) + +type outputSign struct { + Signature string +} + +var commandSignMessage = cli.Command{ + Name: "signmessage", + Usage: "sign a message", + ArgsUsage: " ", + Description: ` +Sign the message with a keyfile. +It is possible to refer to a file containing the message.`, + Flags: []cli.Flag{ + passphraseFlag, + jsonFlag, + }, + Action: func(ctx *cli.Context) error { + keyfilepath := ctx.Args().First() + message := []byte(ctx.Args().Get(1)) + + // Load the keyfile. + keyjson, err := ioutil.ReadFile(keyfilepath) + if err != nil { + utils.Fatalf("Failed to read the keyfile at '%s': %v", + keyfilepath, err) + } + + // Decrypt key with passphrase. + passphrase := getPassPhrase(ctx, false) + key, err := keystore.DecryptKey(keyjson, passphrase) + if err != nil { + utils.Fatalf("Error decrypting key: %v", err) + } + + if len(message) == 0 { + utils.Fatalf("A message must be provided") + } + // Read message if file. + if _, err := os.Stat(string(message)); err == nil { + message, err = ioutil.ReadFile(string(message)) + if err != nil { + utils.Fatalf("Failed to read the message file: %v", err) + } + } + + signature, err := crypto.Sign(signHash(message), key.PrivateKey) + if err != nil { + utils.Fatalf("Failed to sign message: %v", err) + } + + out := outputSign{ + Signature: hex.EncodeToString(signature), + } + if ctx.Bool(jsonFlag.Name) { + mustPrintJSON(out) + } else { + fmt.Println("Signature: ", out.Signature) + } + return nil + }, +} + +type outputVerify struct { + Success bool + RecoveredAddress string + RecoveredPublicKey string +} + +var commandVerifyMessage = cli.Command{ + Name: "verifymessage", + Usage: "verify the signature of a signed message", + ArgsUsage: "
", + Description: ` +Verify the signature of the message. +It is possible to refer to a file containing the message.`, + Flags: []cli.Flag{ + jsonFlag, + }, + Action: func(ctx *cli.Context) error { + addressStr := ctx.Args().First() + signatureHex := ctx.Args().Get(1) + message := []byte(ctx.Args().Get(2)) + + // Determine whether it is a keyfile, public key or address. + if !common.IsHexAddress(addressStr) { + utils.Fatalf("Invalid address: %s", addressStr) + } + address := common.HexToAddress(addressStr) + + signature, err := hex.DecodeString(signatureHex) + if err != nil { + utils.Fatalf("Signature encoding is not hexadecimal: %v", err) + } + + if len(message) == 0 { + utils.Fatalf("A message must be provided") + } + // Read message if file. + if _, err := os.Stat(string(message)); err == nil { + message, err = ioutil.ReadFile(string(message)) + if err != nil { + utils.Fatalf("Failed to read the message file: %v", err) + } + } + + recoveredPubkey, err := crypto.SigToPub(signHash(message), signature) + if err != nil || recoveredPubkey == nil { + utils.Fatalf("Signature verification failed: %v", err) + } + recoveredPubkeyBytes := crypto.FromECDSAPub(recoveredPubkey) + recoveredAddress := crypto.PubkeyToAddress(*recoveredPubkey) + + success := address == recoveredAddress + + out := outputVerify{ + Success: success, + RecoveredPublicKey: hex.EncodeToString(recoveredPubkeyBytes), + RecoveredAddress: strings.ToLower(recoveredAddress.Hex()), + } + if ctx.Bool(jsonFlag.Name) { + mustPrintJSON(out) + } else { + if out.Success { + fmt.Println("Signature verification successful!") + } else { + fmt.Println("Signature verification failed!") + } + fmt.Println("Recovered public key: ", out.RecoveredPublicKey) + fmt.Println("Recovered address: ", out.RecoveredAddress) + } + return nil + }, +} diff --git a/cmd/ethkey/utils.go b/cmd/ethkey/utils.go new file mode 100644 index 000000000..0e563bf92 --- /dev/null +++ b/cmd/ethkey/utils.go @@ -0,0 +1,83 @@ +// 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 . + +package main + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "strings" + + "github.com/ethereum/go-ethereum/cmd/utils" + "github.com/ethereum/go-ethereum/console" + "github.com/ethereum/go-ethereum/crypto" + "gopkg.in/urfave/cli.v1" +) + +// getPassPhrase obtains a passphrase given by the user. It first checks the +// --passphrase command line flag and ultimately prompts the user for a +// passphrase. +func getPassPhrase(ctx *cli.Context, confirmation bool) string { + // Look for the --passphrase flag. + passphraseFile := ctx.String(passphraseFlag.Name) + if passphraseFile != "" { + content, err := ioutil.ReadFile(passphraseFile) + if err != nil { + utils.Fatalf("Failed to read passphrase file '%s': %v", + passphraseFile, err) + } + return strings.TrimRight(string(content), "\r\n") + } + + // Otherwise prompt the user for the passphrase. + passphrase, err := console.Stdin.PromptPassword("Passphrase: ") + if err != nil { + utils.Fatalf("Failed to read passphrase: %v", err) + } + if confirmation { + confirm, err := console.Stdin.PromptPassword("Repeat passphrase: ") + if err != nil { + utils.Fatalf("Failed to read passphrase confirmation: %v", err) + } + if passphrase != confirm { + utils.Fatalf("Passphrases do not match") + } + } + return passphrase +} + +// signHash is a helper function that calculates a hash for the given message +// that can be safely used to calculate a signature from. +// +// The hash is calulcated as +// keccak256("\x19Ethereum Signed Message:\n"${message length}${message}). +// +// This gives context to the signed message and prevents signing of transactions. +func signHash(data []byte) []byte { + msg := fmt.Sprintf("\x19Ethereum Signed Message:\n%d%s", len(data), data) + return crypto.Keccak256([]byte(msg)) +} + +// mustPrintJSON prints the JSON encoding of the given object and +// exits the program with an error message when the marshaling fails. +func mustPrintJSON(jsonObject interface{}) { + str, err := json.MarshalIndent(jsonObject, "", " ") + if err != nil { + utils.Fatalf("Failed to marshal JSON object: %v", err) + } + fmt.Println(string(str)) +} -- cgit v1.2.3 From 5258785c81959109138ebeca613f12c277188abc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Thu, 21 Dec 2017 13:56:11 +0200 Subject: cmd, core, eth/tracers: support fancier js tracing (#15516) * cmd, core, eth/tracers: support fancier js tracing * eth, internal/web3ext: rework trace API, concurrency, chain tracing * eth/tracers: add three more JavaScript tracers * eth/tracers, vendor: swap ottovm to duktape for tracing * core, eth, internal: finalize call tracer and needed extras * eth, tests: prestate tracer, call test suite, rewinding * vendor: fix windows builds for tracer js engine * vendor: temporary duktape fix * eth/tracers: fix up 4byte and evmdis tracer * vendor: pull in latest duktape with my upstream fixes * eth: fix some review comments * eth: rename rewind to reexec to make it more obvious * core/vm: terminate tracing using defers --- cmd/evm/json_logger.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'cmd') diff --git a/cmd/evm/json_logger.go b/cmd/evm/json_logger.go index eb7b0c466..47daf7dbb 100644 --- a/cmd/evm/json_logger.go +++ b/cmd/evm/json_logger.go @@ -19,6 +19,7 @@ package main import ( "encoding/json" "io" + "math/big" "time" "github.com/ethereum/go-ethereum/common" @@ -35,6 +36,10 @@ func NewJSONLogger(cfg *vm.LogConfig, writer io.Writer) *JSONLogger { return &JSONLogger{json.NewEncoder(writer), cfg} } +func (l *JSONLogger) CaptureStart(from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) error { + return nil +} + // CaptureState outputs state information on the logger. func (l *JSONLogger) CaptureState(env *vm.EVM, pc uint64, op vm.OpCode, gas, cost uint64, memory *vm.Memory, stack *vm.Stack, contract *vm.Contract, depth int, err error) error { log := vm.StructLog{ @@ -56,6 +61,11 @@ func (l *JSONLogger) CaptureState(env *vm.EVM, pc uint64, op vm.OpCode, gas, cos return l.encoder.Encode(log) } +// CaptureFault outputs state information on the logger. +func (l *JSONLogger) CaptureFault(env *vm.EVM, pc uint64, op vm.OpCode, gas, cost uint64, memory *vm.Memory, stack *vm.Stack, contract *vm.Contract, depth int, err error) error { + return nil +} + // CaptureEnd is triggered at end of execution. func (l *JSONLogger) CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error) error { type endLog struct { -- cgit v1.2.3 From 68651a2329057aa203f60af85932958e6c32ebe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Thu, 21 Dec 2017 14:14:24 +0200 Subject: cmd/faucet: fix removal of Twitter zlib compression --- cmd/faucet/faucet.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'cmd') diff --git a/cmd/faucet/faucet.go b/cmd/faucet/faucet.go index 5f16f2978..75ec124c1 100644 --- a/cmd/faucet/faucet.go +++ b/cmd/faucet/faucet.go @@ -21,7 +21,6 @@ package main import ( "bytes" - "compress/zlib" "context" "encoding/json" "errors" @@ -698,11 +697,7 @@ func authTwitter(url string) (string, string, common.Address, error) { } defer res.Body.Close() - reader, err := zlib.NewReader(res.Body) - if err != nil { - return "", "", common.Address{}, err - } - body, err := ioutil.ReadAll(reader) + body, err := ioutil.ReadAll(res.Body) if err != nil { return "", "", common.Address{}, err } -- cgit v1.2.3 From 14852810b4bd53bf6e3b04e9b4017a1ee87a4003 Mon Sep 17 00:00:00 2001 From: lash Date: Thu, 21 Dec 2017 14:30:44 +0100 Subject: cmd/utils: add check on fd hard limit, skip test if below target (#15684) * cmd/utils: Add check on hard limit, skip test if below target * cmd/utils: Cross platform compatible fd limit test * cmd/utils: Remove syscall.Rlimit in test * cmd/utils: comment fd utility method --- cmd/utils/fdlimit_freebsd.go | 10 ++++++++++ cmd/utils/fdlimit_test.go | 12 +++++++++++- cmd/utils/fdlimit_unix.go | 10 ++++++++++ cmd/utils/fdlimit_windows.go | 6 ++++++ 4 files changed, 37 insertions(+), 1 deletion(-) (limited to 'cmd') diff --git a/cmd/utils/fdlimit_freebsd.go b/cmd/utils/fdlimit_freebsd.go index 4cb5013c8..f9ed8937e 100644 --- a/cmd/utils/fdlimit_freebsd.go +++ b/cmd/utils/fdlimit_freebsd.go @@ -52,3 +52,13 @@ func getFdLimit() (int, error) { } return int(limit.Cur), nil } + +// getFdMaxLimit retrieves the maximum number of file descriptors this process is +// allowed to request for itself. +func getFdMaxLimit() (int, error) { + var limit syscall.Rlimit + if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + return 0, err + } + return int(limit.Max), nil +} diff --git a/cmd/utils/fdlimit_test.go b/cmd/utils/fdlimit_test.go index 0a950a6c9..48489cf4c 100644 --- a/cmd/utils/fdlimit_test.go +++ b/cmd/utils/fdlimit_test.go @@ -16,12 +16,22 @@ package utils -import "testing" +import ( + "fmt" + "testing" +) // TestFileDescriptorLimits simply tests whether the file descriptor allowance // per this process can be retrieved. func TestFileDescriptorLimits(t *testing.T) { target := 4096 + hardlimit, err := getFdMaxLimit() + if err != nil { + t.Fatal(err) + } + if hardlimit < target { + t.Skip(fmt.Sprintf("system limit is less than desired test target: %d < %d", hardlimit, target)) + } if limit, err := getFdLimit(); err != nil || limit <= 0 { t.Fatalf("failed to retrieve file descriptor limit (%d): %v", limit, err) diff --git a/cmd/utils/fdlimit_unix.go b/cmd/utils/fdlimit_unix.go index 08e153bbd..c08d1fab0 100644 --- a/cmd/utils/fdlimit_unix.go +++ b/cmd/utils/fdlimit_unix.go @@ -48,3 +48,13 @@ func getFdLimit() (int, error) { } return int(limit.Cur), nil } + +// getFdMaxLimit retrieves the maximum number of file descriptors this process is +// allowed to request for itself. +func getFdMaxLimit() (int, error) { + var limit syscall.Rlimit + if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + return 0, err + } + return int(limit.Max), nil +} diff --git a/cmd/utils/fdlimit_windows.go b/cmd/utils/fdlimit_windows.go index 53aad3d7a..f239683d2 100644 --- a/cmd/utils/fdlimit_windows.go +++ b/cmd/utils/fdlimit_windows.go @@ -39,3 +39,9 @@ func getFdLimit() (int, error) { // Please see raiseFdLimit for the reason why we use hard coded 16K as the limit return 16384, nil } + +// getFdMaxLimit retrieves the maximum number of file descriptors this process is +// allowed to request for itself. +func getFdMaxLimit() (int, error) { + return getFdLimit() +} -- cgit v1.2.3 From e4aa882ec55b70c060458c4eda943c37e08a8cc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Thu, 21 Dec 2017 17:25:42 +0200 Subject: cmd/puppeth: fix faucet 502 error due to non-exposed HTTP port --- cmd/puppeth/module_faucet.go | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cmd') diff --git a/cmd/puppeth/module_faucet.go b/cmd/puppeth/module_faucet.go index 57b7a2dc0..92b4cb286 100644 --- a/cmd/puppeth/module_faucet.go +++ b/cmd/puppeth/module_faucet.go @@ -39,6 +39,8 @@ ADD genesis.json /genesis.json ADD account.json /account.json ADD account.pass /account.pass +EXPOSE 8080 30303 30303/udp + ENTRYPOINT [ \ "faucet", "--genesis", "/genesis.json", "--network", "{{.NetworkID}}", "--bootnodes", "{{.Bootnodes}}", "--ethstats", "{{.Ethstats}}", "--ethport", "{{.EthPort}}", \ "--faucet.name", "{{.FaucetName}}", "--faucet.amount", "{{.FaucetAmount}}", "--faucet.minutes", "{{.FaucetMinutes}}", "--faucet.tiers", "{{.FaucetTiers}}", \ -- cgit v1.2.3 From 413cc5b0c80733478f1b94a5e9a509fc7bd3fa4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Tue, 2 Jan 2018 13:48:19 +0200 Subject: cmd/geth: remove trailing newline in license command (#15782) --- cmd/geth/misccmd.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'cmd') diff --git a/cmd/geth/misccmd.go b/cmd/geth/misccmd.go index 2e68dcda3..aa9b1ee56 100644 --- a/cmd/geth/misccmd.go +++ b/cmd/geth/misccmd.go @@ -134,7 +134,6 @@ 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 geth. If not, see . -`) +along with geth. If not, see .`) return nil } -- cgit v1.2.3 From b8caba97099ee5eed33c3b80dd4ea540722e7d8f Mon Sep 17 00:00:00 2001 From: Furkan KAMACI Date: Wed, 3 Jan 2018 15:14:47 +0300 Subject: various: remove redundant parentheses (#15793) --- cmd/swarm/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmd') diff --git a/cmd/swarm/config.go b/cmd/swarm/config.go index 33235ca06..29b5faefa 100644 --- a/cmd/swarm/config.go +++ b/cmd/swarm/config.go @@ -315,7 +315,7 @@ func checkDeprecated(ctx *cli.Context) { func printConfig(config *bzzapi.Config) string { out, err := tomlSettings.Marshal(&config) if err != nil { - return (fmt.Sprintf("Something is not right with the configuration: %v", err)) + return fmt.Sprintf("Something is not right with the configuration: %v", err) } return string(out) } -- cgit v1.2.3 From 6f69cdd109b1dd692b8dfb15e7c53d2051fbc946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Mon, 13 Nov 2017 13:47:27 +0200 Subject: all: switch gas limits from big.Int to uint64 --- cmd/faucet/faucet.go | 2 +- cmd/puppeth/genesis.go | 38 +++++++++++++++++++------------------- cmd/utils/flags.go | 4 ++-- 3 files changed, 22 insertions(+), 22 deletions(-) (limited to 'cmd') diff --git a/cmd/faucet/faucet.go b/cmd/faucet/faucet.go index 75ec124c1..051f9254c 100644 --- a/cmd/faucet/faucet.go +++ b/cmd/faucet/faucet.go @@ -473,7 +473,7 @@ func (f *faucet) apiHandler(conn *websocket.Conn) { amount = new(big.Int).Mul(amount, new(big.Int).Exp(big.NewInt(5), big.NewInt(int64(msg.Tier)), nil)) amount = new(big.Int).Div(amount, new(big.Int).Exp(big.NewInt(2), big.NewInt(int64(msg.Tier)), nil)) - tx := types.NewTransaction(f.nonce+uint64(len(f.reqs)), address, amount, big.NewInt(21000), f.price, nil) + tx := types.NewTransaction(f.nonce+uint64(len(f.reqs)), address, amount, 21000, f.price, nil) signed, err := f.keystore.SignTx(f.account, tx, f.config.ChainId) if err != nil { f.lock.Unlock() diff --git a/cmd/puppeth/genesis.go b/cmd/puppeth/genesis.go index 5e36f7fce..f747f4739 100644 --- a/cmd/puppeth/genesis.go +++ b/cmd/puppeth/genesis.go @@ -44,7 +44,7 @@ type cppEthereumGenesisSpec struct { MaximumExtraDataSize hexutil.Uint64 `json:"maximumExtraDataSize"` MinGasLimit hexutil.Uint64 `json:"minGasLimit"` MaxGasLimit hexutil.Uint64 `json:"maxGasLimit"` - GasLimitBoundDivisor *hexutil.Big `json:"gasLimitBoundDivisor"` + GasLimitBoundDivisor hexutil.Uint64 `json:"gasLimitBoundDivisor"` MinimumDifficulty *hexutil.Big `json:"minimumDifficulty"` DifficultyBoundDivisor *hexutil.Big `json:"difficultyBoundDivisor"` DurationLimit *hexutil.Big `json:"durationLimit"` @@ -107,11 +107,11 @@ func newCppEthereumGenesisSpec(network string, genesis *core.Genesis) (*cppEther spec.Params.ChainID = (hexutil.Uint64)(genesis.Config.ChainId.Uint64()) spec.Params.MaximumExtraDataSize = (hexutil.Uint64)(params.MaximumExtraDataSize) - spec.Params.MinGasLimit = (hexutil.Uint64)(params.MinGasLimit.Uint64()) + spec.Params.MinGasLimit = (hexutil.Uint64)(params.MinGasLimit) spec.Params.MaxGasLimit = (hexutil.Uint64)(math.MaxUint64) spec.Params.MinimumDifficulty = (*hexutil.Big)(params.MinimumDifficulty) spec.Params.DifficultyBoundDivisor = (*hexutil.Big)(params.DifficultyBoundDivisor) - spec.Params.GasLimitBoundDivisor = (*hexutil.Big)(params.GasLimitBoundDivisor) + spec.Params.GasLimitBoundDivisor = (hexutil.Uint64)(params.GasLimitBoundDivisor) spec.Params.DurationLimit = (*hexutil.Big)(params.DurationLimit) spec.Params.BlockReward = (*hexutil.Big)(ethash.FrontierBlockReward) @@ -168,26 +168,26 @@ type parityChainSpec struct { Engine struct { Ethash struct { Params struct { - MinimumDifficulty *hexutil.Big `json:"minimumDifficulty"` - DifficultyBoundDivisor *hexutil.Big `json:"difficultyBoundDivisor"` - GasLimitBoundDivisor *hexutil.Big `json:"gasLimitBoundDivisor"` - DurationLimit *hexutil.Big `json:"durationLimit"` - BlockReward *hexutil.Big `json:"blockReward"` - HomesteadTransition uint64 `json:"homesteadTransition"` - EIP150Transition uint64 `json:"eip150Transition"` - EIP160Transition uint64 `json:"eip160Transition"` - EIP161abcTransition uint64 `json:"eip161abcTransition"` - EIP161dTransition uint64 `json:"eip161dTransition"` - EIP649Reward *hexutil.Big `json:"eip649Reward"` - EIP100bTransition uint64 `json:"eip100bTransition"` - EIP649Transition uint64 `json:"eip649Transition"` + MinimumDifficulty *hexutil.Big `json:"minimumDifficulty"` + DifficultyBoundDivisor *hexutil.Big `json:"difficultyBoundDivisor"` + GasLimitBoundDivisor hexutil.Uint64 `json:"gasLimitBoundDivisor"` + DurationLimit *hexutil.Big `json:"durationLimit"` + BlockReward *hexutil.Big `json:"blockReward"` + HomesteadTransition uint64 `json:"homesteadTransition"` + EIP150Transition uint64 `json:"eip150Transition"` + EIP160Transition uint64 `json:"eip160Transition"` + EIP161abcTransition uint64 `json:"eip161abcTransition"` + EIP161dTransition uint64 `json:"eip161dTransition"` + EIP649Reward *hexutil.Big `json:"eip649Reward"` + EIP100bTransition uint64 `json:"eip100bTransition"` + EIP649Transition uint64 `json:"eip649Transition"` } `json:"params"` } `json:"Ethash"` } `json:"engine"` Params struct { MaximumExtraDataSize hexutil.Uint64 `json:"maximumExtraDataSize"` - MinGasLimit *hexutil.Big `json:"minGasLimit"` + MinGasLimit hexutil.Uint64 `json:"minGasLimit"` NetworkID hexutil.Uint64 `json:"networkID"` MaxCodeSize uint64 `json:"maxCodeSize"` EIP155Transition uint64 `json:"eip155Transition"` @@ -270,7 +270,7 @@ func newParityChainSpec(network string, genesis *core.Genesis, bootnodes []strin } spec.Engine.Ethash.Params.MinimumDifficulty = (*hexutil.Big)(params.MinimumDifficulty) spec.Engine.Ethash.Params.DifficultyBoundDivisor = (*hexutil.Big)(params.DifficultyBoundDivisor) - spec.Engine.Ethash.Params.GasLimitBoundDivisor = (*hexutil.Big)(params.GasLimitBoundDivisor) + spec.Engine.Ethash.Params.GasLimitBoundDivisor = (hexutil.Uint64)(params.GasLimitBoundDivisor) spec.Engine.Ethash.Params.DurationLimit = (*hexutil.Big)(params.DurationLimit) spec.Engine.Ethash.Params.BlockReward = (*hexutil.Big)(ethash.FrontierBlockReward) spec.Engine.Ethash.Params.HomesteadTransition = genesis.Config.HomesteadBlock.Uint64() @@ -283,7 +283,7 @@ func newParityChainSpec(network string, genesis *core.Genesis, bootnodes []strin spec.Engine.Ethash.Params.EIP649Transition = genesis.Config.ByzantiumBlock.Uint64() spec.Params.MaximumExtraDataSize = (hexutil.Uint64)(params.MaximumExtraDataSize) - spec.Params.MinGasLimit = (*hexutil.Big)(params.MinGasLimit) + spec.Params.MinGasLimit = (hexutil.Uint64)(params.MinGasLimit) spec.Params.NetworkID = (hexutil.Uint64)(genesis.Config.ChainId.Uint64()) spec.Params.MaxCodeSize = params.MaxCodeSize spec.Params.EIP155Transition = genesis.Config.EIP155Block.Uint64() diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 30edf199c..734cf6f36 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -313,7 +313,7 @@ var ( TargetGasLimitFlag = cli.Uint64Flag{ Name: "targetgaslimit", Usage: "Target gas limit sets the artificial target gas floor for the blocks to mine", - Value: params.GenesisGasLimit.Uint64(), + Value: params.GenesisGasLimit, } EtherbaseFlag = cli.StringFlag{ Name: "etherbase", @@ -1138,7 +1138,7 @@ func RegisterEthStatsService(stack *node.Node, url string) { // SetupNetwork configures the system for either the main net or some test network. func SetupNetwork(ctx *cli.Context) { // TODO(fjl): move target gas limit into config - params.TargetGasLimit = new(big.Int).SetUint64(ctx.GlobalUint64(TargetGasLimitFlag.Name)) + params.TargetGasLimit = ctx.GlobalUint64(TargetGasLimitFlag.Name) } // MakeChainDatabase open an LevelDB using the flags passed to the client and will hard crash if it fails. -- cgit v1.2.3 From 7a59a9380e9f12729bb094de4151c3d135bdadf9 Mon Sep 17 00:00:00 2001 From: Evangelos Pappas Date: Wed, 3 Jan 2018 16:18:53 +0000 Subject: cmd/utils: handle git commit a bit safer for user specified strings (#15790) * cmd/utils/flags.go: Applying a String len guard for the gitCommit param of the NewApp() * cmd/utils: remove redundant clause in if condition --- cmd/utils/flags.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmd') diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 734cf6f36..edf3dc2c2 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -96,7 +96,7 @@ func NewApp(gitCommit, usage string) *cli.App { //app.Authors = nil app.Email = "" app.Version = params.Version - if gitCommit != "" { + if len(gitCommit) >= 8 { app.Version += "-" + gitCommit[:8] } app.Usage = usage -- cgit v1.2.3 From 5c2f1e00148f16655d3fb63b93920b1108165c56 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Mon, 8 Jan 2018 13:15:57 +0100 Subject: all: update generated code (#15808) * core/types, core/vm, eth, tests: regenerate gencodec files * Makefile: update devtools target Install protoc-gen-go and print reminders about npm, solc and protoc. Also switch to github.com/kevinburke/go-bindata because it's more maintained. * contracts/ens: update contracts and regenerate with solidity v0.4.19 The newer upstream version of the FIFSRegistrar contract doesn't set the resolver anymore. The resolver is now deployed separately. * contracts/release: regenerate with solidity v0.4.19 * contracts/chequebook: fix fallback and regenerate with solidity v0.4.19 The contract didn't have a fallback function, payments would be rejected when compiled with newer solidity. References to 'mortal' and 'owned' use the local file system so we can compile without network access. * p2p/discv5: regenerate with recent stringer * cmd/faucet: regenerate * dashboard: regenerate * eth/tracers: regenerate * internal/jsre/deps: regenerate * dashboard: avoid sed -i because it's not portable * accounts/usbwallet/internal/trezor: fix go generate warnings --- cmd/faucet/faucet.go | 1 + cmd/faucet/website.go | 25 ++++++++++--------------- 2 files changed, 11 insertions(+), 15 deletions(-) (limited to 'cmd') diff --git a/cmd/faucet/faucet.go b/cmd/faucet/faucet.go index 051f9254c..e92924fc9 100644 --- a/cmd/faucet/faucet.go +++ b/cmd/faucet/faucet.go @@ -18,6 +18,7 @@ package main //go:generate go-bindata -nometadata -o website.go faucet.html +//go:generate gofmt -w -s website.go import ( "bytes" diff --git a/cmd/faucet/website.go b/cmd/faucet/website.go index 7936b158e..fab1d4346 100644 --- a/cmd/faucet/website.go +++ b/cmd/faucet/website.go @@ -1,7 +1,6 @@ -// Code generated by go-bindata. +// Code generated by go-bindata. DO NOT EDIT. // sources: // faucet.html -// DO NOT EDIT! package main @@ -92,8 +91,8 @@ func faucetHtml() (*asset, error) { // It returns an error if the asset could not be found or // could not be loaded. func Asset(name string) ([]byte, error) { - cannonicalName := strings.Replace(name, "\\", "/", -1) - if f, ok := _bindata[cannonicalName]; ok { + canonicalName := strings.Replace(name, "\\", "/", -1) + if f, ok := _bindata[canonicalName]; ok { a, err := f() if err != nil { return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err) @@ -118,8 +117,8 @@ func MustAsset(name string) []byte { // It returns an error if the asset could not be found or // could not be loaded. func AssetInfo(name string) (os.FileInfo, error) { - cannonicalName := strings.Replace(name, "\\", "/", -1) - if f, ok := _bindata[cannonicalName]; ok { + canonicalName := strings.Replace(name, "\\", "/", -1) + if f, ok := _bindata[canonicalName]; ok { a, err := f() if err != nil { return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err) @@ -159,8 +158,8 @@ var _bindata = map[string]func() (*asset, error){ func AssetDir(name string) ([]string, error) { node := _bintree if len(name) != 0 { - cannonicalName := strings.Replace(name, "\\", "/", -1) - pathList := strings.Split(cannonicalName, "/") + canonicalName := strings.Replace(name, "\\", "/", -1) + pathList := strings.Split(canonicalName, "/") for _, p := range pathList { node = node.Children[p] if node == nil { @@ -205,11 +204,7 @@ func RestoreAsset(dir, name string) error { if err != nil { return err } - err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime()) - if err != nil { - return err - } - return nil + return os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime()) } // RestoreAssets restores an asset under the given directory recursively @@ -230,6 +225,6 @@ func RestoreAssets(dir, name string) error { } func _filePath(dir, name string) string { - cannonicalName := strings.Replace(name, "\\", "/", -1) - return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...) + canonicalName := strings.Replace(name, "\\", "/", -1) + return filepath.Join(append([]string{dir}, strings.Split(canonicalName, "/")...)...) } -- cgit v1.2.3 From 56152b31ac251d1cc68fcddbdad159ba5234c415 Mon Sep 17 00:00:00 2001 From: Ricardo Domingos Date: Thu, 11 Jan 2018 21:55:21 +0100 Subject: common/fdlimit: Move fdlimit files to separate package (#15850) * common/fdlimit: Move fdlimit files to separate package When go-ethereum is used as a library the calling program need to set the FD limit. This commit extract fdlimit files to a separate package so it can be used outside of go-ethereum. * common/fdlimit: Remove FdLimit from functions signature * common/fdlimit: Rename fdlimit functions --- cmd/utils/fdlimit_freebsd.go | 64 -------------------------------------------- cmd/utils/fdlimit_test.go | 45 ------------------------------- cmd/utils/fdlimit_unix.go | 60 ----------------------------------------- cmd/utils/fdlimit_windows.go | 47 -------------------------------- cmd/utils/flags.go | 5 ++-- 5 files changed, 3 insertions(+), 218 deletions(-) delete mode 100644 cmd/utils/fdlimit_freebsd.go delete mode 100644 cmd/utils/fdlimit_test.go delete mode 100644 cmd/utils/fdlimit_unix.go delete mode 100644 cmd/utils/fdlimit_windows.go (limited to 'cmd') diff --git a/cmd/utils/fdlimit_freebsd.go b/cmd/utils/fdlimit_freebsd.go deleted file mode 100644 index f9ed8937e..000000000 --- a/cmd/utils/fdlimit_freebsd.go +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2016 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 . - -// +build freebsd - -package utils - -import "syscall" - -// This file is largely identical to fdlimit_unix.go, -// but Rlimit fields have type int64 on FreeBSD so it needs -// an extra conversion. - -// raiseFdLimit tries to maximize the file descriptor allowance of this process -// to the maximum hard-limit allowed by the OS. -func raiseFdLimit(max uint64) error { - // Get the current limit - var limit syscall.Rlimit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { - return err - } - // Try to update the limit to the max allowance - limit.Cur = limit.Max - if limit.Cur > int64(max) { - limit.Cur = int64(max) - } - if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { - return err - } - return nil -} - -// getFdLimit retrieves the number of file descriptors allowed to be opened by this -// process. -func getFdLimit() (int, error) { - var limit syscall.Rlimit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { - return 0, err - } - return int(limit.Cur), nil -} - -// getFdMaxLimit retrieves the maximum number of file descriptors this process is -// allowed to request for itself. -func getFdMaxLimit() (int, error) { - var limit syscall.Rlimit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { - return 0, err - } - return int(limit.Max), nil -} diff --git a/cmd/utils/fdlimit_test.go b/cmd/utils/fdlimit_test.go deleted file mode 100644 index 48489cf4c..000000000 --- a/cmd/utils/fdlimit_test.go +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2016 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 . - -package utils - -import ( - "fmt" - "testing" -) - -// TestFileDescriptorLimits simply tests whether the file descriptor allowance -// per this process can be retrieved. -func TestFileDescriptorLimits(t *testing.T) { - target := 4096 - hardlimit, err := getFdMaxLimit() - if err != nil { - t.Fatal(err) - } - if hardlimit < target { - t.Skip(fmt.Sprintf("system limit is less than desired test target: %d < %d", hardlimit, target)) - } - - if limit, err := getFdLimit(); err != nil || limit <= 0 { - t.Fatalf("failed to retrieve file descriptor limit (%d): %v", limit, err) - } - if err := raiseFdLimit(uint64(target)); err != nil { - t.Fatalf("failed to raise file allowance") - } - if limit, err := getFdLimit(); err != nil || limit < target { - t.Fatalf("failed to retrieve raised descriptor limit (have %v, want %v): %v", limit, target, err) - } -} diff --git a/cmd/utils/fdlimit_unix.go b/cmd/utils/fdlimit_unix.go deleted file mode 100644 index c08d1fab0..000000000 --- a/cmd/utils/fdlimit_unix.go +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2016 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 . - -// +build linux darwin netbsd openbsd solaris - -package utils - -import "syscall" - -// raiseFdLimit tries to maximize the file descriptor allowance of this process -// to the maximum hard-limit allowed by the OS. -func raiseFdLimit(max uint64) error { - // Get the current limit - var limit syscall.Rlimit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { - return err - } - // Try to update the limit to the max allowance - limit.Cur = limit.Max - if limit.Cur > max { - limit.Cur = max - } - if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { - return err - } - return nil -} - -// getFdLimit retrieves the number of file descriptors allowed to be opened by this -// process. -func getFdLimit() (int, error) { - var limit syscall.Rlimit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { - return 0, err - } - return int(limit.Cur), nil -} - -// getFdMaxLimit retrieves the maximum number of file descriptors this process is -// allowed to request for itself. -func getFdMaxLimit() (int, error) { - var limit syscall.Rlimit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { - return 0, err - } - return int(limit.Max), nil -} diff --git a/cmd/utils/fdlimit_windows.go b/cmd/utils/fdlimit_windows.go deleted file mode 100644 index f239683d2..000000000 --- a/cmd/utils/fdlimit_windows.go +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2016 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 . - -package utils - -import "errors" - -// raiseFdLimit tries to maximize the file descriptor allowance of this process -// to the maximum hard-limit allowed by the OS. -func raiseFdLimit(max uint64) error { - // This method is NOP by design: - // * Linux/Darwin counterparts need to manually increase per process limits - // * On Windows Go uses the CreateFile API, which is limited to 16K files, non - // changeable from within a running process - // This way we can always "request" raising the limits, which will either have - // or not have effect based on the platform we're running on. - if max > 16384 { - return errors.New("file descriptor limit (16384) reached") - } - return nil -} - -// getFdLimit retrieves the number of file descriptors allowed to be opened by this -// process. -func getFdLimit() (int, error) { - // Please see raiseFdLimit for the reason why we use hard coded 16K as the limit - return 16384, nil -} - -// getFdMaxLimit retrieves the maximum number of file descriptors this process is -// allowed to request for itself. -func getFdMaxLimit() (int, error) { - return getFdLimit() -} diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index edf3dc2c2..94ab64c2e 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -31,6 +31,7 @@ import ( "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/fdlimit" "github.com/ethereum/go-ethereum/consensus" "github.com/ethereum/go-ethereum/consensus/clique" "github.com/ethereum/go-ethereum/consensus/ethash" @@ -721,10 +722,10 @@ func setIPC(ctx *cli.Context, cfg *node.Config) { // makeDatabaseHandles raises out the number of allowed file handles per process // for Geth and returns half of the allowance to assign to the database. func makeDatabaseHandles() int { - if err := raiseFdLimit(2048); err != nil { + if err := fdlimit.Raise(2048); err != nil { Fatalf("Failed to raise file descriptor allowance: %v", err) } - limit, err := getFdLimit() + limit, err := fdlimit.Current() if err != nil { Fatalf("Failed to retrieve file descriptor allowance: %v", err) } -- cgit v1.2.3 From bd0dbfa2a889972814166129e3a166cec7c71951 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Fri, 12 Jan 2018 11:59:18 +0200 Subject: cmd/geth: user friendly light miner error --- cmd/geth/main.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'cmd') diff --git a/cmd/geth/main.go b/cmd/geth/main.go index bdb7fad62..b955bd243 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -278,9 +278,12 @@ func startNode(ctx *cli.Context, stack *node.Node) { // Start auxiliary services if enabled if ctx.GlobalBool(utils.MiningEnabledFlag.Name) || ctx.GlobalBool(utils.DeveloperFlag.Name) { // Mining only makes sense if a full Ethereum node is running + if ctx.GlobalBool(utils.LightModeFlag.Name) || ctx.GlobalString(utils.SyncModeFlag.Name) == "light" { + utils.Fatalf("Light clients do not support mining") + } var ethereum *eth.Ethereum if err := stack.Service(ðereum); err != nil { - utils.Fatalf("ethereum service not running: %v", err) + utils.Fatalf("Ethereum service not running: %v", err) } // Use a reduced number of threads if requested if threads := ctx.GlobalInt(utils.MinerThreadsFlag.Name); threads > 0 { -- cgit v1.2.3 From 938cf4528ab5acbb6013be79a0548956713807a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kurk=C3=B3=20Mih=C3=A1ly?= Date: Mon, 15 Jan 2018 11:20:00 +0200 Subject: dashboard: deep state update, version in footer (#15837) * dashboard: footer, deep state update * dashboard: resolve asset path * dashboard: remove bundle.js * dashboard: prevent state update on every reconnection * dashboard: fix linter issue * dashboard, cmd: minor UI fix, include commit hash * remove geth binary * dashboard: gitCommit renamed to commit * dashboard: move the geth version to the right, make commit optional * dashboard: commit limited to 7 characters * dashboard: limit commit length on client side * dashboard: run go generate --- cmd/geth/config.go | 2 +- cmd/utils/flags.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'cmd') diff --git a/cmd/geth/config.go b/cmd/geth/config.go index 27490c404..9c703758e 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -158,7 +158,7 @@ func makeFullNode(ctx *cli.Context) *node.Node { utils.RegisterEthService(stack, &cfg.Eth) if ctx.GlobalBool(utils.DashboardEnabledFlag.Name) { - utils.RegisterDashboardService(stack, &cfg.Dashboard) + utils.RegisterDashboardService(stack, &cfg.Dashboard, gitCommit) } // Whisper must be explicitly enabled by specifying at least 1 whisper flag or in dev mode shhEnabled := enableWhisper(ctx) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 94ab64c2e..3766ea4a6 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1104,9 +1104,9 @@ func RegisterEthService(stack *node.Node, cfg *eth.Config) { } // RegisterDashboardService adds a dashboard to the stack. -func RegisterDashboardService(stack *node.Node, cfg *dashboard.Config) { +func RegisterDashboardService(stack *node.Node, cfg *dashboard.Config, commit string) { stack.Register(func(ctx *node.ServiceContext) (node.Service, error) { - return dashboard.New(cfg) + return dashboard.New(cfg, commit) }) } -- cgit v1.2.3 From f08cd94fb755471cb78091af99ef7026afb392f3 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 16 Jan 2018 15:42:41 +0100 Subject: cmd/ethkey: fix formatting, review nits (#15807) This commit: - Adds a --msgfile option to read the message to sign from a file instead of command line argument. - Adds a unit test for signing subcommands. - Removes some weird whitespace in the code. --- cmd/ethkey/generate.go | 63 +++++++++++++++--------------- cmd/ethkey/inspect.go | 1 + cmd/ethkey/main.go | 33 +++++++--------- cmd/ethkey/message.go | 97 ++++++++++++++++++++++++++-------------------- cmd/ethkey/message_test.go | 70 +++++++++++++++++++++++++++++++++ cmd/ethkey/run_test.go | 54 ++++++++++++++++++++++++++ 6 files changed, 226 insertions(+), 92 deletions(-) create mode 100644 cmd/ethkey/message_test.go create mode 100644 cmd/ethkey/run_test.go (limited to 'cmd') diff --git a/cmd/ethkey/generate.go b/cmd/ethkey/generate.go index dee0e9d70..6d57d17fb 100644 --- a/cmd/ethkey/generate.go +++ b/cmd/ethkey/generate.go @@ -1,8 +1,23 @@ +// 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 . + package main import ( "crypto/ecdsa" - "crypto/rand" "fmt" "io/ioutil" "os" @@ -26,16 +41,16 @@ var commandGenerate = cli.Command{ ArgsUsage: "[ ]", Description: ` Generate a new keyfile. -If you want to use an existing private key to use in the keyfile, it can be -specified by setting --privatekey with the location of the file containing the -private key.`, + +If you want to encrypt an existing private key, it can be specified by setting +--privatekey with the location of the file containing the private key. +`, Flags: []cli.Flag{ passphraseFlag, jsonFlag, cli.StringFlag{ - Name: "privatekey", - Usage: "the file from where to read the private key to " + - "generate a keyfile for", + Name: "privatekey", + Usage: "file containing a raw private key to encrypt", }, }, Action: func(ctx *cli.Context) error { @@ -51,32 +66,19 @@ private key.`, } var privateKey *ecdsa.PrivateKey - - // First check if a private key file is provided. - privateKeyFile := ctx.String("privatekey") - if privateKeyFile != "" { - privateKeyBytes, err := ioutil.ReadFile(privateKeyFile) + var err error + if file := ctx.String("privatekey"); file != "" { + // Load private key from file. + privateKey, err = crypto.LoadECDSA(file) if err != nil { - utils.Fatalf("Failed to read the private key file '%s': %v", - privateKeyFile, err) + utils.Fatalf("Can't load private key: %v", err) } - - pk, err := crypto.HexToECDSA(string(privateKeyBytes)) - if err != nil { - utils.Fatalf( - "Could not construct ECDSA private key from file content: %v", - err) - } - privateKey = pk - } - - // If not loaded, generate random. - if privateKey == nil { - pk, err := ecdsa.GenerateKey(crypto.S256(), rand.Reader) + } else { + // If not loaded, generate random. + privateKey, err = crypto.GenerateKey() if err != nil { utils.Fatalf("Failed to generate random private key: %v", err) } - privateKey = pk } // Create the keyfile object with a random UUID. @@ -89,8 +91,7 @@ private key.`, // Encrypt key with passphrase. passphrase := getPassPhrase(ctx, true) - keyjson, err := keystore.EncryptKey(key, passphrase, - keystore.StandardScryptN, keystore.StandardScryptP) + keyjson, err := keystore.EncryptKey(key, passphrase, keystore.StandardScryptN, keystore.StandardScryptP) if err != nil { utils.Fatalf("Error encrypting key: %v", err) } @@ -110,7 +111,7 @@ private key.`, if ctx.Bool(jsonFlag.Name) { mustPrintJSON(out) } else { - fmt.Println("Address: ", out.Address) + fmt.Println("Address:", out.Address) } return nil }, diff --git a/cmd/ethkey/inspect.go b/cmd/ethkey/inspect.go index 8a7aeef84..219a5460b 100644 --- a/cmd/ethkey/inspect.go +++ b/cmd/ethkey/inspect.go @@ -23,6 +23,7 @@ var commandInspect = cli.Command{ ArgsUsage: "", Description: ` Print various information about the keyfile. + Private key information can be printed by using the --private flag; make sure to use this feature with great caution!`, Flags: []cli.Flag{ diff --git a/cmd/ethkey/main.go b/cmd/ethkey/main.go index b9b7a18e0..2a9e5ee48 100644 --- a/cmd/ethkey/main.go +++ b/cmd/ethkey/main.go @@ -28,40 +28,37 @@ const ( defaultKeyfileName = "keyfile.json" ) -var ( - gitCommit = "" // Git SHA1 commit hash of the release (set via linker flags) +// Git SHA1 commit hash of the release (set via linker flags) +var gitCommit = "" - app *cli.App // the main app instance -) +var app *cli.App -var ( // Commonly used command line flags. +func init() { + app = utils.NewApp(gitCommit, "an Ethereum key manager") + app.Commands = []cli.Command{ + commandGenerate, + commandInspect, + commandSignMessage, + commandVerifyMessage, + } +} + +// Commonly used command line flags. +var ( passphraseFlag = cli.StringFlag{ Name: "passwordfile", Usage: "the file that contains the passphrase for the keyfile", } - jsonFlag = cli.BoolFlag{ Name: "json", Usage: "output JSON instead of human-readable format", } - messageFlag = cli.StringFlag{ Name: "message", Usage: "the file that contains the message to sign/verify", } ) -// Configure the app instance. -func init() { - app = utils.NewApp(gitCommit, "an Ethereum key manager") - app.Commands = []cli.Command{ - commandGenerate, - commandInspect, - commandSignMessage, - commandVerifyMessage, - } -} - func main() { if err := app.Run(os.Args); err != nil { fmt.Fprintln(os.Stderr, err) diff --git a/cmd/ethkey/message.go b/cmd/ethkey/message.go index ae6b6552d..531a931c8 100644 --- a/cmd/ethkey/message.go +++ b/cmd/ethkey/message.go @@ -1,11 +1,25 @@ +// 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 . + package main import ( "encoding/hex" "fmt" "io/ioutil" - "os" - "strings" "github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/cmd/utils" @@ -18,26 +32,33 @@ type outputSign struct { Signature string } +var msgfileFlag = cli.StringFlag{ + Name: "msgfile", + Usage: "file containing the message to sign/verify", +} + var commandSignMessage = cli.Command{ Name: "signmessage", Usage: "sign a message", - ArgsUsage: " ", + ArgsUsage: " ", Description: ` Sign the message with a keyfile. -It is possible to refer to a file containing the message.`, + +To sign a message contained in a file, use the --msgfile flag. +`, Flags: []cli.Flag{ passphraseFlag, jsonFlag, + msgfileFlag, }, Action: func(ctx *cli.Context) error { - keyfilepath := ctx.Args().First() - message := []byte(ctx.Args().Get(1)) + message := getMessage(ctx, 1) // Load the keyfile. + keyfilepath := ctx.Args().First() keyjson, err := ioutil.ReadFile(keyfilepath) if err != nil { - utils.Fatalf("Failed to read the keyfile at '%s': %v", - keyfilepath, err) + utils.Fatalf("Failed to read the keyfile at '%s': %v", keyfilepath, err) } // Decrypt key with passphrase. @@ -47,29 +68,15 @@ It is possible to refer to a file containing the message.`, utils.Fatalf("Error decrypting key: %v", err) } - if len(message) == 0 { - utils.Fatalf("A message must be provided") - } - // Read message if file. - if _, err := os.Stat(string(message)); err == nil { - message, err = ioutil.ReadFile(string(message)) - if err != nil { - utils.Fatalf("Failed to read the message file: %v", err) - } - } - signature, err := crypto.Sign(signHash(message), key.PrivateKey) if err != nil { utils.Fatalf("Failed to sign message: %v", err) } - - out := outputSign{ - Signature: hex.EncodeToString(signature), - } + out := outputSign{Signature: hex.EncodeToString(signature)} if ctx.Bool(jsonFlag.Name) { mustPrintJSON(out) } else { - fmt.Println("Signature: ", out.Signature) + fmt.Println("Signature:", out.Signature) } return nil }, @@ -84,53 +91,40 @@ type outputVerify struct { var commandVerifyMessage = cli.Command{ Name: "verifymessage", Usage: "verify the signature of a signed message", - ArgsUsage: "
", + ArgsUsage: "
", Description: ` Verify the signature of the message. It is possible to refer to a file containing the message.`, Flags: []cli.Flag{ jsonFlag, + msgfileFlag, }, Action: func(ctx *cli.Context) error { addressStr := ctx.Args().First() signatureHex := ctx.Args().Get(1) - message := []byte(ctx.Args().Get(2)) + message := getMessage(ctx, 2) - // Determine whether it is a keyfile, public key or address. if !common.IsHexAddress(addressStr) { utils.Fatalf("Invalid address: %s", addressStr) } address := common.HexToAddress(addressStr) - signature, err := hex.DecodeString(signatureHex) if err != nil { utils.Fatalf("Signature encoding is not hexadecimal: %v", err) } - if len(message) == 0 { - utils.Fatalf("A message must be provided") - } - // Read message if file. - if _, err := os.Stat(string(message)); err == nil { - message, err = ioutil.ReadFile(string(message)) - if err != nil { - utils.Fatalf("Failed to read the message file: %v", err) - } - } - recoveredPubkey, err := crypto.SigToPub(signHash(message), signature) if err != nil || recoveredPubkey == nil { utils.Fatalf("Signature verification failed: %v", err) } recoveredPubkeyBytes := crypto.FromECDSAPub(recoveredPubkey) recoveredAddress := crypto.PubkeyToAddress(*recoveredPubkey) - success := address == recoveredAddress out := outputVerify{ Success: success, RecoveredPublicKey: hex.EncodeToString(recoveredPubkeyBytes), - RecoveredAddress: strings.ToLower(recoveredAddress.Hex()), + RecoveredAddress: recoveredAddress.Hex(), } if ctx.Bool(jsonFlag.Name) { mustPrintJSON(out) @@ -140,9 +134,26 @@ It is possible to refer to a file containing the message.`, } else { fmt.Println("Signature verification failed!") } - fmt.Println("Recovered public key: ", out.RecoveredPublicKey) - fmt.Println("Recovered address: ", out.RecoveredAddress) + fmt.Println("Recovered public key:", out.RecoveredPublicKey) + fmt.Println("Recovered address:", out.RecoveredAddress) } return nil }, } + +func getMessage(ctx *cli.Context, msgarg int) []byte { + if file := ctx.String("msgfile"); file != "" { + if len(ctx.Args()) > msgarg { + utils.Fatalf("Can't use --msgfile and message argument at the same time.") + } + msg, err := ioutil.ReadFile(file) + if err != nil { + utils.Fatalf("Can't read message file: %v", err) + } + return msg + } else if len(ctx.Args()) == msgarg+1 { + return []byte(ctx.Args().Get(msgarg)) + } + utils.Fatalf("Invalid number of arguments: want %d, got %d", msgarg+1, len(ctx.Args())) + return nil +} diff --git a/cmd/ethkey/message_test.go b/cmd/ethkey/message_test.go new file mode 100644 index 000000000..fb16f03d0 --- /dev/null +++ b/cmd/ethkey/message_test.go @@ -0,0 +1,70 @@ +// 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 . + +package main + +import ( + "io/ioutil" + "os" + "path/filepath" + "testing" +) + +func TestMessageSignVerify(t *testing.T) { + tmpdir, err := ioutil.TempDir("", "ethkey-test") + if err != nil { + t.Fatal("Can't create temporary directory:", err) + } + defer os.RemoveAll(tmpdir) + + keyfile := filepath.Join(tmpdir, "the-keyfile") + message := "test message" + + // Create the key. + generate := runEthkey(t, "generate", keyfile) + generate.Expect(` +!! Unsupported terminal, password will be echoed. +Passphrase: {{.InputLine "foobar"}} +Repeat passphrase: {{.InputLine "foobar"}} +`) + _, matches := generate.ExpectRegexp(`Address: (0x[0-9a-fA-F]{40})\n`) + address := matches[1] + generate.ExpectExit() + + // Sign a message. + sign := runEthkey(t, "signmessage", keyfile, message) + sign.Expect(` +!! Unsupported terminal, password will be echoed. +Passphrase: {{.InputLine "foobar"}} +`) + _, matches = sign.ExpectRegexp(`Signature: ([0-9a-f]+)\n`) + signature := matches[1] + sign.ExpectExit() + + // Verify the message. + verify := runEthkey(t, "verifymessage", address, signature, message) + _, matches = verify.ExpectRegexp(` +Signature verification successful! +Recovered public key: [0-9a-f]+ +Recovered address: (0x[0-9a-fA-F]{40}) +`) + recovered := matches[1] + verify.ExpectExit() + + if recovered != address { + t.Error("recovered address doesn't match generated key") + } +} diff --git a/cmd/ethkey/run_test.go b/cmd/ethkey/run_test.go new file mode 100644 index 000000000..8ce4fe5cd --- /dev/null +++ b/cmd/ethkey/run_test.go @@ -0,0 +1,54 @@ +// 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 . + +package main + +import ( + "fmt" + "os" + "testing" + + "github.com/docker/docker/pkg/reexec" + "github.com/ethereum/go-ethereum/internal/cmdtest" +) + +type testEthkey struct { + *cmdtest.TestCmd +} + +// spawns ethkey with the given command line args. +func runEthkey(t *testing.T, args ...string) *testEthkey { + tt := new(testEthkey) + tt.TestCmd = cmdtest.NewTestCmd(t, tt) + tt.Run("ethkey-test", args...) + return tt +} + +func TestMain(m *testing.M) { + // Run the app if we've been exec'd as "ethkey-test" in runEthkey. + reexec.Register("ethkey-test", func() { + if err := app.Run(os.Args); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + os.Exit(0) + }) + // check if we have been reexec'd + if reexec.Init() { + return + } + os.Exit(m.Run()) +} -- cgit v1.2.3 From 92580d69d3156e5d2f0788eb5d48664cc3fb0ef3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felf=C3=B6ldi=20Zsolt?= Date: Mon, 22 Jan 2018 13:38:34 +0100 Subject: p2p, p2p/discover, p2p/discv5: implement UDP port sharing (#15200) This commit affects p2p/discv5 "topic discovery" by running it on the same UDP port where the old discovery works. This is realized by giving an "unhandled" packet channel to the old v4 discovery packet handler where all invalid packets are sent. These packets are then processed by v5. v5 packets are always invalid when interpreted by v4 and vice versa. This is ensured by adding one to the first byte of the packet hash in v5 packets. DiscoveryV5Bootnodes is also changed to point to new bootnodes that are implementing the changed packet format with modified hash. Existing and new v5 bootnodes are both running on different ports ATM. --- cmd/bootnode/main.go | 25 +++++++++++++++++++++++-- cmd/faucet/faucet.go | 1 - cmd/utils/flags.go | 10 ---------- 3 files changed, 23 insertions(+), 13 deletions(-) (limited to 'cmd') diff --git a/cmd/bootnode/main.go b/cmd/bootnode/main.go index e1734d89a..ecfc6fc24 100644 --- a/cmd/bootnode/main.go +++ b/cmd/bootnode/main.go @@ -21,6 +21,7 @@ import ( "crypto/ecdsa" "flag" "fmt" + "net" "os" "github.com/ethereum/go-ethereum/cmd/utils" @@ -96,12 +97,32 @@ func main() { } } + addr, err := net.ResolveUDPAddr("udp", *listenAddr) + if err != nil { + utils.Fatalf("-ResolveUDPAddr: %v", err) + } + conn, err := net.ListenUDP("udp", addr) + if err != nil { + utils.Fatalf("-ListenUDP: %v", err) + } + + realaddr := conn.LocalAddr().(*net.UDPAddr) + if natm != nil { + if !realaddr.IP.IsLoopback() { + go nat.Map(natm, nil, "udp", realaddr.Port, realaddr.Port, "ethereum discovery") + } + // TODO: react to external IP changes over time. + if ext, err := natm.ExternalIP(); err == nil { + realaddr = &net.UDPAddr{IP: ext, Port: realaddr.Port} + } + } + if *runv5 { - if _, err := discv5.ListenUDP(nodeKey, *listenAddr, natm, "", restrictList); err != nil { + if _, err := discv5.ListenUDP(nodeKey, conn, realaddr, "", restrictList); err != nil { utils.Fatalf("%v", err) } } else { - if _, err := discover.ListenUDP(nodeKey, *listenAddr, natm, "", restrictList); err != nil { + if _, err := discover.ListenUDP(nodeKey, conn, realaddr, nil, "", restrictList); err != nil { utils.Fatalf("%v", err) } } diff --git a/cmd/faucet/faucet.go b/cmd/faucet/faucet.go index e92924fc9..99527f9d1 100644 --- a/cmd/faucet/faucet.go +++ b/cmd/faucet/faucet.go @@ -223,7 +223,6 @@ func newFaucet(genesis *core.Genesis, port int, enodes []*discv5.Node, network u NoDiscovery: true, DiscoveryV5: true, ListenAddr: fmt.Sprintf(":%d", port), - DiscoveryV5Addr: fmt.Sprintf(":%d", port+1), MaxPeers: 25, BootstrapNodesV5: enodes, }, diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 3766ea4a6..89dcd230c 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -636,14 +636,6 @@ func setListenAddress(ctx *cli.Context, cfg *p2p.Config) { } } -// setDiscoveryV5Address creates a UDP listening address string from set command -// line flags for the V5 discovery protocol. -func setDiscoveryV5Address(ctx *cli.Context, cfg *p2p.Config) { - if ctx.GlobalIsSet(ListenPortFlag.Name) { - cfg.DiscoveryV5Addr = fmt.Sprintf(":%d", ctx.GlobalInt(ListenPortFlag.Name)+1) - } -} - // setNAT creates a port mapper from command line flags. func setNAT(ctx *cli.Context, cfg *p2p.Config) { if ctx.GlobalIsSet(NATFlag.Name) { @@ -794,7 +786,6 @@ func SetP2PConfig(ctx *cli.Context, cfg *p2p.Config) { setNodeKey(ctx, cfg) setNAT(ctx, cfg) setListenAddress(ctx, cfg) - setDiscoveryV5Address(ctx, cfg) setBootstrapNodes(ctx, cfg) setBootstrapNodesV5(ctx, cfg) @@ -830,7 +821,6 @@ func SetP2PConfig(ctx *cli.Context, cfg *p2p.Config) { // --dev mode can't use p2p networking. cfg.MaxPeers = 0 cfg.ListenAddr = ":0" - cfg.DiscoveryV5Addr = ":0" cfg.NoDiscovery = true cfg.DiscoveryV5 = false } -- cgit v1.2.3 From 1bf508b449ebd42653f521ada92c782e8cb664d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Fri, 5 Jan 2018 12:39:24 +0200 Subject: accounts/abi/bind: support event filtering in abigen --- cmd/geth/config.go | 17 ----------------- 1 file changed, 17 deletions(-) (limited to 'cmd') diff --git a/cmd/geth/config.go b/cmd/geth/config.go index 9c703758e..50e4de2e7 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -18,7 +18,6 @@ package main import ( "bufio" - "encoding/hex" "errors" "fmt" "io" @@ -29,7 +28,6 @@ import ( cli "gopkg.in/urfave/cli.v1" "github.com/ethereum/go-ethereum/cmd/utils" - "github.com/ethereum/go-ethereum/contracts/release" "github.com/ethereum/go-ethereum/dashboard" "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/node" @@ -177,21 +175,6 @@ func makeFullNode(ctx *cli.Context) *node.Node { if cfg.Ethstats.URL != "" { utils.RegisterEthStatsService(stack, cfg.Ethstats.URL) } - - // Add the release oracle service so it boots along with node. - if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) { - config := release.Config{ - Oracle: relOracle, - Major: uint32(params.VersionMajor), - Minor: uint32(params.VersionMinor), - Patch: uint32(params.VersionPatch), - } - commit, _ := hex.DecodeString(gitCommit) - copy(config.Commit[:], commit) - return release.NewReleaseService(ctx, config) - }); err != nil { - utils.Fatalf("Failed to register the Geth release oracle service: %v", err) - } return stack } -- cgit v1.2.3 From c335821479db9930a98cbd48996f880c35a59797 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felf=C3=B6ldi=20Zsolt?= Date: Thu, 25 Jan 2018 11:25:00 +0100 Subject: cmd, params: update discovery v5 bootnodes (#15954) --- cmd/utils/flags.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmd') diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 89dcd230c..89d16b968 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -612,7 +612,7 @@ func setBootstrapNodesV5(ctx *cli.Context, cfg *p2p.Config) { urls = strings.Split(ctx.GlobalString(BootnodesFlag.Name), ",") } case ctx.GlobalBool(RinkebyFlag.Name): - urls = params.RinkebyV5Bootnodes + urls = params.RinkebyBootnodes case cfg.BootstrapNodesV5 != nil: return // already set, don't apply defaults. } -- cgit v1.2.3 From 367c329b88617a2831a9fe20f7b47bb6ab7e255d Mon Sep 17 00:00:00 2001 From: Guillaume Ballet Date: Fri, 26 Jan 2018 12:45:10 +0100 Subject: whisper: remove linter warnings (#15972) * whisper: fixes warnings from the code linter * whisper: more non-API-breaking changes The remaining lint errors are because of auto-generated files and one is because an exported function has a non- exported return type. Changing this would break the API, and will be part of another commit for easier reversal. * whisper: un-export NewSentMessage to please the linter This is an API change, which is why it's in its own commit. This change was initiated after the linter complained that the returned type wasn't exported. I chose to un-export the function instead of exporting the type, because that type is an implementation detail that I would like to change in the near future to make the code more readable and with an increased coverage. * whisper: update gencodec output after upgrading it to new lint standards --- cmd/wnode/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cmd') diff --git a/cmd/wnode/main.go b/cmd/wnode/main.go index 05e6b2908..e69b57d69 100644 --- a/cmd/wnode/main.go +++ b/cmd/wnode/main.go @@ -601,7 +601,7 @@ func requestExpiredMessagesLoop() { if err != nil { utils.Fatalf("Failed to save symmetric key for mail request: %s", err) } - peerID = extractIdFromEnode(*argEnode) + peerID = extractIDFromEnode(*argEnode) shh.AllowP2PMessagesFromPeer(peerID) for { @@ -652,7 +652,7 @@ func requestExpiredMessagesLoop() { } } -func extractIdFromEnode(s string) []byte { +func extractIDFromEnode(s string) []byte { n, err := discover.ParseNode(s) if err != nil { utils.Fatalf("Failed to parse enode: %s", err) -- cgit v1.2.3 From ec28a58cc1cc1671a09061d5aa24d1c4c9c77b9f Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Fri, 2 Feb 2018 09:33:33 +0100 Subject: utils: fix #16006 by not lowering OS ulimit --- cmd/utils/flags.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'cmd') diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 89d16b968..58bb95243 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -714,13 +714,15 @@ func setIPC(ctx *cli.Context, cfg *node.Config) { // makeDatabaseHandles raises out the number of allowed file handles per process // for Geth and returns half of the allowance to assign to the database. func makeDatabaseHandles() int { - if err := fdlimit.Raise(2048); err != nil { - Fatalf("Failed to raise file descriptor allowance: %v", err) - } limit, err := fdlimit.Current() if err != nil { Fatalf("Failed to retrieve file descriptor allowance: %v", err) } + if limit < 2048 { + if err := fdlimit.Raise(2048); err != nil { + Fatalf("Failed to raise file descriptor allowance: %v", err) + } + } if limit > 2048 { // cap database file descriptors even if more is available limit = 2048 } -- cgit v1.2.3 From c3f238dd5371961d309350fb0f9d5136c9fc6afa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felf=C3=B6ldi=20Zsolt?= Date: Mon, 5 Feb 2018 14:41:53 +0100 Subject: les: limit LES peer count and improve peer configuration logic (#16010) * les: limit number of LES connections * eth, cmd/utils: light vs max peer configuration logic --- cmd/utils/flags.go | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'cmd') diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 58bb95243..833cd95de 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -179,7 +179,7 @@ var ( LightPeersFlag = cli.IntFlag{ Name: "lightpeers", Usage: "Maximum number of LES client peers", - Value: 20, + Value: eth.DefaultConfig.LightPeers, } LightKDFFlag = cli.BoolFlag{ Name: "lightkdf", @@ -791,20 +791,40 @@ func SetP2PConfig(ctx *cli.Context, cfg *p2p.Config) { setBootstrapNodes(ctx, cfg) setBootstrapNodesV5(ctx, cfg) + lightClient := ctx.GlobalBool(LightModeFlag.Name) || ctx.GlobalString(SyncModeFlag.Name) == "light" + lightServer := ctx.GlobalInt(LightServFlag.Name) != 0 + lightPeers := ctx.GlobalInt(LightPeersFlag.Name) + if ctx.GlobalIsSet(MaxPeersFlag.Name) { cfg.MaxPeers = ctx.GlobalInt(MaxPeersFlag.Name) + } else { + if lightServer { + cfg.MaxPeers += lightPeers + } + if lightClient && ctx.GlobalIsSet(LightPeersFlag.Name) && cfg.MaxPeers < lightPeers { + cfg.MaxPeers = lightPeers + } } + if !(lightClient || lightServer) { + lightPeers = 0 + } + ethPeers := cfg.MaxPeers - lightPeers + if lightClient { + ethPeers = 0 + } + log.Info("Maximum peer count", "ETH", ethPeers, "LES", lightPeers, "total", cfg.MaxPeers) + if ctx.GlobalIsSet(MaxPendingPeersFlag.Name) { cfg.MaxPendingPeers = ctx.GlobalInt(MaxPendingPeersFlag.Name) } - if ctx.GlobalIsSet(NoDiscoverFlag.Name) || ctx.GlobalBool(LightModeFlag.Name) { + if ctx.GlobalIsSet(NoDiscoverFlag.Name) || lightClient { cfg.NoDiscovery = true } // if we're running a light client or server, force enable the v5 peer discovery // unless it is explicitly disabled with --nodiscover note that explicitly specifying // --v5disc overrides --nodiscover, in which case the later only disables v4 discovery - forceV5Discovery := (ctx.GlobalBool(LightModeFlag.Name) || ctx.GlobalInt(LightServFlag.Name) > 0) && !ctx.GlobalBool(NoDiscoverFlag.Name) + forceV5Discovery := (lightClient || lightServer) && !ctx.GlobalBool(NoDiscoverFlag.Name) if ctx.GlobalIsSet(DiscoveryV5Flag.Name) { cfg.DiscoveryV5 = ctx.GlobalBool(DiscoveryV5Flag.Name) } else if forceV5Discovery { -- cgit v1.2.3 From 55599ee95d4151a2502465e0afc7c47bd1acba77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Mon, 5 Feb 2018 18:40:32 +0200 Subject: core, trie: intermediate mempool between trie and database (#15857) This commit reduces database I/O by not writing every state trie to disk. --- cmd/evm/runner.go | 4 +++- cmd/geth/chaincmd.go | 4 ++-- cmd/geth/main.go | 3 +++ cmd/geth/usage.go | 6 +++++- cmd/utils/cmd.go | 26 +++++++++++++++++--------- cmd/utils/flags.go | 47 ++++++++++++++++++++++++++++++++++++++++------- 6 files changed, 70 insertions(+), 20 deletions(-) (limited to 'cmd') diff --git a/cmd/evm/runner.go b/cmd/evm/runner.go index 96de0c76a..a9a2e5420 100644 --- a/cmd/evm/runner.go +++ b/cmd/evm/runner.go @@ -96,7 +96,9 @@ func runCmd(ctx *cli.Context) error { } if ctx.GlobalString(GenesisFlag.Name) != "" { gen := readGenesis(ctx.GlobalString(GenesisFlag.Name)) - _, statedb = gen.ToBlock() + db, _ := ethdb.NewMemDatabase() + genesis := gen.ToBlock(db) + statedb, _ = state.New(genesis.Root(), state.NewDatabase(db)) chainConfig = gen.Config } else { db, _ := ethdb.NewMemDatabase() diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go index 4a9a7b11b..35bf576e1 100644 --- a/cmd/geth/chaincmd.go +++ b/cmd/geth/chaincmd.go @@ -202,7 +202,7 @@ func importChain(ctx *cli.Context) error { if len(ctx.Args()) == 1 { if err := utils.ImportChain(chain, ctx.Args().First()); err != nil { - utils.Fatalf("Import error: %v", err) + log.Error("Import error", "err", err) } } else { for _, arg := range ctx.Args() { @@ -211,7 +211,7 @@ func importChain(ctx *cli.Context) error { } } } - + chain.Stop() fmt.Printf("Import done in %v.\n\n", time.Since(start)) // Output pre-compaction stats mostly to see the import trashing diff --git a/cmd/geth/main.go b/cmd/geth/main.go index b955bd243..cb8d63bf7 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -85,10 +85,13 @@ var ( utils.FastSyncFlag, utils.LightModeFlag, utils.SyncModeFlag, + utils.GCModeFlag, utils.LightServFlag, utils.LightPeersFlag, utils.LightKDFFlag, utils.CacheFlag, + utils.CacheDatabaseFlag, + utils.CacheGCFlag, utils.TrieCacheGenFlag, utils.ListenPortFlag, utils.MaxPeersFlag, diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go index a834d5b7a..a2bcaff02 100644 --- a/cmd/geth/usage.go +++ b/cmd/geth/usage.go @@ -22,10 +22,11 @@ import ( "io" "sort" + "strings" + "github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/internal/debug" "gopkg.in/urfave/cli.v1" - "strings" ) // AppHelpTemplate is the test template for the default, global app help topic. @@ -74,6 +75,7 @@ var AppHelpFlagGroups = []flagGroup{ utils.TestnetFlag, utils.RinkebyFlag, utils.SyncModeFlag, + utils.GCModeFlag, utils.EthStatsURLFlag, utils.IdentityFlag, utils.LightServFlag, @@ -127,6 +129,8 @@ var AppHelpFlagGroups = []flagGroup{ Name: "PERFORMANCE TUNING", Flags: []cli.Flag{ utils.CacheFlag, + utils.CacheDatabaseFlag, + utils.CacheGCFlag, utils.TrieCacheGenFlag, }, }, diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index 23b10c2d7..53cdf7861 100644 --- a/cmd/utils/cmd.go +++ b/cmd/utils/cmd.go @@ -116,7 +116,6 @@ func ImportChain(chain *core.BlockChain, fn string) error { return err } } - stream := rlp.NewStream(reader, 0) // Run actual the import. @@ -150,25 +149,34 @@ func ImportChain(chain *core.BlockChain, fn string) error { if checkInterrupt() { return fmt.Errorf("interrupted") } - if hasAllBlocks(chain, blocks[:i]) { + missing := missingBlocks(chain, blocks[:i]) + if len(missing) == 0 { log.Info("Skipping batch as all blocks present", "batch", batch, "first", blocks[0].Hash(), "last", blocks[i-1].Hash()) continue } - - if _, err := chain.InsertChain(blocks[:i]); err != nil { + if _, err := chain.InsertChain(missing); err != nil { return fmt.Errorf("invalid block %d: %v", n, err) } } return nil } -func hasAllBlocks(chain *core.BlockChain, bs []*types.Block) bool { - for _, b := range bs { - if !chain.HasBlock(b.Hash(), b.NumberU64()) { - return false +func missingBlocks(chain *core.BlockChain, blocks []*types.Block) []*types.Block { + head := chain.CurrentBlock() + for i, block := range blocks { + // If we're behind the chain head, only check block, state is available at head + if head.NumberU64() > block.NumberU64() { + if !chain.HasBlock(block.Hash(), block.NumberU64()) { + return blocks[i:] + } + continue + } + // If we're above the chain head, state availability is a must + if !chain.HasBlockAndState(block.Hash(), block.NumberU64()) { + return blocks[i:] } } - return true + return nil } func ExportChain(blockchain *core.BlockChain, fn string) error { diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 833cd95de..2a2909ff2 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -170,7 +170,11 @@ var ( Usage: `Blockchain sync mode ("fast", "full", or "light")`, Value: &defaultSyncMode, } - + GCModeFlag = cli.StringFlag{ + Name: "gcmode", + Usage: `Blockchain garbage collection mode ("full", "archive")`, + Value: "full", + } LightServFlag = cli.IntFlag{ Name: "lightserv", Usage: "Maximum percentage of time allowed for serving LES requests (0-90)", @@ -293,8 +297,18 @@ var ( // Performance tuning settings CacheFlag = cli.IntFlag{ Name: "cache", - Usage: "Megabytes of memory allocated to internal caching (min 16MB / database forced)", - Value: 128, + Usage: "Megabytes of memory allocated to internal caching", + Value: 1024, + } + CacheDatabaseFlag = cli.IntFlag{ + Name: "cache.database", + Usage: "Percentage of cache memory allowance to use for database io", + Value: 75, + } + CacheGCFlag = cli.IntFlag{ + Name: "cache.gc", + Usage: "Percentage of cache memory allowance to use for trie pruning", + Value: 25, } TrieCacheGenFlag = cli.IntFlag{ Name: "trie-cache-gens", @@ -1021,11 +1035,19 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) { cfg.NetworkId = ctx.GlobalUint64(NetworkIdFlag.Name) } - if ctx.GlobalIsSet(CacheFlag.Name) { - cfg.DatabaseCache = ctx.GlobalInt(CacheFlag.Name) + if ctx.GlobalIsSet(CacheFlag.Name) || ctx.GlobalIsSet(CacheDatabaseFlag.Name) { + cfg.DatabaseCache = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheDatabaseFlag.Name) / 100 } cfg.DatabaseHandles = makeDatabaseHandles() + if gcmode := ctx.GlobalString(GCModeFlag.Name); gcmode != "full" && gcmode != "archive" { + Fatalf("--%s must be either 'full' or 'archive'", GCModeFlag.Name) + } + cfg.NoPruning = ctx.GlobalString(GCModeFlag.Name) == "archive" + + if ctx.GlobalIsSet(CacheFlag.Name) || ctx.GlobalIsSet(CacheGCFlag.Name) { + cfg.TrieCache = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheGCFlag.Name) / 100 + } if ctx.GlobalIsSet(MinerThreadsFlag.Name) { cfg.MinerThreads = ctx.GlobalInt(MinerThreadsFlag.Name) } @@ -1157,7 +1179,7 @@ func SetupNetwork(ctx *cli.Context) { // MakeChainDatabase open an LevelDB using the flags passed to the client and will hard crash if it fails. func MakeChainDatabase(ctx *cli.Context, stack *node.Node) ethdb.Database { var ( - cache = ctx.GlobalInt(CacheFlag.Name) + cache = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheDatabaseFlag.Name) / 100 handles = makeDatabaseHandles() ) name := "chaindata" @@ -1209,8 +1231,19 @@ func MakeChain(ctx *cli.Context, stack *node.Node) (chain *core.BlockChain, chai }) } } + if gcmode := ctx.GlobalString(GCModeFlag.Name); gcmode != "full" && gcmode != "archive" { + Fatalf("--%s must be either 'full' or 'archive'", GCModeFlag.Name) + } + cache := &core.CacheConfig{ + Disabled: ctx.GlobalString(GCModeFlag.Name) == "archive", + TrieNodeLimit: eth.DefaultConfig.TrieCache, + TrieTimeLimit: eth.DefaultConfig.TrieTimeout, + } + if ctx.GlobalIsSet(CacheFlag.Name) || ctx.GlobalIsSet(CacheGCFlag.Name) { + cache.TrieNodeLimit = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheGCFlag.Name) / 100 + } vmcfg := vm.Config{EnablePreimageRecording: ctx.GlobalBool(VMEnableDebugFlag.Name)} - chain, err = core.NewBlockChain(chainDb, config, engine, vmcfg) + chain, err = core.NewBlockChain(chainDb, cache, config, engine, vmcfg) if err != nil { Fatalf("Can't create BlockChain: %v", err) } -- cgit v1.2.3