diff --git a/Cargo.toml b/Cargo.toml index bc3b08c5..d483f58f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ members = ["crates/*"] resolver = "2" [workspace.package] -version = "0.4.0" +version = "0.4.1" edition = "2021" rust-version = "1.81" authors = ["init4"] diff --git a/crates/bundle/src/send/bundle.rs b/crates/bundle/src/send/bundle.rs index a6be0ef1..ef3178bd 100644 --- a/crates/bundle/src/send/bundle.rs +++ b/crates/bundle/src/send/bundle.rs @@ -68,6 +68,18 @@ impl SignetEthBundle { self.bundle.replacement_uuid.as_deref() } + /// Checks if the bundle is valid at a given timestamp. + pub fn is_valid_at_timestamp(&self, timestamp: u64) -> bool { + let min_timestamp = self.bundle.min_timestamp.unwrap_or(0); + let max_timestamp = self.bundle.max_timestamp.unwrap_or(u64::MAX); + timestamp >= min_timestamp && timestamp <= max_timestamp + } + + /// Checks if the bundle is valid at a given block number. + pub const fn is_valid_at_block_number(&self, block_number: u64) -> bool { + self.bundle.block_number == block_number + } + /// Decode and validate the transactions in the bundle. pub fn decode_and_validate_txs( &self, diff --git a/crates/sim/src/cache.rs b/crates/sim/src/cache.rs index e81d17c2..1be9528b 100644 --- a/crates/sim/src/cache.rs +++ b/crates/sim/src/cache.rs @@ -172,16 +172,14 @@ impl SimCache { items.retain(|_, item| { // Retain only items that are not bundles or are valid in the current block. if let SimItem::Bundle(bundle) = item { - let should_remove = bundle.bundle.block_number == block_number - && bundle.min_timestamp().is_some_and(|ts| ts <= block_timestamp) - && bundle.max_timestamp().is_some_and(|ts| ts >= block_timestamp); + let should_keep = bundle.is_valid_at_block_number(block_number) + && bundle.is_valid_at_timestamp(block_timestamp); - let retain = !should_remove; - - if should_remove { + if !should_keep { seen.remove(item.identifier().as_bytes()); } - retain + + should_keep } else { true // Non-bundle items are retained }