forked from cerc-io/plugeth
ethdb/remotedb, cmd: add support for remote (readonly) databases (#24836)
* ethdb/remotedb, cmd: add support for remote (readonly) databases * ethdb/remotedb: minor changes * ethdb/remotedb: close the conn * cmd, ethdb: add rpc accessor for ancient data * internal/ethapi: license * ethdb/remotedb: linter fixes
This commit is contained in:
+14
-6
@@ -49,6 +49,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/eth/gasprice"
|
||||
"github.com/ethereum/go-ethereum/eth/tracers"
|
||||
"github.com/ethereum/go-ethereum/ethdb"
|
||||
"github.com/ethereum/go-ethereum/ethdb/remotedb"
|
||||
"github.com/ethereum/go-ethereum/ethstats"
|
||||
"github.com/ethereum/go-ethereum/graphql"
|
||||
"github.com/ethereum/go-ethereum/internal/ethapi"
|
||||
@@ -113,6 +114,10 @@ var (
|
||||
Usage: "Data directory for the databases and keystore",
|
||||
Value: DirectoryString(node.DefaultDataDir()),
|
||||
}
|
||||
RemoteDBFlag = cli.StringFlag{
|
||||
Name: "remotedb",
|
||||
Usage: "URL for remote database",
|
||||
}
|
||||
AncientFlag = DirectoryFlag{
|
||||
Name: "datadir.ancient",
|
||||
Usage: "Data directory for ancient chain segments (default = inside chaindata)",
|
||||
@@ -840,6 +845,7 @@ var (
|
||||
DatabasePathFlags = []cli.Flag{
|
||||
DataDirFlag,
|
||||
AncientFlag,
|
||||
RemoteDBFlag,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1962,12 +1968,14 @@ func MakeChainDatabase(ctx *cli.Context, stack *node.Node, readonly bool) ethdb.
|
||||
err error
|
||||
chainDb ethdb.Database
|
||||
)
|
||||
if ctx.GlobalString(SyncModeFlag.Name) == "light" {
|
||||
name := "lightchaindata"
|
||||
chainDb, err = stack.OpenDatabase(name, cache, handles, "", readonly)
|
||||
} else {
|
||||
name := "chaindata"
|
||||
chainDb, err = stack.OpenDatabaseWithFreezer(name, cache, handles, ctx.GlobalString(AncientFlag.Name), "", readonly)
|
||||
switch {
|
||||
case ctx.GlobalIsSet(RemoteDBFlag.Name):
|
||||
log.Info("Using remote db", "url", ctx.GlobalString(RemoteDBFlag.Name))
|
||||
chainDb, err = remotedb.New(ctx.GlobalString(RemoteDBFlag.Name))
|
||||
case ctx.GlobalString(SyncModeFlag.Name) == "light":
|
||||
chainDb, err = stack.OpenDatabase("lightchaindata", cache, handles, "", readonly)
|
||||
default:
|
||||
chainDb, err = stack.OpenDatabaseWithFreezer("chaindata", cache, handles, ctx.GlobalString(AncientFlag.Name), "", readonly)
|
||||
}
|
||||
if err != nil {
|
||||
Fatalf("Could not open database: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user