@@ -186,7 +186,7 @@ struct DepGraphFormatter
186
186
/* * The dependency graph which we deserialize into first, with transactions in
187
187
* topological serialization order, not original cluster order. */
188
188
DepGraph<SetType> topo_depgraph;
189
- /* * Mapping from cluster order to serialization order, used later to reconstruct the
189
+ /* * Mapping from serialization order to cluster order, used later to reconstruct the
190
190
* cluster order. */
191
191
std::vector<ClusterIndex> reordering;
192
192
@@ -205,9 +205,9 @@ struct DepGraphFormatter
205
205
coded_fee &= 0xFFFFFFFFFFFFF ; // Enough for fee between -21M...21M BTC.
206
206
static_assert (0xFFFFFFFFFFFFF > uint64_t {2 } * 21000000 * 100000000 );
207
207
auto fee = UnsignedToSigned (coded_fee);
208
- // Extend topo_depgraph with the new transaction (at the end).
208
+ // Extend topo_depgraph with the new transaction (preliminarily at the end).
209
209
auto topo_idx = topo_depgraph.AddTransaction ({fee, size});
210
- reordering.push_back (topo_idx );
210
+ reordering.push_back (reordering. size () );
211
211
// Read dependency information.
212
212
uint64_t diff = 0 ; // !< How many potential parents we have to skip.
213
213
s >> VARINT (diff);
@@ -226,31 +226,23 @@ struct DepGraphFormatter
226
226
--diff;
227
227
}
228
228
}
229
- // If we reach this point, we can interpret the remaining skip value as how far from the
230
- // end of reordering topo_idx should be placed (wrapping around), so move it to its
231
- // correct location. The preliminary reordering.push_back(topo_idx) above was to make
232
- // sure that if a deserialization exception occurs, topo_idx still appears somewhere.
229
+ // If we reach this point, we can interpret the remaining skip value as how far
230
+ // from the end of reordering the new transaction should be placed (wrapping
231
+ // around), so remove the preliminary position it was put in above (which was to
232
+ // make sure that if a deserialization exception occurs, the new transaction still
233
+ // has some entry in reordering).
233
234
reordering.pop_back ();
234
- reordering.insert (reordering.end () - (diff % (reordering.size () + 1 )), topo_idx);
235
+ ClusterIndex insert_distance = diff % (reordering.size () + 1 );
236
+ // And then update reordering to reflect this new transaction's insertion.
237
+ for (auto & pos : reordering) {
238
+ pos += (pos >= reordering.size () - insert_distance);
239
+ }
240
+ reordering.push_back (reordering.size () - insert_distance);
235
241
}
236
242
} catch (const std::ios_base::failure&) {}
237
243
238
244
// Construct the original cluster order depgraph.
239
- depgraph = {};
240
- // Add transactions to depgraph in the original cluster order.
241
- for (auto topo_idx : reordering) {
242
- depgraph.AddTransaction (topo_depgraph.FeeRate (topo_idx));
243
- }
244
- // Translate dependencies from topological to cluster order.
245
- for (ClusterIndex idx = 0 ; idx < reordering.size (); ++idx) {
246
- ClusterIndex topo_idx = reordering[idx];
247
- for (ClusterIndex dep_idx = 0 ; dep_idx < reordering.size (); ++dep_idx) {
248
- ClusterIndex dep_topo_idx = reordering[dep_idx];
249
- if (topo_depgraph.Ancestors (topo_idx)[dep_topo_idx]) {
250
- depgraph.AddDependency (dep_idx, idx);
251
- }
252
- }
253
- }
245
+ depgraph = DepGraph (topo_depgraph, reordering);
254
246
}
255
247
};
256
248
0 commit comments