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

Do not fetch every block body from transaction pool #5981

Merged
merged 1 commit into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions client/transaction-pool/graph/src/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,11 @@ impl<H: hash::Hash + traits::Member + Serialize, C: ChainApi> Listener<H, C> {
}

/// Notify all watchers that transactions have been finalized
pub fn finalized(&mut self, block_hash: BlockHash<C>, txs: Vec<H>) {
self.finality_watchers.remove(&block_hash);
for h in txs {
self.fire(&h, |s| s.finalized(block_hash.clone()))
pub fn finalized(&mut self, block_hash: BlockHash<C>) {
if let Some(hashes) = self.finality_watchers.remove(&block_hash) {
for hash in hashes {
self.fire(&hash, |s| s.finalized(block_hash))
}
}
}
}
10 changes: 1 addition & 9 deletions client/transaction-pool/graph/src/validated_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,15 +559,7 @@ impl<B: ChainApi> ValidatedPool<B> {
/// Notify all watchers that transactions in the block with hash have been finalized
pub async fn on_block_finalized(&self, block_hash: BlockHash<B>) -> Result<(), B::Error> {
debug!(target: "txpool", "Attempting to notify watchers of finalization for {}", block_hash);
// fetch all extrinsic hashes
if let Some(txs) = self.api.block_body(&BlockId::Hash(block_hash.clone())).await? {
let tx_hashes = txs.into_iter()
.map(|tx| self.api.hash_and_length(&tx).0)
.collect::<Vec<_>>();
// notify the watcher that these extrinsics have been finalized
self.listener.write().finalized(block_hash, tx_hashes);
}

self.listener.write().finalized(block_hash);
Ok(())
}

Expand Down