diff --git a/postgres/shared/util.go b/postgres/shared/util.go index 93ad211..8c29a74 100644 --- a/postgres/shared/util.go +++ b/postgres/shared/util.go @@ -16,22 +16,28 @@ package shared -import "github.com/jmoiron/sqlx" +import ( + "github.com/jmoiron/sqlx" -/* - Hostname: "localhost", - Port: 8077, - DatabaseName: "cerc_testing", - Username: "vdbm", - Password: "password", -*/ + "github.com/ethereum/go-ethereum/statediff/indexer/database/sql/postgres" +) + +var ( + testDBConfig, _ = postgres.Config{ + Hostname: "localhost", + DatabaseName: "cerc_testing", + Username: "vdbm", + Password: "password", + Port: 8077, + Driver: "SQLX", + }.WithEnv() +) // TestDB connect to the testing database // it assumes the database has the IPFS ipld.blocks table present // DO NOT use a production db for the test db, as it will remove all contents of the ipld.blocks table func TestDB() (*sqlx.DB, error) { - connectStr := "postgresql://vdbm:password@localhost:8077/cerc_testing?sslmode=disable" - return sqlx.Connect("postgres", connectStr) + return sqlx.Connect("postgres", testDBConfig.DbConnectionString()) } // ResetTestDB drops all rows in the test db ipld.blocks table diff --git a/postgres/v0/database.go b/postgres/v0/database.go index 41a0400..4872df4 100644 --- a/postgres/v0/database.go +++ b/postgres/v0/database.go @@ -119,7 +119,7 @@ func (d *Database) dbGet(key string) ([]byte, error) { var data []byte err := d.db.Get(&data, getPgStr, key) if err == sql.ErrNoRows { - log.Warn("Database miss for key", key) + log.Warn("Database miss for key ", key) } return data, err diff --git a/postgres/v1/database.go b/postgres/v1/database.go index ef514f7..87ea9e9 100644 --- a/postgres/v1/database.go +++ b/postgres/v1/database.go @@ -40,6 +40,12 @@ var ( putPgStr = "INSERT INTO ipld.blocks (key, data, block_number) VALUES ($1, $2, $3) ON CONFLICT DO NOTHING" deletePgStr = "DELETE FROM ipld.blocks WHERE key = $1" dbSizePgStr = "SELECT pg_database_size(current_database())" + + DefaultCacheConfig = CacheConfig{ + Name: "db", + Size: 3000000, // 3MB + ExpiryDuration: time.Hour, + } ) var _ ethdb.Database = &Database{} diff --git a/util.go b/util.go index 5735952..544fa74 100644 --- a/util.go +++ b/util.go @@ -29,7 +29,7 @@ func Keccak256ToCid(h []byte, codec uint64) (cid.Cid, error) { if err != nil { return cid.Cid{}, err } - return cid.NewCidV1(codec, multihash.Multihash(buf)), nil + return cid.NewCidV1(codec, buf), nil } // NewBlock takes a keccak256 hash key and the rlp []byte value it was derived from and creates an ipfs block object