txgraph: Introduce TxGraph::GetWorstMainChunk (feature)

It returns the last chunk that would be suggested for mining by BlockBuilder
objects. This is intended for eviction.
This commit is contained in:
Pieter Wuille
2025-01-08 17:18:12 -05:00
parent 394dbe2142
commit c734081454
3 changed files with 62 additions and 0 deletions

View File

@@ -545,6 +545,7 @@ public:
std::pair<std::vector<FeeFrac>, std::vector<FeeFrac>> GetMainStagingDiagrams() noexcept final;
std::unique_ptr<BlockBuilder> GetBlockBuilder() noexcept final;
std::pair<std::vector<Ref*>, FeePerWeight> GetWorstMainChunk() noexcept final;
void SanityCheck() const final;
};
@@ -2379,6 +2380,26 @@ std::unique_ptr<TxGraph::BlockBuilder> TxGraphImpl::GetBlockBuilder() noexcept
return std::make_unique<BlockBuilderImpl>(*this);
}
std::pair<std::vector<TxGraph::Ref*>, FeePerWeight> TxGraphImpl::GetWorstMainChunk() noexcept
{
std::pair<std::vector<Ref*>, FeePerWeight> ret;
// Make sure all clusters in main are up to date, and acceptable.
MakeAllAcceptable(0);
Assume(m_main_clusterset.m_deps_to_add.empty());
// If the graph is not empty, populate ret.
if (!m_main_chunkindex.empty()) {
const auto& chunk_data = *m_main_chunkindex.rbegin();
const auto& chunk_end_entry = m_entries[chunk_data.m_graph_index];
Cluster* 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;
cluster->GetClusterRefs(*this, ret.first, start_pos);
std::reverse(ret.first.begin(), ret.first.end());
ret.second = chunk_end_entry.m_main_chunk_feerate;
}
return ret;
}
} // namespace
TxGraph::Ref::~Ref()