Insert new mempool transactions, then check for rejections (#2874)

Previously, we checked some rejections before inserting,
so we could accept some new transactions that should be rejected.
This commit is contained in:
teor 2021-10-14 23:19:21 +10:00 committed by GitHub
parent be5c7fa7c9
commit a21dd26a5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 18 deletions

View File

@ -267,24 +267,6 @@ impl Service<Request> for Mempool {
storage,
tx_downloads,
} => {
if let Some(tip_action) = self.chain_tip_change.last_tip_change() {
match tip_action {
// Clear the mempool and cancel downloads if there has been a chain tip reset.
TipAction::Reset { .. } => {
storage.clear();
tx_downloads.cancel_all();
}
// Cancel downloads/verifications/storage of transactions
// with the same mined IDs as recently mined transactions.
TipAction::Grow { block } => {
let mined_ids = block.transaction_hashes.iter().cloned().collect();
tx_downloads.cancel(&mined_ids);
storage.remove_same_effects(&mined_ids);
storage.clear_tip_rejections();
}
}
}
// Collect inserted transaction ids.
let mut send_to_peers_ids = HashSet::<_>::new();
@ -304,6 +286,25 @@ impl Service<Request> for Mempool {
};
}
// Handle best chain tip changes
if let Some(tip_action) = self.chain_tip_change.last_tip_change() {
match tip_action {
// Clear the mempool and cancel downloads if there has been a chain tip reset.
TipAction::Reset { .. } => {
storage.clear();
tx_downloads.cancel_all();
}
TipAction::Grow { block } => {
// Cancel downloads/verifications/storage of transactions
// with the same mined IDs as recently mined transactions.
let mined_ids = block.transaction_hashes.iter().cloned().collect();
tx_downloads.cancel(&mined_ids);
storage.remove_same_effects(&mined_ids);
storage.clear_tip_rejections();
}
}
}
// Remove expired transactions from the mempool.
if let Some(tip_height) = self.latest_chain_tip.best_tip_height() {
let expired_transactions = remove_expired_transactions(storage, tip_height);