pub struct BlockTracker { /* private fields */ }Expand description
Tracks the last N block headers to enable reorg detection.
When a new block arrives, the tracker checks whether its parent_hash
matches the hash of the previous block. A mismatch means a reorg occurred.
Implementations§
Source§impl BlockTracker
impl BlockTracker
Sourcepub fn new(window_size: usize) -> Self
pub fn new(window_size: usize) -> Self
Create a new tracker with the given window size. A window of 128 covers deep reorgs for all major EVM chains.
Sourcepub fn push(&mut self, block: BlockInfo) -> Result<(), u64>
pub fn push(&mut self, block: BlockInfo) -> Result<(), u64>
Add a new block to the tracker.
Returns Ok(()) if the block extends the current head.
Returns Err(reorg_depth) if a reorg is detected (parent hash mismatch).
Sourcepub fn head(&self) -> Option<&BlockInfo>
pub fn head(&self) -> Option<&BlockInfo>
Returns the current chain head (most recently added block).
Auto Trait Implementations§
impl Freeze for BlockTracker
impl RefUnwindSafe for BlockTracker
impl Send for BlockTracker
impl Sync for BlockTracker
impl Unpin for BlockTracker
impl UnsafeUnpin for BlockTracker
impl UnwindSafe for BlockTracker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more