Skip to content

Commit 69f2f66

Browse files
committed
Fix get_commitment_by_index on fullnode
1 parent d6715c2 commit 69f2f66

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

crates/fullnode/src/da_block_handler.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,8 @@ where
453453
) -> Result<ProcessingResult, ProcessingError> {
454454
// Skip if this commitment index was already processed
455455
// This prevents double-processing and handles conflicting commitments
456-
if let Some(existing_commitment) = self
457-
.ledger_db
458-
.get_commitment_by_index(sequencer_commitment.index)?
456+
if let Some(existing_commitment) =
457+
self.get_commitment_by_index(sequencer_commitment.index, schema_batch)?
459458
{
460459
// Check if the new commitment has a different merkle root but keep the first processed one as canonical
461460
if existing_commitment.merkle_root != sequencer_commitment.merkle_root {
@@ -508,10 +507,7 @@ where
508507
let start_l2_height = if sequencer_commitment.index == 1 {
509508
get_tangerine_activation_height_non_zero()
510509
} else {
511-
match self
512-
.ledger_db
513-
.get_commitment_by_index(sequencer_commitment.index - 1)?
514-
{
510+
match self.get_commitment_by_index(sequencer_commitment.index - 1, schema_batch)? {
515511
Some(previous_commitment) => previous_commitment.l2_end_block_number + 1,
516512
None => {
517513
// If previous commitment is missing, store this one as pending
@@ -899,7 +895,8 @@ where
899895
let end_l2_height = commitment.l2_end_block_number;
900896
end_l2_height <= head_l2_height
901897
} else {
902-
self.ledger_db.get_commitment_by_index(index - 1)?.is_some()
898+
self.get_commitment_by_index(index - 1, schema_batch)?
899+
.is_some()
903900
};
904901

905902
if processable {
@@ -1053,4 +1050,20 @@ where
10531050
}
10541051
Ok(sequencer_commitment.l2_end_block_number)
10551052
}
1053+
1054+
/// Retrieves a sequencer commitment by its index
1055+
/// First checks the schema batch, then falls back to the ledger DB
1056+
fn get_commitment_by_index(
1057+
&self,
1058+
index: u32,
1059+
schema_batch: &SchemaBatch,
1060+
) -> Result<Option<SequencerCommitment>, ProcessingError> {
1061+
if let Some(Some(commitment)) =
1062+
schema_batch.read_latest::<SequencerCommitmentByIndex>(&index)?
1063+
{
1064+
Ok(Some(commitment))
1065+
} else {
1066+
Ok(self.ledger_db.get_commitment_by_index(index)?)
1067+
}
1068+
}
10561069
}

0 commit comments

Comments
 (0)