chore(txpool): remove Arc for internals (#1733)

This commit is contained in:
Matthias Seitz
2023-03-13 14:00:47 +01:00
committed by GitHub
parent 102a5a378f
commit e33e93c9a0
8 changed files with 14 additions and 18 deletions

View File

@@ -148,8 +148,8 @@ where
T: TransactionOrdering<Transaction = <V as TransactionValidator>::Transaction>,
{
/// Create a new transaction pool instance.
pub fn new(client: Arc<V>, ordering: Arc<T>, config: PoolConfig) -> Self {
Self { pool: Arc::new(PoolInner::new(client, ordering, config)) }
pub fn new(validator: V, ordering: T, config: PoolConfig) -> Self {
Self { pool: Arc::new(PoolInner::new(validator, ordering, config)) }
}
/// Returns the wrapped pool.
@@ -302,7 +302,7 @@ where
}
}
impl<V: TransactionValidator, O: TransactionOrdering> Clone for Pool<V, O> {
impl<V: TransactionValidator, T: TransactionOrdering> Clone for Pool<V, T> {
fn clone(&self) -> Self {
Self { pool: Arc::clone(&self.pool) }
}

View File

@@ -83,7 +83,7 @@ mod tests {
#[test]
fn test_best_iter() {
let mut pool = PendingPool::new(Arc::new(MockOrdering::default()));
let mut pool = PendingPool::new(MockOrdering::default());
let mut f = MockTransactionFactory::default();
let num_tx = 10;
@@ -109,7 +109,7 @@ mod tests {
#[test]
fn test_best_iter_invalid() {
let mut pool = PendingPool::new(Arc::new(MockOrdering::default()));
let mut pool = PendingPool::new(MockOrdering::default());
let mut f = MockTransactionFactory::default();
let num_tx = 10;

View File

@@ -100,7 +100,7 @@ pub struct PoolInner<V: TransactionValidator, T: TransactionOrdering> {
/// Internal mapping of addresses to plain ints.
identifiers: RwLock<SenderIdentifiers>,
/// Transaction validation.
validator: Arc<V>,
validator: V,
/// The internal pool that manages all transactions.
pool: RwLock<TxPool<T>>,
/// Pool settings.
@@ -115,13 +115,13 @@ pub struct PoolInner<V: TransactionValidator, T: TransactionOrdering> {
// === impl PoolInner ===
impl<V: TransactionValidator, T: TransactionOrdering> PoolInner<V, T>
impl<V, T> PoolInner<V, T>
where
V: TransactionValidator,
T: TransactionOrdering<Transaction = <V as TransactionValidator>::Transaction>,
{
/// Create a new transaction pool instance.
pub(crate) fn new(validator: Arc<V>, ordering: Arc<T>, config: PoolConfig) -> Self {
pub(crate) fn new(validator: V, ordering: T, config: PoolConfig) -> Self {
Self {
identifiers: Default::default(),
validator,

View File

@@ -22,7 +22,7 @@ use std::{
/// is also pending, then this will be moved to the `independent` queue.
pub(crate) struct PendingPool<T: TransactionOrdering> {
/// How to order transactions.
ordering: Arc<T>,
ordering: T,
/// Keeps track of transactions inserted in the pool.
///
/// This way we can determine when transactions where submitted to the pool.
@@ -46,7 +46,7 @@ pub(crate) struct PendingPool<T: TransactionOrdering> {
impl<T: TransactionOrdering> PendingPool<T> {
/// Create a new pool instance.
pub(crate) fn new(ordering: Arc<T>) -> Self {
pub(crate) fn new(ordering: T) -> Self {
Self {
ordering,
submission_id: 0,

View File

@@ -98,7 +98,7 @@ pub struct TxPool<T: TransactionOrdering> {
impl<T: TransactionOrdering> TxPool<T> {
/// Create a new graph pool instance.
pub(crate) fn new(ordering: Arc<T>, config: PoolConfig) -> Self {
pub(crate) fn new(ordering: T, config: PoolConfig) -> Self {
Self {
sender_info: Default::default(),
pending_pool: PendingPool::new(ordering),

View File

@@ -23,7 +23,7 @@ pub type MockValidTx = ValidPoolTransaction<MockTransaction>;
/// Create an empty `TxPool`
pub(crate) fn mock_tx_pool() -> MockTxPool {
MockTxPool::new(Arc::new(Default::default()), Default::default())
MockTxPool::new(Default::default(), Default::default())
}
/// Sets the value for the field

View File

@@ -16,11 +16,7 @@ pub type TestPool = Pool<NoopTransactionValidator<MockTransaction>, MockOrdering
/// Returns a new [Pool] used for testing purposes
pub fn testing_pool() -> TestPool {
Pool::new(
Arc::new(NoopTransactionValidator::default()),
Arc::new(MockOrdering::default()),
Default::default(),
)
Pool::new(NoopTransactionValidator::default(), MockOrdering::default(), Default::default())
}
// A [`TransactionValidator`] that does nothing.

View File

@@ -41,7 +41,7 @@ impl MockPool {
impl Default for MockPool {
fn default() -> Self {
Self { pool: TxPool::new(Arc::new(MockOrdering::default()), Default::default()) }
Self { pool: TxPool::new(MockOrdering::default(), Default::default()) }
}
}