split ethdb out of service

This commit is contained in:
Roy Crihfield 2022-01-10 23:37:27 -06:00
parent 1fab8ac1c8
commit 2bb06e0a8d
4 changed files with 22 additions and 15 deletions

View File

@ -44,7 +44,12 @@ func stateSnapshot() {
if err != nil {
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 {
logWithCommand.Fatal(err)
}

View File

@ -37,6 +37,7 @@ type DBConfig struct {
ConnConfig postgres.ConnectionConfig
}
// EthConfig is config parameters for the chain.
type EthConfig struct {
LevelDBPath string
AncientDBPath string

View File

@ -63,13 +63,14 @@ func NewPostgresDB(con *DBConfig) (*postgres.DB, error) {
return pgDB, nil
}
// NewSnapshotService creates Service.
func NewSnapshotService(con *EthConfig, pub *Publisher) (*Service, error) {
edb, err := rawdb.NewLevelDBDatabaseWithFreezer(con.LevelDBPath, 1024, 256, con.AncientDBPath, "eth-pg-ipfs-state-snapshot", false)
if err != nil {
return nil, err
}
func NewLevelDB(con *EthConfig) (ethdb.Database, error) {
return rawdb.NewLevelDBDatabaseWithFreezer(
con.LevelDBPath, 1024, 256, con.AncientDBPath, "eth-pg-ipfs-state-snapshot", false,
)
}
// NewSnapshotService creates Service.
func NewSnapshotService(edb ethdb.Database, pub *Publisher) (*Service, error) {
return &Service{
ethDB: edb,
stateDB: state.NewDatabase(edb),

View File

@ -9,13 +9,13 @@ import (
)
func testConfig(leveldbpath, ancientdbpath string) *Config {
dbParams := postgres.ConnectionParams{}
dbParams.Name = "snapshot_test"
dbParams.Hostname = "localhost"
dbParams.Port = 5432
dbParams.User = "tester"
dbParams.Password = "test_pw"
uri := postgres.DbConnectionString(dbParams)
dbParams := postgres.ConnectionParams{
Name: "snapshot_test",
Hostname: "localhost",
Port: 5432,
User: "tester",
Password: "test_pw",
}
connconfig := postgres.ConnectionConfig{
MaxIdle: 0,
MaxLifetime: 0,
@ -32,7 +32,7 @@ func testConfig(leveldbpath, ancientdbpath string) *Config {
return &Config{
DB: &DBConfig{
Node: nodeinfo,
URI: uri,
URI: postgres.DbConnectionString(dbParams),
ConnConfig: connconfig,
},
Eth: &EthConfig{