Skip to content
Merged
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
19 changes: 9 additions & 10 deletions bin/katana/src/cli/db/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use std::path::{self};

use anyhow::{Context, Result};
use anyhow::Result;
use clap::{Args, Subcommand};
use comfy_table::modifiers::UTF8_ROUND_CORNERS;
use comfy_table::presets::UTF8_FULL;
use comfy_table::Table;
use katana_db::mdbx::{DbEnv, DbEnvKind};

mod prune;
mod stats;
Expand Down Expand Up @@ -43,16 +42,16 @@ impl DbArgs {
///
/// The path is expanded and resolved to an absolute path before opening the database for clearer
/// error messages.
pub fn open_db_ro(path: &str) -> Result<DbEnv> {
let path = path::absolute(shellexpand::full(path)?.into_owned())?;
DbEnv::open(&path, DbEnvKind::RO).with_context(|| {
format!("Opening database file in read-only mode at path {}", path.display())
})
pub fn open_db_ro(path: &str) -> Result<katana_db::Db> {
katana_db::Db::open_ro(&path::absolute(shellexpand::full(path)?.into_owned())?)
}

pub fn open_db_rw(path: &str) -> Result<DbEnv> {
let path = path::absolute(shellexpand::full(path)?.into_owned())?;
katana_db::open_db(path)
/// Open the database at `path` in read-write mode.
///
/// The path is expanded and resolved to an absolute path before opening the database for clearer
/// error messages.
pub fn open_db_rw(path: &str) -> Result<katana_db::Db> {
katana_db::Db::open(&path::absolute(shellexpand::full(path)?.into_owned())?)
}

/// Create a table with the default UTF-8 full border and rounded corners.
Expand Down
7 changes: 3 additions & 4 deletions bin/katana/tests/fixtures.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::collections::{BTreeMap, BTreeSet};

use katana_db::mdbx::DbEnv;
use katana_primitives::block::{Block, BlockHash, FinalityStatus};
use katana_primitives::class::{ClassHash, CompiledClassHash};
use katana_primitives::contract::{ContractAddress, Nonce, StorageKey, StorageValue};
Expand All @@ -20,7 +19,7 @@ pub struct TempDb {
impl TempDb {
pub fn new() -> Self {
let temp_dir = tempfile::tempdir().expect("failed to create temp dir");
katana_db::init_db(temp_dir.path()).expect("failed to initialize database");
katana_db::Db::new(temp_dir.path()).expect("failed to initialize database");
Self { temp_dir }
}

Expand All @@ -32,11 +31,11 @@ impl TempDb {
DbProvider::new(self.open_rw())
}

fn open_ro(&self) -> DbEnv {
fn open_ro(&self) -> katana_db::Db {
katana::cli::db::open_db_ro(self.path_str()).unwrap()
}

fn open_rw(&self) -> DbEnv {
fn open_rw(&self) -> katana_db::Db {
katana::cli::db::open_db_rw(self.path_str()).unwrap()
}

Expand Down
4 changes: 2 additions & 2 deletions crates/chain-spec/src/rollup/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ mod tests {
fn valid_transactions() {
let chain_spec = chain_spec(1, true);

let provider = DbProvider::new_ephemeral();
let provider = DbProvider::new_in_memory();
let ef = executor(&chain_spec);

let mut executor = ef.with_state(provider.latest().unwrap());
Expand All @@ -426,7 +426,7 @@ mod tests {
fn genesis_states() {
let chain_spec = chain_spec(1, true);

let provider = DbProvider::new_ephemeral();
let provider = DbProvider::new_in_memory();
let ef = executor(&chain_spec);

let mut executor = ef.with_state(provider.latest().unwrap());
Expand Down
4 changes: 2 additions & 2 deletions crates/core/benches/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ fn commit_small(c: &mut Criterion) {
small_transactions,
small_receipts.as_slice(),
&small_state_updates,
DbProvider::new_ephemeral(),
DbProvider::new_in_memory(),
);

c.bench_function("Serial", |b| {
Expand All @@ -168,7 +168,7 @@ fn commit_big(c: &mut Criterion) {
big_transactions,
big_receipts.as_slice(),
&big_state_updates,
DbProvider::new_ephemeral(),
DbProvider::new_in_memory(),
);

c.bench_function("Serial", |b| {
Expand Down
5 changes: 2 additions & 3 deletions crates/core/src/backend/storage.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::sync::Arc;

use anyhow::{anyhow, bail, Context, Result};
use katana_db::mdbx::DbEnv;
use katana_primitives::block::{
BlockHashOrNumber, BlockIdOrTag, BlockNumber, FinalityStatus, GasPrice, SealedBlockWithStatus,
};
Expand Down Expand Up @@ -85,13 +84,13 @@ impl Blockchain {
}

/// Creates a new [Blockchain] from a database at `path` and `genesis` state.
pub fn new_with_db(db: DbEnv) -> Self {
pub fn new_with_db(db: katana_db::Db) -> Self {
Self::new(DbProvider::new(db))
}

/// Builds a new blockchain with a forked block.
pub async fn new_from_forked(
db: DbEnv,
db: katana_db::Db,
fork_url: Url,
fork_block: Option<BlockHashOrNumber>,
chain: &mut katana_chain_spec::dev::ChainSpec,
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/service/block_producer_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::backend::storage::Blockchain;
fn test_backend() -> Arc<Backend<NoopExecutorFactory>> {
let chain_spec = Arc::new(ChainSpec::dev());
let executor_factory = NoopExecutorFactory::new();
let blockchain = Blockchain::new(DbProvider::new_ephemeral());
let blockchain = Blockchain::new(DbProvider::new_in_memory());
let gas_oracle = GasOracle::fixed(Default::default(), Default::default());
let backend = Arc::new(Backend::new(chain_spec, blockchain, gas_oracle, executor_factory));
backend.init_genesis().expect("failed to initialize genesis");
Expand Down
6 changes: 3 additions & 3 deletions crates/core/tests/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn executor(chain_spec: &ChainSpec) -> BlockifierFactory {
}

fn backend(chain_spec: &ChainSpec) -> Backend<BlockifierFactory> {
backend_with_db(chain_spec, DbProvider::new_ephemeral())
backend_with_db(chain_spec, DbProvider::new_in_memory())
}

fn backend_with_db(chain_spec: &ChainSpec, provider: impl Database) -> Backend<BlockifierFactory> {
Expand Down Expand Up @@ -83,7 +83,7 @@ fn can_initialize_genesis(#[case] chain: ChainSpec) {
#[case::dev(ChainSpec::Dev(dev_chain_spec()))]
#[case::rollup(ChainSpec::Rollup(rollup_chain_spec()))]
fn can_reinitialize_genesis(#[case] chain: ChainSpec) {
let db = DbProvider::new_ephemeral();
let db = DbProvider::new_in_memory();

let backend = backend_with_db(&chain, db.clone());
backend.init_genesis().expect("failed to initialize genesis");
Expand All @@ -94,7 +94,7 @@ fn can_reinitialize_genesis(#[case] chain: ChainSpec) {

#[test]
fn reinitialize_with_different_rollup_chain_spec() {
let db = DbProvider::new_ephemeral();
let db = DbProvider::new_in_memory();

let chain1 = ChainSpec::Rollup(rollup_chain_spec());
let backend1 = backend_with_db(&chain1, db.clone());
Expand Down
2 changes: 1 addition & 1 deletion crates/executor/tests/fixtures/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub fn state_provider(chain: &ChainSpec) -> Box<dyn StateProvider> {
let ChainSpec::Dev(chain) = chain else { panic!("should be dev chain spec") };

let states = chain.state_updates();
let provider = DbProvider::new_ephemeral();
let provider = DbProvider::new_in_memory();

let block = SealedBlockWithStatus {
status: FinalityStatus::AcceptedOnL2,
Expand Down
7 changes: 3 additions & 4 deletions crates/node/src/full/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

use anyhow::Result;
use exit::NodeStoppedFuture;
use katana_db::mdbx::DbEnv;
use katana_feeder_gateway::client::SequencerGateway;
use katana_metrics::exporters::prometheus::PrometheusRecorder;
use katana_metrics::{Report, Server as MetricsServer};
Expand Down Expand Up @@ -38,7 +37,7 @@

#[derive(Debug)]
pub struct Node {
pub db: DbEnv,
pub db: katana_db::Db,
pub pool: TxPool,
pub config: Arc<Config>,
pub task_manager: TaskManager,
Expand All @@ -62,7 +61,7 @@
let path = config.db.dir.clone().expect("database path must exist");

info!(target: "node", path = %path.display(), "Initializing database.");
let db = katana_db::init_db(path)?;
let db = katana_db::Db::new(path)?;

Check warning on line 64 in crates/node/src/full/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/node/src/full/mod.rs#L64

Added line #L64 was not covered by tests

let provider = DbProvider::new(db.clone());

Expand Down Expand Up @@ -134,7 +133,7 @@

#[derive(Debug)]
pub struct LaunchedNode {
pub db: DbEnv,
pub db: katana_db::Db,
pub pool: TxPool,
pub task_manager: TaskManager,
pub config: Arc<Config>,
Expand Down
12 changes: 6 additions & 6 deletions crates/node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
};
use katana_core::env::BlockContextGenerator;
use katana_core::service::block_producer::BlockProducer;
use katana_db::mdbx::DbEnv;
use katana_db::Db;
use katana_executor::implementation::blockifier::cache::ClassCache;
use katana_executor::implementation::blockifier::BlockifierFactory;
use katana_executor::ExecutionFlags;
Expand Down Expand Up @@ -63,7 +63,7 @@
pub struct Node {
config: Arc<Config>,
pool: TxPool,
db: DbEnv,
db: katana_db::Db,
rpc_server: RpcServer,
task_manager: TaskManager,
backend: Arc<Backend<BlockifierFactory>>,
Expand Down Expand Up @@ -138,7 +138,7 @@
return Err(anyhow::anyhow!("Forking is only supported in dev mode for now"));
};

let db = katana_db::init_ephemeral_db()?;
let db = katana_db::Db::in_memory()?;
let (bc, block_num) =
Blockchain::new_from_forked(db.clone(), cfg.url.clone(), cfg.block, chain_spec)
.await?;
Expand All @@ -149,10 +149,10 @@

(bc, db, Some(forked_client))
} else if let Some(db_path) = &config.db.dir {
let db = katana_db::init_db(db_path)?;
let db = katana_db::Db::new(db_path)?;

Check warning on line 152 in crates/node/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/node/src/lib.rs#L152

Added line #L152 was not covered by tests
(Blockchain::new_with_db(db.clone()), db, None)
} else {
let db = katana_db::init_ephemeral_db()?;
let db = katana_db::Db::in_memory()?;
(Blockchain::new_with_db(db.clone()), db, None)
};

Expand Down Expand Up @@ -371,7 +371,7 @@
}

/// Returns a reference to the node's database environment (if any).
pub fn db(&self) -> &DbEnv {
pub fn db(&self) -> &Db {

Check warning on line 374 in crates/node/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/node/src/lib.rs#L374

Added line #L374 was not covered by tests
&self.db
}

Expand Down
Loading