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:
parent
be5c7fa7c9
commit
a21dd26a5e
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue