Skip to content

Commit

Permalink
feat: add TransactionPool blob getters (#4272)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Aug 18, 2023
1 parent 9d46ab4 commit 82a42c9
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 8 deletions.
15 changes: 13 additions & 2 deletions crates/transaction-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
//! - `test-utils`: Export utilities for testing
use crate::pool::PoolInner;
use aquamarine as _;
use reth_primitives::{Address, TxHash, U256};
use reth_primitives::{Address, BlobTransactionSidecar, TxHash, U256};
use reth_provider::StateProviderFactory;
use std::{
collections::{HashMap, HashSet},
Expand All @@ -163,7 +163,7 @@ use std::{
use tokio::sync::mpsc::Receiver;
use tracing::{instrument, trace};

use crate::blobstore::BlobStore;
use crate::blobstore::{BlobStore, BlobStoreError};
pub use crate::{
config::{
PoolConfig, PriceBumpConfig, SubPoolLimit, DEFAULT_PRICE_BUMP, REPLACE_BLOB_PRICE_BUMP,
Expand Down Expand Up @@ -458,6 +458,17 @@ where
fn unique_senders(&self) -> HashSet<Address> {
self.pool.unique_senders()
}

fn get_blob(&self, tx_hash: TxHash) -> Result<Option<BlobTransactionSidecar>, BlobStoreError> {
self.pool.blob_store().get(tx_hash)
}

fn get_all_blobs(
&self,
tx_hashes: Vec<TxHash>,
) -> Result<Vec<(TxHash, BlobTransactionSidecar)>, BlobStoreError> {
self.pool.blob_store().get_all(tx_hashes)
}
}

impl<V: TransactionValidator, T: TransactionOrdering, S> TransactionPoolExt for Pool<V, T, S>
Expand Down
23 changes: 17 additions & 6 deletions crates/transaction-pool/src/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
//! to be generic over it.

use crate::{
error::PoolError, traits::PendingTransactionListenerKind, validate::ValidTransaction,
AllPoolTransactions, AllTransactionsEvents, BestTransactions, BlockInfo, EthPooledTransaction,
NewTransactionEvent, PoolResult, PoolSize, PoolTransaction, PropagatedTransactions,
TransactionEvents, TransactionOrigin, TransactionPool, TransactionValidationOutcome,
TransactionValidator, ValidPoolTransaction,
blobstore::BlobStoreError, error::PoolError, traits::PendingTransactionListenerKind,
validate::ValidTransaction, AllPoolTransactions, AllTransactionsEvents, BestTransactions,
BlockInfo, EthPooledTransaction, NewTransactionEvent, PoolResult, PoolSize, PoolTransaction,
PropagatedTransactions, TransactionEvents, TransactionOrigin, TransactionPool,
TransactionValidationOutcome, TransactionValidator, ValidPoolTransaction,
};
use reth_primitives::{Address, TxHash};
use reth_primitives::{Address, BlobTransactionSidecar, TxHash};
use std::{collections::HashSet, marker::PhantomData, sync::Arc};
use tokio::sync::{mpsc, mpsc::Receiver};

Expand Down Expand Up @@ -162,6 +162,17 @@ impl TransactionPool for NoopTransactionPool {
fn unique_senders(&self) -> HashSet<Address> {
Default::default()
}

fn get_blob(&self, _tx_hash: TxHash) -> Result<Option<BlobTransactionSidecar>, BlobStoreError> {
Ok(None)
}

fn get_all_blobs(
&self,
_tx_hashes: Vec<TxHash>,
) -> Result<Vec<(TxHash, BlobTransactionSidecar)>, BlobStoreError> {
Ok(vec![])
}
}

/// A [`TransactionValidator`] that does nothing.
Expand Down
5 changes: 5 additions & 0 deletions crates/transaction-pool/src/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ where
}
}

/// Returns the configured blob store.
pub(crate) fn blob_store(&self) -> &S {
&self.blob_store
}

/// Returns stats about the size of the pool.
pub(crate) fn size(&self) -> PoolSize {
self.pool.read().size()
Expand Down
15 changes: 15 additions & 0 deletions crates/transaction-pool/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use std::{
};
use tokio::sync::mpsc::Receiver;

use crate::blobstore::BlobStoreError;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -266,6 +267,20 @@ pub trait TransactionPool: Send + Sync + Clone {

/// Returns a set of all senders of transactions in the pool
fn unique_senders(&self) -> HashSet<Address>;

/// Returns the [BlobTransactionSidecar] for the given transaction hash if it exists in the blob
/// store.
fn get_blob(&self, tx_hash: TxHash) -> Result<Option<BlobTransactionSidecar>, BlobStoreError>;

/// Returns all [BlobTransactionSidecar] for the given transaction hashes if they exists in the
/// blob store.
///
/// This only returns the blobs that were found in the store.
/// If there's no blob it will not be returned.
fn get_all_blobs(
&self,
tx_hashes: Vec<TxHash>,
) -> Result<Vec<(TxHash, BlobTransactionSidecar)>, BlobStoreError>;
}

/// Extension for [TransactionPool] trait that allows to set the current block info.
Expand Down

0 comments on commit 82a42c9

Please sign in to comment.