Skip to content

Commit 247e9de

Browse files
committed
Merge bitcoin/bitcoin#32191: Make TxGraph fuzz tests more deterministic
2835216 txgraph: make GroupClusters use partition numbers directly (optimization) (Pieter Wuille) c72c8d5 txgraph: compare sequence numbers instead of Cluster* (bugfix) (Pieter Wuille) Pull request description: Part of cluster mempool: #30289 The implicit transaction ordering for transactions in a TxGraphImpl is defined by: 1. higher chunk feerate first 2. lower Cluster* object pointer first 3. lower position within cluster linearization first. Number (2) is not deterministic, as it intricately depends on the heap allocation algorithm. Fix this by giving each Cluster a unique `uint64_t m_sequence` value, and sorting by those instead. The second commit then uses this new approach to optimize GroupClusters a bit more, avoiding some repeated checks and dereferences, by making a local copy of the involved sequence numbers. Thanks to @dergoegge for pointing this out. ACKs for top commit: instagibbs: reACK 2835216 marcofleon: ACK 2835216 glozow: utACK 2835216 Tree-SHA512: d772a55b9ed620159b934a42a39fca7f900d4aa89c099a280a0c61ea0bd7c4fc39b388281ffc775064ea77b0b17263871b4c9763aa71c710a79287d5eb2cd4b4
2 parents bfeacc1 + 2835216 commit 247e9de

File tree

2 files changed

+102
-76
lines changed

2 files changed

+102
-76
lines changed

src/test/fuzz/txgraph.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,14 @@ struct SimTxGraph
206206
ret.push_back(ptr);
207207
}
208208
}
209-
// Deduplicate.
210-
std::sort(ret.begin(), ret.end());
211-
ret.erase(std::unique(ret.begin(), ret.end()), ret.end());
212-
// Replace input.
213-
arg = std::move(ret);
209+
// Construct deduplicated version in input (do not use std::sort/std::unique for
210+
// deduplication as it'd rely on non-deterministic pointer comparison).
211+
arg.clear();
212+
for (auto ptr : ret) {
213+
if (std::find(arg.begin(), arg.end(), ptr) == arg.end()) {
214+
arg.push_back(ptr);
215+
}
216+
}
214217
}
215218
};
216219

0 commit comments

Comments
 (0)