diff --git a/cmd/stateSnapshot.go b/cmd/stateSnapshot.go index 6a28319..ba910f3 100644 --- a/cmd/stateSnapshot.go +++ b/cmd/stateSnapshot.go @@ -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) } diff --git a/pkg/snapshot/config.go b/pkg/snapshot/config.go index b052eb6..c8b00d2 100644 --- a/pkg/snapshot/config.go +++ b/pkg/snapshot/config.go @@ -37,6 +37,7 @@ type DBConfig struct { ConnConfig postgres.ConnectionConfig } +// EthConfig is config parameters for the chain. type EthConfig struct { LevelDBPath string AncientDBPath string diff --git a/pkg/snapshot/service.go b/pkg/snapshot/service.go index 01391f2..61c6b2a 100644 --- a/pkg/snapshot/service.go +++ b/pkg/snapshot/service.go @@ -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), diff --git a/pkg/snapshot/service_test.go b/pkg/snapshot/service_test.go index b690249..e3789d6 100644 --- a/pkg/snapshot/service_test.go +++ b/pkg/snapshot/service_test.go @@ -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{