Skip to content

Commit

Permalink
consensus: impl exceeds_allowed_future_timestamp for Header (#1237)
Browse files Browse the repository at this point in the history
consensus: impl exceeds_allowed_future_timestamp for Header

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
  • Loading branch information
tcoratger and mattsse authored Sep 4, 2024
1 parent aa1f234 commit 7cb6804
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions crates/consensus/src/header.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use alloy_eips::{
eip1559::{calc_next_block_base_fee, BaseFeeParams},
eip4844::{calc_blob_gasprice, calc_excess_blob_gas},
merge::ALLOWED_FUTURE_BLOCK_TIME_SECONDS,
BlockNumHash,
};
use alloy_primitives::{
Expand Down Expand Up @@ -363,6 +364,15 @@ impl Header {
pub fn is_zero_difficulty(&self) -> bool {
self.difficulty.is_zero()
}

/// Checks if the block's timestamp is in the future based on the present timestamp.
///
/// Clock can drift but this can be consensus issue.
///
/// Note: This check is relevant only pre-merge.
pub const fn exceeds_allowed_future_timestamp(&self, present_timestamp: u64) -> bool {
self.timestamp > present_timestamp + ALLOWED_FUTURE_BLOCK_TIME_SECONDS
}
}

impl Encodable for Header {
Expand Down

0 comments on commit 7cb6804

Please sign in to comment.