-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pruning of the transaction by TTL (#1033)
Added basic pruning of the transaction by the TTL. It is done periodically for constant period of time. We can do it often(based on the remaining time to the next timeout), but I tried to avoid to often locking. --------- Co-authored-by: Voxelot <[email protected]>
- Loading branch information
Showing
20 changed files
with
463 additions
and
127 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
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
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
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
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,2 +1,4 @@ | ||
pub mod dependency; | ||
pub mod price_sort; | ||
pub mod sort; | ||
pub mod time_sort; |
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
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,56 @@ | ||
use crate::{ | ||
types::*, | ||
TxInfo, | ||
}; | ||
use fuel_core_types::services::txpool::ArcPoolTx; | ||
use std::collections::BTreeMap; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct Sort<Key> { | ||
/// all transactions sorted by min/max value | ||
pub sort: BTreeMap<Key, ArcPoolTx>, | ||
} | ||
|
||
impl<Key> Default for Sort<Key> { | ||
fn default() -> Self { | ||
Self { | ||
sort: Default::default(), | ||
} | ||
} | ||
} | ||
|
||
impl<Key> Sort<Key> | ||
where | ||
Key: SortableKey, | ||
{ | ||
pub fn remove(&mut self, info: &TxInfo) { | ||
self.sort.remove(&Key::new(info)); | ||
} | ||
|
||
pub fn lowest_tx(&self) -> Option<ArcPoolTx> { | ||
self.sort.iter().next().map(|(_, tx)| tx.clone()) | ||
} | ||
|
||
pub fn lowest_value(&self) -> Option<Key::Value> { | ||
self.sort.iter().next().map(|(key, _)| key.value().clone()) | ||
} | ||
|
||
pub fn lowest(&self) -> Option<(&Key, &ArcPoolTx)> { | ||
self.sort.iter().next() | ||
} | ||
|
||
pub fn insert(&mut self, info: &TxInfo) { | ||
let tx = info.tx().clone(); | ||
self.sort.insert(Key::new(info), tx); | ||
} | ||
} | ||
|
||
pub trait SortableKey: Ord { | ||
type Value: Clone; | ||
|
||
fn new(info: &TxInfo) -> Self; | ||
|
||
fn value(&self) -> &Self::Value; | ||
|
||
fn tx_id(&self) -> &TxId; | ||
} |
Oops, something went wrong.