mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-21 22:42:04 +01:00
MOVEONLY: add helper function for calculating ancestors and checking limits
This commit is contained in:
parent
f95bbf58aa
commit
97dd1c729d
2 changed files with 62 additions and 26 deletions
|
@ -150,33 +150,15 @@ void CTxMemPool::UpdateTransactionsFromBlock(const std::vector<uint256> &vHashes
|
|||
UpdateForDescendants(it, mapMemPoolDescendantsToUpdate, setAlreadyIncluded);
|
||||
}
|
||||
}
|
||||
|
||||
bool CTxMemPool::CalculateMemPoolAncestors(const CTxMemPoolEntry &entry, setEntries &setAncestors, uint64_t limitAncestorCount, uint64_t limitAncestorSize, uint64_t limitDescendantCount, uint64_t limitDescendantSize, std::string &errString, bool fSearchForParents /* = true */) const
|
||||
bool CTxMemPool::CalculateAncestorsAndCheckLimits(const CTxMemPoolEntry& entry,
|
||||
setEntries& setAncestors,
|
||||
CTxMemPoolEntry::Parents &staged_ancestors,
|
||||
uint64_t limitAncestorCount,
|
||||
uint64_t limitAncestorSize,
|
||||
uint64_t limitDescendantCount,
|
||||
uint64_t limitDescendantSize,
|
||||
std::string &errString) const
|
||||
{
|
||||
CTxMemPoolEntry::Parents staged_ancestors;
|
||||
const CTransaction &tx = entry.GetTx();
|
||||
|
||||
if (fSearchForParents) {
|
||||
// Get parents of this transaction that are in the mempool
|
||||
// GetMemPoolParents() is only valid for entries in the mempool, so we
|
||||
// iterate mapTx to find parents.
|
||||
for (unsigned int i = 0; i < tx.vin.size(); i++) {
|
||||
std::optional<txiter> piter = GetIter(tx.vin[i].prevout.hash);
|
||||
if (piter) {
|
||||
staged_ancestors.insert(**piter);
|
||||
if (staged_ancestors.size() + 1 > limitAncestorCount) {
|
||||
errString = strprintf("too many unconfirmed parents [limit: %u]", limitAncestorCount);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// If we're not searching for parents, we require this to be an
|
||||
// entry in the mempool already.
|
||||
txiter it = mapTx.iterator_to(entry);
|
||||
staged_ancestors = it->GetMemPoolParentsConst();
|
||||
}
|
||||
|
||||
size_t totalSizeWithAncestors = entry.GetTxSize();
|
||||
|
||||
while (!staged_ancestors.empty()) {
|
||||
|
@ -216,6 +198,44 @@ bool CTxMemPool::CalculateMemPoolAncestors(const CTxMemPoolEntry &entry, setEntr
|
|||
return true;
|
||||
}
|
||||
|
||||
bool CTxMemPool::CalculateMemPoolAncestors(const CTxMemPoolEntry &entry,
|
||||
setEntries &setAncestors,
|
||||
uint64_t limitAncestorCount,
|
||||
uint64_t limitAncestorSize,
|
||||
uint64_t limitDescendantCount,
|
||||
uint64_t limitDescendantSize,
|
||||
std::string &errString,
|
||||
bool fSearchForParents /* = true */) const
|
||||
{
|
||||
CTxMemPoolEntry::Parents staged_ancestors;
|
||||
const CTransaction &tx = entry.GetTx();
|
||||
|
||||
if (fSearchForParents) {
|
||||
// Get parents of this transaction that are in the mempool
|
||||
// GetMemPoolParents() is only valid for entries in the mempool, so we
|
||||
// iterate mapTx to find parents.
|
||||
for (unsigned int i = 0; i < tx.vin.size(); i++) {
|
||||
std::optional<txiter> piter = GetIter(tx.vin[i].prevout.hash);
|
||||
if (piter) {
|
||||
staged_ancestors.insert(**piter);
|
||||
if (staged_ancestors.size() + 1 > limitAncestorCount) {
|
||||
errString = strprintf("too many unconfirmed parents [limit: %u]", limitAncestorCount);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// If we're not searching for parents, we require this to already be an
|
||||
// entry in the mempool and use the entry's cached parents.
|
||||
txiter it = mapTx.iterator_to(entry);
|
||||
staged_ancestors = it->GetMemPoolParentsConst();
|
||||
}
|
||||
|
||||
return CalculateAncestorsAndCheckLimits(entry, setAncestors, staged_ancestors,
|
||||
limitAncestorCount, limitAncestorSize,
|
||||
limitDescendantCount, limitDescendantSize, errString);
|
||||
}
|
||||
|
||||
void CTxMemPool::UpdateAncestorsOf(bool add, txiter it, setEntries &setAncestors)
|
||||
{
|
||||
CTxMemPoolEntry::Parents parents = it->GetMemPoolParents();
|
||||
|
|
|
@ -585,6 +585,22 @@ private:
|
|||
*/
|
||||
std::set<uint256> m_unbroadcast_txids GUARDED_BY(cs);
|
||||
|
||||
|
||||
/**
|
||||
* Helper function to populate setAncestors with all the ancestors of entry and apply ancestor
|
||||
* and descendant limits.
|
||||
* param@[out] setAncestors Will be populated with all mempool ancestors of entry.
|
||||
* param@[in] staged_ancestors Should contain mempool parents of entry.
|
||||
*/
|
||||
bool CalculateAncestorsAndCheckLimits(const CTxMemPoolEntry& entry,
|
||||
setEntries& setAncestors,
|
||||
CTxMemPoolEntry::Parents &staged_ancestors,
|
||||
uint64_t limitAncestorCount,
|
||||
uint64_t limitAncestorSize,
|
||||
uint64_t limitDescendantCount,
|
||||
uint64_t limitDescendantSize,
|
||||
std::string &errString) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||
|
||||
public:
|
||||
indirectmap<COutPoint, const CTransaction*> mapNextTx GUARDED_BY(cs);
|
||||
std::map<uint256, CAmount> mapDeltas GUARDED_BY(cs);
|
||||
|
|
Loading…
Add table
Reference in a new issue