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:
1 parent
9095d8ac1c
commit
c28a602e00
1 file changed
+14
-1
+14
-1
@@ -318,6 +318,8 @@ private:
|
|||||||
/** Index of ChunkData objects, indexing the last transaction in each chunk in the main
|
/** Index of ChunkData objects, indexing the last transaction in each chunk in the main
|
||||||
* graph. */
|
* graph. */
|
||||||
ChunkIndex m_main_chunkindex;
|
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.
|
/** 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.
|
* 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];
|
auto& entry = m_entries[idx];
|
||||||
Assume(entry.m_ref != nullptr);
|
Assume(entry.m_ref != nullptr);
|
||||||
|
Assume(m_main_chunkindex_observers == 0 || !entry.m_locator[0].IsPresent());
|
||||||
entry.m_ref = nullptr;
|
entry.m_ref = nullptr;
|
||||||
// Mark the transaction as to be removed in all levels where it explicitly or implicitly
|
// Mark the transaction as to be removed in all levels where it explicitly or implicitly
|
||||||
// exists.
|
// 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()) {
|
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);
|
m_main_chunkindex.erase(entry.m_main_chunkindex_iterator);
|
||||||
entry.m_main_chunkindex_iterator = m_main_chunkindex.end();
|
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()) {
|
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
|
// Destroy any potential ChunkData prior to modifying the Cluster (as that could
|
||||||
// invalidate its ordering).
|
// invalidate its ordering).
|
||||||
|
Assume(graph.m_main_chunkindex_observers == 0);
|
||||||
graph.m_main_chunkindex.erase(entry.m_main_chunkindex_iterator);
|
graph.m_main_chunkindex.erase(entry.m_main_chunkindex_iterator);
|
||||||
entry.m_main_chunkindex_iterator = graph.m_main_chunkindex.end();
|
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()) {
|
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
|
// Destroy any potential ChunkData prior to modifying the Cluster (as that could
|
||||||
// invalidate its ordering).
|
// invalidate its ordering).
|
||||||
|
Assume(graph.m_main_chunkindex_observers == 0);
|
||||||
graph.m_main_chunkindex.erase(entry.m_main_chunkindex_iterator);
|
graph.m_main_chunkindex.erase(entry.m_main_chunkindex_iterator);
|
||||||
entry.m_main_chunkindex_iterator = graph.m_main_chunkindex.end();
|
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
|
TxGraph::Ref TxGraphImpl::AddTransaction(const FeePerWeight& feerate) noexcept
|
||||||
{
|
{
|
||||||
|
Assume(m_main_chunkindex_observers == 0 || GetTopLevel() != 0);
|
||||||
// Construct a new Ref.
|
// Construct a new Ref.
|
||||||
Ref ret;
|
Ref ret;
|
||||||
// Construct a new Entry, and link it with the Ref.
|
// Construct a new Entry, and link it with the Ref.
|
||||||
@@ -1539,6 +1546,7 @@ void TxGraphImpl::RemoveTransaction(const Ref& arg) noexcept
|
|||||||
// having been removed).
|
// having been removed).
|
||||||
if (GetRefGraph(arg) == nullptr) return;
|
if (GetRefGraph(arg) == nullptr) return;
|
||||||
Assume(GetRefGraph(arg) == this);
|
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.
|
// Find the Cluster the transaction is in, and stop if it isn't in any.
|
||||||
int level = GetTopLevel();
|
int level = GetTopLevel();
|
||||||
auto cluster = FindCluster(GetRefIndex(arg), level);
|
auto cluster = FindCluster(GetRefIndex(arg), level);
|
||||||
@@ -1557,6 +1565,7 @@ void TxGraphImpl::AddDependency(const Ref& parent, const Ref& child) noexcept
|
|||||||
// removed).
|
// removed).
|
||||||
if (GetRefGraph(parent) == nullptr || GetRefGraph(child) == nullptr) return;
|
if (GetRefGraph(parent) == nullptr || GetRefGraph(child) == nullptr) return;
|
||||||
Assume(GetRefGraph(parent) == this && GetRefGraph(child) == this);
|
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.
|
// Don't do anything if this is a dependency on self.
|
||||||
if (GetRefIndex(parent) == GetRefIndex(child)) return;
|
if (GetRefIndex(parent) == GetRefIndex(child)) return;
|
||||||
// Find the Cluster the parent and child transaction are in, and stop if either appears to be
|
// 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.
|
// Staging must exist.
|
||||||
Assume(m_staging_clusterset.has_value());
|
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
|
// 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().
|
// there. All of these have been copied to staging in PullIn().
|
||||||
auto conflicts = GetConflicts();
|
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.
|
// Don't do anything if the passed Ref is empty.
|
||||||
if (GetRefGraph(ref) == nullptr) return;
|
if (GetRefGraph(ref) == nullptr) return;
|
||||||
Assume(GetRefGraph(ref) == this);
|
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.
|
// Find the entry, its locator, and inform its Cluster about the new feerate, if any.
|
||||||
auto& entry = m_entries[GetRefIndex(ref)];
|
auto& entry = m_entries[GetRefIndex(ref)];
|
||||||
for (int level = 0; level < MAX_LEVELS; ++level) {
|
for (int level = 0; level < MAX_LEVELS; ++level) {
|
||||||
@@ -2247,7 +2258,9 @@ void TxGraphImpl::SanityCheck() const
|
|||||||
void TxGraphImpl::DoWork() noexcept
|
void TxGraphImpl::DoWork() noexcept
|
||||||
{
|
{
|
||||||
for (int level = 0; level <= GetTopLevel(); ++level) {
|
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