Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions prdoc/pr_8500.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
title: 'txpool: fix tx removal from unlocks set'
doc:
- audience: Node Dev
description: |-
Now removing a tx subtree will correctly remove it from the transactions that would unlock it.

crates:
- name: sc-transaction-pool
bump: major
40 changes: 38 additions & 2 deletions substrate/client/transaction-pool/src/graph/ready.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ 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) {
remove_item(&mut tx_unlocking.unlocks, &tx_hash);
}
}
}
Expand Down Expand Up @@ -788,4 +788,40 @@ mod tests {
assert_eq!(it.next().as_ref().map(data), Some(7));
assert_eq!(it.next().as_ref().map(data), None);
}

#[test]
fn should_remove_tx_from_unlocks_set_of_its_parent() {
// given
let mut ready = ReadyTransactions::default();
populate_pool(&mut ready);

// when
let mut it = ready.get();
let tx1 = it.next().unwrap();
let tx2 = it.next().unwrap();
let tx3 = it.next().unwrap();
let tx4 = it.next().unwrap();
let lock = ready.ready.read();
let tx1_unlocks = &lock.get(&tx1.hash).unwrap().unlocks;

// There are two tags provided by tx1 and required by tx2.
assert_eq!(tx1_unlocks[0], tx2.hash);
assert_eq!(tx1_unlocks[1], tx2.hash);
assert_eq!(tx1_unlocks[2], tx3.hash);
assert_eq!(tx1_unlocks[4], tx4.hash);
drop(lock);

// then consider tx2 invalid, and hence, remove it.
let removed = ready.remove_subtree(&[tx2.hash]);
assert_eq!(removed.len(), 2);
assert_eq!(removed[0].hash, tx2.hash);
// tx3 is removed too, since it requires tx2 provides tags.
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));
assert!(!tx1_unlocks.contains(&tx3.hash));
assert!(tx1_unlocks.contains(&tx4.hash));
}
}
Loading