MCPcopy Create free account
hub / github.com/ElementsProject/elements / UpdateForDescendants

Method UpdateForDescendants

src/txmempool.cpp:131–179  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

129}
130
131void CTxMemPool::UpdateForDescendants(txiter updateIt, cacheMap& cachedDescendants,
132 const std::set<uint256>& setExclude, std::set<uint256>& descendants_to_remove,
133 uint64_t ancestor_size_limit, uint64_t ancestor_count_limit)
134{
135 CTxMemPoolEntry::Children stageEntries, descendants;
136 stageEntries = updateIt->GetMemPoolChildrenConst();
137
138 while (!stageEntries.empty()) {
139 const CTxMemPoolEntry& descendant = *stageEntries.begin();
140 descendants.insert(descendant);
141 stageEntries.erase(descendant);
142 const CTxMemPoolEntry::Children& children = descendant.GetMemPoolChildrenConst();
143 for (const CTxMemPoolEntry& childEntry : children) {
144 cacheMap::iterator cacheIt = cachedDescendants.find(mapTx.iterator_to(childEntry));
145 if (cacheIt != cachedDescendants.end()) {
146 // We've already calculated this one, just add the entries for this set
147 // but don't traverse again.
148 for (txiter cacheEntry : cacheIt->second) {
149 descendants.insert(*cacheEntry);
150 }
151 } else if (!descendants.count(childEntry)) {
152 // Schedule for later processing
153 stageEntries.insert(childEntry);
154 }
155 }
156 }
157 // descendants now contains all in-mempool descendants of updateIt.
158 // Update and add to cached descendant map
159 int64_t modifySize = 0;
160 CAmount modifyFee = 0;
161 int64_t modifyCount = 0;
162 for (const CTxMemPoolEntry& descendant : descendants) {
163 if (!setExclude.count(descendant.GetTx().GetHash())) {
164 modifySize += descendant.GetTxSize();
165 modifyFee += descendant.GetModifiedFee();
166 modifyCount++;
167 cachedDescendants[updateIt].insert(mapTx.iterator_to(descendant));
168 // Update ancestor state for each descendant
169 mapTx.modify(mapTx.iterator_to(descendant), update_ancestor_state(updateIt->GetTxSize(), updateIt->GetModifiedFee(), 1, updateIt->GetSigOpCost(), updateIt->GetDiscountTxSize()));
170 // Don't directly remove the transaction here -- doing so would
171 // invalidate iterators in cachedDescendants. Mark it for removal
172 // by inserting into descendants_to_remove.
173 if (descendant.GetCountWithAncestors() > ancestor_count_limit || descendant.GetSizeWithAncestors() > ancestor_size_limit) {
174 descendants_to_remove.insert(descendant.GetTx().GetHash());
175 }
176 }
177 }
178 mapTx.modify(updateIt, update_descendant_state(modifySize, modifyFee, modifyCount));
179}
180
181void CTxMemPool::UpdateTransactionsFromBlock(const std::vector<uint256> &vHashesToUpdate, uint64_t ancestor_size_limit, uint64_t ancestor_count_limit)
182{

Callers

nothing calls this directly

Calls 15

findMethod · 0.80
countMethod · 0.80
GetTxMethod · 0.80
GetSigOpCostMethod · 0.80
GetCountWithAncestorsMethod · 0.80
emptyMethod · 0.45
beginMethod · 0.45
insertMethod · 0.45
eraseMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected