mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-04 10:12:28 +02:00
scripted-diff: (refactor) ClusterIndex -> DepGraphIndex
Since cluster_linearize.h does not actually have a Cluster type anymore, it is more appropriate to rename the index type to DepGraphIndex. -BEGIN VERIFY SCRIPT- sed -i 's/Data type to represent transaction indices in clusters./Data type to represent transaction indices in DepGraphs and the clusters they represent./' $(git grep -l 'using ClusterIndex') sed -i 's|\<ClusterIndex\>|DepGraphIndex|g' $(git grep -l 'ClusterIndex') -END VERIFY SCRIPT-
This commit is contained in:
@@ -122,10 +122,10 @@ struct DepGraphFormatter
|
||||
static void Ser(Stream& s, const DepGraph<SetType>& depgraph)
|
||||
{
|
||||
/** Construct a topological order to serialize the transactions in. */
|
||||
std::vector<ClusterIndex> topo_order;
|
||||
std::vector<DepGraphIndex> topo_order;
|
||||
topo_order.reserve(depgraph.TxCount());
|
||||
for (auto i : depgraph.Positions()) topo_order.push_back(i);
|
||||
std::sort(topo_order.begin(), topo_order.end(), [&](ClusterIndex a, ClusterIndex b) {
|
||||
std::sort(topo_order.begin(), topo_order.end(), [&](DepGraphIndex a, DepGraphIndex b) {
|
||||
auto anc_a = depgraph.Ancestors(a).Count(), anc_b = depgraph.Ancestors(b).Count();
|
||||
if (anc_a != anc_b) return anc_a < anc_b;
|
||||
return a < b;
|
||||
@@ -136,9 +136,9 @@ struct DepGraphFormatter
|
||||
SetType done;
|
||||
|
||||
// Loop over the transactions in topological order.
|
||||
for (ClusterIndex topo_idx = 0; topo_idx < topo_order.size(); ++topo_idx) {
|
||||
for (DepGraphIndex topo_idx = 0; topo_idx < topo_order.size(); ++topo_idx) {
|
||||
/** Which depgraph index we are currently writing. */
|
||||
ClusterIndex idx = topo_order[topo_idx];
|
||||
DepGraphIndex idx = topo_order[topo_idx];
|
||||
// Write size, which must be larger than 0.
|
||||
s << VARINT_MODE(depgraph.FeeRate(idx).size, VarIntMode::NONNEGATIVE_SIGNED);
|
||||
// Write fee, encoded as an unsigned varint (odd=negative, even=non-negative).
|
||||
@@ -146,9 +146,9 @@ struct DepGraphFormatter
|
||||
// Write dependency information.
|
||||
SetType written_parents;
|
||||
uint64_t diff = 0; //!< How many potential parent/child relations we have skipped over.
|
||||
for (ClusterIndex dep_dist = 0; dep_dist < topo_idx; ++dep_dist) {
|
||||
for (DepGraphIndex dep_dist = 0; dep_dist < topo_idx; ++dep_dist) {
|
||||
/** Which depgraph index we are currently considering as parent of idx. */
|
||||
ClusterIndex dep_idx = topo_order[topo_idx - 1 - dep_dist];
|
||||
DepGraphIndex dep_idx = topo_order[topo_idx - 1 - dep_dist];
|
||||
// Ignore transactions which are already known to be ancestors.
|
||||
if (depgraph.Descendants(dep_idx).Overlaps(written_parents)) continue;
|
||||
if (depgraph.Ancestors(idx)[dep_idx]) {
|
||||
@@ -191,9 +191,9 @@ struct DepGraphFormatter
|
||||
DepGraph<SetType> topo_depgraph;
|
||||
/** Mapping from serialization order to cluster order, used later to reconstruct the
|
||||
* cluster order. */
|
||||
std::vector<ClusterIndex> reordering;
|
||||
std::vector<DepGraphIndex> reordering;
|
||||
/** How big the entries vector in the reconstructed depgraph will be (including holes). */
|
||||
ClusterIndex total_size{0};
|
||||
DepGraphIndex total_size{0};
|
||||
|
||||
// Read transactions in topological order.
|
||||
while (true) {
|
||||
@@ -217,9 +217,9 @@ struct DepGraphFormatter
|
||||
// Read dependency information.
|
||||
auto topo_idx = reordering.size();
|
||||
s >> VARINT(diff);
|
||||
for (ClusterIndex dep_dist = 0; dep_dist < topo_idx; ++dep_dist) {
|
||||
for (DepGraphIndex dep_dist = 0; dep_dist < topo_idx; ++dep_dist) {
|
||||
/** Which topo_depgraph index we are currently considering as parent of topo_idx. */
|
||||
ClusterIndex dep_topo_idx = topo_idx - 1 - dep_dist;
|
||||
DepGraphIndex dep_topo_idx = topo_idx - 1 - dep_dist;
|
||||
// Ignore transactions which are already known ancestors of topo_idx.
|
||||
if (new_ancestors[dep_topo_idx]) continue;
|
||||
if (diff == 0) {
|
||||
@@ -286,9 +286,9 @@ template<typename SetType>
|
||||
void SanityCheck(const DepGraph<SetType>& depgraph)
|
||||
{
|
||||
// Verify Positions and PositionRange consistency.
|
||||
ClusterIndex num_positions{0};
|
||||
ClusterIndex position_range{0};
|
||||
for (ClusterIndex i : depgraph.Positions()) {
|
||||
DepGraphIndex num_positions{0};
|
||||
DepGraphIndex position_range{0};
|
||||
for (DepGraphIndex i : depgraph.Positions()) {
|
||||
++num_positions;
|
||||
position_range = i + 1;
|
||||
}
|
||||
@@ -297,7 +297,7 @@ void SanityCheck(const DepGraph<SetType>& depgraph)
|
||||
assert(position_range >= num_positions);
|
||||
assert(position_range <= SetType::Size());
|
||||
// Consistency check between ancestors internally.
|
||||
for (ClusterIndex i : depgraph.Positions()) {
|
||||
for (DepGraphIndex i : depgraph.Positions()) {
|
||||
// Transactions include themselves as ancestors.
|
||||
assert(depgraph.Ancestors(i)[i]);
|
||||
// If a is an ancestor of b, then b's ancestors must include all of a's ancestors.
|
||||
@@ -306,8 +306,8 @@ void SanityCheck(const DepGraph<SetType>& depgraph)
|
||||
}
|
||||
}
|
||||
// Consistency check between ancestors and descendants.
|
||||
for (ClusterIndex i : depgraph.Positions()) {
|
||||
for (ClusterIndex j : depgraph.Positions()) {
|
||||
for (DepGraphIndex i : depgraph.Positions()) {
|
||||
for (DepGraphIndex j : depgraph.Positions()) {
|
||||
assert(depgraph.Ancestors(i)[j] == depgraph.Descendants(j)[i]);
|
||||
}
|
||||
// No transaction is a parent or child of itself.
|
||||
@@ -348,7 +348,7 @@ void SanityCheck(const DepGraph<SetType>& depgraph)
|
||||
// In acyclic graphs, the union of parents with parents of parents etc. yields the
|
||||
// full ancestor set (and similar for children and descendants).
|
||||
std::vector<SetType> parents(depgraph.PositionRange()), children(depgraph.PositionRange());
|
||||
for (ClusterIndex i : depgraph.Positions()) {
|
||||
for (DepGraphIndex i : depgraph.Positions()) {
|
||||
parents[i] = depgraph.GetReducedParents(i);
|
||||
children[i] = depgraph.GetReducedChildren(i);
|
||||
}
|
||||
@@ -380,7 +380,7 @@ void SanityCheck(const DepGraph<SetType>& depgraph)
|
||||
|
||||
/** Perform a sanity check on a linearization. */
|
||||
template<typename SetType>
|
||||
void SanityCheck(const DepGraph<SetType>& depgraph, std::span<const ClusterIndex> linearization)
|
||||
void SanityCheck(const DepGraph<SetType>& depgraph, std::span<const DepGraphIndex> linearization)
|
||||
{
|
||||
// Check completeness.
|
||||
assert(linearization.size() == depgraph.TxCount());
|
||||
|
||||
Reference in New Issue
Block a user