From d52454b07bc023b3160fdc74e90c2e354ee922f2 Mon Sep 17 00:00:00 2001 From: evalir Date: Thu, 26 Jun 2025 13:16:04 +0200 Subject: [PATCH 1/4] fix(sim): correct `clean` logic for keeping bundles --- crates/sim/src/cache.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/crates/sim/src/cache.rs b/crates/sim/src/cache.rs index e81d17c2..1bff4a80 100644 --- a/crates/sim/src/cache.rs +++ b/crates/sim/src/cache.rs @@ -172,16 +172,15 @@ 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.bundle.block_number == block_number + && bundle.min_timestamp().is_some_and(|min_timestamp| block_timestamp >= min_timestamp) + && bundle.max_timestamp().is_some_and(|max_timestamp| block_timestamp <= max_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 } From 8f8707f1da6633355c2d06a7887bab08f4e23b82 Mon Sep 17 00:00:00 2001 From: evalir Date: Thu, 26 Jun 2025 13:16:42 +0200 Subject: [PATCH 2/4] chore: version bump --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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"] From 97f05f02b68b01402e9d13ab6a60ef6b81e67ab2 Mon Sep 17 00:00:00 2001 From: evalir Date: Thu, 26 Jun 2025 13:18:24 +0200 Subject: [PATCH 3/4] chore: clippy --- crates/sim/src/cache.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/sim/src/cache.rs b/crates/sim/src/cache.rs index 1bff4a80..599f2a7c 100644 --- a/crates/sim/src/cache.rs +++ b/crates/sim/src/cache.rs @@ -173,8 +173,12 @@ impl SimCache { // Retain only items that are not bundles or are valid in the current block. if let SimItem::Bundle(bundle) = item { let should_keep = bundle.bundle.block_number == block_number - && bundle.min_timestamp().is_some_and(|min_timestamp| block_timestamp >= min_timestamp) - && bundle.max_timestamp().is_some_and(|max_timestamp| block_timestamp <= max_timestamp); + && bundle + .min_timestamp() + .is_some_and(|min_timestamp| block_timestamp >= min_timestamp) + && bundle + .max_timestamp() + .is_some_and(|max_timestamp| block_timestamp <= max_timestamp); if !should_keep { seen.remove(item.identifier().as_bytes()); From c53b04ade0fcef3a3dd0a754fb8ce118031fa5f6 Mon Sep 17 00:00:00 2001 From: evalir Date: Fri, 27 Jun 2025 18:44:57 +0200 Subject: [PATCH 4/4] feat(bundle): utility fns for checking bundle validity --- crates/bundle/src/send/bundle.rs | 12 ++++++++++++ crates/sim/src/cache.rs | 9 ++------- 2 files changed, 14 insertions(+), 7 deletions(-) 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 599f2a7c..1be9528b 100644 --- a/crates/sim/src/cache.rs +++ b/crates/sim/src/cache.rs @@ -172,13 +172,8 @@ 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_keep = bundle.bundle.block_number == block_number - && bundle - .min_timestamp() - .is_some_and(|min_timestamp| block_timestamp >= min_timestamp) - && bundle - .max_timestamp() - .is_some_and(|max_timestamp| block_timestamp <= max_timestamp); + let should_keep = bundle.is_valid_at_block_number(block_number) + && bundle.is_valid_at_timestamp(block_timestamp); if !should_keep { seen.remove(item.identifier().as_bytes());