-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0983198
commit 328fca5
Showing
4 changed files
with
75 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use std::collections::HashSet; | ||
use std::ops::RangeInclusive; | ||
|
||
use reth_primitives::{BlockNumber, TransactionSignedEcRecovered}; | ||
|
||
pub mod pool; | ||
|
||
#[derive(Clone, Debug, Eq, PartialEq, Hash)] | ||
pub(crate) struct BundleCompact(pub Vec<TransactionSignedEcRecovered>); | ||
|
||
impl BundleCompact { | ||
/// returns whether `self` conflicts with `other` in the sense that both cannot be executed | ||
pub fn conflicts(&self, other: &Self) -> bool { | ||
let hashes = self | ||
.0 | ||
.iter() | ||
.map(|tx| tx.hash_ref()) | ||
.collect::<HashSet<_>>(); | ||
let other_hashes = other | ||
.0 | ||
.iter() | ||
.map(|tx| tx.hash_ref()) | ||
.collect::<HashSet<_>>(); | ||
!hashes.is_disjoint(&other_hashes) | ||
} | ||
} | ||
|
||
pub type BundleId = u64; | ||
|
||
#[derive(Clone, Debug, Eq, PartialEq, Hash)] | ||
pub struct Bundle { | ||
pub id: BundleId, | ||
pub txs: Vec<TransactionSignedEcRecovered>, | ||
pub block_num: BlockNumber, | ||
pub eligibility: RangeInclusive<u64>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use std::collections::HashSet; | ||
use std::time::{SystemTime, UNIX_EPOCH}; | ||
|
||
use super::{Bundle, BundleId}; | ||
|
||
use reth_primitives::BlockNumber; | ||
use reth_provider::CanonStateNotification; | ||
|
||
#[derive(Default)] | ||
pub struct BundlePool(pub(crate) HashSet<Bundle>); | ||
|
||
impl BundlePool { | ||
/// returns all bundles eligible w.r.t. time `now` and canonical chain tip `block` | ||
pub fn eligible(&self, block: BlockNumber, now: SystemTime) -> Vec<Bundle> { | ||
let now = now.duration_since(UNIX_EPOCH).unwrap().as_secs(); | ||
self.0 | ||
.iter() | ||
.filter(|bundle| bundle.eligibility.contains(&now) && bundle.block_num == block) | ||
.cloned() | ||
.collect() | ||
} | ||
|
||
/// removes all bundles whose eligibility expires w.r.t. time `now` | ||
pub fn tick(&mut self, now: SystemTime) { | ||
let now = now.duration_since(UNIX_EPOCH).unwrap().as_secs(); | ||
self.0.retain(|bundle| *bundle.eligibility.end() >= now); | ||
} | ||
|
||
/// maintains the pool based on updates to the canonical state. | ||
/// | ||
/// returns the IDs of the bundles removed from the pool. | ||
pub fn maintain(&mut self, _event: CanonStateNotification) -> Vec<BundleId> { | ||
// remove all bundles | ||
self.0.drain().map(|bundle| bundle.id).collect() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod builder; | ||
pub mod bundle; |