Skip to content

Commit

Permalink
fix mtp check?
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejka committed Oct 21, 2024
1 parent 11557e9 commit d87d425
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/consensus/src/types/chain_state.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ pub impl BlockValidatorImpl of BlockValidator {
let block_height = self.block_height + 1;

let prev_block_time = *self.prev_timestamps[self.prev_timestamps.len() - 1];

let median_time_past = compute_median_time_past(self.prev_timestamps);
let prev_timestamps = next_prev_timestamps(self.prev_timestamps, block.header.time);
let median_time_past = compute_median_time_past(prev_timestamps);

validate_timestamp(median_time_past, block.header.time)?;

Expand Down
8 changes: 7 additions & 1 deletion packages/consensus/src/validation/timestamp.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ pub fn validate_timestamp(median_time_past: u32, block_time: u32) -> Result<(),
if block_time > median_time_past {
Result::Ok(())
} else {
Result::Err("Median time past is greater than or equal to block's timestamp")
Result::Err(
format!(
"Median time past: {} >= block's timestamp: {}.",
median_time_past,
block_time
)
)
}
}

Expand Down

0 comments on commit d87d425

Please sign in to comment.