Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
254 changes: 251 additions & 3 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ BUILD_PATH_RISCV64 = "target/$(RISCV64_TAG)/release"
PINNED_NIGHTLY ?= nightly

# List of features to use when cross-compiling. Can be overridden via the environment.
CROSS_FEATURES ?= gnosis,slasher-lmdb,slasher-mdbx,slasher-redb,beacon-node-leveldb,beacon-node-redb
CROSS_FEATURES ?= gnosis,slasher-lmdb,slasher-mdbx,slasher-redb,beacon-node-leveldb,beacon-node-redb,beacon-node-postgres

# Cargo profile for Cross builds. Default is for local builds, CI uses an override.
CROSS_PROFILE ?= release
Expand Down Expand Up @@ -264,7 +264,7 @@ lint-fix:

# Also run the lints on the optimized-only tests
lint-full:
TEST_FEATURES="beacon-node-leveldb,beacon-node-redb,${TEST_FEATURES}" RUSTFLAGS="-C debug-assertions=no $(RUSTFLAGS)" $(MAKE) lint
TEST_FEATURES="beacon-node-leveldb,beacon-node-redb,beacon-node-postgres,${TEST_FEATURES}" RUSTFLAGS="-C debug-assertions=no $(RUSTFLAGS)" $(MAKE) lint

# Runs the makefile in the `ef_tests` repo.
#
Expand Down
7 changes: 6 additions & 1 deletion beacon_node/store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,28 @@ authors = ["Paul Hauner <[email protected]>"]
edition = { workspace = true }

[features]
default = ["leveldb"]
default = ["postgres"]
leveldb = ["dep:leveldb"]
redb = ["dep:redb"]
postgres = ["dep:sqlx", "dep:tokio"]

[dependencies]
bls = { workspace = true }
db-key = "0.0.5"
directory = { workspace = true }
ethereum_ssz = { workspace = true }
ethereum_ssz_derive = { workspace = true }
heck = "0.4"
itertools = { workspace = true }
leveldb = { version = "0.8.6", optional = true, default-features = false }
logging = { workspace = true }
lru = { workspace = true }
metrics = { workspace = true }
once_cell = "1.21.3"
parking_lot = { workspace = true }
redb = { version = "2.1.3", optional = true }
tokio = { workspace = true, optional = true }
sqlx = { version = "0.7", optional = true, default-features = false, features = ["runtime-tokio", "postgres"] }
safe_arith = { workspace = true }
serde = { workspace = true }
smallvec = { workspace = true }
Expand Down
9 changes: 7 additions & 2 deletions beacon_node/store/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ use types::EthSpec;
use types::non_zero_usize::new_non_zero_usize;
use zstd::{Decoder, Encoder};

#[cfg(all(feature = "redb", not(feature = "leveldb")))]
#[cfg(all(feature = "redb", not(feature = "leveldb"), not(feature = "postgres")))]
pub const DEFAULT_BACKEND: DatabaseBackend = DatabaseBackend::Redb;
#[cfg(feature = "leveldb")]

#[cfg(all(feature = "leveldb", not(feature = "postgres"), not(feature = "redb")))]
pub const DEFAULT_BACKEND: DatabaseBackend = DatabaseBackend::LevelDb;
#[cfg(feature = "postgres")]
pub const DEFAULT_BACKEND: DatabaseBackend = DatabaseBackend::Postgres;

pub const PREV_DEFAULT_SLOTS_PER_RESTORE_POINT: u64 = 2048;
pub const DEFAULT_SLOTS_PER_RESTORE_POINT: u64 = 8192;
Expand Down Expand Up @@ -275,4 +278,6 @@ pub enum DatabaseBackend {
LevelDb,
#[cfg(feature = "redb")]
Redb,
#[cfg(feature = "postgres")]
Postgres,
}
2 changes: 2 additions & 0 deletions beacon_node/store/src/database.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pub mod interface;
#[cfg(feature = "leveldb")]
pub mod leveldb_impl;
#[cfg(feature = "postgres")]
pub mod postgres_impl;
#[cfg(feature = "redb")]
pub mod redb_impl;
50 changes: 50 additions & 0 deletions beacon_node/store/src/database/interface.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#[cfg(feature = "leveldb")]
use crate::database::leveldb_impl;
#[cfg(feature = "postgres")]
use crate::database::postgres_impl::{self, PostgresDB};
#[cfg(feature = "redb")]
use crate::database::redb_impl;
use crate::{ColumnIter, ColumnKeyIter, DBColumn, Error, ItemStore, Key, KeyValueStore, metrics};
Expand All @@ -13,6 +15,8 @@ pub enum BeaconNodeBackend<E: EthSpec> {
LevelDb(leveldb_impl::LevelDB<E>),
#[cfg(feature = "redb")]
Redb(redb_impl::Redb<E>),
#[cfg(feature = "postgres")]
Postgres(PostgresDB<E>),
}

