Merge branch 'ethersphere-frontier/cli-private-network' into develop

This commit is contained in:
obscuren 2015-03-18 18:39:56 +01:00
commit c12046d6bf
7 changed files with 102 additions and 102 deletions

View File

@ -42,7 +42,7 @@ import (
const ( const (
ClientIdentifier = "Ethereum(G)" ClientIdentifier = "Ethereum(G)"
Version = "0.9.1" Version = "Frontier - 0.9.1"
) )
var ( var (
@ -148,8 +148,8 @@ The Ethereum JavaScript VM exposes a node admin interface as well as the DAPP Ja
utils.RPCPortFlag, utils.RPCPortFlag,
utils.UnencryptedKeysFlag, utils.UnencryptedKeysFlag,
utils.VMDebugFlag, utils.VMDebugFlag,
utils.ProtocolVersionFlag,
//utils.VMTypeFlag, utils.NetworkIdFlag,
} }
// missing: // missing:
@ -348,7 +348,7 @@ GO: %s
OS: %s OS: %s
GOPATH=%s GOPATH=%s
GOROOT=%s GOROOT=%s
`, ClientIdentifier, Version, eth.ProtocolVersion, eth.NetworkId, runtime.Version(), runtime.GOOS, os.Getenv("GOPATH"), runtime.GOROOT()) `, ClientIdentifier, Version, c.GlobalInt(utils.ProtocolVersionFlag.Name), c.GlobalInt(utils.NetworkIdFlag.Name), runtime.Version(), runtime.GOOS, os.Getenv("GOPATH"), runtime.GOROOT())
} }
// hashish returns true for strings that look like hashes. // hashish returns true for strings that look like hashes.

View File

@ -28,8 +28,8 @@ import (
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
"github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/ui/qt/webengine" "github.com/ethereum/go-ethereum/ui/qt/webengine"
"github.com/obscuren/qml" "github.com/obscuren/qml"
@ -66,6 +66,8 @@ func init() {
utils.RPCListenAddrFlag, utils.RPCListenAddrFlag,
utils.RPCPortFlag, utils.RPCPortFlag,
utils.JSpathFlag, utils.JSpathFlag,
utils.ProtocolVersionFlag,
utils.NetworkIdFlag,
} }
} }

View File

