From db4d61f39595e4cf98367dd688e4e3c9c84cd714 Mon Sep 17 00:00:00 2001 From: rev-chaos Date: Mon, 10 Feb 2020 16:19:47 +0800 Subject: [PATCH] filter callback_cache while pull txs --- core/mempool/src/lib.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/core/mempool/src/lib.rs b/core/mempool/src/lib.rs index e857a19b3..45ec6bfd4 100644 --- a/core/mempool/src/lib.rs +++ b/core/mempool/src/lib.rs @@ -67,6 +67,14 @@ where pub fn get_adapter(&self) -> &Adapter { &self.adapter } + + fn show_unknown_txs(&self, tx_hashes: Vec) -> Vec { + self.tx_cache + .show_unknown(tx_hashes) + .into_iter() + .filter(|tx_hash| !self.callback_cache.contains_key(tx_hash)) + .collect() + } } #[async_trait] @@ -145,7 +153,7 @@ where ctx: Context, order_tx_hashes: Vec, ) -> ProtocolResult<()> { - let unknown_hashes = self.tx_cache.show_unknown(order_tx_hashes); + let unknown_hashes = self.show_unknown_txs(order_tx_hashes); if !unknown_hashes.is_empty() { let unknown_len = unknown_hashes.len(); let txs = self.adapter.pull_txs(ctx.clone(), unknown_hashes).await?; @@ -170,7 +178,7 @@ where ctx: Context, propose_tx_hashes: Vec, ) -> ProtocolResult<()> { - let unknown_hashes = self.tx_cache.show_unknown(propose_tx_hashes); + let unknown_hashes = self.show_unknown_txs(propose_tx_hashes); if !unknown_hashes.is_empty() { let txs = self.adapter.pull_txs(ctx.clone(), unknown_hashes).await?; txs.into_iter().for_each(|tx| {