Skip to content

Commit

Permalink
fix forkmanager and some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eyusufatik committed Jan 2, 2025
1 parent a69ebad commit 798971b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion bin/citrea/tests/bitcoin_e2e/light_client_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl TestCase for LightClientProvingTestMultipleProofs {

fn sequencer_config() -> SequencerConfig {
SequencerConfig {
min_soft_confirmations_per_commitment: 20,
min_soft_confirmations_per_commitment: 50,
da_update_interval_ms: 500,
mempool_conf: SequencerMempoolConfig {
pending_tx_size: 2000,
Expand Down
8 changes: 4 additions & 4 deletions crates/batch-prover/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,10 @@ where
.clone()
.try_into()
.context("Failed to parse transactions")?;
// Register this new block with the fork manager to active
// the new fork on the next block
self.fork_manager.register_block(l2_height)?;

let current_spec = self.fork_manager.active_fork().spec_id;
let soft_confirmation_result = self.stf.apply_soft_confirmation(
current_spec,
Expand Down Expand Up @@ -473,10 +477,6 @@ where
SoftConfirmationNumber(l2_height),
)?;

// Register this new block with the fork manager to active
// the new fork on the next block
self.fork_manager.register_block(l2_height)?;

// Only errors when there are no receivers
let _ = self.soft_confirmation_tx.send(l2_height);

Expand Down
9 changes: 5 additions & 4 deletions crates/fullnode/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@ where
.clone()
.try_into()
.context("Failed to parse transactions")?;

// Register this new block with the fork manager to active
// the new fork on the next block.
self.fork_manager.register_block(l2_height)?;

let current_spec = self.fork_manager.active_fork().spec_id;
let soft_confirmation_result = self.stf.apply_soft_confirmation(
current_spec,
Expand Down Expand Up @@ -296,10 +301,6 @@ where
SoftConfirmationNumber(l2_height),
)?;

// Register this new block with the fork manager to active
// the new fork on the next block.
self.fork_manager.register_block(l2_height)?;

// Only errors when there are no receivers
let _ = self.soft_confirmation_tx.send(l2_height);

Expand Down
8 changes: 4 additions & 4 deletions crates/sequencer/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,10 @@ where
.lock()
.fetch_deposits(self.config.deposit_mempool_fetch_limit);

// Register this new block with the fork manager to active
// the new fork on the next block
self.fork_manager.register_block(l2_height)?;

let active_fork_spec = self.fork_manager.active_fork().spec_id;

let soft_confirmation_info = HookSoftConfirmationInfo {
Expand Down Expand Up @@ -584,10 +588,6 @@ where
SoftConfirmationNumber(l2_height),
)?;

// Register this new block with the fork manager to active
// the new fork on the next block
self.fork_manager.register_block(l2_height)?;

let l1_height = da_block.header().height();
info!(
"New block #{}, DA #{}, Tx count: #{}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,6 @@ where
let mut previous_batch_hash = soft_confirmations[0][0].prev_hash();
let mut last_commitment_end_height: Option<u64> = None;

let mut fork_manager = ForkManager::new(forks, sequencer_commitments_range.0 as u64);

// should panic if number of sequencer commitments, soft confirmations, slot headers and witnesses don't match
for (((sequencer_commitment, soft_confirmations), da_block_headers), witnesses) in
sequencer_commitments_iter
Expand Down Expand Up @@ -658,6 +656,8 @@ where

let mut l2_height = sequencer_commitment.l2_start_block_number;

let mut fork_manager = ForkManager::new(forks, l2_height);

// now that we verified the claimed root, we can apply the soft confirmations
// should panic if the number of witnesses and soft confirmations don't match
for (mut soft_confirmation, (state_witness, offchain_witness)) in
Expand All @@ -673,6 +673,12 @@ where
"Soft confirmation heights not sequential"
);

// Notify fork manager about the block so that the next spec / fork
// is transitioned into if criteria is met.
if let Err(e) = fork_manager.register_block(l2_height) {
panic!("Fork transition failed {}", e);
}

let result = self
.apply_soft_confirmation(
fork_manager.active_fork().spec_id,
Expand All @@ -693,11 +699,6 @@ where
current_state_root = result.state_root_transition.final_root;
state_diff.extend(result.state_diff);

// Notify fork manager about the block so that the next spec / fork
// is transitioned into if criteria is met.
if let Err(e) = fork_manager.register_block(l2_height) {
panic!("Fork transition failed {}", e);
}
l2_height += 1;
}
assert_eq!(sequencer_commitment.l2_end_block_number, l2_height - 1);
Expand Down

0 comments on commit 798971b

Please sign in to comment.