@ -11,11 +11,11 @@ import (
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
"github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/p2p/nat" "github.com/ethereum/go-ethereum/p2p/nat"
@ -70,25 +70,23 @@ func NewApp(version, usage string) *cli.App {
var ( var (
// General settings // General settings
/*
VMTypeFlag = cli.IntFlag{
Name: "vm",
Usage: "Virtual Machine type: 0 is standard VM, 1 is debug VM",
}
*/
UnlockedAccountFlag = cli.StringFlag{
Name: "unlock",
Usage: "Unlock a given account untill this programs exits (address:password)",
}
VMDebugFlag = cli.BoolFlag{
Name: "vmdebug",
Usage: "Virtual Machine debug output",
}
DataDirFlag = cli.StringFlag{ DataDirFlag = cli.StringFlag{
Name: "datadir", Name: "datadir",
Usage: "Data directory to be used", Usage: "Data directory to be used",
Value: common.DefaultDataDir(), Value: common.DefaultDataDir(),
} }
ProtocolVersionFlag = cli.IntFlag{
Name: "protocolversion",
Usage: "ETH protocol version",
Value: eth.ProtocolVersion,
}
NetworkIdFlag = cli.IntFlag{
Name: "networkid",
Usage: "Network Id",
Value: eth.NetworkId,
}
// miner settings
MinerThreadsFlag = cli.IntFlag{ MinerThreadsFlag = cli.IntFlag{
Name: "minerthreads", Name: "minerthreads",
Usage: "Number of miner threads", Usage: "Number of miner threads",
@ -98,11 +96,18 @@ var (
Name: "mine", Name: "mine",
Usage: "Enable mining", Usage: "Enable mining",
} }
// key settings
UnencryptedKeysFlag = cli.BoolFlag{ UnencryptedKeysFlag = cli.BoolFlag{
Name: "unencrypted-keys", Name: "unencrypted-keys",
Usage: "disable private key disk encryption (for testing)", Usage: "disable private key disk encryption (for testing)",
} }
UnlockedAccountFlag = cli.StringFlag{
Name: "unlock",
Usage: "Unlock a given account untill this programs exits (address:password)",
}
// logging and debug settings
LogFileFlag = cli.StringFlag{ LogFileFlag = cli.StringFlag{
Name: "logfile", Name: "logfile",
Usage: "Send log output to a file", Usage: "Send log output to a file",
@ -117,6 +122,10 @@ var (
Usage: `"std" or "raw"`, Usage: `"std" or "raw"`,
Value: "std", Value: "std",
} }
VMDebugFlag = cli.BoolFlag{
Name: "vmdebug",
Usage: "Virtual Machine debug output",
}
// RPC settings // RPC settings
RPCEnabledFlag = cli.BoolFlag{ RPCEnabledFlag = cli.BoolFlag{
@ -200,6 +209,8 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
return &eth.Config{ return &eth.Config{
Name: common.MakeName(clientID, version), Name: common.MakeName(clientID, version),
DataDir: ctx.GlobalString(DataDirFlag.Name), DataDir: ctx.GlobalString(DataDirFlag.Name),
ProtocolVersion: ctx.GlobalInt(ProtocolVersionFlag.Name),
NetworkId: ctx.GlobalInt(NetworkIdFlag.Name),
LogFile: ctx.GlobalString(LogFileFlag.Name), LogFile: ctx.GlobalString(LogFileFlag.Name),
LogLevel: ctx.GlobalInt(LogLevelFlag.Name), LogLevel: ctx.GlobalInt(LogLevelFlag.Name),
LogFormat: ctx.GlobalString(LogFormatFlag.Name), LogFormat: ctx.GlobalString(LogFormatFlag.Name),

View File

@ -10,11 +10,11 @@ import (
"github.com/ethereum/ethash" "github.com/ethereum/ethash"
"github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/blockpool" "github.com/ethereum/go-ethereum/blockpool"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/miner" "github.com/ethereum/go-ethereum/miner"
@ -39,6 +39,9 @@ var (
type Config struct { type Config struct {
Name string Name string
ProtocolVersion int
NetworkId int
DataDir string DataDir string
LogFile string LogFile string
LogLevel int LogLevel int
@ -138,11 +141,13 @@ type Ethereum struct {
Mining bool Mining bool
DataDir string DataDir string
version string version string
ProtocolVersion int
NetworkId int
} }
func New(config *Config) (*Ethereum, error) { func New(config *Config) (*Ethereum, error) {
// Boostrap database // Boostrap database
servlogger := logger.New(config.DataDir, config.LogFile, config.LogLevel, config.LogFormat) servlogsystem := logger.New(config.DataDir, config.LogFile, config.LogLevel, config.LogFormat)
newdb := config.NewDB newdb := config.NewDB
if newdb == nil { if newdb == nil {
@ -159,13 +164,14 @@ func New(config *Config) (*Ethereum, error) {
extraDb, err := ethdb.NewLDBDatabase(path.Join(config.DataDir, "extra")) extraDb, err := ethdb.NewLDBDatabase(path.Join(config.DataDir, "extra"))
// Perform database sanity checks // Perform database sanity checks
d, _ := blockDb.Get([]byte("ProtocolVersion")) d, _ := extraDb.Get([]byte("ProtocolVersion"))
protov := common.NewValue(d).Uint() protov := int(common.NewValue(d).Uint())
if protov != ProtocolVersion && protov != 0 { if protov != config.ProtocolVersion && protov != 0 {
path := path.Join(config.DataDir, "blockchain") path := path.Join(config.DataDir, "blockchain")
return nil, fmt.Errorf("Database version mismatch. Protocol(%d / %d). `rm -rf %s`", protov, ProtocolVersion, path) return nil, fmt.Errorf("Database version mismatch. Protocol(%d / %d). `rm -rf %s`", protov, config.ProtocolVersion, path)
} }
saveProtocolVersion(extraDb) saveProtocolVersion(extraDb, config.ProtocolVersion)
servlogger.Infof("Protocol Version: %v, Network Id: %v", config.ProtocolVersion, config.NetworkId)
eth := &Ethereum{ eth := &Ethereum{
shutdownChan: make(chan bool), shutdownChan: make(chan bool),
@ -173,7 +179,7 @@ func New(config *Config) (*Ethereum, error) {
stateDb: stateDb, stateDb: stateDb,
extraDb: extraDb, extraDb: extraDb,
eventMux: &event.TypeMux{}, eventMux: &event.TypeMux{},
logger: servlogger, logger: servlogsystem,
accountManager: config.AccountManager, accountManager: config.AccountManager,
DataDir: config.DataDir, DataDir: config.DataDir,
version: config.Name, // TODO should separate from Name version: config.Name, // TODO should separate from Name
@ -195,7 +201,8 @@ func New(config *Config) (*Ethereum, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
ethProto := EthProtocol(eth.txPool, eth.chainManager, eth.blockPool)
ethProto := EthProtocol(config.ProtocolVersion, config.NetworkId, eth.txPool, eth.chainManager, eth.blockPool)
protocols := []p2p.Protocol{ethProto} protocols := []p2p.Protocol{ethProto}
if config.Shh { if config.Shh {
protocols = append(protocols, eth.whisper.Protocol()) protocols = append(protocols, eth.whisper.Protocol())
@ -309,7 +316,6 @@ func (s *Ethereum) StateDb() common.Database { return s.stateDb }
func (s *Ethereum) ExtraDb() common.Database { return s.extraDb } func (s *Ethereum) ExtraDb() common.Database { return s.extraDb }
func (s *Ethereum) IsListening() bool { return true } // Always listening func (s *Ethereum) IsListening() bool { return true } // Always listening
func (s *Ethereum) PeerCount() int { return s.net.PeerCount() } func (s *Ethereum) PeerCount() int { return s.net.PeerCount() }
func (s *Ethereum) PeerInfo() int { return s.net.PeerCount() }
func (s *Ethereum) Peers() []*p2p.Peer { return s.net.Peers() } func (s *Ethereum) Peers() []*p2p.Peer { return s.net.Peers() }
func (s *Ethereum) MaxPeers() int { return s.net.MaxPeers } func (s *Ethereum) MaxPeers() int { return s.net.MaxPeers }
func (s *Ethereum) Version() string { return s.version } func (s *Ethereum) Version() string { return s.version }
@ -413,11 +419,11 @@ func (self *Ethereum) blockBroadcastLoop() {
} }
} }
func saveProtocolVersion(db common.Database) { func saveProtocolVersion(db common.Database, protov int) {
d, _ := db.Get([]byte("ProtocolVersion")) d, _ := db.Get([]byte("ProtocolVersion"))
protocolVersion := common.NewValue(d).Uint() protocolVersion := common.NewValue(d).Uint()
if protocolVersion == 0 { if protocolVersion == 0 {
db.Put([]byte("ProtocolVersion"), common.NewValue(ProtocolVersion).Bytes()) db.Put([]byte("ProtocolVersion"), common.NewValue(protov).Bytes())
} }
} }

View File

@ -1,23 +0,0 @@
package eth
import (
"encoding/json"
"github.com/ethereum/go-ethereum/common"
)
func WritePeers(path string, addresses []string) {
if len(addresses) > 0 {
data, _ := json.MarshalIndent(addresses, "", " ")
common.WriteFile(path, data)
}
}
func ReadPeers(path string) (ips []string, err error) {
var data string
data, err = common.ReadAllFile(path)
if err != nil {
json.Unmarshal([]byte(data), &ips)
}
return
}

View File

@ -5,9 +5,9 @@ import (
"fmt" "fmt"
"math/big" "math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/errs" "github.com/ethereum/go-ethereum/errs"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
@ -66,6 +66,8 @@ type ethProtocol struct {
id string id string
rw p2p.MsgReadWriter rw p2p.MsgReadWriter
errors *errs.Errors errors *errs.Errors
protocolVersion int
networkId int
} }
// backend is the interface the ethereum protocol backend should implement // backend is the interface the ethereum protocol backend should implement
@ -102,20 +104,20 @@ type getBlockHashesMsgData struct {
// main entrypoint, wrappers starting a server running the eth protocol // main entrypoint, wrappers starting a server running the eth protocol
// use this constructor to attach the protocol ("class") to server caps // use this constructor to attach the protocol ("class") to server caps
// the Dev p2p layer then runs the protocol instance on each peer // the Dev p2p layer then runs the protocol instance on each peer
func EthProtocol(txPool txPool, chainManager chainManager, blockPool blockPool) p2p.Protocol { func EthProtocol(protocolVersion, networkId int, txPool txPool, chainManager chainManager, blockPool blockPool) p2p.Protocol {
return p2p.Protocol{ return p2p.Protocol{
Name: "eth", Name: "eth",
Version: ProtocolVersion, Version: uint(protocolVersion),
Length: ProtocolLength, Length: ProtocolLength,
Run: func(peer *p2p.Peer, rw p2p.MsgReadWriter) error { Run: func(peer *p2p.Peer, rw p2p.MsgReadWriter) error {
return runEthProtocol(txPool, chainManager, blockPool, peer, rw) return runEthProtocol(protocolVersion, networkId, txPool, chainManager, blockPool, peer, rw)
}, },
} }
} }
// the main loop that handles incoming messages // the main loop that handles incoming messages
// note RemovePeer in the post-disconnect hook // note RemovePeer in the post-disconnect hook
func runEthProtocol(txPool txPool, chainManager chainManager, blockPool blockPool, peer *p2p.Peer, rw p2p.MsgReadWriter) (err error) { func runEthProtocol(protocolVersion, networkId int, txPool txPool, chainManager chainManager, blockPool blockPool, peer *p2p.Peer, rw p2p.MsgReadWriter) (err error) {
id := peer.ID() id := peer.ID()
self := &ethProtocol{ self := &ethProtocol{
txPool: txPool, txPool: txPool,
@ -123,6 +125,8 @@ func runEthProtocol(txPool txPool, chainManager chainManager, blockPool blockPoo
blockPool: blockPool, blockPool: blockPool,
rw: rw, rw: rw,
peer: peer, peer: peer,
protocolVersion: protocolVersion,
networkId: networkId,
errors: &errs.Errors{ errors: &errs.Errors{
Package: "ETH", Package: "ETH",
Errors: errorToString, Errors: errorToString,
@ -290,8 +294,8 @@ func (self *ethProtocol) statusMsg() p2p.Msg {
td, currentBlock, genesisBlock := self.chainManager.Status() td, currentBlock, genesisBlock := self.chainManager.Status()
return p2p.NewMsg(StatusMsg, return p2p.NewMsg(StatusMsg,
uint32(ProtocolVersion), uint32(self.protocolVersion),
uint32(NetworkId), uint32(self.networkId),
td, td,
currentBlock, currentBlock,
genesisBlock, genesisBlock,
@ -329,12 +333,12 @@ func (self *ethProtocol) handleStatus() error {
return self.protoError(ErrGenesisBlockMismatch, "%x (!= %x)", status.GenesisBlock, genesisBlock) return self.protoError(ErrGenesisBlockMismatch, "%x (!= %x)", status.GenesisBlock, genesisBlock)
} }
if status.NetworkId != NetworkId { if int(status.NetworkId) != self.networkId {
return self.protoError(ErrNetworkIdMismatch, "%d (!= %d)", status.NetworkId, NetworkId) return self.protoError(ErrNetworkIdMismatch, "%d (!= %d)", status.NetworkId, self.networkId)
} }
if ProtocolVersion != status.ProtocolVersion { if int(status.ProtocolVersion) != self.protocolVersion {
return self.protoError(ErrProtocolVersionMismatch, "%d (!= %d)", status.ProtocolVersion, ProtocolVersion) return self.protoError(ErrProtocolVersionMismatch, "%d (!= %d)", status.ProtocolVersion, self.protocolVersion)
} }
self.peer.Infof("Peer is [eth] capable (%d/%d). TD=%v H=%x\n", status.ProtocolVersion, status.NetworkId, status.TD, status.CurrentBlock[:4]) self.peer.Infof("Peer is [eth] capable (%d/%d). TD=%v H=%x\n", status.ProtocolVersion, status.NetworkId, status.TD, status.CurrentBlock[:4])

View File

@ -9,10 +9,10 @@ import (
"testing" "testing"
"time" "time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/errs" "github.com/ethereum/go-ethereum/errs"
"github.com/ethereum/go-ethereum/common"
ethlogger "github.com/ethereum/go-ethereum/logger" ethlogger "github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/discover" "github.com/ethereum/go-ethereum/p2p/discover"
@ -216,7 +216,7 @@ func (self *ethProtocolTester) checkMsg(i int, code uint64, val interface{}) (ms
} }
func (self *ethProtocolTester) run() { func (self *ethProtocolTester) run() {
err := runEthProtocol(self.txPool, self.chainManager, self.blockPool, testPeer(), self.rw) err := runEthProtocol(ProtocolVersion, NetworkId, self.txPool, self.chainManager, self.blockPool, testPeer(), self.rw)
self.quit <- err self.quit <- err
} }