aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/utils
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2016-08-16 00:38:32 +0800
committerFelix Lange <fjl@twurst.com>2016-08-17 23:39:03 +0800
commit312263c7d9457fe7c24aac8e42a4cf2efc6ccd8e (patch)
treee10f9cc260af1ce13cb67b02bbce9c17c3b09de2 /cmd/utils
parentd6625ac34dad741f5659ca1dad3b0179603d37f0 (diff)
downloadgo-tangerine-312263c7d9457fe7c24aac8e42a4cf2efc6ccd8e.tar.gz
go-tangerine-312263c7d9457fe7c24aac8e42a4cf2efc6ccd8e.tar.zst
go-tangerine-312263c7d9457fe7c24aac8e42a4cf2efc6ccd8e.zip
cmd/utils, node: create account manager in package node
The account manager was previously created by packge cmd/utils as part of flag processing and then passed down into eth.Ethereum through its config struct. Since we are starting to create nodes which do not have eth.Ethereum as a registered service, the code was rearranged to register the account manager as its own service. Making it a service is ugly though and it doesn't really fix the root cause: creating nodes without eth.Ethereum requires duplicating lots of code. This commit splits utils.MakeSystemNode into three functions, making creation of other node/service configurations easier. It also moves the account manager into Node so it can be used by those configurations without requiring package eth.
Diffstat (limited to 'cmd/utils')
-rw-r--r--cmd/utils/flags.go135
1 files changed, 50 insertions, 85 deletions
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go
index de379f84f..067faf3ce 100644
--- a/cmd/utils/flags.go
+++ b/cmd/utils/flags.go
@@ -413,16 +413,6 @@ func MustMakeDataDir(ctx *cli.Context) string {
return ""
}
-// MakeKeyStoreDir resolves the folder to use for storing the account keys from the
-// set command line flags, returning the explicitly requested path, or one inside
-// the data directory otherwise.
-func MakeKeyStoreDir(datadir string, ctx *cli.Context) string {
- if path := ctx.GlobalString(KeyStoreDirFlag.Name); path != "" {
- return path
- }
- return filepath.Join(datadir, "keystore")
-}
-
// MakeIPCPath creates an IPC path configuration from the set command line flags,
// returning an empty string if IPC was explicitly disabled, or the set path.
func MakeIPCPath(ctx *cli.Context) string {
@@ -555,20 +545,6 @@ func MakeDatabaseHandles() int {
return limit / 2 // Leave half for networking and other stuff
}
-// MakeAccountManager creates an account manager from set command line flags.
-func MakeAccountManager(ctx *cli.Context) *accounts.Manager {
- // Create the keystore crypto primitive, light if requested
- scryptN := accounts.StandardScryptN
- scryptP := accounts.StandardScryptP
- if ctx.GlobalBool(LightKDFFlag.Name) {
- scryptN = accounts.LightScryptN
- scryptP = accounts.LightScryptP
- }
- datadir := MustMakeDataDir(ctx)
- keydir := MakeKeyStoreDir(datadir, ctx)
- return accounts.NewManager(keydir, scryptN, scryptP)
-}
-
// MakeAddress converts an account specified directly as a hex encoded string or
// a key index in the key store to an internal account representation.
func MakeAddress(accman *accounts.Manager, account string) (accounts.Account, error) {
@@ -631,9 +607,48 @@ func MakePasswordList(ctx *cli.Context) []string {
return lines
}
-// MakeSystemNode sets up a local node, configures the services to launch and
-// assembles the P2P protocol stack.
-func MakeSystemNode(name, version string, relconf release.Config, extra []byte, ctx *cli.Context) *node.Node {
+// MakeNode configures a node with no services from command line flags.
+func MakeNode(ctx *cli.Context, name, version string) *node.Node {
+ config := &node.Config{
+ DataDir: MustMakeDataDir(ctx),
+ KeyStoreDir: ctx.GlobalString(KeyStoreDirFlag.Name),
+ UseLightweightKDF: ctx.GlobalBool(LightKDFFlag.Name),
+ PrivateKey: MakeNodeKey(ctx),
+ Name: MakeNodeName(name, version, ctx),
+ NoDiscovery: ctx.GlobalBool(NoDiscoverFlag.Name),
+ BootstrapNodes: MakeBootstrapNodes(ctx),
+ ListenAddr: MakeListenAddress(ctx),
+ NAT: MakeNAT(ctx),
+ MaxPeers: ctx.GlobalInt(MaxPeersFlag.Name),
+ MaxPendingPeers: ctx.GlobalInt(MaxPendingPeersFlag.Name),
+ IPCPath: MakeIPCPath(ctx),
+ HTTPHost: MakeHTTPRpcHost(ctx),
+ HTTPPort: ctx.GlobalInt(RPCPortFlag.Name),
+ HTTPCors: ctx.GlobalString(RPCCORSDomainFlag.Name),
+ HTTPModules: MakeRPCModules(ctx.GlobalString(RPCApiFlag.Name)),
+ WSHost: MakeWSRpcHost(ctx),
+ WSPort: ctx.GlobalInt(WSPortFlag.Name),
+ WSOrigins: ctx.GlobalString(WSAllowedOriginsFlag.Name),
+ WSModules: MakeRPCModules(ctx.GlobalString(WSApiFlag.Name)),
+ }
+ if ctx.GlobalBool(DevModeFlag.Name) {
+ if !ctx.GlobalIsSet(DataDirFlag.Name) {
+ config.DataDir = filepath.Join(os.TempDir(), "/ethereum_dev_mode")
+ }
+ // --dev mode does not need p2p networking.
+ config.MaxPeers = 0
+ config.ListenAddr = ":0"
+ }
+ stack, err := node.New(config)
+ if err != nil {
+ Fatalf("Failed to create the protocol stack: %v", err)
+ }
+ return stack
+}
+
+// RegisterEthService configures eth.Ethereum from command line flags and adds it to the
+// given node.
+func RegisterEthService(ctx *cli.Context, stack *node.Node, relconf release.Config, extra []byte) {
// Avoid conflicting network flags
networks, netFlags := 0, []cli.BoolFlag{DevModeFlag, TestNetFlag, OlympicFlag}
for _, flag := range netFlags {
@@ -644,29 +659,6 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte,
if networks > 1 {
Fatalf("The %v flags are mutually exclusive", netFlags)
}
- // Configure the node's service container
- stackConf := &node.Config{
- DataDir: MustMakeDataDir(ctx),
- PrivateKey: MakeNodeKey(ctx),
- Name: MakeNodeName(name, version, ctx),
- NoDiscovery: ctx.GlobalBool(NoDiscoverFlag.Name),
- BootstrapNodes: MakeBootstrapNodes(ctx),
- ListenAddr: MakeListenAddress(ctx),
- NAT: MakeNAT(ctx),
- MaxPeers: ctx.GlobalInt(MaxPeersFlag.Name),
- MaxPendingPeers: ctx.GlobalInt(MaxPendingPeersFlag.Name),
- IPCPath: MakeIPCPath(ctx),
- HTTPHost: MakeHTTPRpcHost(ctx),
- HTTPPort: ctx.GlobalInt(RPCPortFlag.Name),
- HTTPCors: ctx.GlobalString(RPCCORSDomainFlag.Name),
- HTTPModules: MakeRPCModules(ctx.GlobalString(RPCApiFlag.Name)),
- WSHost: MakeWSRpcHost(ctx),
- WSPort: ctx.GlobalInt(WSPortFlag.Name),
- WSOrigins: ctx.GlobalString(WSAllowedOriginsFlag.Name),
- WSModules: MakeRPCModules(ctx.GlobalString(WSApiFlag.Name)),
- }
- // Configure the Ethereum service
- accman := MakeAccountManager(ctx)
// initialise new random number generator
rand := rand.New(rand.NewSource(time.Now().UnixNano()))
@@ -679,14 +671,13 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte,
}
ethConf := &eth.Config{
+ Etherbase: MakeEtherbase(stack.AccountManager(), ctx),
ChainConfig: MustMakeChainConfig(ctx),
FastSync: ctx.GlobalBool(FastSyncFlag.Name),
BlockChainVersion: ctx.GlobalInt(BlockchainVersionFlag.Name),
DatabaseCache: ctx.GlobalInt(CacheFlag.Name),
DatabaseHandles: MakeDatabaseHandles(),
NetworkId: ctx.GlobalInt(NetworkIdFlag.Name),
- AccountManager: accman,
- Etherbase: MakeEtherbase(accman, ctx),
MinerThreads: ctx.GlobalInt(MinerThreadsFlag.Name),
ExtraData: MakeMinerExtra(extra, ctx),
NatSpec: ctx.GlobalBool(NatspecEnabledFlag.Name),
@@ -703,8 +694,6 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte,
SolcPath: ctx.GlobalString(SolcPathFlag.Name),
AutoDAG: ctx.GlobalBool(AutoDAGFlag.Name) || ctx.GlobalBool(MiningEnabledFlag.Name),
}
- // Configure the Whisper service
- shhEnable := ctx.GlobalBool(WhisperEnabledFlag.Name)
// Override any default configs in dev mode or the test net
switch {
@@ -722,54 +711,30 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte,
state.StartingNonce = 1048576 // (2**20)
case ctx.GlobalBool(DevModeFlag.Name):
- // Override the base network stack configs
- if !ctx.GlobalIsSet(DataDirFlag.Name) {
- stackConf.DataDir = filepath.Join(os.TempDir(), "/ethereum_dev_mode")
- }
- if !ctx.GlobalIsSet(MaxPeersFlag.Name) {
- stackConf.MaxPeers = 0
- }
- if !ctx.GlobalIsSet(ListenPortFlag.Name) {
- stackConf.ListenAddr = ":0"
- }
- // Override the Ethereum protocol configs
ethConf.Genesis = core.OlympicGenesisBlock()
if !ctx.GlobalIsSet(GasPriceFlag.Name) {
ethConf.GasPrice = new(big.Int)
}
- if !ctx.GlobalIsSet(WhisperEnabledFlag.Name) {
- shhEnable = true
- }
ethConf.PowTest = true
}
- // Assemble and return the protocol stack
- stack, err := node.New(stackConf)
- if err != nil {
- Fatalf("Failed to create the protocol stack: %v", err)
- }
-
- if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
- return accman, nil
- }); err != nil {
- Fatalf("Failed to register the account manager service: %v", err)
- }
if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
return eth.New(ctx, ethConf)
}); err != nil {
Fatalf("Failed to register the Ethereum service: %v", err)
}
- if shhEnable {
- if err := stack.Register(func(*node.ServiceContext) (node.Service, error) { return whisper.New(), nil }); err != nil {
- Fatalf("Failed to register the Whisper service: %v", err)
- }
- }
if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
return release.NewReleaseService(ctx, relconf)
}); err != nil {
Fatalf("Failed to register the Geth release oracle service: %v", err)
}
- return stack
+}
+
+// RegisterShhService configures whisper and adds it to the given node.
+func RegisterShhService(stack *node.Node) {
+ if err := stack.Register(func(*node.ServiceContext) (node.Service, error) { return whisper.New(), nil }); err != nil {
+ Fatalf("Failed to register the Whisper service: %v", err)
+ }
}
// SetupNetwork configures the system for either the main net or some test network.
c38'>Update to 2.2.1sunpoet2018-03-212-4/+4 * Remove expired ports:rene2018-03-218-81/+0 * textproc/elasticsearch5-search-guard: Update to 5.6.8feld2018-03-214-69/+49 * textproc/elasticsearch{5,6}: Pidfiles should be in a writable subdirectoryfeld2018-03-214-6/+6 * Fix order of IGNORE_WITH_PHP variabledbaio2018-03-204-8/+4 * Update to 2018.03.18sunpoet2018-03-192-4/+4 * devel/oniguruma: Update to 6.8.1yuri2018-03-191-1/+1 * - Update to 2.25wen2018-03-182-4/+4 * Mark DEPRECATED and set EXPIRATION_DATE to 2018-03-31sunpoet2018-03-181-0/+3 * Add py-pylons-sphinx-themes 1.0.6sunpoet2018-03-184-0/+30 * Made 14 Go ports respect MAKE_ENV. This is expected to unbreak them.yuri2018-03-181-1/+1 * Mark these ports broken on armvX and mips: fail to package.linimon2018-03-182-0/+8 * devel/oniguruma: Update to 6.8.0yuri2018-03-181-1/+1 * New port: textproc/py-pypandoc: Thin wrapper for pandocyuri2018-03-184-0/+31 * Fix order of variablesdbaio2018-03-179-17/+22 * textproc/fzf: Fix patchesdbaio2018-03-173-7/+5 * Re-added port: textproc/ibus-table: Table-based input method framework for IB...yuri2018-03-175-0/+96 * Update to 1.1.7sunpoet2018-03-162-4/+4 * Update to 4.6.1sunpoet2018-03-162-4/+4 * Change MASTER_SITES to CHEESESHOPsunpoet2018-03-162-5/+7 * textproc/freexl: Update to 1.0.5yuri2018-03-162-7/+6 * Stop touching the filesystem during build.bdrewery2018-03-163-16/+22 * Fix plistbdrewery2018-03-162-1/+22 * Update to 1.3.0sunpoet2018-03-162-4/+4 * textproc/p5-YAML: Update to 1.24tobik2018-03-152-3/+7 * Update to 1.0.3matthew2018-03-152-4/+4 * Update to 1.6.1matthew2018-03-152-4/+4 * New port: textproc/py-bibtexparser: Bibtex parseryuri2018-03-154-0/+30 * textproc/kibana6: Fix ability to install pluginsfeld2018-03-152-10/+18 * textproc/elasticsearch6: Fix ability to install pluginsfeld2018-03-153-8/+26 * Update to 2.9.0sunpoet2018-03-152-4/+4 * - Add LICENSEamdmi32018-03-141-0/+3 * textproc/p5-XML-RSS: update to 1.60swills2018-03-143-7/+15 * - Update to 1.1.7tota2018-03-142-5/+4 * - Update to 1.9tota2018-03-142-7/+7 * Update to 1.1.6sunpoet2018-03-142-4/+4 * Update to 0.17.9sunpoet2018-03-142-4/+4 * Update to 2018.03.11sunpoet2018-03-132-4/+4 * Add rubygem-chewy 5.0.0sunpoet2018-03-134-0/+31 * Add rubygem-elasticsearch-dsl 0.1.5sunpoet2018-03-134-0/+27 * Add rubygem-commonmarker 0.17.8sunpoet2018-03-134-0/+33 * Update py-sip to 4.19.8 and qscintilla2 to 2.10.3tcberner2018-03-134-4/+4 * Update KDE Frameworks to 5.44tcberner2018-03-133-9/+9 * - Add new port: textproc/R-cran-utf8tota2018-03-124-0/+25 * Update to 3.0.8sunpoet2018-03-122-4/+4 * Update to 0.300sunpoet2018-03-122-4/+4 * Expand _LICENSE_PERMS_DEFAULTsunpoet2018-03-121-1/+1 * Update YAML::Tiny to 1.73adamw2018-03-112-3/+4 * Bump PORTREVISIONs of all users of math/mpc that we just updated togerald2018-03-1133-15/+33 * Bump PORTREVISION due upgrade of devel/boehm-gc to 7.6.4cpm2018-03-101-1/+1 * Introduce PHP flavors.mat2018-03-0920-47/+37 * Make 41 Go ports respect MAKE_ENV. This is expected to unbreak them.yuri2018-03-072-2/+2 * textproc/py-qt5-xml:jhale2018-03-072-2/+14 * Update to 2.8.4sunpoet2018-03-072-4/+4 * Update to 1.06sunpoet2018-03-072-6/+6 * Update to 1.60sunpoet2018-03-072-4/+4 * Update to 1.51sunpoet2018-03-062-4/+6 * Update to 2018.03.04sunpoet2018-03-062-4/+4 * Change MASTER_SITES to GitHubsunpoet2018-03-062-5/+4 * textproc/kibana{5,6}: Change node dependency to www/node6feld2018-03-062-4/+4 * textproc/py-mwparserfromhell: Update to 0.5.1yuri2018-03-052-4/+5 * Bump PORTREVISION on *-sbcl ports after lang/sbcl upgrade.krion2018-03-052-2/+2 * - Update to 0.10.0danilo2018-03-052-4/+4 * Update to 2.8.3sunpoet2018-03-052-4/+4 * - Add LICENSEamdmi32018-03-041-0/+4 * Update to 8.1.0sunpoet2018-03-042-4/+4 * Update to 1.4.1sunpoet2018-03-042-0/+2 * Update MAINTAINER for Elastic related portsfeld2018-03-0313-13/+13 * PyHamcrest is a framework for writing matcher objects, allowing youultima2018-03-034-0/+46 * textproc/elasticsearch6: Update pkg-messagefeld2018-03-032-8/+1 * Kibana is an open source (Apache Licensed), browser based analytics and searchfeld2018-03-036-0/+110 * Delete textproc/kibana6feld2018-03-036-110/+0 * Kibana is an open source (Apache Licensed), browser based analytics and searchfeld2018-03-036-0/+110 * textproc/elasticsearch{5,6}: Fix symlinkfeld2018-03-022-4/+4 * textproc/elasticsearch5: Fix buildfeld2018-03-021-1/+2 * textproc/elasticsearch6: Fix run issuesfeld2018-03-024-18/+29 * Update to 0.12sunpoet2018-02-282-6/+5 * Update to 0.20.2antoine2018-02-282-4/+4 * Update WWWsunpoet2018-02-281-1/+1 * Add LICENSEsunpoet2018-02-282-18/+22 * Update to 0.57.0sunpoet2018-02-272-5/+5 * Update to 0.7.0sunpoet2018-02-273-7/+7 * Switch some MASTER_SITES from http/ftp to https.mat2018-02-275-9/+7 * textproc/p5-XML-SAX: fix checksum mismatch for ParserDetails.inipi2018-02-274-2/+24 * textproc/elasticsearch{5,6}: Fix buildfeld2018-02-272-6/+6 * textproc/elasticsearch6: Fix JNA supportfeld2018-02-271-1/+4 * textproc/elasticsearch5: Fix JNA supportfeld2018-02-271-1/+4 * Update to 1.8.1sunpoet2018-02-272-4/+4 * Update to 2018.02.25sunpoet2018-02-272-4/+4 * Update to 0.990118adamw2018-02-264-13/+16 * New port: textproc/py-gambit-elasticsearch: Micro library for performing mult...yuri2018-02-264-0/+27 * Canonicalize dependency on libpngantoine2018-02-261-1/+1 * textproc/link-grammar: Update to 5.4.3yuri2018-02-254-14/+32 * Replaced my old rawbw.com maintainer's address with yuri@FreeBSD.orgyuri2018-02-256-6/+6 * Return pawel@'s ports to the pool after he resigned.rene2018-02-252-2/+2 * textproc/ripgrep: Update to 0.8.1tobik2018-02-252-28/+20 * textproc/kibana5: Fix buildfeld2018-02-251-1/+1 * textproc/elasticsearch6: Update to 6.2.2feld2018-02-245-202/+70 * Deprecate old versions of ElasticSearchfeld2018-02-242-0/+6 * Explain unclear license situation (see Makefile); bump PORTREVISIONriggs2018-02-241-1/+8 * Update ElasticSearch5 to 5.6.8feld2018-02-2418-29222/+107 * Remove outdated post-configure:sunpoet2018-02-241-3/+0 * Fix build with clang 6antoine2018-02-243-0/+88 * textproc/wv: Added license, dependencies, etc.yuri2018-02-241-6/+10 * Reset vg@'s ports after he resigned.rene2018-02-244-4/+4 * textproc/multimarkdown: Upgrade to 6.3.0pizzamig2018-02-234-45/+70 * textproc/zorba: Fixed plistyuri2018-02-232-3/+12 * textproc/elasticsearch5: Use native facilites for manging the processfeld2018-02-232-50/+4 * Update to 2018.02.21sunpoet2018-02-232-5/+5 * Update to 1.2sunpoet2018-02-232-5/+5 * Give the KDE SC4 applications ports a -kde4 suffixtcberner2018-02-239-5/+5 * textproc/elasticsearch5: rc script improvementfeld2018-02-223-48/+28 * New port: textproc/py-CommonMark: Python parser for the CommonMark Markdown specromain2018-02-224-0/+26 * - Switch to options helpersamdmi32018-02-222-3/+5 * Update to 1.96sunpoet2018-02-212-5/+5 * Update to 0.51sunpoet2018-02-212-4/+4 * Add textproc/libqxp, library for parsing QuarkXPress documentslwhsu2018-02-216-0/+76 * add textproc/libepubgen library for generating documents in ePub formatlwhsu2018-02-215-0/+65 * Update to 2.84sunpoet2018-02-212-4/+4 * Remove dependency on the python metaportsantoine2018-02-191-7/+3 * Reduce dependency on the python2 metaportantoine2018-02-1925-40/+49 * Update to 2018.02.18sunpoet2018-02-192-4/+4 * textproc/rubygem-github-linguist47: Limit PORTSCOUT checks; sortingjrm2018-02-191-4/+5 * Sort plistrakuco2018-02-191-1/+1 * Update to 1.1.9sunpoet2018-02-184-32/+38 * Move textproc/rubygem-sass-rails5 to textproc/rubygem-sass-rails-rails4sunpoet2018-02-186-5/+6 * Update WWWsunpoet2018-02-181-1/+1 * Update WWWsunpoet2018-02-181-1/+1 * Update WWWsunpoet2018-02-181-1/+1 * Update QScintilla 2.10.2.rakuco2018-02-184-6/+8 * Deprecate ports broken for more than 6 monthsantoine2018-02-182-0/+4 * Update CONFLICTS_INSTALLsunpoet2018-02-181-1/+1 * Mark CONFLICTS_INSTALL with qtchooser, rubygem-github-linguist and rubygem-gi...sunpoet2018-02-181-0/+3 * Update CONFLICTS_INSTALLsunpoet2018-02-181-1/+1 * Fix PKGNAME collisionsunpoet2018-02-181-6/+6