-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds rpc method for anvil to drop all pending transactions #7643
Adds rpc method for anvil to drop all pending transactions #7643
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
supportive
smol suggestion
crates/anvil/src/eth/pool/mod.rs
Outdated
let mut transactions_iterator = pool.pending_transactions.transactions(); | ||
|
||
while let Some(pool_transaction) = transactions_iterator.next() { | ||
let tx_hash = pool_transaction.as_ref().hash(); | ||
self.drop_transaction(tx_hash); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, I think we want a fn clear
on both tx sets
foundry/crates/anvil/src/eth/pool/mod.rs
Lines 202 to 203 in d8a1625
ready_transactions: ReadyTransactions, | |
pending_transactions: PendingTransactions, |
that clear all maps
@mattsse thank you for the quick review! if I understand you correctly, we want to clear both pending and ready transactions in the drop all transactions method? |
Now iterating over the ready transactions map and dropping them too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style suggestion
crates/anvil/src/eth/pool/mod.rs
Outdated
pub fn drop_all_transactions(&self) { | ||
let pool = self.inner.write(); | ||
|
||
let pending_transactions = pool.pending_transactions.transactions(); | ||
let ready_transactions = pool.ready_transactions.get_transactions(); | ||
|
||
pending_transactions.for_each(|pool_transaction| { | ||
let tx_hash = pool_transaction.as_ref().hash(); | ||
self.drop_transaction(tx_hash); | ||
}); | ||
|
||
ready_transactions.for_each(|pool_transaction| { | ||
let tx_hash = pool_transaction.as_ref().hash(); | ||
self.drop_transaction(tx_hash); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while this works, I want this to be
fn clear(&self) {
let pool = self.inner.write();
pool.clear(); // this clears both tx sets, calls clear on all their internals
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, and this should be more performant too
…c to clear transaction internals + be more performant
Moved to a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clean
Motivation
Fixes #7249
Solution
Added a new rpc method, and added the corresponding implementation in the mod.rs file for pool.