Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

fix(mempool): filter callback_cache while pull txs #158

Merged
merged 1 commit into from
Feb 10, 2020
Merged
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
12 changes: 10 additions & 2 deletions core/mempool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ where
pub fn get_adapter(&self) -> &Adapter {
&self.adapter
}

fn show_unknown_txs(&self, tx_hashes: Vec<Hash>) -> Vec<Hash> {
self.tx_cache
.show_unknown(tx_hashes)
.into_iter()
.filter(|tx_hash| !self.callback_cache.contains_key(tx_hash))
.collect()
}
}

#[async_trait]
Expand Down Expand Up @@ -145,7 +153,7 @@ where
ctx: Context,
order_tx_hashes: Vec<Hash>,
) -> 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?;
Expand All @@ -170,7 +178,7 @@ where
ctx: Context,
propose_tx_hashes: Vec<Hash>,
) -> 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| {
Expand Down