impl<E: EthSpec> ItemStore<E> for BeaconNodeBackend<E> {}
Expand All @@ -24,6 +28,10 @@ impl<E: EthSpec> KeyValueStore<E> for BeaconNodeBackend<E> {
BeaconNodeBackend::LevelDb(txn) => leveldb_impl::LevelDB::get_bytes(txn, column, key),
#[cfg(feature = "redb")]
BeaconNodeBackend::Redb(txn) => redb_impl::Redb::get_bytes(txn, column, key),
#[cfg(feature = "postgres")]
BeaconNodeBackend::Postgres(txn) => {
postgres_impl::PostgresDB::get_bytes(txn, column, key)
}
}
}

Expand All @@ -45,6 +53,10 @@ impl<E: EthSpec> KeyValueStore<E> for BeaconNodeBackend<E> {
value,
txn.write_options(),
),
#[cfg(feature = "postgres")]
BeaconNodeBackend::Postgres(txn) => {
postgres_impl::PostgresDB::put_bytes(txn, column, key, value)
}
}
}

Expand All @@ -66,6 +78,10 @@ impl<E: EthSpec> KeyValueStore<E> for BeaconNodeBackend<E> {
value,
txn.write_options_sync(),
),
#[cfg(feature = "postgres")]
BeaconNodeBackend::Postgres(txn) => {
postgres_impl::PostgresDB::put_bytes(txn, column, key, value)
}
}
}

Expand All @@ -75,6 +91,8 @@ impl<E: EthSpec> KeyValueStore<E> for BeaconNodeBackend<E> {
BeaconNodeBackend::LevelDb(txn) => leveldb_impl::LevelDB::sync(txn),
#[cfg(feature = "redb")]
BeaconNodeBackend::Redb(txn) => redb_impl::Redb::sync(txn),
#[cfg(feature = "postgres")]
BeaconNodeBackend::Postgres(_) => Ok(()),
}
}

Expand All @@ -84,6 +102,10 @@ impl<E: EthSpec> KeyValueStore<E> for BeaconNodeBackend<E> {
BeaconNodeBackend::LevelDb(txn) => leveldb_impl::LevelDB::key_exists(txn, column, key),
#[cfg(feature = "redb")]
BeaconNodeBackend::Redb(txn) => redb_impl::Redb::key_exists(txn, column, key),
#[cfg(feature = "postgres")]
BeaconNodeBackend::Postgres(txn) => {
postgres_impl::PostgresDB::key_exists(txn, column, key)
}
}
}

Expand All @@ -93,6 +115,10 @@ impl<E: EthSpec> KeyValueStore<E> for BeaconNodeBackend<E> {
BeaconNodeBackend::LevelDb(txn) => leveldb_impl::LevelDB::key_delete(txn, column, key),
#[cfg(feature = "redb")]
BeaconNodeBackend::Redb(txn) => redb_impl::Redb::key_delete(txn, column, key),
#[cfg(feature = "postgres")]
BeaconNodeBackend::Postgres(txn) => {
postgres_impl::PostgresDB::key_delete(txn, column, key)
}
}
}

Expand All @@ -102,6 +128,10 @@ impl<E: EthSpec> KeyValueStore<E> for BeaconNodeBackend<E> {
BeaconNodeBackend::LevelDb(txn) => leveldb_impl::LevelDB::do_atomically(txn, batch),
#[cfg(feature = "redb")]
BeaconNodeBackend::Redb(txn) => redb_impl::Redb::do_atomically(txn, batch),
#[cfg(feature = "postgres")]
BeaconNodeBackend::Postgres(txn) => {
postgres_impl::PostgresDB::do_atomically(txn, batch)
}
}
}

