MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / UnlinkRef

Method UnlinkRef

src/txgraph.cpp:730–769  ·  view source on GitHub ↗

Only called by Ref::~Ref to unlink Refs, and Ref's move assignment. */

Source from the content-addressed store, hash-verified

728
729 /** Only called by Ref::~Ref to unlink Refs, and Ref's move assignment. */
730 void UnlinkRef(GraphIndex idx) noexcept final
731 {
732 auto& entry = m_entries[idx];
733 Assume(entry.m_ref != nullptr);
734 Assume(m_main_chunkindex_observers == 0 || !entry.m_locator[0].IsPresent());
735 // Remove all chunk index entries for the affected cluster, to avoid any chunk indexes
736 // referencing unlinked/destroyed Refs.
737 if (entry.m_locator[0].IsPresent()) {
738 entry.m_locator[0].cluster->RemoveChunkData(*this);
739 }
740 entry.m_ref = nullptr;
741 // Mark the transaction as to be removed in all levels where it explicitly or implicitly
742 // exists.
743 bool exists_anywhere{false};
744 bool exists{false};
745 for (int level = 0; level <= GetTopLevel(); ++level) {
746 if (entry.m_locator[level].IsPresent()) {
747 exists_anywhere = true;
748 exists = true;
749 } else if (entry.m_locator[level].IsRemoved()) {
750 exists = false;
751 }
752 if (exists) {
753 auto& clusterset = GetClusterSet(level);
754 clusterset.m_to_remove.push_back(idx);
755 // Force recomputation of grouping data.
756 clusterset.m_group_data = std::nullopt;
757 // Do not wipe the oversized state of main if staging exists. The reason for this
758 // is that the alternative would mean that cluster merges may need to be applied to
759 // a formerly-oversized main graph while staging exists (to satisfy chunk feerate
760 // queries into main, for example), and such merges could conflict with pulls of
761 // some of their constituents into staging.
762 if (level == GetTopLevel() && clusterset.m_oversized == true) {
763 clusterset.m_oversized = std::nullopt;
764 }
765 }
766 }
767 m_unlinked.push_back(idx);
768 if (!exists_anywhere) Compact();
769 }
770
771 // Functions related to various normalization/application steps.
772 /** Get rid of unlinked Entry objects in m_entries, if possible (this changes the GraphIndex

Callers 1

~RefMethod · 0.80

Calls 4

IsPresentMethod · 0.80
RemoveChunkDataMethod · 0.80
IsRemovedMethod · 0.80
push_backMethod · 0.45

Tested by

no test coverage detected