Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy committed Dec 10, 2023
1 parent 6ac7adf commit eeecaab
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/katana/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ repository.workspace = true
version.workspace = true

[dependencies]
katana-db = { path = "../storage/db" }
katana-executor = { path = "../executor" }
katana-primitives = { path = "../primitives" }
katana-provider = { path = "../storage/provider" }
Expand Down
4 changes: 3 additions & 1 deletion crates/katana/core/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use katana_primitives::state::StateUpdatesWithDeclaredClasses;
use katana_primitives::transaction::TxWithHash;
use katana_primitives::FieldElement;
use katana_provider::providers::fork::ForkedProvider;
use katana_provider::providers::in_memory::InMemoryProvider;
use katana_provider::traits::block::{BlockHashProvider, BlockWriter};
use katana_provider::traits::state::{StateFactoryProvider, StateProvider};
use parking_lot::RwLock;
Expand Down Expand Up @@ -102,6 +101,9 @@ impl Backend {
)
.expect("able to create forked blockchain")
} else {
// let db_env = katana_db::init_db("./katana_db").unwrap();
// Box::new(db_env)

Blockchain::new_with_genesis(InMemoryProvider::new(), &block_context)
.expect("able to create blockchain from genesis block")
};
Expand Down
4 changes: 1 addition & 3 deletions crates/katana/core/src/backend/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use katana_primitives::block::{
use katana_primitives::state::StateUpdatesWithDeclaredClasses;
use katana_primitives::FieldElement;
use katana_provider::traits::block::{BlockProvider, BlockWriter};
use katana_provider::traits::contract::{ContractClassWriter, ContractInfoProvider};
use katana_provider::traits::contract::ContractClassWriter;
use katana_provider::traits::state::{StateFactoryProvider, StateRootProvider, StateWriter};
use katana_provider::traits::state_update::StateUpdateProvider;
use katana_provider::traits::transaction::{
Expand All @@ -26,7 +26,6 @@ pub trait Database:
+ ReceiptProvider
+ StateUpdateProvider
+ StateRootProvider
+ ContractInfoProvider
+ StateWriter
+ ContractClassWriter
+ StateFactoryProvider
Expand All @@ -44,7 +43,6 @@ impl<T> Database for T where
+ TransactionsProviderExt
+ ReceiptProvider
+ StateUpdateProvider
+ ContractInfoProvider
+ StateRootProvider
+ StateWriter
+ ContractClassWriter
Expand Down
13 changes: 8 additions & 5 deletions crates/katana/rpc/src/starknet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,14 @@ impl StarknetApiServer for StarknetApi {
entry_point_selector: request.entry_point_selector,
};

let res = self.sequencer.call(request, block_id).map_err(|e| match e {
SequencerError::BlockNotFound(_) => StarknetApiError::BlockNotFound,
SequencerError::ContractNotFound(_) => StarknetApiError::ContractNotFound,
SequencerError::EntryPointExecution(_) => StarknetApiError::ContractError,
_ => StarknetApiError::UnexpectedError,
let res = self.sequencer.call(request, block_id).map_err(|e| {
println!("call error: {e}");
match e {
SequencerError::BlockNotFound(_) => StarknetApiError::BlockNotFound,
SequencerError::ContractNotFound(_) => StarknetApiError::ContractNotFound,
SequencerError::EntryPointExecution(_) => StarknetApiError::ContractError,
_ => StarknetApiError::UnexpectedError,
}
})?;

Ok(res.into_iter().map(|v| v.into()).collect())
Expand Down
3 changes: 2 additions & 1 deletion crates/katana/storage/provider/src/providers/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ impl BlockHashProvider for DbEnv {
fn latest_hash(&self) -> Result<BlockHash> {
let db_tx = self.tx()?;
let total_blocks = db_tx.entries::<BlockNumbers>()? as u64;
dbg!(total_blocks);
let latest_block = if total_blocks == 0 { 0 } else { total_blocks - 1 };
let latest_hash = db_tx.get::<BlockHashes>(latest_block)?.expect("should exist");
let latest_hash = db_tx.get::<BlockHashes>(latest_block)?.expect("block hash should exist");
db_tx.commit()?;
Ok(latest_hash)
}
Expand Down

0 comments on commit eeecaab

Please sign in to comment.