mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: using smallvec (#6740)
Co-authored-by: Emilia Hane <emiliaha95@gmail.com>
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -6973,6 +6973,7 @@ dependencies = [
|
||||
"schnellru",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"smallvec",
|
||||
"tempfile",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
|
||||
@ -224,6 +224,7 @@ hex-literal = "0.4"
|
||||
once_cell = "1.17"
|
||||
syn = "2.0"
|
||||
nybbles = "0.1"
|
||||
smallvec = "1.13"
|
||||
|
||||
# proc-macros
|
||||
proc-macro2 = "1.0"
|
||||
|
||||
@ -48,6 +48,7 @@ serde = { workspace = true, features = ["derive", "rc"], optional = true }
|
||||
fnv = "1.0.7"
|
||||
bitflags.workspace = true
|
||||
auto_impl = "1.0"
|
||||
smallvec.workspace = true
|
||||
|
||||
# testing
|
||||
rand = { workspace = true, optional = true }
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
use crate::{
|
||||
identifier::{SenderId, TransactionId},
|
||||
pool::size::SizeTracker,
|
||||
PoolTransaction, SubPoolLimit, ValidPoolTransaction,
|
||||
PoolTransaction, SubPoolLimit, ValidPoolTransaction, TXPOOL_MAX_ACCOUNT_SLOTS_PER_SENDER,
|
||||
};
|
||||
use fnv::FnvHashMap;
|
||||
use smallvec::SmallVec;
|
||||
use std::{
|
||||
cmp::Ordering,
|
||||
collections::{hash_map::Entry, BTreeMap, BTreeSet},
|
||||
@ -151,8 +152,12 @@ impl<T: ParkedOrd> ParkedPool<T> {
|
||||
Some(tx.transaction.into())
|
||||
}
|
||||
|
||||
/// Get transactions by sender
|
||||
pub(crate) fn get_txs_by_sender(&self, sender: SenderId) -> Vec<TransactionId> {
|
||||
/// Retrieves transactions by sender, using `SmallVec` to efficiently handle up to
|
||||
/// `TXPOOL_MAX_ACCOUNT_SLOTS_PER_SENDER` transactions.
|
||||
pub(crate) fn get_txs_by_sender(
|
||||
&self,
|
||||
sender: SenderId,
|
||||
) -> SmallVec<[TransactionId; TXPOOL_MAX_ACCOUNT_SLOTS_PER_SENDER]> {
|
||||
self.by_id
|
||||
.range((sender.start_bound(), Unbounded))
|
||||
.take_while(move |(other, _)| sender == other.sender)
|
||||
|
||||
@ -25,6 +25,7 @@ use reth_primitives::{
|
||||
},
|
||||
Address, TxHash, B256,
|
||||
};
|
||||
use smallvec::SmallVec;
|
||||
use std::{
|
||||
cmp::Ordering,
|
||||
collections::{btree_map::Entry, hash_map, BTreeMap, HashMap, HashSet},
|
||||
@ -366,7 +367,7 @@ impl<T: TransactionOrdering> TxPool<T> {
|
||||
pub fn queued_and_pending_txs_by_sender(
|
||||
&self,
|
||||
sender: SenderId,
|
||||
) -> (Vec<TransactionId>, Vec<TransactionId>) {
|
||||
) -> (SmallVec<[TransactionId; TXPOOL_MAX_ACCOUNT_SLOTS_PER_SENDER]>, Vec<TransactionId>) {
|
||||
(self.queued_pool.get_txs_by_sender(sender), self.pending_pool.get_txs_by_sender(sender))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user