Changeset View
Changeset View
Standalone View
Standalone View
src/txmempool.cpp
Show All 40 Lines | CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef &_tx, const Amount _nFee, | ||||
feeDelta = Amount::zero(); | feeDelta = Amount::zero(); | ||||
nCountWithAncestors = 1; | nCountWithAncestors = 1; | ||||
nSizeWithAncestors = GetTxSize(); | nSizeWithAncestors = GetTxSize(); | ||||
nModFeesWithAncestors = nFee; | nModFeesWithAncestors = nFee; | ||||
nSigOpCountWithAncestors = sigOpCount; | nSigOpCountWithAncestors = sigOpCount; | ||||
} | } | ||||
size_t CTxMemPoolEntry::GetTxVirtualSize() const { | uint64_t CTxMemPoolEntry::GetVirtualSizeWithAncestors() const { | ||||
return GetVirtualTransactionSize(nTxSize, sigOpCount); | return GetVirtualTransactionSize(nSizeWithAncestors, | ||||
nSigOpCountWithAncestors); | |||||
} | } | ||||
uint64_t CTxMemPoolEntry::GetVirtualSizeWithDescendants() const { | uint64_t CTxMemPoolEntry::GetIncrementalVirtualSize() const { | ||||
// note this is distinct from the sum of descendants' individual virtual | uint64_t vsize_with_me = GetVirtualSizeWithAncestors(); | ||||
// sizes, and may be smaller. | uint64_t vsize_without_me = GetVirtualTransactionSize( | ||||
return GetVirtualTransactionSize(nSizeWithDescendants, | nSizeWithAncestors - nTxSize, nSigOpCountWithAncestors - sigOpCount); | ||||
nSigOpCountWithDescendants); | return vsize_with_me - vsize_without_me; | ||||
} | } | ||||
uint64_t CTxMemPoolEntry::GetVirtualSizeWithAncestors() const { | uint64_t CTxMemPoolEntry::GetIncrementalVirtualSizeWithDescendants() const { | ||||
// note this is distinct from the sum of ancestors' individual virtual | // "us" = me + descendants | ||||
// sizes, and may be smaller. | uint64_t vsize_with_us = GetVirtualTransactionSize( | ||||
return GetVirtualTransactionSize(nSizeWithAncestors, | nSizeWithAncestors + nSizeWithDescendants - nTxSize, | ||||
nSigOpCountWithAncestors); | nSigOpCountWithAncestors + nSigOpCountWithDescendants - sigOpCount); | ||||
uint64_t vsize_without_us = GetVirtualTransactionSize( | |||||
nSizeWithAncestors - nTxSize, nSigOpCountWithAncestors - sigOpCount); | |||||
return vsize_with_us - vsize_without_us; | |||||
} | } | ||||
deadalnix: I spent a fair amount of time verifying that these actually compute what I'd expect. It doesn't… | |||||
void CTxMemPoolEntry::UpdateFeeDelta(Amount newFeeDelta) { | void CTxMemPoolEntry::UpdateFeeDelta(Amount newFeeDelta) { | ||||
nModFeesWithDescendants += newFeeDelta - feeDelta; | nModFeesWithDescendants += newFeeDelta - feeDelta; | ||||
nModFeesWithAncestors += newFeeDelta - feeDelta; | nModFeesWithAncestors += newFeeDelta - feeDelta; | ||||
feeDelta = newFeeDelta; | feeDelta = newFeeDelta; | ||||
} | } | ||||
void CTxMemPoolEntry::UpdateLockPoints(const LockPoints &lp) { | void CTxMemPoolEntry::UpdateLockPoints(const LockPoints &lp) { | ||||
▲ Show 20 Lines • Show All 1,111 Lines • ▼ Show 20 Lines | while (!mapTx.empty() && DynamicMemoryUsage() > sizelimit) { | ||||
mapTx.get<descendant_score>().begin(); | mapTx.get<descendant_score>().begin(); | ||||
// We set the new mempool min fee to the feerate of the removed set, | // We set the new mempool min fee to the feerate of the removed set, | ||||
// plus the "minimum reasonable fee rate" (ie some value under which we | // plus the "minimum reasonable fee rate" (ie some value under which we | ||||
// consider txn to have 0 fee). This way, we don't allow txn to enter | // consider txn to have 0 fee). This way, we don't allow txn to enter | ||||
// mempool with feerate equal to txn which were removed with no block in | // mempool with feerate equal to txn which were removed with no block in | ||||
// between. | // between. | ||||
CFeeRate removed(it->GetModFeesWithDescendants(), | CFeeRate removed(it->GetModFeesWithDescendants(), | ||||
it->GetVirtualSizeWithDescendants()); | it->GetIncrementalVirtualSizeWithDescendants()); | ||||
removed += MEMPOOL_FULL_FEE_INCREMENT; | removed += MEMPOOL_FULL_FEE_INCREMENT; | ||||
trackPackageRemoved(removed); | trackPackageRemoved(removed); | ||||
maxFeeRateRemoved = std::max(maxFeeRateRemoved, removed); | maxFeeRateRemoved = std::max(maxFeeRateRemoved, removed); | ||||
setEntries stage; | setEntries stage; | ||||
CalculateDescendants(mapTx.project<0>(it), stage); | CalculateDescendants(mapTx.project<0>(it), stage); | ||||
nTxnRemoved += stage.size(); | nTxnRemoved += stage.size(); | ||||
▲ Show 20 Lines • Show All 222 Lines • Show Last 20 Lines |
I spent a fair amount of time verifying that these actually compute what I'd expect. It doesn't look like there are unit tests specifically for these. Even though some test are indirectly using them, it would be beneficial to add a unittest that verifies that the value actually are what we expect.
Note that doing it so before this refactoring and then changing the test to adapt to this refactoring would provide a strong guarantee that it is correct.