-
Notifications
You must be signed in to change notification settings - Fork 889
feat(store): Add PostgresDB backend with basic get/put and tests #7685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: unstable
Are you sure you want to change the base?
Conversation
); | ||
|
||
INSERT INTO store (col, key, value) | ||
VALUES ('example', decode('aabbcc', 'hex'), decode('112233', 'hex')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think we need this file?
use store::database::postgres_impl::PostgresDB; | ||
use store::{AsyncKeyValueStore, DBColumn}; | ||
use types::MainnetEthSpec; | ||
|
||
#[tokio::test] | ||
async fn test_postgres_store() { | ||
dotenvy::dotenv().ok(); | ||
|
||
let db_url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set"); | ||
|
||
let db = PostgresDB::<MainnetEthSpec>::new(&db_url) | ||
.await | ||
.expect("failed to connect"); | ||
|
||
let key = b"test_key"; | ||
let value = b"test_value"; | ||
|
||
db.put_bytes(DBColumn::BeaconBlock, key, value) | ||
.await | ||
.expect("put failed"); | ||
|
||
let result = db.get_bytes(DBColumn::BeaconBlock, key) | ||
.await | ||
.expect("get failed"); | ||
|
||
assert_eq!(result, Some(value.to_vec())); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can delete this test eventually. We should instead enable our test suite to run with a postgres db backend enabled
Looks like a good start. I don't think we'll want to provide a database url via env variable, we'll probably want to do that via a cli flag. |
@eserilev I've pushed new commits addressing the recent work on the Postgres backend. It's ready for review when you have time. Let me know what you think. |
beacon_node/store/Cargo.toml
Outdated
tracing = { workspace = true } | ||
tracing-subscriber = { workspace = true } | ||
types = { workspace = true } | ||
xdelta3 = { workspace = true } | ||
zstd = { workspace = true } | ||
dotenvy = "0.15.7" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think we need dotenvy
Issue Addressed
Supersedes: #7639
Context: Initial draft PR for adding a PostgresDB backend to the Beacon Node store.
Proposed Changes
PostgresDB
backend implementation tostore
crate.get_bytes
put_bytes
tests/postgres_store.rs
that exercises these methods using a real Postgres database.Additional Info
interface.rs
.do_atomically
,key_exists
, etc.) will be added after initial review, wiring, and interface agreement.@eserilev