diff --git a/substrate/core/service/src/components.rs b/substrate/core/service/src/components.rs index d5a4c5bc8a..20f01676a3 100644 --- a/substrate/core/service/src/components.rs +++ b/substrate/core/service/src/components.rs @@ -196,6 +196,11 @@ impl MaintainTransactionPool for C where ) -> error::Result<()> { use runtime_primitives::transaction_validity::TransactionValidity; + // Avoid calling into runtime if there is nothing to prune from the pool anyway. + if transaction_pool.status().is_empty() { + return Ok(()) + } + let block = client.block(id)?; let tags = match block { None => return Ok(()), @@ -222,7 +227,6 @@ impl MaintainTransactionPool for C where } } - /// The super trait that combines all required traits a `Service` needs to implement. pub trait ServiceTrait: Deref> diff --git a/substrate/core/transaction-pool/graph/src/base_pool.rs b/substrate/core/transaction-pool/graph/src/base_pool.rs index e6ad3cd6dd..2e96cc75c2 100644 --- a/substrate/core/transaction-pool/graph/src/base_pool.rs +++ b/substrate/core/transaction-pool/graph/src/base_pool.rs @@ -294,6 +294,13 @@ pub struct Status { pub future: usize, } +impl Status { + /// Returns true if the are no transactions in the pool. + pub fn is_empty(&self) -> bool { + self.ready == 0 && self.future == 0 + } +} + #[cfg(test)] mod tests { use super::*;