Skip to content

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

Draft
wants to merge 7 commits into
base: unstable
Choose a base branch
from

Conversation

owanikin
Copy link

@owanikin owanikin commented Jul 1, 2025

Issue Addressed

Supersedes: #7639
Context: Initial draft PR for adding a PostgresDB backend to the Beacon Node store.

Proposed Changes

  • Adds PostgresDB backend implementation to store crate.
  • Currently implemented methods:
    • get_bytes
    • put_bytes
  • Includes a test in tests/postgres_store.rs that exercises these methods using a real Postgres database.

Additional Info

  • This is a WIP PR seeking early feedback before full integration into interface.rs.
  • Other methods (do_atomically, key_exists, etc.) will be added after initial review, wiring, and interface agreement.
  • Design goal: make the Beacon Node database pluggable with async-safe backends like Postgres for NFS compatibility.

@eserilev

);

INSERT INTO store (col, key, value)
VALUES ('example', decode('aabbcc', 'hex'), decode('112233', 'hex'));
Copy link
Member

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?

Comment on lines 1 to 27
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()));
}
Copy link
Member

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

@eserilev
Copy link
Member

eserilev commented Jul 3, 2025

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.

@owanikin
Copy link
Author

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

tracing = { workspace = true }
tracing-subscriber = { workspace = true }
types = { workspace = true }
xdelta3 = { workspace = true }
zstd = { workspace = true }
dotenvy = "0.15.7"
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants