mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-18 11:30:44 +01:00
txgraph: initialize Ref in AddTransaction (preparation)
Instead of returning a TxGraph::Ref from TxGraph::AddTransaction(), pass in a TxGraph::Ref& which is updated to refer to the new transaction in that graph. This cleans up the usage somewhat, avoiding the need for dummy Refs in CTxMemPoolEntry constructor calls, but the motivation is that a future commit will allow a callback to passed to MakeTxGraph to define a fallback order on the transaction objects. This does not work when a Ref is created separately from the CTxMemPoolEntry it ends up living in, as passing the newly-created Ref to the callback would be UB before it's emplaced in its final CTxMemPoolEntry.
This commit is contained in:
@@ -137,15 +137,16 @@ struct SimTxGraph
|
||||
return simmap[pos].get();
|
||||
}
|
||||
|
||||
/** Add a new transaction to the simulation. */
|
||||
void AddTransaction(TxGraph::Ref&& ref, const FeePerWeight& feerate)
|
||||
/** Add a new transaction to the simulation and the specified real graph. */
|
||||
void AddTransaction(TxGraph& txgraph, const FeePerWeight& feerate)
|
||||
{
|
||||
assert(graph.TxCount() < MAX_TRANSACTIONS);
|
||||
auto simpos = graph.AddTransaction(feerate);
|
||||
real_is_optimal = false;
|
||||
MakeModified(simpos);
|
||||
assert(graph.Positions()[simpos]);
|
||||
simmap[simpos] = std::make_shared<TxGraph::Ref>(std::move(ref));
|
||||
simmap[simpos] = std::make_shared<TxGraph::Ref>();
|
||||
txgraph.AddTransaction(*simmap[simpos], feerate);
|
||||
auto ptr = simmap[simpos].get();
|
||||
simrevmap[ptr] = simpos;
|
||||
// This may invalidate our cached oversized value.
|
||||
@@ -455,10 +456,8 @@ FUZZ_TARGET(txgraph)
|
||||
size = provider.ConsumeIntegralInRange<uint32_t>(1, 0xff);
|
||||
}
|
||||
FeePerWeight feerate{fee, size};
|
||||
// Create a real TxGraph::Ref.
|
||||
auto ref = real->AddTransaction(feerate);
|
||||
// Create a shared_ptr place in the simulation to put the Ref in.
|
||||
top_sim.AddTransaction(std::move(ref), feerate);
|
||||
// Create the transaction in the simulation and the real graph.
|
||||
top_sim.AddTransaction(*real, feerate);
|
||||
break;
|
||||
} else if ((block_builders.empty() || sims.size() > 1) && top_sim.GetTransactionCount() + top_sim.removed.size() > 1 && command-- == 0) {
|
||||
// AddDependency.
|
||||
|
||||
Reference in New Issue
Block a user