mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
txgraph: Skipping end of cluster has no impact (optimization)
This commit is contained in:
parent
e3d3ad9723
commit
df4578d2aa
1 changed files with 18 additions and 7 deletions
|
@ -153,8 +153,9 @@ public:
|
|||
* union of their descendants to output. */
|
||||
void GetDescendantRefs(const TxGraphImpl& graph, std::span<std::pair<Cluster*, DepGraphIndex>>& args, std::vector<TxGraph::Ref*>& output) noexcept;
|
||||
/** Populate range with refs for the transactions in this Cluster's linearization, from
|
||||
* position start_pos until start_pos+range.size()-1, inclusive. */
|
||||
void GetClusterRefs(TxGraphImpl& graph, std::span<TxGraph::Ref*> range, LinearizationIndex start_pos) noexcept;
|
||||
* position start_pos until start_pos+range.size()-1, inclusive. Returns whether that
|
||||
* range includes the last transaction in the linearization. */
|
||||
bool GetClusterRefs(TxGraphImpl& graph, std::span<TxGraph::Ref*> range, LinearizationIndex start_pos) noexcept;
|
||||
/** Get the individual transaction feerate of a Cluster element. */
|
||||
FeePerWeight GetIndividualFeerate(DepGraphIndex idx) noexcept;
|
||||
/** Modify the fee of a Cluster element. */
|
||||
|
@ -574,7 +575,8 @@ class BlockBuilderImpl final : public TxGraph::BlockBuilder
|
|||
/** Iterator to the current chunk in the chunk index. end() if nothing further remains. */
|
||||
TxGraphImpl::ChunkIndex::const_iterator m_cur_iter;
|
||||
/** Which cluster the current chunk belongs to, so we can exclude further transactions from it
|
||||
* when that chunk is skipped. */
|
||||
* when that chunk is skipped, or nullptr if we know we're at the end of the current
|
||||
* cluster. */
|
||||
Cluster* m_cur_cluster;
|
||||
|
||||
// Move m_cur_iter / m_cur_cluster to the next acceptable chunk.
|
||||
|
@ -1682,7 +1684,7 @@ void Cluster::GetDescendantRefs(const TxGraphImpl& graph, std::span<std::pair<Cl
|
|||
}
|
||||
}
|
||||
|
||||
void Cluster::GetClusterRefs(TxGraphImpl& graph, std::span<TxGraph::Ref*> range, LinearizationIndex start_pos) noexcept
|
||||
bool Cluster::GetClusterRefs(TxGraphImpl& graph, std::span<TxGraph::Ref*> range, LinearizationIndex start_pos) noexcept
|
||||
{
|
||||
// Translate the transactions in the Cluster (in linearization order, starting at start_pos in
|
||||
// the linearization) to Refs, and fill them in range.
|
||||
|
@ -1692,6 +1694,8 @@ void Cluster::GetClusterRefs(TxGraphImpl& graph, std::span<TxGraph::Ref*> range,
|
|||
Assume(entry.m_ref != nullptr);
|
||||
ref = entry.m_ref;
|
||||
}
|
||||
// Return whether start_pos has advanced to the end of the Cluster.
|
||||
return start_pos == m_linearization.size();
|
||||
}
|
||||
|
||||
FeePerWeight Cluster::GetIndividualFeerate(DepGraphIndex idx) noexcept
|
||||
|
@ -2349,10 +2353,15 @@ std::optional<std::pair<std::vector<TxGraph::Ref*>, FeePerWeight>> BlockBuilderI
|
|||
ret.emplace();
|
||||
const auto& chunk_data = *m_cur_iter;
|
||||
const auto& chunk_end_entry = m_graph->m_entries[chunk_data.m_graph_index];
|
||||
auto cluster = chunk_end_entry.m_locator[0].cluster;
|
||||
ret->first.resize(chunk_data.m_chunk_count);
|
||||
auto start_pos = chunk_end_entry.m_main_lin_index + 1 - chunk_data.m_chunk_count;
|
||||
Assume(m_cur_cluster);
|
||||
m_cur_cluster->GetClusterRefs(*m_graph, ret->first, start_pos);
|
||||
bool is_end = cluster->GetClusterRefs(*m_graph, ret->first, start_pos);
|
||||
if (is_end) {
|
||||
m_cur_cluster = nullptr;
|
||||
} else {
|
||||
Assume(cluster == m_cur_cluster);
|
||||
}
|
||||
ret->second = chunk_end_entry.m_main_chunk_feerate;
|
||||
}
|
||||
return ret;
|
||||
|
@ -2395,7 +2404,9 @@ void BlockBuilderImpl::Include() noexcept
|
|||
void BlockBuilderImpl::Skip() noexcept
|
||||
{
|
||||
// When skipping a chunk we need to not include anything more of the cluster, as that could make
|
||||
// the result topologically invalid.
|
||||
// the result topologically invalid. Note that m_cur_cluster == nullptr when this was the last
|
||||
// chunk of a cluster, so in that case nothing is added here. This may significantly reduce the
|
||||
// size of m_excluded_clusters, especially when many singleton clusters are ignored.
|
||||
if (m_cur_cluster != nullptr) m_excluded_clusters.insert(m_cur_cluster);
|
||||
Next();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue