@@ -396,13 +396,14 @@ var (
396396 }
397397)
398398
399- // MustMakeDataDir retrieves the currently requested data directory, terminating
399+ // MakeDataDir retrieves the currently requested data directory, terminating
400400// if none (or the empty string) is specified. If the node is starting a testnet,
401401// the a subdirectory of the specified datadir will be used.
402- func MustMakeDataDir (ctx * cli.Context ) string {
402+ func MakeDataDir (ctx * cli.Context ) string {
403403 if path := ctx .GlobalString (DataDirFlag .Name ); path != "" {
404+ // TODO: choose a different location outside of the regular datadir.
404405 if ctx .GlobalBool (TestNetFlag .Name ) {
405- return filepath .Join (path , "/ testnet" )
406+ return filepath .Join (path , "testnet" )
406407 }
407408 return path
408409 }
@@ -447,16 +448,16 @@ func MakeNodeKey(ctx *cli.Context) *ecdsa.PrivateKey {
447448 return key
448449}
449450
450- // MakeNodeName creates a node name from a base set and the command line flags.
451- func MakeNodeName ( client , version string , ctx * cli.Context ) string {
452- name := common . MakeName ( client , version )
451+ // makeNodeUserIdent creates the user identifier from CLI flags.
452+ func makeNodeUserIdent ( ctx * cli.Context ) string {
453+ var comps [] string
453454 if identity := ctx .GlobalString (IdentityFlag .Name ); len (identity ) > 0 {
454- name += "/" + identity
455+ comps = append ( comps , identity )
455456 }
456457 if ctx .GlobalBool (VMEnableJitFlag .Name ) {
457- name += "/ JIT"
458+ comps = append ( comps , " JIT")
458459 }
459- return name
460+ return strings . Join ( comps , "/" )
460461}
461462
462463// MakeBootstrapNodes creates a list of bootstrap nodes from the command line
@@ -612,11 +613,13 @@ func MakeNode(ctx *cli.Context, name, gitCommit string) *node.Node {
612613 }
613614
614615 config := & node.Config {
615- DataDir : MustMakeDataDir (ctx ),
616+ DataDir : MakeDataDir (ctx ),
616617 KeyStoreDir : ctx .GlobalString (KeyStoreDirFlag .Name ),
617618 UseLightweightKDF : ctx .GlobalBool (LightKDFFlag .Name ),
618619 PrivateKey : MakeNodeKey (ctx ),
619- Name : MakeNodeName (name , vsn , ctx ),
620+ Name : name ,
621+ Version : vsn ,
622+ UserIdent : makeNodeUserIdent (ctx ),
620623 NoDiscovery : ctx .GlobalBool (NoDiscoverFlag .Name ),
621624 BootstrapNodes : MakeBootstrapNodes (ctx ),
622625 ListenAddr : MakeListenAddress (ctx ),
@@ -674,7 +677,7 @@ func RegisterEthService(ctx *cli.Context, stack *node.Node, extra []byte) {
674677
675678 ethConf := & eth.Config {
676679 Etherbase : MakeEtherbase (stack .AccountManager (), ctx ),
677- ChainConfig : MustMakeChainConfig (ctx ),
680+ ChainConfig : MakeChainConfig (ctx , stack ),
678681 FastSync : ctx .GlobalBool (FastSyncFlag .Name ),
679682 DatabaseCache : ctx .GlobalInt (CacheFlag .Name ),
680683 DatabaseHandles : MakeDatabaseHandles (),
@@ -748,16 +751,16 @@ func SetupNetwork(ctx *cli.Context) {
748751 params .TargetGasLimit = common .String2Big (ctx .GlobalString (TargetGasLimitFlag .Name ))
749752}
750753
751- // MustMakeChainConfig reads the chain configuration from the database in ctx.Datadir.
752- func MustMakeChainConfig (ctx * cli.Context ) * core.ChainConfig {
753- db := MakeChainDatabase (ctx )
754+ // MakeChainConfig reads the chain configuration from the database in ctx.Datadir.
755+ func MakeChainConfig (ctx * cli.Context , stack * node. Node ) * core.ChainConfig {
756+ db := MakeChainDatabase (ctx , stack )
754757 defer db .Close ()
755758
756- return MustMakeChainConfigFromDb (ctx , db )
759+ return MakeChainConfigFromDb (ctx , db )
757760}
758761
759- // MustMakeChainConfigFromDb reads the chain configuration from the given database.
760- func MustMakeChainConfigFromDb (ctx * cli.Context , db ethdb.Database ) * core.ChainConfig {
762+ // MakeChainConfigFromDb reads the chain configuration from the given database.
763+ func MakeChainConfigFromDb (ctx * cli.Context , db ethdb.Database ) * core.ChainConfig {
761764 // If the chain is already initialized, use any existing chain configs
762765 config := new (core.ChainConfig )
763766
@@ -800,32 +803,31 @@ func MustMakeChainConfigFromDb(ctx *cli.Context, db ethdb.Database) *core.ChainC
800803}
801804
802805// MakeChainDatabase open an LevelDB using the flags passed to the client and will hard crash if it fails.
803- func MakeChainDatabase (ctx * cli.Context ) ethdb.Database {
806+ func MakeChainDatabase (ctx * cli.Context , stack * node. Node ) ethdb.Database {
804807 var (
805- datadir = MustMakeDataDir (ctx )
806808 cache = ctx .GlobalInt (CacheFlag .Name )
807809 handles = MakeDatabaseHandles ()
808810 )
809811
810- chainDb , err := ethdb . NewLDBDatabase ( filepath . Join ( datadir , "chaindata" ) , cache , handles )
812+ chainDb , err := stack . OpenDatabase ( "chaindata" , cache , handles )
811813 if err != nil {
812814 Fatalf ("Could not open database: %v" , err )
813815 }
814816 return chainDb
815817}
816818
817819// MakeChain creates a chain manager from set command line flags.
818- func MakeChain (ctx * cli.Context ) (chain * core.BlockChain , chainDb ethdb.Database ) {
820+ func MakeChain (ctx * cli.Context , stack * node. Node ) (chain * core.BlockChain , chainDb ethdb.Database ) {
819821 var err error
820- chainDb = MakeChainDatabase (ctx )
822+ chainDb = MakeChainDatabase (ctx , stack )
821823
822824 if ctx .GlobalBool (OlympicFlag .Name ) {
823825 _ , err := core .WriteTestNetGenesisBlock (chainDb )
824826 if err != nil {
825827 glog .Fatalln (err )
826828 }
827829 }
828- chainConfig := MustMakeChainConfigFromDb (ctx , chainDb )
830+ chainConfig := MakeChainConfigFromDb (ctx , chainDb )
829831
830832 pow := pow .PoW (core.FakePow {})
831833 if ! ctx .GlobalBool (FakePoWFlag .Name ) {
0 commit comments