aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/geth/admin.go85
-rw-r--r--cmd/geth/js.go18
-rw-r--r--cmd/geth/main.go24
-rw-r--r--cmd/rlpdump/main.go2
-rw-r--r--cmd/utils/cmd.go2
-rw-r--r--cmd/utils/flags.go67
6 files changed, 167 insertions, 31 deletions
diff --git a/cmd/geth/admin.go b/cmd/geth/admin.go
index 3b37cba75..bd09291bf 100644
--- a/cmd/geth/admin.go
+++ b/cmd/geth/admin.go
@@ -1,6 +1,7 @@
package main
import (
+ "errors"
"fmt"
"os"
"time"
@@ -9,6 +10,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
+ "github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc"
@@ -35,6 +37,7 @@ func (js *jsre) adminBindings() {
admin.Set("export", js.exportChain)
admin.Set("verbosity", js.verbosity)
admin.Set("backtrace", js.backtrace)
+ admin.Set("progress", js.downloadProgress)
admin.Set("miner", struct{}{})
t, _ = admin.Get("miner")
@@ -49,6 +52,88 @@ func (js *jsre) adminBindings() {
debug := t.Object()
debug.Set("printBlock", js.printBlock)
debug.Set("dumpBlock", js.dumpBlock)
+ debug.Set("getBlockRlp", js.getBlockRlp)
+ debug.Set("setHead", js.setHead)
+ debug.Set("block", js.debugBlock)
+}
+
+func (js *jsre) getBlock(call otto.FunctionCall) (*types.Block, error) {
+ var block *types.Block
+ if len(call.ArgumentList) > 0 {
+ if call.Argument(0).IsNumber() {
+ num, _ := call.Argument(0).ToInteger()
+ block = js.ethereum.ChainManager().GetBlockByNumber(uint64(num))
+ } else if call.Argument(0).IsString() {
+ hash, _ := call.Argument(0).ToString()
+ block = js.ethereum.ChainManager().GetBlock(common.HexToHash(hash))
+ } else {
+ return nil, errors.New("invalid argument for dump. Either hex string or number")
+ }
+ return block, nil
+ }
+
+ return nil, errors.New("requires block number or block hash as argument")
+}
+
+func (js *jsre) debugBlock(call otto.FunctionCall) otto.Value {
+ block, err := js.getBlock(call)
+ if err != nil {
+ fmt.Println(err)
+ return otto.UndefinedValue()
+ }
+
+ if block == nil {
+ fmt.Println("block not found")
+ return otto.UndefinedValue()
+ }
+
+ old := vm.Debug
+ vm.Debug = true
+ _, err = js.ethereum.BlockProcessor().RetryProcess(block)
+ if err != nil {
+ glog.Infoln(err)
+ }
+ vm.Debug = old
+
+ return otto.UndefinedValue()
+}
+
+func (js *jsre) setHead(call otto.FunctionCall) otto.Value {
+ block, err := js.getBlock(call)
+ if err != nil {
+ fmt.Println(err)
+ return otto.UndefinedValue()
+ }
+
+ if block == nil {
+ fmt.Println("block not found")
+ return otto.UndefinedValue()
+ }
+
+ js.ethereum.ChainManager().SetHead(block)
+ return otto.UndefinedValue()
+}
+
+func (js *jsre) downloadProgress(call otto.FunctionCall) otto.Value {
+ current, max := js.ethereum.Downloader().Stats()
+
+ return js.re.ToVal(fmt.Sprintf("%d/%d", current, max))
+}
+
+func (js *jsre) getBlockRlp(call otto.FunctionCall) otto.Value {
+ block, err := js.getBlock(call)
+ if err != nil {
+ fmt.Println(err)
+ return otto.UndefinedValue()
+ }
+
+ if block == nil {
+ fmt.Println("block not found")
+ return otto.UndefinedValue()
+ }
+
+ encoded, _ := rlp.EncodeToBytes(block)
+ return js.re.ToVal(fmt.Sprintf("%x", encoded))
}
func (js *jsre) setExtra(call otto.FunctionCall) otto.Value {
diff --git a/cmd/geth/js.go b/cmd/geth/js.go
index 0061f20cf..6e5a6f1c7 100644
--- a/cmd/geth/js.go
+++ b/cmd/geth/js.go
@@ -25,7 +25,8 @@ import (
"strings"
"github.com/ethereum/go-ethereum/cmd/utils"
- "github.com/ethereum/go-ethereum/core/types"
+ "github.com/ethereum/go-ethereum/common/docserver"
+ "github.com/ethereum/go-ethereum/common/natspec"
"github.com/ethereum/go-ethereum/eth"
re "github.com/ethereum/go-ethereum/jsre"
"github.com/ethereum/go-ethereum/rpc"
@@ -139,10 +140,17 @@ var net = web3.net;
js.re.Eval(globalRegistrar + "registrar = new GlobalRegistrar(\"" + globalRegistrarAddr + "\");")
}
-func (self *jsre) ConfirmTransaction(tx *types.Transaction) bool {
- p := fmt.Sprintf("Confirm Transaction %v\n[y/n] ", tx)
- answer, _ := self.Prompt(p)
- return strings.HasPrefix(strings.Trim(answer, " "), "y")
+var ds, _ = docserver.New(utils.JSpathFlag.String())
+
+func (self *jsre) ConfirmTransaction(tx string) bool {
+ if self.ethereum.NatSpec {
+ notice := natspec.GetNotice(self.xeth, tx, ds)
+ fmt.Println(notice)
+ answer, _ := self.Prompt("Confirm Transaction\n[y/n] ")
+ return strings.HasPrefix(strings.Trim(answer, " "), "y")
+ } else {
+ return true
+ }
}
func (self *jsre) UnlockAccount(addr []byte) bool {
diff --git a/cmd/geth/main.go b/cmd/geth/main.go
index e18b92a2e..ddbd1f129 100644
--- a/cmd/geth/main.go
+++ b/cmd/geth/main.go
@@ -24,13 +24,13 @@ import (
"bufio"
"fmt"
"io/ioutil"
- "log"
- "net/http"
"os"
"runtime"
"strconv"
"time"
+ "path"
+
"github.com/codegangsta/cli"
"github.com/ethereum/ethash"
"github.com/ethereum/go-ethereum/accounts"
@@ -42,13 +42,12 @@ import (
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/logger"
"github.com/peterh/liner"
- "path"
)
import _ "net/http/pprof"
const (
ClientIdentifier = "Geth"
- Version = "0.9.9"
+ Version = "0.9.11"
)
var app = utils.NewApp(Version, "the go-ethereum command line interface")
@@ -217,6 +216,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
},
}
app.Flags = []cli.Flag{
+ utils.IdentityFlag,
utils.UnlockedAccountFlag,
utils.PasswordFileFlag,
utils.BootnodesFlag,
@@ -229,11 +229,13 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
utils.MinerThreadsFlag,
utils.MiningEnabledFlag,
utils.NATFlag,
+ utils.NatspecEnabledFlag,
utils.NodeKeyFileFlag,
utils.NodeKeyHexFlag,
utils.RPCEnabledFlag,
utils.RPCListenAddrFlag,
utils.RPCPortFlag,
+ utils.WhisperEnabledFlag,
utils.VMDebugFlag,
utils.ProtocolVersionFlag,
utils.NetworkIdFlag,
@@ -244,6 +246,14 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
utils.LogVModuleFlag,
utils.LogFileFlag,
utils.LogJSONFlag,
+ utils.PProfEanbledFlag,
+ utils.PProfPortFlag,
+ }
+ app.Before = func(ctx *cli.Context) error {
+ if ctx.GlobalBool(utils.PProfEanbledFlag.Name) {
+ utils.StartPProf(ctx)
+ }
+ return nil
}
// missing:
@@ -258,11 +268,6 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
}
func main() {
- // Start up the default http server for pprof
- go func() {
- log.Println(http.ListenAndServe("localhost:6060", nil))
- }()
-
fmt.Printf("Welcome to the FRONTIER\n")
runtime.GOMAXPROCS(runtime.NumCPU())
defer logger.Flush()
@@ -334,6 +339,7 @@ func unlockAccount(ctx *cli.Context, am *accounts.Manager, account string) (pass
}
func startEth(ctx *cli.Context, eth *eth.Ethereum) {
+ // Start Ethereum itself
utils.StartEthereum(eth)
am := eth.AccountManager()
diff --git a/cmd/rlpdump/main.go b/cmd/rlpdump/main.go
index 8567dcff8..528ccc6bd 100644
--- a/cmd/rlpdump/main.go
+++ b/cmd/rlpdump/main.go
@@ -78,7 +78,7 @@ func main() {
os.Exit(2)
}
- s := rlp.NewStream(r)
+ s := rlp.NewStream(r, 0)
for {
if err := dump(s, 0); err != nil {
if err != io.EOF {
diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go
index 7286f5c5e..64faf6ad1 100644
--- a/cmd/utils/cmd.go
+++ b/cmd/utils/cmd.go
@@ -154,7 +154,7 @@ func ImportChain(chainmgr *core.ChainManager, fn string) error {
defer fh.Close()
chainmgr.Reset()
- stream := rlp.NewStream(fh)
+ stream := rlp.NewStream(fh, 0)
var i, n int
batchSize := 2500
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go
index 8141fae82..b8f3982e2 100644
--- a/cmd/utils/flags.go
+++ b/cmd/utils/flags.go
@@ -2,6 +2,9 @@ package utils
import (
"crypto/ecdsa"
+ "fmt"
+ "log"
+ "net/http"
"os"
"path"
"runtime"
@@ -89,6 +92,14 @@ var (
Usage: "Blockchain version",
Value: core.BlockChainVersion,
}
+ IdentityFlag = cli.StringFlag{
+ Name: "identity",
+ Usage: "node name",
+ }
+ NatspecEnabledFlag = cli.BoolFlag{
+ Name: "natspec",
+ Usage: "Enable NatSpec confirmation notice",
+ }
// miner settings
MinerThreadsFlag = cli.IntFlag{
@@ -132,10 +143,33 @@ var (
Usage: "Send json structured log output to a file or '-' for standard output (default: no json output)",
Value: "",
}
+ LogToStdErrFlag = cli.BoolFlag{
+ Name: "logtostderr",
+ Usage: "Logs are written to standard error instead of to files.",
+ }
+ LogVModuleFlag = cli.GenericFlag{
+ Name: "vmodule",
+ Usage: "The syntax of the argument is a comma-separated list of pattern=N, where pattern is a literal file name (minus the \".go\" suffix) or \"glob\" pattern and N is a V level.",
+ Value: glog.GetVModule(),
+ }
VMDebugFlag = cli.BoolFlag{
Name: "vmdebug",
Usage: "Virtual Machine debug output",
}
+ BacktraceAtFlag = cli.GenericFlag{
+ Name: "backtrace_at",
+ Usage: "When set to a file and line number holding a logging statement a stack trace will be written to the Info log",
+ Value: glog.GetTraceLocation(),
+ }
+ PProfEanbledFlag = cli.BoolFlag{
+ Name: "pprof",
+ Usage: "Whether the profiling server should be enabled",
+ }
+ PProfPortFlag = cli.IntFlag{
+ Name: "pprofport",
+ Usage: "Port on which the profiler should listen",
+ Value: 6060,
+ }
// RPC settings
RPCEnabledFlag = cli.BoolFlag{
@@ -186,25 +220,15 @@ var (
Usage: "Port mapping mechanism (any|none|upnp|pmp|extip:<IP>)",
Value: "any",
}
+ WhisperEnabledFlag = cli.BoolFlag{
+ Name: "shh",
+ Usage: "Whether the whisper sub-protocol is enabled",
+ }
JSpathFlag = cli.StringFlag{
Name: "jspath",
Usage: "JS library path to be used with console and js subcommands",
Value: ".",
}
- BacktraceAtFlag = cli.GenericFlag{
- Name: "backtrace_at",
- Usage: "When set to a file and line number holding a logging statement a stack trace will be written to the Info log",
- Value: glog.GetTraceLocation(),
- }
- LogToStdErrFlag = cli.BoolFlag{
- Name: "logtostderr",
- Usage: "Logs are written to standard error instead of to files.",
- }
- LogVModuleFlag = cli.GenericFlag{
- Name: "vmodule",
- Usage: "The syntax of the argument is a comma-separated list of pattern=N, where pattern is a literal file name (minus the \".go\" suffix) or \"glob\" pattern and N is a V level.",
- Value: glog.GetVModule(),
- }
)
func GetNAT(ctx *cli.Context) nat.Interface {
@@ -242,6 +266,11 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
// Set the log dir
glog.SetLogDir(ctx.GlobalString(LogFileFlag.Name))
+ customName := ctx.GlobalString(IdentityFlag.Name)
+ if len(customName) > 0 {
+ clientID += "/" + customName
+ }
+
return &eth.Config{
Name: common.MakeName(clientID, version),
DataDir: ctx.GlobalString(DataDirFlag.Name),
@@ -259,8 +288,9 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
MaxPeers: ctx.GlobalInt(MaxPeersFlag.Name),
Port: ctx.GlobalString(ListenPortFlag.Name),
NAT: GetNAT(ctx),
+ NatSpec: ctx.GlobalBool(NatspecEnabledFlag.Name),
NodeKey: GetNodeKey(ctx),
- Shh: true,
+ Shh: ctx.GlobalBool(WhisperEnabledFlag.Name),
Dial: true,
BootNodes: ctx.GlobalString(BootnodesFlag.Name),
}
@@ -310,3 +340,10 @@ func StartRPC(eth *eth.Ethereum, ctx *cli.Context) {
xeth := xeth.New(eth, nil)
_ = rpc.Start(xeth, config)
}
+
+func StartPProf(ctx *cli.Context) {
+ address := fmt.Sprintf("localhost:%d", ctx.GlobalInt(PProfPortFlag.Name))
+ go func() {
+ log.Println(http.ListenAndServe(address, nil))
+ }()
+}