Skip to content

Commit

Permalink
fix(katana): init interval block producer with updated block env (#1477)
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy authored Jan 25, 2024
1 parent 6233fa5 commit 1cf9caf
Showing 1 changed file with 32 additions and 1 deletion.
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
.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"
);
}
}

0 comments on commit 1cf9caf

Please sign in to comment.