Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy committed Jan 25, 2024
1 parent 1c87c94 commit 2834824
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bin/katana/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl KatanaArgs {
pub fn init_logging(&self) -> Result<(), Box<dyn std::error::Error>> {
const DEFAULT_LOG_FILTER: &str = "info,executor=trace,forked_backend=trace,server=debug,\
katana_core=trace,blockifier=off,jsonrpsee_server=off,\
hyper=off,messaging=debug";
hyper=off,messaging=debug,node=error";

let builder = fmt::Subscriber::builder().with_env_filter(
EnvFilter::try_from_default_env().or(EnvFilter::try_new(DEFAULT_LOG_FILTER))?,
Expand Down
33 changes: 32 additions & 1 deletion crates/katana/core/src/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ impl KatanaSequencer {
let block_producer = if config.block_time.is_some() || config.no_mining {
let block_num = backend.blockchain.provider().latest_number()?;

let block_env = backend.blockchain.provider().block_env_at(block_num.into())?.unwrap();
let mut block_env =
backend.blockchain.provider().block_env_at(block_num.into())?.unwrap();
backend.update_block_env(&mut block_env);
let cfg_env = backend.chain_cfg_env();

if let Some(interval) = config.block_time {
Expand Down Expand Up @@ -551,3 +553,32 @@ fn filter_events_by_params(
}
(filtered_events, index)
}

#[cfg(test)]
mod tests {
use katana_provider::traits::block::BlockNumberProvider;

use super::{KatanaSequencer, SequencerConfig};
use crate::backend::config::StarknetConfig;

#[tokio::test]
async fn init_interval_block_producer_with_correct_block_env() {
let sequencer = KatanaSequencer::new(
SequencerConfig { no_mining: true, ..Default::default() },
StarknetConfig::default(),
)
.await

Check warning on line 570 in crates/katana/core/src/sequencer.rs

View check run for this annotation

Codecov / codecov/patch

crates/katana/core/src/sequencer.rs#L570

Added line #L570 was not covered by tests
.unwrap();

let provider = sequencer.backend.blockchain.provider();

let latest_num = provider.latest_number().unwrap();
let producer_block_env = sequencer.pending_state().unwrap().block_execution_envs().0;

assert_eq!(
producer_block_env.number,
latest_num + 1,
"Pending block number should be latest block number + 1"

Check warning on line 581 in crates/katana/core/src/sequencer.rs

View check run for this annotation

Codecov / codecov/patch

crates/katana/core/src/sequencer.rs#L581

Added line #L581 was not covered by tests
);
}
}
4 changes: 2 additions & 2 deletions crates/katana/core/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use futures::channel::mpsc::Receiver;
use futures::stream::{Fuse, Stream, StreamExt};
use katana_primitives::transaction::ExecutableTxWithHash;
use starknet::core::types::FieldElement;
use tracing::trace;
use tracing::{error, trace};

use self::block_producer::BlockProducer;
use crate::pool::TransactionPool;
Expand Down Expand Up @@ -68,7 +68,7 @@ impl Future for NodeService {
}

Err(err) => {
trace!(target: "node", "failed to mine block: {err}");
error!(target: "node", "failed to mine block: {err}");

Check warning on line 71 in crates/katana/core/src/service/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/katana/core/src/service/mod.rs#L71

Added line #L71 was not covered by tests
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion crates/katana/storage/provider/tests/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use katana_provider::providers::db::DbProvider;
use katana_provider::providers::fork::ForkedProvider;
use katana_provider::providers::in_memory::InMemoryProvider;
use katana_provider::traits::block::{
BlockHashProvider, BlockProvider, BlockStatusProvider, BlockWriter,
BlockHashProvider, BlockNumberProvider, BlockProvider, BlockStatusProvider, BlockWriter,
};
use katana_provider::traits::env::BlockEnvProvider;
use katana_provider::traits::state::StateRootProvider;
Expand Down Expand Up @@ -69,6 +69,9 @@ where
Default::default(),
receipts.clone(),
)?;

assert_eq!(provider.latest_number().unwrap(), block.block.header.header.number);
assert_eq!(provider.latest_hash().unwrap(), block.block.header.hash);
}

let actual_blocks_in_range = provider.blocks_in_range(0..=count)?;
Expand Down

0 comments on commit 2834824

Please sign in to comment.