use statediff indexer config; other nits

This commit is contained in:
Roy Crihfield 2023-03-22 12:53:42 +08:00
parent 4695984e1d
commit 4a4ae2f2ea
4 changed files with 24 additions and 12 deletions

View File

@ -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

View File

@ -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

View File

@ -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{}

View File

@ -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