split ethdb out of service
This commit is contained in:
parent
1fab8ac1c8
commit
2bb06e0a8d
@ -44,7 +44,12 @@ func stateSnapshot() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
logWithCommand.Fatal(err)
|
logWithCommand.Fatal(err)
|
||||||
}
|
}
|
||||||
snapshotService, err := snapshot.NewSnapshotService(snapConfig.Eth, snapshot.NewPublisher(pgDB))
|
edb, err := snapshot.NewLevelDB(snapConfig.Eth)
|
||||||
|
if err != nil {
|
||||||
|
logWithCommand.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
snapshotService, err := snapshot.NewSnapshotService(edb, snapshot.NewPublisher(pgDB))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logWithCommand.Fatal(err)
|
logWithCommand.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@ type DBConfig struct {
|
|||||||
ConnConfig postgres.ConnectionConfig
|
ConnConfig postgres.ConnectionConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EthConfig is config parameters for the chain.
|
||||||
type EthConfig struct {
|
type EthConfig struct {
|
||||||
LevelDBPath string
|
LevelDBPath string
|
||||||
AncientDBPath string
|
AncientDBPath string
|
||||||
|
@ -63,13 +63,14 @@ func NewPostgresDB(con *DBConfig) (*postgres.DB, error) {
|
|||||||
return pgDB, nil
|
return pgDB, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSnapshotService creates Service.
|
func NewLevelDB(con *EthConfig) (ethdb.Database, error) {
|
||||||
func NewSnapshotService(con *EthConfig, pub *Publisher) (*Service, error) {
|
return rawdb.NewLevelDBDatabaseWithFreezer(
|
||||||
edb, err := rawdb.NewLevelDBDatabaseWithFreezer(con.LevelDBPath, 1024, 256, con.AncientDBPath, "eth-pg-ipfs-state-snapshot", false)
|
con.LevelDBPath, 1024, 256, con.AncientDBPath, "eth-pg-ipfs-state-snapshot", false,
|
||||||
if err != nil {
|
)
|
||||||
return nil, err
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
// NewSnapshotService creates Service.
|
||||||
|
func NewSnapshotService(edb ethdb.Database, pub *Publisher) (*Service, error) {
|
||||||
return &Service{
|
return &Service{
|
||||||
ethDB: edb,
|
ethDB: edb,
|
||||||
stateDB: state.NewDatabase(edb),
|
stateDB: state.NewDatabase(edb),
|
||||||
|
@ -9,13 +9,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func testConfig(leveldbpath, ancientdbpath string) *Config {
|
func testConfig(leveldbpath, ancientdbpath string) *Config {
|
||||||
dbParams := postgres.ConnectionParams{}
|
dbParams := postgres.ConnectionParams{
|
||||||
dbParams.Name = "snapshot_test"
|
Name: "snapshot_test",
|
||||||
dbParams.Hostname = "localhost"
|
Hostname: "localhost",
|
||||||
dbParams.Port = 5432
|
Port: 5432,
|
||||||
dbParams.User = "tester"
|
User: "tester",
|
||||||
dbParams.Password = "test_pw"
|
Password: "test_pw",
|
||||||
uri := postgres.DbConnectionString(dbParams)
|
}
|
||||||
connconfig := postgres.ConnectionConfig{
|
connconfig := postgres.ConnectionConfig{
|
||||||
MaxIdle: 0,
|
MaxIdle: 0,
|
||||||
MaxLifetime: 0,
|
MaxLifetime: 0,
|
||||||
@ -32,7 +32,7 @@ func testConfig(leveldbpath, ancientdbpath string) *Config {
|
|||||||
return &Config{
|
return &Config{
|
||||||
DB: &DBConfig{
|
DB: &DBConfig{
|
||||||
Node: nodeinfo,
|
Node: nodeinfo,
|
||||||
URI: uri,
|
URI: postgres.DbConnectionString(dbParams),
|
||||||
ConnConfig: connconfig,
|
ConnConfig: connconfig,
|
||||||
},
|
},
|
||||||
Eth: &EthConfig{
|
Eth: &EthConfig{
|
||||||
|
Loading…
Reference in New Issue
Block a user