Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
NikVolf committed Jan 21, 2020
1 parent cada84b commit d25dde4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
19 changes: 12 additions & 7 deletions client/transaction-pool/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,18 @@ impl<Client, F, Block> sc_transaction_graph::ChainApi for LightChainApi<Client,
let fetcher = self.fetcher.clone();
async move {
let transactions = fetcher.remote_body({
RemoteBodyRequest {
header,
retry_count: None,
}
}).await;

Ok(Some(transactions.unwrap_or(Vec::new())))
RemoteBodyRequest {
header,
retry_count: None,
}
})
.await
.unwrap_or_else(|e| {
log::warn!(target: "txpool", "Failed to fetch block body: {:?}", e);
Vec::new()
});

Ok(Some(transactions))
}.boxed()
}
}
25 changes: 15 additions & 10 deletions client/transaction-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use parking_lot::Mutex;

use sp_runtime::{
generic::BlockId,
traits::{Block as BlockT, NumberFor, SimpleArithmetic},
traits::{Block as BlockT, NumberFor, SimpleArithmetic, Extrinsic},
};
use sp_transaction_pool::{
TransactionPool, PoolStatus, ImportNotificationStream,
Expand Down Expand Up @@ -278,7 +278,7 @@ where
let block_number = match api.block_id_to_number(&id) {
Ok(Some(number)) => number,
_ => {
log::trace!(target: "txqueue", "Skipping chain event - no numbrer for that block {:?}", id);
log::trace!(target: "txqueue", "Skipping chain event - no number for that block {:?}", id);
return Box::pin(ready(()));
}
};
Expand All @@ -292,18 +292,21 @@ where
let retracted = retracted.to_vec();

async move {
let hashes = api.block_body(&id).await
.unwrap_or_else(|e| {
log::warn!("Prune known transactions: error request {:?}!", e);
None
})
// We don't query block if we won't prune anything
if !pool.status().is_empty() {
let hashes = api.block_body(&id).await
.unwrap_or_else(|e| {
log::warn!("Prune known transactions: error request {:?}!", e);
None
})
.unwrap_or_default()
.into_iter()
.map(|tx| pool.hash_of(&tx))
.collect::<Vec<_>>();

if let Err(e) = pool.prune_known(&id, &hashes) {
log::error!("Cannot prune known in the pool {:?}!", e);
if let Err(e) = pool.prune_known(&id, &hashes) {
log::error!("Cannot prune known in the pool {:?}!", e);
}
}

if next_action.resubmit {
Expand All @@ -315,7 +318,9 @@ where
log::warn!("Failed to fetch block body {:?}!", e);
None
})
.unwrap_or_default();
.unwrap_or_default()
.into_iter()
.filter(|tx| tx.is_signed().unwrap_or(true));

resubmit_transactions.extend(block_transactions);
}
Expand Down

0 comments on commit d25dde4

Please sign in to comment.