diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go index 321551ce05..fe63dfcca6 100644 --- a/cmd/geth/chaincmd.go +++ b/cmd/geth/chaincmd.go @@ -128,7 +128,7 @@ func removeDB(ctx *cli.Context) error { fmt.Println("Removing chaindata...") start := time.Now() - os.RemoveAll(filepath.Join(ctx.GlobalString(utils.DataDirFlag.Name), "chaindata")) + os.RemoveAll(filepath.Join(ctx.GlobalString(utils.DataDirFlag.Name), utils.ChainDbName(ctx))) fmt.Printf("Removed in %v\n", time.Since(start)) } else { @@ -153,7 +153,7 @@ func upgradeDB(ctx *cli.Context) error { utils.Fatalf("Unable to export chain for reimport %s", err) } chainDb.Close() - os.RemoveAll(filepath.Join(ctx.GlobalString(utils.DataDirFlag.Name), "chaindata")) + os.RemoveAll(filepath.Join(ctx.GlobalString(utils.DataDirFlag.Name), utils.ChainDbName(ctx))) // Import the chain file. chain, chainDb = utils.MakeChain(ctx) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 898a20cfe5..f32d341b5d 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -291,7 +291,7 @@ func initGenesis(ctx *cli.Context) error { utils.Fatalf("must supply path to genesis JSON file") } - chainDb, err := ethdb.NewLDBDatabase(filepath.Join(utils.MustMakeDataDir(ctx), "chaindata"), 0, 0) + chainDb, err := ethdb.NewLDBDatabase(filepath.Join(utils.MustMakeDataDir(ctx), utils.ChainDbName(ctx)), 0, 0) if err != nil { utils.Fatalf("could not open database: %v", err) } diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 50d3ca43a7..2d2281d984 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -708,8 +708,8 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte, Genesis: MakeGenesisBlock(ctx), FastSync: ctx.GlobalBool(FastSyncFlag.Name), LightMode: ctx.GlobalBool(LightModeFlag.Name), - LightServ: ctx.GlobalInt(LightServFlag.Name), - LightPeers: ctx.GlobalInt(LightPeersFlag.Name), + LightServ: ctx.GlobalInt(LightServFlag.Name), + LightPeers: ctx.GlobalInt(LightPeersFlag.Name), BlockChainVersion: ctx.GlobalInt(BlockchainVersionFlag.Name), DatabaseCache: ctx.GlobalInt(CacheFlag.Name), DatabaseHandles: MakeDatabaseHandles(), @@ -789,7 +789,7 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte, }); err != nil { Fatalf("Failed to register the account manager service: %v", err) } - + if ethConf.LightMode { if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) { return les.New(ctx, ethConf) @@ -866,15 +866,24 @@ func MustMakeChainConfigFromDb(ctx *cli.Context, db ethdb.Database) *core.ChainC return &core.ChainConfig{HomesteadBlock: homesteadBlockNo} } +func ChainDbName(ctx *cli.Context) string { + if ctx.GlobalBool(LightModeFlag.Name) { + return "lightchaindata" + } else { + return "chaindata" + } +} + // MakeChainDatabase open an LevelDB using the flags passed to the client and will hard crash if it fails. func MakeChainDatabase(ctx *cli.Context) ethdb.Database { var ( datadir = MustMakeDataDir(ctx) cache = ctx.GlobalInt(CacheFlag.Name) handles = MakeDatabaseHandles() + name = ChainDbName(ctx) ) - chainDb, err := ethdb.NewLDBDatabase(filepath.Join(datadir, "chaindata"), cache, handles) + chainDb, err := ethdb.NewLDBDatabase(filepath.Join(datadir, name), cache, handles) if err != nil { Fatalf("Could not open database: %v", err) } diff --git a/eth/backend.go b/eth/backend.go index b13d408351..360acacfc9 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -157,7 +157,7 @@ func (s *FullNodeService) AddLesServer(ls LesServer) { // New creates a new FullNodeService object (including the // initialisation of the common Ethereum object) func New(ctx *node.ServiceContext, config *Config) (*FullNodeService, error) { - chainDb, dappDb, err := CreateDBs(ctx, config) + chainDb, dappDb, err := CreateDBs(ctx, config, "chaindata") if err != nil { return nil, err } @@ -257,9 +257,9 @@ func New(ctx *node.ServiceContext, config *Config) (*FullNodeService, error) { } // CreateDBs creates the chain and dapp databases for an Ethereum service -func CreateDBs(ctx *node.ServiceContext, config *Config) (chainDb, dappDb ethdb.Database, err error) { +func CreateDBs(ctx *node.ServiceContext, config *Config, name string) (chainDb, dappDb ethdb.Database, err error) { // Open the chain database and perform any upgrades needed - chainDb, err = ctx.OpenDatabase("chaindata", config.DatabaseCache, config.DatabaseHandles) + chainDb, err = ctx.OpenDatabase(name, config.DatabaseCache, config.DatabaseHandles) if err != nil { return nil, nil, err } diff --git a/ethdb/database.go b/ethdb/database.go index dffb42e2b0..83b6896311 100644 --- a/ethdb/database.go +++ b/ethdb/database.go @@ -39,15 +39,17 @@ var OpenFileLimit = 64 // cacheRatio specifies how the total alloted cache is distributed between the // various system databases. var cacheRatio = map[string]float64{ - "dapp": 0.0, - "chaindata": 1.0, + "dapp": 0.0, + "chaindata": 1.0, + "lightchaindata": 1.0, } // handleRatio specifies how the total alloted file descriptors is distributed // between the various system databases. var handleRatio = map[string]float64{ - "dapp": 0.0, - "chaindata": 1.0, + "dapp": 0.0, + "chaindata": 1.0, + "lightchaindata": 1.0, } type LDBDatabase struct { diff --git a/les/backend.go b/les/backend.go index 8b2e006d88..2eb2429a0e 100644 --- a/les/backend.go +++ b/les/backend.go @@ -72,7 +72,7 @@ type LightNodeService struct { } func New(ctx *node.ServiceContext, config *eth.Config) (*LightNodeService, error) { - chainDb, dappDb, err := eth.CreateDBs(ctx, config) + chainDb, dappDb, err := eth.CreateDBs(ctx, config, "lightchaindata") if err != nil { return nil, err }