Skip to content

Commit

Permalink
Insert new mempool transactions, then check for rejections (#2874)
Browse files Browse the repository at this point in the history
Previously, we checked some rejections before inserting,
so we could accept some new transactions that should be rejected.
  • Loading branch information
teor2345 authored Oct 14, 2021
1 parent be5c7fa commit a21dd26
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions zebrad/src/components/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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);
Expand Down

0 comments on commit a21dd26

Please sign in to comment.