Postgres datastore constructor methods
This commit is contained in:
parent
c0b4f6fe24
commit
29259bc3e6
@ -24,6 +24,8 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/ethdb/postgres"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/consensus/ethash"
|
"github.com/ethereum/go-ethereum/consensus/ethash"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
@ -160,4 +162,7 @@ type Config struct {
|
|||||||
|
|
||||||
// MuirGlacier block override (TODO: remove after the fork)
|
// MuirGlacier block override (TODO: remove after the fork)
|
||||||
OverrideMuirGlacier *big.Int
|
OverrideMuirGlacier *big.Int
|
||||||
|
|
||||||
|
// Config params for Postgres database
|
||||||
|
PostgresConfig *postgres.Config
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/ethdb/postgres"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts"
|
"github.com/ethereum/go-ethereum/accounts"
|
||||||
"github.com/ethereum/go-ethereum/accounts/external"
|
"github.com/ethereum/go-ethereum/accounts/external"
|
||||||
"github.com/ethereum/go-ethereum/accounts/keystore"
|
"github.com/ethereum/go-ethereum/accounts/keystore"
|
||||||
@ -191,6 +193,9 @@ type Config struct {
|
|||||||
staticNodesWarning bool
|
staticNodesWarning bool
|
||||||
trustedNodesWarning bool
|
trustedNodesWarning bool
|
||||||
oldGethResourceWarning bool
|
oldGethResourceWarning bool
|
||||||
|
|
||||||
|
// Config params for using Postgres database
|
||||||
|
PostgresConfig *postgres.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
// IPCEndpoint resolves an IPC endpoint based on a configured value, taking into
|
// IPCEndpoint resolves an IPC endpoint based on a configured value, taking into
|
||||||
|
16
node/node.go
16
node/node.go
@ -26,6 +26,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/ethdb/postgres"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts"
|
"github.com/ethereum/go-ethereum/accounts"
|
||||||
"github.com/ethereum/go-ethereum/core/rawdb"
|
"github.com/ethereum/go-ethereum/core/rawdb"
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
@ -607,6 +609,9 @@ func (n *Node) EventMux() *event.TypeMux {
|
|||||||
// previous can be found) from within the node's instance directory. If the node is
|
// previous can be found) from within the node's instance directory. If the node is
|
||||||
// ephemeral, a memory database is returned.
|
// ephemeral, a memory database is returned.
|
||||||
func (n *Node) OpenDatabase(name string, cache, handles int, namespace string) (ethdb.Database, error) {
|
func (n *Node) OpenDatabase(name string, cache, handles int, namespace string) (ethdb.Database, error) {
|
||||||
|
if n.config.PostgresConfig != nil {
|
||||||
|
return n.openPostgresDatabase()
|
||||||
|
}
|
||||||
if n.config.DataDir == "" {
|
if n.config.DataDir == "" {
|
||||||
return rawdb.NewMemoryDatabase(), nil
|
return rawdb.NewMemoryDatabase(), nil
|
||||||
}
|
}
|
||||||
@ -619,6 +624,9 @@ func (n *Node) OpenDatabase(name string, cache, handles int, namespace string) (
|
|||||||
// database to immutable append-only files. If the node is an ephemeral one, a
|
// database to immutable append-only files. If the node is an ephemeral one, a
|
||||||
// memory database is returned.
|
// memory database is returned.
|
||||||
func (n *Node) OpenDatabaseWithFreezer(name string, cache, handles int, freezer, namespace string) (ethdb.Database, error) {
|
func (n *Node) OpenDatabaseWithFreezer(name string, cache, handles int, freezer, namespace string) (ethdb.Database, error) {
|
||||||
|
if n.config.PostgresConfig != nil {
|
||||||
|
return n.openPostgresDatabase()
|
||||||
|
}
|
||||||
if n.config.DataDir == "" {
|
if n.config.DataDir == "" {
|
||||||
return rawdb.NewMemoryDatabase(), nil
|
return rawdb.NewMemoryDatabase(), nil
|
||||||
}
|
}
|
||||||
@ -633,6 +641,14 @@ func (n *Node) OpenDatabaseWithFreezer(name string, cache, handles int, freezer,
|
|||||||
return rawdb.NewLevelDBDatabaseWithFreezer(root, cache, handles, freezer, namespace)
|
return rawdb.NewLevelDBDatabaseWithFreezer(root, cache, handles, freezer, namespace)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n *Node) openPostgresDatabase() (ethdb.Database, error) {
|
||||||
|
db, err := postgres.NewDB(n.config.PostgresConfig)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return postgres.NewDatabase(db), nil
|
||||||
|
}
|
||||||
|
|
||||||
// ResolvePath returns the absolute path of a resource in the instance directory.
|
// ResolvePath returns the absolute path of a resource in the instance directory.
|
||||||
func (n *Node) ResolvePath(x string) string {
|
func (n *Node) ResolvePath(x string) string {
|
||||||
return n.config.ResolvePath(x)
|
return n.config.ResolvePath(x)
|
||||||
|
@ -20,6 +20,8 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/ethdb/postgres"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts"
|
"github.com/ethereum/go-ethereum/accounts"
|
||||||
"github.com/ethereum/go-ethereum/core/rawdb"
|
"github.com/ethereum/go-ethereum/core/rawdb"
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
@ -42,6 +44,9 @@ type ServiceContext struct {
|
|||||||
// if no previous can be found) from within the node's data directory. If the
|
// if no previous can be found) from within the node's data directory. If the
|
||||||
// node is an ephemeral one, a memory database is returned.
|
// node is an ephemeral one, a memory database is returned.
|
||||||
func (ctx *ServiceContext) OpenDatabase(name string, cache int, handles int, namespace string) (ethdb.Database, error) {
|
func (ctx *ServiceContext) OpenDatabase(name string, cache int, handles int, namespace string) (ethdb.Database, error) {
|
||||||
|
if ctx.config.PostgresConfig != nil {
|
||||||
|
return ctx.openPostgresDatabase()
|
||||||
|
}
|
||||||
if ctx.config.DataDir == "" {
|
if ctx.config.DataDir == "" {
|
||||||
return rawdb.NewMemoryDatabase(), nil
|
return rawdb.NewMemoryDatabase(), nil
|
||||||
}
|
}
|
||||||
@ -54,6 +59,9 @@ func (ctx *ServiceContext) OpenDatabase(name string, cache int, handles int, nam
|
|||||||
// database to immutable append-only files. If the node is an ephemeral one, a
|
// database to immutable append-only files. If the node is an ephemeral one, a
|
||||||
// memory database is returned.
|
// memory database is returned.
|
||||||
func (ctx *ServiceContext) OpenDatabaseWithFreezer(name string, cache int, handles int, freezer string, namespace string) (ethdb.Database, error) {
|
func (ctx *ServiceContext) OpenDatabaseWithFreezer(name string, cache int, handles int, freezer string, namespace string) (ethdb.Database, error) {
|
||||||
|
if ctx.config.PostgresConfig != nil {
|
||||||
|
return ctx.openPostgresDatabase()
|
||||||
|
}
|
||||||
if ctx.config.DataDir == "" {
|
if ctx.config.DataDir == "" {
|
||||||
return rawdb.NewMemoryDatabase(), nil
|
return rawdb.NewMemoryDatabase(), nil
|
||||||
}
|
}
|
||||||
@ -68,6 +76,14 @@ func (ctx *ServiceContext) OpenDatabaseWithFreezer(name string, cache int, handl
|
|||||||
return rawdb.NewLevelDBDatabaseWithFreezer(root, cache, handles, freezer, namespace)
|
return rawdb.NewLevelDBDatabaseWithFreezer(root, cache, handles, freezer, namespace)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ctx *ServiceContext) openPostgresDatabase() (ethdb.Database, error) {
|
||||||
|
db, err := postgres.NewDB(ctx.config.PostgresConfig)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return postgres.NewDatabase(db), nil
|
||||||
|
}
|
||||||
|
|
||||||
// ResolvePath resolves a user path into the data directory if that was relative
|
// ResolvePath resolves a user path into the data directory if that was relative
|
||||||
// and if the user actually uses persistent storage. It will return an empty string
|
// and if the user actually uses persistent storage. It will return an empty string
|
||||||
// for emphemeral storage and the user's own input for absolute paths.
|
// for emphemeral storage and the user's own input for absolute paths.
|
||||||
|
Loading…
Reference in New Issue
Block a user