txgraph test: subclass TxGraph::Ref like mempool does (preparation)
What changed, and why it matters
This commit only changes an internal fuzz test file. It replaces direct use of a base class (TxGraph::Ref) with a new empty subclass (SimTxObject) inside the test code, so the test structure better matches how the real mempool uses derived objects. There is no change to production code, network behavior, wallets, consensus, or any user-facing functionality.
No security action needed. This is a benign test refactoring; routine code review is sufficient.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies src/test/fuzz/txgraph.cpp. It introduces a trivial struct SimTxObject : public TxGraph::Ref and updates the simulated graph’s maps, vectors, helper functions, and the fuzz target’s local variables to use SimTxObject / std::shared_ptr
Changed components
src/test/fuzz/txgraph.cppInspect captured patch +16 / −12
diff --git a/src/test/fuzz/txgraph.cpp b/src/test/fuzz/txgraph.cpp
index 214ed9e2..51546f61 100644
--- a/src/test/fuzz/txgraph.cpp
+++ b/src/test/fuzz/txgraph.cpp
@@ -23,6 +23,10 @@ using namespace cluster_linearize;
namespace {
+struct SimTxObject : public TxGraph::Ref
+{
+};
+
/** Data type representing a naive simulated TxGraph, keeping all transactions (even from
* disconnected components) in a single DepGraph. Unlike the real TxGraph, this only models
* a single graph, and multiple instances are used to simulate main/staging. */
@@ -42,14 +46,14 @@ struct SimTxGraph
/** The dependency graph (for all transactions in the simulation, regardless of
* connectivity/clustering). */
DepGraph<SetType> graph;
- /** For each position in graph, which TxGraph::Ref it corresponds with (if any). Use shared_ptr
+ /** For each position in graph, which SimTxObject it corresponds with (if any). Use shared_ptr
* so that a SimTxGraph can be copied to create a staging one, while sharing Refs with
* the main graph. */
- std::array<std::shared_ptr<TxGraph::Ref>, MAX_TRANSACTIONS> simmap;
+ std::array<std::shared_ptr<SimTxObject>, MAX_TRANSACTIONS> simmap;
/** For each TxGraph::Ref in graph, the position it corresponds with. */
std::map<const TxGraph::Ref*, Pos> simrevmap;
- /** The set of TxGraph::Ref entries that have been removed, but not yet destroyed. */
- std::vector<std::shared_ptr<TxGraph::Ref>> removed;
+ /** The set of SimTxObject entries that have been removed, but not yet destroyed. */
+ std::vector<std::shared_ptr<SimTxObject>> removed;
/** Whether the graph is oversized (true = yes, false = no, std::nullopt = unknown). */
std::optional<bool> oversized;
/** The configured maximum number of transactions per cluster. */
@@ -129,8 +133,8 @@ struct SimTxGraph
return MISSING;
}
- /** Given a position in this simulated graph, get the corresponding TxGraph::Ref. */
- TxGraph::Ref* GetRef(Pos pos)
+ /** Given a position in this simulated graph, get the corresponding SimTxObject. */
+ SimTxObject* GetRef(Pos pos)
{
assert(graph.Positions()[pos]);
assert(simmap[pos]);
@@ -145,7 +149,7 @@ struct SimTxGraph
real_is_optimal = false;
MakeModified(simpos);
assert(graph.Positions()[simpos]);
- simmap[simpos] = std::make_shared<TxGraph::Ref>();
+ simmap[simpos] = std::make_shared<SimTxObject>();
txgraph.AddTransaction(*simmap[simpos], feerate);
auto ptr = simmap[simpos].get();
simrevmap[ptr] = simpos;
@@ -309,8 +313,8 @@ FUZZ_TARGET(txgraph)
* specialized test cases that are hard to perform more generically. */
InsecureRandomContext rng(provider.ConsumeIntegral<uint64_t>());
- /** Variable used whenever an empty TxGraph::Ref is needed. */
- TxGraph::Ref empty_ref;
+ /** Variable used whenever an empty SimTxObject is needed. */
+ SimTxObject empty_ref;
/** The maximum number of transactions per (non-oversized) cluster we will use in this
* simulation. */
@@ -344,9 +348,9 @@ FUZZ_TARGET(txgraph)
/** Currently active block builders. */
std::vector<BlockBuilderData> block_builders;
- /** Function to pick any Ref (for either sim in sims: from sim.simmap or sim.removed, or the
- * empty Ref). */
- auto pick_fn = [&]() noexcept -> TxGraph::Ref* {
+ /** Function to pick any SimTxObject (for either sim in sims: from sim.simmap or sim.removed, or the
+ * empty one). */
+ auto pick_fn = [&]() noexcept -> SimTxObject* {
size_t tx_count[2] = {sims[0].GetTransactionCount(), 0};
/** The number of possible choices. */
size_t choices = tx_count[0] + sims[0].removed.size() + 1;
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.