Skip to content

Commit f5fb38e

Browse files
committed
fix: flashbots bundle eligibility
1 parent a67ef95 commit f5fb38e

File tree

1 file changed

+38
-49
lines changed

1 file changed

+38
-49
lines changed

src/platform/bundle.rs

Lines changed: 38 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -301,61 +301,17 @@ impl<P: Platform> Bundle<P> for FlashbotsBundle<P> {
301301
}
302302

303303
fn is_eligible(&self, block: &BlockContext<P>) -> Eligibility {
304-
if self.transactions().is_empty() {
305-
// empty bundles are never eligible
306-
return Eligibility::PermanentlyIneligible;
307-
}
308-
309-
if self
310-
.max_timestamp
311-
.is_some_and(|max_ts| max_ts > block.timestamp())
312-
{
313-
// this bundle will never be eligible for inclusion anymore
314-
return Eligibility::PermanentlyIneligible;
315-
}
316-
317-
if self
318-
.min_timestamp
319-
.is_some_and(|min_ts| min_ts < block.timestamp())
320-
{
321-
// this bundle is not eligible yet
322-
return Eligibility::TemporarilyIneligible;
323-
}
324-
325-
if self.block_number != 0 && self.block_number > block.parent().number() {
326-
// this bundle is not eligible yet
327-
return Eligibility::TemporarilyIneligible;
328-
}
329-
330-
if self.block_number != 0 && self.block_number < block.parent().number() {
331-
// this bundle will never be eligible for inclusion anymore
332-
return Eligibility::PermanentlyIneligible;
333-
}
334-
335-
Eligibility::Eligible
304+
self.eligibility_at(block.timestamp(), block.number())
336305
}
337306

338307
fn is_permanently_ineligible(
339308
&self,
340309
block: &SealedHeader<types::Header<P>>,
341310
) -> bool {
342-
if self.transactions().is_empty() {
343-
// empty bundles are never eligible
344-
return true;
345-
}
346-
347-
if self
348-
.max_timestamp
349-
.is_some_and(|max_ts| max_ts < block.timestamp())
350-
{
351-
return true;
352-
}
353-
354-
if self.block_number != 0 && self.block_number < block.number() {
355-
return true;
356-
}
357-
358-
false
311+
matches!(
312+
self.eligibility_at(block.timestamp(), block.number()),
313+
Eligibility::PermanentlyIneligible
314+
)
359315
}
360316

361317
fn is_allowed_to_fail(&self, tx: TxHash) -> bool {
@@ -375,6 +331,39 @@ impl<P: Platform> Bundle<P> for FlashbotsBundle<P> {
375331
}
376332
}
377333

334+
impl<P: Platform> FlashbotsBundle<P> {
335+
fn eligibility_at(&self, timestamp: u64, number: u64) -> Eligibility {
336+
// Permanent ineligibility checked first
337+
if self.transactions().is_empty() {
338+
// empty bundles are never eligible
339+
return Eligibility::PermanentlyIneligible;
340+
}
341+
342+
if self.max_timestamp.is_some_and(|max_ts| max_ts < timestamp) {
343+
// this bundle will never be eligible for inclusion anymore
344+
return Eligibility::PermanentlyIneligible;
345+
}
346+
347+
if self.block_number != 0 && self.block_number < number {
348+
// this bundle will never be eligible for inclusion anymore
349+
return Eligibility::PermanentlyIneligible;
350+
}
351+
352+
// Temporary ineligibility checked next
353+
if self.min_timestamp.is_some_and(|min_ts| min_ts < timestamp) {
354+
// this bundle is not eligible yet
355+
return Eligibility::TemporarilyIneligible;
356+
}
357+
358+
if self.block_number != 0 && self.block_number > number {
359+
// this bundle is not eligible
360+
return Eligibility::TemporarilyIneligible;
361+
}
362+
363+
Eligibility::Eligible
364+
}
365+
}
366+
378367
#[derive(Debug, thiserror::Error)]
379368
pub enum BundleConversionError {
380369
#[error("EIP-2718 decoding error: {0}")]

0 commit comments

Comments
 (0)