Skip to content

Commit

Permalink
chaintsn, consensus-logic: fixed slot not advancing past end of secon…
Browse files Browse the repository at this point in the history
…d epoch
  • Loading branch information
delbonis committed Dec 19, 2024
1 parent 14d6c29 commit 9fb5e5c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 14 deletions.
6 changes: 3 additions & 3 deletions crates/chaintsn/src/epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ fn process_l1_segment(
let new_tip_blkid = new_tip_block.record().blkid();
let new_tip_height = new_tip_block.idx();

// Set the new L1 height according to the new block.
state.set_safe_l1_tip(new_tip_height, *new_tip_blkid);

// Check that the new chain is actually longer, if it's shorter then we
// didn't do anything.
if new_tip_height <= state.safe_l1_height() {
return Err(TsnError::L1SegNotExtend);
}

// Set the new L1 height according to the new block.
state.set_safe_l1_tip(new_tip_height, *new_tip_blkid);

// TODO make sure that the block hashes all connect up sensibly.

// Collect the indexes of current operators.
Expand Down
4 changes: 2 additions & 2 deletions crates/consensus-logic/src/csm/client_transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn process_event<D: Database>(
// If the block is before the horizon we don't care about it.
if *height < params.rollup().horizon_l1_height {
#[cfg(test)]
eprintln!("early L1 block at h={height}, you may have set up the test env wrong");
warn!("early L1 block at h={height}, you may have set up the test env wrong");

warn!(%height, "ignoring unexpected L1Block event before horizon");
return Ok(ClientUpdateOutput::new(writes, actions));
Expand Down Expand Up @@ -85,7 +85,7 @@ pub fn process_event<D: Database>(
writes.push(ClientStateWrite::AcceptL1Block(*l1blkid));
} else {
#[cfg(test)]
eprintln!("not sure what to do here h={height} exp={next_exp_height}");
warn!("not sure what to do here h={height} exp={next_exp_height}");
return Err(Error::OutOfOrderL1Block(next_exp_height, *height, *l1blkid));
}

Expand Down
2 changes: 1 addition & 1 deletion crates/consensus-logic/src/csm/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ fn handle_sync_event<D: Database>(
// Make sure that the new state index is set as expected.
assert_eq!(state.state_tracker.cur_state_idx(), ev_idx);

// Write the client state checkpoint periodically based on the event idx..
// Write the client state checkpoint periodically based on the event idx.
if ev_idx % state.params.run.client_checkpoint_interval as u64 == 0 {
let client_state_db = state.database.client_state_db();
client_state_db.write_client_state_checkpoint(ev_idx, new_state.as_ref().clone())?;
Expand Down
14 changes: 11 additions & 3 deletions crates/consensus-logic/src/duty/block_assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,19 @@ fn prepare_l1_segment(
params: &RollupParams,
) -> Result<L1Segment, Error> {
let unacc_blocks = local_l1_state.unacc_blocks_iter().collect::<Vec<_>>();
trace!(unacc_blocks = %unacc_blocks.len(), "figuring out which blocks to include in L1 segment");
let state_l1_height = prev_chstate.epoch_state().safe_l1_height();
trace!(unacc_blocks = %unacc_blocks.len(), %state_l1_height, "figuring out which blocks to include in L1 segment");

// We don't have to worry about reorgs now, just shove it all in.
// We don't have to worry about reorgs now, just shove all the ones above
// the current height in.
//
// TODO only put ones that are buryable
let mut payloads = Vec::new();
for (h, _b) in unacc_blocks.iter().take(max_l1_entries) {
for (h, _b) in unacc_blocks
.iter()
.filter(|(h, _)| *h > state_l1_height)
.take(max_l1_entries)
{
let rec = load_header_record(*h, l1_db)?;
let deposit_update_tx = fetch_deposit_update_txs(*h, l1_db)?;
payloads.push(
Expand Down
19 changes: 14 additions & 5 deletions crates/consensus-logic/src/fork_choice_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,14 +429,23 @@ fn handle_new_state<D: Database>(
let csm_tip = sync.chain_tip_blkid();
debug!(?csm_tip, "got new CSM state");

// Decide if we're going to update the finalized tip first. If it didn't
// change then there's no point.
let new_fin_tip = sync.finalized_blkid();
let should_update_fin_tip = match fcm_state.cur_csm_state.sync() {
Some(ss) => ss.finalized_blkid() != new_fin_tip,
None => true,
};

// Update the new state.
fcm_state.cur_csm_state = Arc::new(cs);

let blkid = sync.finalized_blkid();
let fin_report = fcm_state.chain_tracker.update_finalized_tip(blkid)?;
info!(?blkid, "updated finalized tip");
trace!(?fin_report, "finalization report");
// TODO do something with the finalization report
if should_update_fin_tip {
let fin_report = fcm_state.chain_tracker.update_finalized_tip(new_fin_tip)?;
info!(blkid = ?new_fin_tip, "updated finalized tip");
trace!(?fin_report, "finalization report");
// TODO do something with the finalization report?
}

// TODO recheck every remaining block's validity using the new state
// starting from the bottom up, putting into a new chain tracker
Expand Down

0 comments on commit 9fb5e5c

Please sign in to comment.