diff options
author | Péter Szilágyi <peterke@gmail.com> | 2019-03-08 21:56:20 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2019-05-16 15:39:29 +0800 |
commit | 006c21efc7af8bdf04d003ef256d8e2eb30006bb (patch) | |
tree | 17df1f265b2f17355e7e6be75edbc2ffd695afe2 /node | |
parent | 0c5f8c078abca7dc5954e30f307495a5c41c5f6c (diff) | |
download | go-tangerine-006c21efc7af8bdf04d003ef256d8e2eb30006bb.tar go-tangerine-006c21efc7af8bdf04d003ef256d8e2eb30006bb.tar.gz go-tangerine-006c21efc7af8bdf04d003ef256d8e2eb30006bb.tar.bz2 go-tangerine-006c21efc7af8bdf04d003ef256d8e2eb30006bb.tar.lz go-tangerine-006c21efc7af8bdf04d003ef256d8e2eb30006bb.tar.xz go-tangerine-006c21efc7af8bdf04d003ef256d8e2eb30006bb.tar.zst go-tangerine-006c21efc7af8bdf04d003ef256d8e2eb30006bb.zip |
cmd, core, eth, les, node: chain freezer on top of db rework
Diffstat (limited to 'node')
-rw-r--r-- | node/node.go | 20 | ||||
-rw-r--r-- | node/service.go | 25 |
2 files changed, 41 insertions, 4 deletions
diff --git a/node/node.go b/node/node.go index 78bb492f0..08daeeee0 100644 --- a/node/node.go +++ b/node/node.go @@ -614,6 +614,26 @@ func (n *Node) OpenDatabase(name string, cache, handles int, namespace string) ( return rawdb.NewLevelDBDatabase(n.config.ResolvePath(name), cache, handles, namespace) } +// OpenDatabaseWithFreezer opens an existing database with the given name (or +// creates one if no previous can be found) from within the node's data directory, +// also attaching a chain freezer to it that moves ancient chain data from the +// database to immutable append-only files. If the node is an ephemeral one, a +// memory database is returned. +func (n *Node) OpenDatabaseWithFreezer(name string, cache, handles int, freezer, namespace string) (ethdb.Database, error) { + if n.config.DataDir == "" { + return rawdb.NewMemoryDatabase(), nil + } + root := n.config.ResolvePath(name) + + switch { + case freezer == "": + freezer = filepath.Join(root, "ancient") + case !filepath.IsAbs(freezer): + freezer = n.config.ResolvePath(freezer) + } + return rawdb.NewLevelDBDatabaseWithFreezer(root, cache, handles, freezer, namespace) +} + // ResolvePath returns the absolute path of a resource in the instance directory. func (n *Node) ResolvePath(x string) string { return n.config.ResolvePath(x) diff --git a/node/service.go b/node/service.go index 24f809743..4dea00995 100644 --- a/node/service.go +++ b/node/service.go @@ -17,6 +17,7 @@ package node import ( + "path/filepath" "reflect" "github.com/ethereum/go-ethereum/accounts" @@ -44,11 +45,27 @@ func (ctx *ServiceContext) OpenDatabase(name string, cache int, handles int, nam if ctx.config.DataDir == "" { return rawdb.NewMemoryDatabase(), nil } - db, err := rawdb.NewLevelDBDatabase(ctx.config.ResolvePath(name), cache, handles, namespace) - if err != nil { - return nil, err + return rawdb.NewLevelDBDatabase(ctx.config.ResolvePath(name), cache, handles, namespace) +} + +// OpenDatabaseWithFreezer opens an existing database with the given name (or +// creates one if no previous can be found) from within the node's data directory, +// also attaching a chain freezer to it that moves ancient chain data from the +// database to immutable append-only files. If the node is an ephemeral one, a +// memory database is returned. +func (ctx *ServiceContext) OpenDatabaseWithFreezer(name string, cache int, handles int, freezer string, namespace string) (ethdb.Database, error) { + if ctx.config.DataDir == "" { + return rawdb.NewMemoryDatabase(), nil + } + root := ctx.config.ResolvePath(name) + + switch { + case freezer == "": + freezer = filepath.Join(root, "ancient") + case !filepath.IsAbs(freezer): + freezer = ctx.config.ResolvePath(freezer) } - return db, nil + return rawdb.NewLevelDBDatabaseWithFreezer(root, cache, handles, freezer, namespace) } // ResolvePath resolves a user path into the data directory if that was relative |