Expand All @@ -111,6 +141,8 @@ impl<E: EthSpec> KeyValueStore<E> for BeaconNodeBackend<E> {
BeaconNodeBackend::LevelDb(txn) => leveldb_impl::LevelDB::compact(txn),
#[cfg(feature = "redb")]
BeaconNodeBackend::Redb(txn) => redb_impl::Redb::compact(txn),
#[cfg(feature = "postgres")]
BeaconNodeBackend::Postgres(txn) => postgres_impl::PostgresDB::compact(txn),
}
}

Expand All @@ -128,6 +160,10 @@ impl<E: EthSpec> KeyValueStore<E> for BeaconNodeBackend<E> {
BeaconNodeBackend::Redb(txn) => {
redb_impl::Redb::iter_column_keys_from(txn, _column, from)
}
#[cfg(feature = "postgres")]
BeaconNodeBackend::Postgres(txn) => {
postgres_impl::PostgresDB::iter_column_keys_from(txn, _column, from)
}
}
}

Expand All @@ -137,6 +173,8 @@ impl<E: EthSpec> KeyValueStore<E> for BeaconNodeBackend<E> {
BeaconNodeBackend::LevelDb(txn) => leveldb_impl::LevelDB::iter_column_keys(txn, column),
#[cfg(feature = "redb")]
BeaconNodeBackend::Redb(txn) => redb_impl::Redb::iter_column_keys(txn, column),
#[cfg(feature = "postgres")]
BeaconNodeBackend::Postgres(txn) => postgres_impl::PostgresDB::iter_column_keys(txn, column)
}
}

Expand All @@ -148,6 +186,8 @@ impl<E: EthSpec> KeyValueStore<E> for BeaconNodeBackend<E> {
}
#[cfg(feature = "redb")]
BeaconNodeBackend::Redb(txn) => redb_impl::Redb::iter_column_from(txn, column, from),
#[cfg(feature = "postgres")]
BeaconNodeBackend::Postgres(txn) => postgres_impl::PostgresDB::iter_column_from(txn, column, from)
}
}

Expand All @@ -157,6 +197,8 @@ impl<E: EthSpec> KeyValueStore<E> for BeaconNodeBackend<E> {
BeaconNodeBackend::LevelDb(txn) => leveldb_impl::LevelDB::compact_column(txn, _column),
#[cfg(feature = "redb")]
BeaconNodeBackend::Redb(txn) => redb_impl::Redb::compact(txn),
#[cfg(feature = "postgres")]
BeaconNodeBackend::Postgres(txn) => postgres_impl::PostgresDB::compact_column(txn, _column)
}
}

Expand All @@ -166,6 +208,8 @@ impl<E: EthSpec> KeyValueStore<E> for BeaconNodeBackend<E> {
BeaconNodeBackend::LevelDb(txn) => leveldb_impl::LevelDB::delete_batch(txn, col, ops),
#[cfg(feature = "redb")]
BeaconNodeBackend::Redb(txn) => redb_impl::Redb::delete_batch(txn, col, ops),
#[cfg(feature = "postgres")]
BeaconNodeBackend::Postgres(txn) => postgres_impl::PostgresDB::delete_batch(txn, col, ops)
}
}

Expand All @@ -179,6 +223,8 @@ impl<E: EthSpec> KeyValueStore<E> for BeaconNodeBackend<E> {
BeaconNodeBackend::LevelDb(txn) => leveldb_impl::LevelDB::delete_if(txn, column, f),
#[cfg(feature = "redb")]
BeaconNodeBackend::Redb(txn) => redb_impl::Redb::delete_if(txn, column, f),
#[cfg(feature = "postgres")]
BeaconNodeBackend::Postgres(txn) => postgres_impl::PostgresDB::delete_if(txn, column, f)
}
}
}
Expand All @@ -193,6 +239,10 @@ impl<E: EthSpec> BeaconNodeBackend<E> {
}
#[cfg(feature = "redb")]
DatabaseBackend::Redb => redb_impl::Redb::open(path).map(BeaconNodeBackend::Redb),
#[cfg(feature = "postgres")]
DatabaseBackend::Postgres => {
postgres_impl::PostgresDB::open(path).map(BeaconNodeBackend::Postgres)
}
}
}
}
Expand Down
Loading