mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 23:03:45 +01:00
txgraph: Add GetMainStagingDiagrams function (feature)
This allows determining whether the changes in a staging diagram unambiguously improve the graph, through CompareChunks().
This commit is contained in:
@@ -140,6 +140,8 @@ public:
|
||||
void ApplyDependencies(TxGraphImpl& graph, std::span<std::pair<GraphIndex, GraphIndex>> to_apply) noexcept;
|
||||
/** Improve the linearization of this Cluster. */
|
||||
void Relinearize(TxGraphImpl& graph, uint64_t max_iters) noexcept;
|
||||
/** For every chunk in the cluster, append its FeeFrac to ret. */
|
||||
void AppendChunkFeerates(std::vector<FeeFrac>& ret) const noexcept;
|
||||
|
||||
// Functions that implement the Cluster-specific side of public TxGraph functions.
|
||||
|
||||
@@ -478,6 +480,7 @@ public:
|
||||
bool IsOversized(bool main_only = false) noexcept final;
|
||||
std::strong_ordering CompareMainOrder(const Ref& a, const Ref& b) noexcept final;
|
||||
GraphIndex CountDistinctClusters(std::span<const Ref* const> refs, bool main_only = false) noexcept final;
|
||||
std::pair<std::vector<FeeFrac>, std::vector<FeeFrac>> GetMainStagingDiagrams() noexcept final;
|
||||
|
||||
void SanityCheck() const final;
|
||||
};
|
||||
@@ -692,6 +695,13 @@ void Cluster::MoveToMain(TxGraphImpl& graph) noexcept
|
||||
Updated(graph);
|
||||
}
|
||||
|
||||
void Cluster::AppendChunkFeerates(std::vector<FeeFrac>& ret) const noexcept
|
||||
{
|
||||
auto chunk_feerates = ChunkLinearization(m_depgraph, m_linearization);
|
||||
ret.reserve(ret.size() + chunk_feerates.size());
|
||||
ret.insert(ret.end(), chunk_feerates.begin(), chunk_feerates.end());
|
||||
}
|
||||
|
||||
bool Cluster::Split(TxGraphImpl& graph) noexcept
|
||||
{
|
||||
// This function can only be called when the Cluster needs splitting.
|
||||
@@ -1916,6 +1926,32 @@ TxGraph::GraphIndex TxGraphImpl::CountDistinctClusters(std::span<const Ref* cons
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::pair<std::vector<FeeFrac>, std::vector<FeeFrac>> TxGraphImpl::GetMainStagingDiagrams() noexcept
|
||||
{
|
||||
Assume(m_staging_clusterset.has_value());
|
||||
MakeAllAcceptable(0);
|
||||
Assume(m_main_clusterset.m_deps_to_add.empty()); // can only fail if main is oversized
|
||||
MakeAllAcceptable(1);
|
||||
Assume(m_staging_clusterset->m_deps_to_add.empty()); // can only fail if staging is oversized
|
||||
// For all Clusters in main which conflict with Clusters in staging (i.e., all that are removed
|
||||
// by, or replaced in, staging), gather their chunk feerates.
|
||||
auto main_clusters = GetConflicts();
|
||||
std::vector<FeeFrac> main_feerates, staging_feerates;
|
||||
for (Cluster* cluster : main_clusters) {
|
||||
cluster->AppendChunkFeerates(main_feerates);
|
||||
}
|
||||
// Do the same for the Clusters in staging themselves.
|
||||
for (int quality = 0; quality < int(QualityLevel::NONE); ++quality) {
|
||||
for (const auto& cluster : m_staging_clusterset->m_clusters[quality]) {
|
||||
cluster->AppendChunkFeerates(staging_feerates);
|
||||
}
|
||||
}
|
||||
// Sort both by decreasing feerate to obtain diagrams, and return them.
|
||||
std::sort(main_feerates.begin(), main_feerates.end(), [](auto& a, auto& b) { return a > b; });
|
||||
std::sort(staging_feerates.begin(), staging_feerates.end(), [](auto& a, auto& b) { return a > b; });
|
||||
return std::make_pair(std::move(main_feerates), std::move(staging_feerates));
|
||||
}
|
||||
|
||||
void Cluster::SanityCheck(const TxGraphImpl& graph, int level) const
|
||||
{
|
||||
// There must be an m_mapping for each m_depgraph position (including holes).
|
||||
|
||||
Reference in New Issue
Block a user