diff options
Diffstat (limited to 'cmd/utils')
-rw-r--r-- | cmd/utils/cmd.go | 52 | ||||
-rw-r--r-- | cmd/utils/customflags.go | 4 | ||||
-rw-r--r-- | cmd/utils/customflags_test.go | 4 | ||||
-rw-r--r-- | cmd/utils/flags.go | 47 | ||||
-rw-r--r-- | cmd/utils/legalese.go | 41 |
5 files changed, 116 insertions, 32 deletions
diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index 2949d2470..f8f7f6376 100644 --- a/cmd/utils/cmd.go +++ b/cmd/utils/cmd.go @@ -8,11 +8,11 @@ // // 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 +// 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 <http://www.gnu.org/licenses/>. +// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. // Package utils contains internal helper functions for go-ethereum commands. package utils @@ -21,6 +21,7 @@ import ( "bufio" "fmt" "io" + "math/big" "os" "os/signal" "regexp" @@ -32,6 +33,7 @@ import ( "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rlp" "github.com/peterh/liner" ) @@ -58,15 +60,16 @@ func PromptConfirm(prompt string) (bool, error) { ) prompt = prompt + " [y/N] " - if liner.TerminalSupported() { - lr := liner.NewLiner() - defer lr.Close() - input, err = lr.Prompt(prompt) - } else { - fmt.Print(prompt) - input, err = bufio.NewReader(os.Stdin).ReadString('\n') - fmt.Println() - } + // if liner.TerminalSupported() { + // fmt.Println("term") + // lr := liner.NewLiner() + // defer lr.Close() + // input, err = lr.Prompt(prompt) + // } else { + fmt.Print(prompt) + input, err = bufio.NewReader(os.Stdin).ReadString('\n') + fmt.Println() + // } if len(input) > 0 && strings.ToUpper(input[:1]) == "Y" { return true, nil @@ -92,12 +95,12 @@ func PromptPassword(prompt string, warnTerm bool) (string, error) { return input, err } -func initDataDir(Datadir string) { - _, err := os.Stat(Datadir) - if err != nil { - if os.IsNotExist(err) { - fmt.Printf("Data directory '%s' doesn't exist, creating it\n", Datadir) - os.Mkdir(Datadir, 0777) +func CheckLegalese(datadir string) { + // check "first run" + if !common.FileExist(datadir) { + r, _ := PromptConfirm(legalese) + if !r { + Fatalf("Must accept to continue. Shutting down...\n") } } } @@ -142,6 +145,15 @@ func StartEthereum(ethereum *eth.Ethereum) { }() } +func InitOlympic() { + params.DurationLimit = big.NewInt(8) + params.GenesisGasLimit = big.NewInt(3141592) + params.MinGasLimit = big.NewInt(125000) + params.MaximumExtraDataSize = big.NewInt(1024) + NetworkIdFlag.Value = 0 + core.BlockReward = big.NewInt(1.5e+18) +} + func FormatTransactionData(data string) []byte { d := common.StringToByteFunc(data, func(s string) (ret []byte) { slice := regexp.MustCompile("\\n|\\s").Split(s, 1000000000) @@ -202,6 +214,11 @@ func ImportChain(chain *core.ChainManager, fn string) error { } else if err != nil { return fmt.Errorf("at block %d: %v", n, err) } + // don't import first block + if b.NumberU64() == 0 { + i-- + continue + } blocks[i] = &b n++ } @@ -217,6 +234,7 @@ func ImportChain(chain *core.ChainManager, fn string) error { batch, blocks[0].Hash().Bytes()[:4], blocks[i-1].Hash().Bytes()[:4]) continue } + if _, err := chain.InsertChain(blocks[:i]); err != nil { return fmt.Errorf("invalid block %d: %v", n, err) } diff --git a/cmd/utils/customflags.go b/cmd/utils/customflags.go index 6aeec448c..e7efed4e3 100644 --- a/cmd/utils/customflags.go +++ b/cmd/utils/customflags.go @@ -8,11 +8,11 @@ // // 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 +// 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 <http://www.gnu.org/licenses/>. +// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. package utils diff --git a/cmd/utils/customflags_test.go b/cmd/utils/customflags_test.go index 726d1ab47..0fb0af63b 100644 --- a/cmd/utils/customflags_test.go +++ b/cmd/utils/customflags_test.go @@ -8,11 +8,11 @@ // // 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 +// 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 <http://www.gnu.org/licenses/>. +// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. package utils diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 903c97e71..815d48124 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -8,11 +8,11 @@ // // 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 +// 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 <http://www.gnu.org/licenses/>. +// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. package utils @@ -114,6 +114,10 @@ var ( Usage: "Sets the genesis nonce", Value: 42, } + GenesisFileFlag = cli.StringFlag{ + Name: "genesis", + Usage: "Inserts/Overwrites the genesis block (json format)", + } IdentityFlag = cli.StringFlag{ Name: "identity", Usage: "Custom node name", @@ -122,6 +126,15 @@ var ( Name: "natspec", Usage: "Enable NatSpec confirmation notice", } + CacheFlag = cli.IntFlag{ + Name: "cache", + Usage: "Megabytes of memory allocated to internal caching", + Value: 0, + } + OlympicFlag = cli.BoolFlag{ + Name: "olympic", + Usage: "Use olympic style protocol", + } // miner settings MinerThreadsFlag = cli.IntFlag{ @@ -145,7 +158,7 @@ var ( GasPriceFlag = cli.StringFlag{ Name: "gasprice", Usage: "Sets the minimal gasprice when mining transactions", - Value: new(big.Int).Mul(big.NewInt(1), common.Szabo).String(), + Value: new(big.Int).Mul(big.NewInt(50), common.Shannon).String(), } UnlockedAccountFlag = cli.StringFlag{ @@ -305,12 +318,12 @@ var ( GpoMinGasPriceFlag = cli.StringFlag{ Name: "gpomin", Usage: "Minimum suggested gas price", - Value: new(big.Int).Mul(big.NewInt(1), common.Szabo).String(), + Value: new(big.Int).Mul(big.NewInt(50), common.Shannon).String(), } GpoMaxGasPriceFlag = cli.StringFlag{ Name: "gpomax", Usage: "Maximum suggested gas price", - Value: new(big.Int).Mul(big.NewInt(100), common.Szabo).String(), + Value: new(big.Int).Mul(big.NewInt(500), common.Shannon).String(), } GpoFullBlockRatioFlag = cli.IntFlag{ Name: "gpofull", @@ -378,7 +391,9 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config { Name: common.MakeName(clientID, version), DataDir: ctx.GlobalString(DataDirFlag.Name), GenesisNonce: ctx.GlobalInt(GenesisNonceFlag.Name), + GenesisFile: ctx.GlobalString(GenesisFileFlag.Name), BlockChainVersion: ctx.GlobalInt(BlockchainVersionFlag.Name), + DatabaseCache: ctx.GlobalInt(CacheFlag.Name), SkipBcVersionCheck: false, NetworkId: ctx.GlobalInt(NetworkIdFlag.Name), LogFile: ctx.GlobalString(LogFileFlag.Name), @@ -391,6 +406,7 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config { MaxPeers: ctx.GlobalInt(MaxPeersFlag.Name), MaxPendingPeers: ctx.GlobalInt(MaxPendingPeersFlag.Name), Port: ctx.GlobalString(ListenPortFlag.Name), + Olympic: ctx.GlobalBool(OlympicFlag.Name), NAT: MakeNAT(ctx), NatSpec: ctx.GlobalBool(NatspecEnabledFlag.Name), Discovery: !ctx.GlobalBool(NoDiscoverFlag.Name), @@ -420,22 +436,31 @@ func SetupLogger(ctx *cli.Context) { // MakeChain creates a chain manager from set command line flags. func MakeChain(ctx *cli.Context) (chain *core.ChainManager, blockDB, stateDB, extraDB common.Database) { - dd := ctx.GlobalString(DataDirFlag.Name) + datadir := ctx.GlobalString(DataDirFlag.Name) + cache := ctx.GlobalInt(CacheFlag.Name) + var err error - if blockDB, err = ethdb.NewLDBDatabase(filepath.Join(dd, "blockchain")); err != nil { + if blockDB, err = ethdb.NewLDBDatabase(filepath.Join(datadir, "blockchain"), cache); err != nil { Fatalf("Could not open database: %v", err) } - if stateDB, err = ethdb.NewLDBDatabase(filepath.Join(dd, "state")); err != nil { + if stateDB, err = ethdb.NewLDBDatabase(filepath.Join(datadir, "state"), cache); err != nil { Fatalf("Could not open database: %v", err) } - if extraDB, err = ethdb.NewLDBDatabase(filepath.Join(dd, "extra")); err != nil { + if extraDB, err = ethdb.NewLDBDatabase(filepath.Join(datadir, "extra"), cache); err != nil { Fatalf("Could not open database: %v", err) } + if ctx.GlobalBool(OlympicFlag.Name) { + InitOlympic() + _, err := core.WriteTestNetGenesisBlock(stateDB, blockDB, 42) + if err != nil { + glog.Fatalln(err) + } + } eventMux := new(event.TypeMux) pow := ethash.New() - genesis := core.GenesisBlock(uint64(ctx.GlobalInt(GenesisNonceFlag.Name)), blockDB) - chain, err = core.NewChainManager(genesis, blockDB, stateDB, extraDB, pow, eventMux) + //genesis := core.GenesisBlock(uint64(ctx.GlobalInt(GenesisNonceFlag.Name)), blockDB) + chain, err = core.NewChainManager(blockDB, stateDB, extraDB, pow, eventMux) if err != nil { Fatalf("Could not start chainmanager: %v", err) } diff --git a/cmd/utils/legalese.go b/cmd/utils/legalese.go new file mode 100644 index 000000000..09e687c17 --- /dev/null +++ b/cmd/utils/legalese.go @@ -0,0 +1,41 @@ +// Copyright 2015 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 <http://www.gnu.org/licenses/>. + +package utils + +const ( + legalese = ` +======================================= +Disclaimer of Liabilites and Warranties +======================================= + +THE USER EXPRESSLY KNOWS AND AGREES THAT THE USER IS USING THE ETHEREUM PLATFORM AT THE USER’S SOLE +RISK. THE USER REPRESENTS THAT THE USER HAS AN ADEQUATE UNDERSTANDING OF THE RISKS, USAGE AND +INTRICACIES OF CRYPTOGRAPHIC TOKENS AND BLOCKCHAIN-BASED OPEN SOURCE SOFTWARE, ETH PLATFORM AND ETH. +THE USER ACKNOWLEDGES AND AGREES THAT, TO THE FULLEST EXTENT PERMITTED BY ANY APPLICABLE LAW, THE +DISCLAIMERS OF LIABILITY CONTAINED HEREIN APPLY TO ANY AND ALL DAMAGES OR INJURY WHATSOEVER CAUSED +BY OR RELATED TO RISKS OF, USE OF, OR INABILITY TO USE, ETH OR THE ETHEREUM PLATFORM UNDER ANY CAUSE +OR ACTION WHATSOEVER OF ANY KIND IN ANY JURISDICTION, INCLUDING, WITHOUT LIMITATION, ACTIONS FOR +BREACH OF WARRANTY, BREACH OF CONTRACT OR TORT (INCLUDING NEGLIGENCE) AND THAT NEITHER STIFTUNG +ETHEREUM NOR ETHEREUM TEAM SHALL BE LIABLE FOR ANY INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY OR +CONSEQUENTIAL DAMAGES, INCLUDING FOR LOSS OF PROFITS, GOODWILL OR DATA. SOME JURISDICTIONS DO NOT +ALLOW THE EXCLUSION OF CERTAIN WARRANTIES OR THE LIMITATION OR EXCLUSION OF LIABILITY FOR CERTAIN +TYPES OF DAMAGES. THEREFORE, SOME OF THE ABOVE LIMITATIONS IN THIS SECTION MAY NOT APPLY TO A USER. +IN PARTICULAR, NOTHING IN THESE TERMS SHALL AFFECT THE STATUTORY RIGHTS OF ANY USER OR EXCLUDE +INJURY ARISING FROM ANY WILLFUL MISCONDUCT OR FRAUD OF STIFTUNG ETHEREUM. + +Do you accept this agreement?` +) |