mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-29 03:03:04 +02:00
txgraph: Introduce TxGraphImpl observer tracking (preparation)
This is preparation for a next commit which will introduce a class whose objects hold references to internals in TxGraphImpl, which disallows modifications to the graph while such objects exist.
This commit is contained in:
@@ -318,6 +318,8 @@ private:
|
||||
/** Index of ChunkData objects, indexing the last transaction in each chunk in the main
|
||||
* graph. */
|
||||
ChunkIndex m_main_chunkindex;
|
||||
/** Number of index-observing objects in existence. */
|
||||
size_t m_main_chunkindex_observers{0};
|
||||
|
||||
/** A Locator that describes whether, where, and in which Cluster an Entry appears.
|
||||
* Every Entry has MAX_LEVELS locators, as it may appear in one Cluster per level.
|
||||
@@ -453,6 +455,7 @@ public:
|
||||
{
|
||||
auto& entry = m_entries[idx];
|
||||
Assume(entry.m_ref != nullptr);
|
||||
Assume(m_main_chunkindex_observers == 0 || !entry.m_locator[0].IsPresent());
|
||||
entry.m_ref = nullptr;
|
||||
// Mark the transaction as to be removed in all levels where it explicitly or implicitly
|
||||
// exists.
|
||||
@@ -581,6 +584,7 @@ void TxGraphImpl::ClearLocator(int level, GraphIndex idx) noexcept
|
||||
}
|
||||
}
|
||||
if (level == 0 && entry.m_main_chunkindex_iterator != m_main_chunkindex.end()) {
|
||||
Assume(m_main_chunkindex_observers == 0);
|
||||
m_main_chunkindex.erase(entry.m_main_chunkindex_iterator);
|
||||
entry.m_main_chunkindex_iterator = m_main_chunkindex.end();
|
||||
}
|
||||
@@ -594,6 +598,7 @@ void Cluster::Updated(TxGraphImpl& graph) noexcept
|
||||
if (m_level == 0 && entry.m_main_chunkindex_iterator != graph.m_main_chunkindex.end()) {
|
||||
// Destroy any potential ChunkData prior to modifying the Cluster (as that could
|
||||
// invalidate its ordering).
|
||||
Assume(graph.m_main_chunkindex_observers == 0);
|
||||
graph.m_main_chunkindex.erase(entry.m_main_chunkindex_iterator);
|
||||
entry.m_main_chunkindex_iterator = graph.m_main_chunkindex.end();
|
||||
}
|
||||
@@ -887,6 +892,7 @@ void Cluster::Merge(TxGraphImpl& graph, Cluster& other) noexcept
|
||||
if (m_level == 0 && entry.m_main_chunkindex_iterator != graph.m_main_chunkindex.end()) {
|
||||
// Destroy any potential ChunkData prior to modifying the Cluster (as that could
|
||||
// invalidate its ordering).
|
||||
Assume(graph.m_main_chunkindex_observers == 0);
|
||||
graph.m_main_chunkindex.erase(entry.m_main_chunkindex_iterator);
|
||||
entry.m_main_chunkindex_iterator = graph.m_main_chunkindex.end();
|
||||
}
|
||||
@@ -1511,6 +1517,7 @@ Cluster::Cluster(uint64_t sequence, TxGraphImpl& graph, const FeePerWeight& feer
|
||||
|
||||
TxGraph::Ref TxGraphImpl::AddTransaction(const FeePerWeight& feerate) noexcept
|
||||
{
|
||||
Assume(m_main_chunkindex_observers == 0 || GetTopLevel() != 0);
|
||||
// Construct a new Ref.
|
||||
Ref ret;
|
||||
// Construct a new Entry, and link it with the Ref.
|
||||
@@ -1539,6 +1546,7 @@ void TxGraphImpl::RemoveTransaction(const Ref& arg) noexcept
|
||||
// having been removed).
|
||||
if (GetRefGraph(arg) == nullptr) return;
|
||||
Assume(GetRefGraph(arg) == this);
|
||||
Assume(m_main_chunkindex_observers == 0 || GetTopLevel() != 0);
|
||||
// Find the Cluster the transaction is in, and stop if it isn't in any.
|
||||
int level = GetTopLevel();
|
||||
auto cluster = FindCluster(GetRefIndex(arg), level);
|
||||
@@ -1557,6 +1565,7 @@ void TxGraphImpl::AddDependency(const Ref& parent, const Ref& child) noexcept
|
||||
// removed).
|
||||
if (GetRefGraph(parent) == nullptr || GetRefGraph(child) == nullptr) return;
|
||||
Assume(GetRefGraph(parent) == this && GetRefGraph(child) == this);
|
||||
Assume(m_main_chunkindex_observers == 0 || GetTopLevel() != 0);
|
||||
// Don't do anything if this is a dependency on self.
|
||||
if (GetRefIndex(parent) == GetRefIndex(child)) return;
|
||||
// Find the Cluster the parent and child transaction are in, and stop if either appears to be
|
||||
@@ -1895,6 +1904,7 @@ void TxGraphImpl::CommitStaging() noexcept
|
||||
{
|
||||
// Staging must exist.
|
||||
Assume(m_staging_clusterset.has_value());
|
||||
Assume(m_main_chunkindex_observers == 0);
|
||||
// Delete all conflicting Clusters in main, to make place for moving the staging ones
|
||||
// there. All of these have been copied to staging in PullIn().
|
||||
auto conflicts = GetConflicts();
|
||||
@@ -1947,6 +1957,7 @@ void TxGraphImpl::SetTransactionFee(const Ref& ref, int64_t fee) noexcept
|
||||
// Don't do anything if the passed Ref is empty.
|
||||
if (GetRefGraph(ref) == nullptr) return;
|
||||
Assume(GetRefGraph(ref) == this);
|
||||
Assume(m_main_chunkindex_observers == 0);
|
||||
// Find the entry, its locator, and inform its Cluster about the new feerate, if any.
|
||||
auto& entry = m_entries[GetRefIndex(ref)];
|
||||
for (int level = 0; level < MAX_LEVELS; ++level) {
|
||||
@@ -2247,7 +2258,9 @@ void TxGraphImpl::SanityCheck() const
|
||||
void TxGraphImpl::DoWork() noexcept
|
||||
{
|
||||
for (int level = 0; level <= GetTopLevel(); ++level) {
|
||||
MakeAllAcceptable(level);
|
||||
if (level > 0 || m_main_chunkindex_observers == 0) {
|
||||
MakeAllAcceptable(level);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user