Skip to content

txpool: fix tx removal from unlocks set #8500

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

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

iulianbarbu
Copy link
Contributor

@iulianbarbu iulianbarbu commented May 12, 2025

Description

Removing a tx subtree means partly removing some txs from the unlocks set of other txs. This logic is buggy and the PR attempts to fix it.

Closes #8498

Integration

N/A

Review Notes

This doesn't seem to be an important bug. Unit tests for txpool still pass after the fix, so txpool behavior isn't changing much.

TODOs

  • test with a heavy load test (5 millions txs) - all txs were validated successfully
  • added a unit test

Signed-off-by: Iulian Barbu <iulian.barbu@parity.io>
@iulianbarbu iulianbarbu self-assigned this May 12, 2025
@iulianbarbu iulianbarbu added the I2-bug The node fails to follow expected behavior. label May 12, 2025
@iulianbarbu iulianbarbu changed the title txpool: fix of tx removal from unlocks set txpool: fix tx removal from unlocks set May 15, 2025
iulianbarbu and others added 3 commits May 15, 2025 14:05
Signed-off-by: Iulian Barbu <iulian.barbu@parity.io>
Signed-off-by: Iulian Barbu <iulian.barbu@parity.io>
@iulianbarbu iulianbarbu marked this pull request as ready for review May 15, 2025 14:19
@iulianbarbu
Copy link
Contributor Author

/cmd prdoc

github-actions bot and others added 2 commits May 15, 2025 14:23
Signed-off-by: Iulian Barbu <iulian.barbu@parity.io>
@iulianbarbu
Copy link
Contributor Author

/cmd fmt

Copy link
Contributor

Command "fmt" has failed ❌! See logs here

iulianbarbu and others added 3 commits May 15, 2025 17:39
Signed-off-by: Iulian Barbu <iulian.barbu@parity.io>
Signed-off-by: Iulian Barbu <iulian.barbu@parity.io>
if let Some(tx_unlocking) = ready.get_mut(hash) {
remove_item(
&mut tx_unlocking.unlocks,
&tx.transaction.transaction.hash,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be just tx_hash ?:

Suggested change
&tx.transaction.transaction.hash,
&tx_hash,

@@ -298,8 +298,11 @@ impl<Hash: hash::Hash + Member + Serialize, Ex> ReadyTransactions<Hash, Ex> {
// remove from unlocks
for tag in &tx.transaction.transaction.requires {
if let Some(hash) = self.provided_tags.get(tag) {
if let Some(tx) = ready.get_mut(hash) {
remove_item(&mut tx.unlocks, hash);
if let Some(tx_unlocking) = ready.get_mut(hash) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like the name change here 👍

let tx3 = it.next().unwrap();
let lock = ready.ready.read();
let tx1_unlocks = &lock.get(&tx1.hash).unwrap().unlocks;
assert_eq!(tx1_unlocks[0], tx2.hash);
Copy link
Contributor

@michalkucharczyk michalkucharczyk May 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could check tx3 is also unlocked by tx1.

assert_eq!(removed[1].hash, tx3.hash);
let lock = ready.ready.read();
let tx1_unlocks = &lock.get(&tx1.hash).unwrap().unlocks;
assert!(!tx1_unlocks.contains(&tx2.hash));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here tx3 shall still be unlocked by tx1 (assuming I read populate_pool correctly :) )

@michalkucharczyk
Copy link
Contributor

note - just for the record - I think this bug was not causing any user-facing problems. Not removing transactions from unlocks set deep in graph module should not have been causing any issue with validity of ready set iterator, (or other graph related problems). At least these problems were not identified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I2-bug The node fails to follow expected behavior.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fatxpool: fix incomplete removal for tx subtree
2 participants