Skip to content

Commit

Permalink
feat: add futures api to TransactionPool (#1348)
Browse files Browse the repository at this point in the history
* feat: add futures api to `TransactionPool`

* fix clippy
  • Loading branch information
yjhmelody authored and Daanvdplas committed Sep 11, 2023
1 parent a4f84c4 commit de88cba
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions substrate/bin/node/bench/src/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ impl sc_transaction_pool_api::TransactionPool for Transactions {
Default::default()
}

fn futures(&self) -> Vec<Self::InPoolTransaction> {
unimplemented!()
}

fn status(&self) -> PoolStatus {
unimplemented!()
}
Expand Down
3 changes: 3 additions & 0 deletions substrate/client/transaction-pool/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ pub trait TransactionPool: Send + Sync {
fn remove_invalid(&self, hashes: &[TxHash<Self>]) -> Vec<Arc<Self::InPoolTransaction>>;

// *** logging
/// Get futures transaction list.
fn futures(&self) -> Vec<Self::InPoolTransaction>;

/// Returns pool status.
fn status(&self) -> PoolStatus;

Expand Down
3 changes: 1 addition & 2 deletions substrate/client/transaction-pool/src/graph/base_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ pub struct PruneStatus<Hash, Ex> {
}

/// Immutable transaction
#[cfg_attr(test, derive(Clone))]
#[derive(PartialEq, Eq)]
#[derive(PartialEq, Eq, Clone)]
pub struct Transaction<Hash, Extrinsic> {
/// Raw extrinsic representing that transaction.
pub data: Extrinsic,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub struct ValidatedPool<B: ChainApi> {
is_validator: IsValidator,
options: Options,
listener: RwLock<Listener<ExtrinsicHash<B>, B>>,
pool: RwLock<base::BasePool<ExtrinsicHash<B>, ExtrinsicFor<B>>>,
pub(crate) pool: RwLock<base::BasePool<ExtrinsicHash<B>, ExtrinsicFor<B>>>,
import_notification_sinks: Mutex<Vec<Sender<ExtrinsicHash<B>>>>,
rotator: PoolRotator<ExtrinsicHash<B>>,
}
Expand Down
6 changes: 6 additions & 0 deletions substrate/client/transaction-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,12 @@ where
fn ready(&self) -> ReadyIteratorFor<PoolApi> {
Box::new(self.pool.validated_pool().ready())
}

fn futures(&self) -> Vec<Self::InPoolTransaction> {
let pool = self.pool.validated_pool().pool.read();

pool.futures().cloned().collect::<Vec<_>>()
}
}

impl<Block, Client> FullPool<Block, Client>
Expand Down

0 comments on commit de88cba

Please sign in to comment.