Skip to content

Commit

Permalink
add v0 table enum
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy committed Apr 15, 2024
1 parent 7cb2d7d commit 3a26ffe
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
23 changes: 21 additions & 2 deletions crates/katana/storage/db/src/mdbx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,28 @@ impl DbEnv {

#[cfg(any(test, feature = "test-utils"))]
pub mod test_utils {
use std::path::Path;
use super::*;
use crate::tables::v0::Tables as V0Tables;

impl DbEnv {
/// Creates all the defined tables in [`Tables`], if necessary.
pub fn create_v0_tables(&self) -> Result<(), DatabaseError> {
let tx = self.0.begin_rw_txn().map_err(DatabaseError::CreateRWTx)?;

Check warning on line 120 in crates/katana/storage/db/src/mdbx/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/katana/storage/db/src/mdbx/mod.rs#L119-L120

Added lines #L119 - L120 were not covered by tests

for table in V0Tables::ALL {
let flags = match table.table_type() {
TableType::Table => DatabaseFlags::default(),
TableType::DupSort => DatabaseFlags::DUP_SORT,

Check warning on line 125 in crates/katana/storage/db/src/mdbx/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/katana/storage/db/src/mdbx/mod.rs#L122-L125

Added lines #L122 - L125 were not covered by tests
};

tx.create_db(Some(table.name()), flags).map_err(DatabaseError::CreateTable)?;

Check warning on line 128 in crates/katana/storage/db/src/mdbx/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/katana/storage/db/src/mdbx/mod.rs#L128

Added line #L128 was not covered by tests
}

use super::{DbEnv, DbEnvKind};
tx.commit().map_err(DatabaseError::Commit)?;

Check warning on line 131 in crates/katana/storage/db/src/mdbx/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/katana/storage/db/src/mdbx/mod.rs#L131

Added line #L131 was not covered by tests

Ok(())
}

Check warning on line 134 in crates/katana/storage/db/src/mdbx/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/katana/storage/db/src/mdbx/mod.rs#L133-L134

Added lines #L133 - L134 were not covered by tests
}

const ERROR_DB_CREATION: &str = "Not able to create the mdbx file.";

Expand Down
30 changes: 28 additions & 2 deletions crates/katana/storage/db/src/tables/v0.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
use katana_primitives::block::BlockNumber;
use katana_primitives::contract::{ContractAddress, StorageKey};

use super::{DupSort, Table};
use super::*;
use crate::codecs::{Compress, Decode, Decompress, Encode};
use crate::error::CodecError;
use crate::models::contract::{ContractClassChange, ContractNonceChange};
use crate::models::storage::ContractStorageEntry;
use crate::models::storage::ContractStorageKey;
use crate::{dupsort, tables};
use crate::{define_tables_enum, dupsort, tables};

// TODO(kariy): can we somehow define this without repeating existing tables, and only add the older ones?
define_tables_enum! {[
(Headers, TableType::Table),
(BlockHashes, TableType::Table),
(BlockNumbers, TableType::Table),
(BlockBodyIndices, TableType::Table),
(BlockStatusses, TableType::Table),
(TxNumbers, TableType::Table),
(TxBlocks, TableType::Table),
(TxHashes, TableType::Table),
(Transactions, TableType::Table),
(Receipts, TableType::Table),
(CompiledClassHashes, TableType::Table),
(CompiledClasses, TableType::Table),
(SierraClasses, TableType::Table),
(ContractInfo, TableType::Table),
(ContractStorage, TableType::DupSort),
(ClassDeclarationBlock, TableType::Table),
(ClassDeclarations, TableType::DupSort),
(ContractInfoChangeSet, TableType::Table),
(NonceChanges, TableType::DupSort),
(ContractClassChanges, TableType::DupSort),
(StorageChanges, TableType::DupSort),
(StorageChangeSet, TableType::DupSort)
]}

tables! {
/// Contract nonce changes by block.
Expand Down

0 comments on commit 3a26ffe

Please sign in to comment.