@ -64,21 +64,13 @@ void CTxMemPoolEntry::UpdateFeeDelta(int64_t newFeeDelta)
// Update the given tx for any in-mempool descendants.
// Update the given tx for any in-mempool descendants.
// Assumes that setMemPoolChildren is correct for the given tx and all
// Assumes that setMemPoolChildren is correct for the given tx and all
// descendants.
// descendants.
bool CTxMemPool : : UpdateForDescendants ( txiter updateIt , int maxDescendantsToVisi t , cacheMap & cachedDescendants , const std : : set < uint256 > & setExclude )
void CTxMemPool : : UpdateForDescendants ( txiter updateIt , cacheMap & cachedDescendants , const std : : set < uint256 > & setExclude )
{
{
// Track the number of entries (outside setExclude) that we'd need to visit
// (will bail out if it exceeds maxDescendantsToVisit)
int nChildrenToVisit = 0 ;
setEntries stageEntries , setAllDescendants ;
setEntries stageEntries , setAllDescendants ;
stageEntries = GetMemPoolChildren ( updateIt ) ;
stageEntries = GetMemPoolChildren ( updateIt ) ;
while ( ! stageEntries . empty ( ) ) {
while ( ! stageEntries . empty ( ) ) {
const txiter cit = * stageEntries . begin ( ) ;
const txiter cit = * stageEntries . begin ( ) ;
if ( cit - > IsDirty ( ) ) {
// Don't consider any more children if any descendant is dirty
return false ;
}
setAllDescendants . insert ( cit ) ;
setAllDescendants . insert ( cit ) ;
stageEntries . erase ( cit ) ;
stageEntries . erase ( cit ) ;
const setEntries & setChildren = GetMemPoolChildren ( cit ) ;
const setEntries & setChildren = GetMemPoolChildren ( cit ) ;
@ -88,22 +80,11 @@ bool CTxMemPool::UpdateForDescendants(txiter updateIt, int maxDescendantsToVisit
// We've already calculated this one, just add the entries for this set
// We've already calculated this one, just add the entries for this set
// but don't traverse again.
// but don't traverse again.
BOOST_FOREACH ( const txiter cacheEntry , cacheIt - > second ) {
BOOST_FOREACH ( const txiter cacheEntry , cacheIt - > second ) {
// update visit count only for new child transactions
setAllDescendants . insert ( cacheEntry ) ;
// (outside of setExclude and stageEntries)
if ( setAllDescendants . insert ( cacheEntry ) . second & &
! setExclude . count ( cacheEntry - > GetTx ( ) . GetHash ( ) ) & &
! stageEntries . count ( cacheEntry ) ) {
nChildrenToVisit + + ;
}
}
}
} else if ( ! setAllDescendants . count ( childEntry ) ) {
} else if ( ! setAllDescendants . count ( childEntry ) ) {
// Schedule for later processing and update our visit count
// Schedule for later processing
if ( stageEntries . insert ( childEntry ) . second & & ! setExclude . count ( childEntry - > GetTx ( ) . GetHash ( ) ) ) {
stageEntries . insert ( childEntry ) ;
nChildrenToVisit + + ;
}
}
if ( nChildrenToVisit > maxDescendantsToVisit ) {
return false ;
}
}
}
}
}
}
@ -121,7 +102,6 @@ bool CTxMemPool::UpdateForDescendants(txiter updateIt, int maxDescendantsToVisit
}
}
}
}
mapTx . modify ( updateIt , update_descendant_state ( modifySize , modifyFee , modifyCount ) ) ;
mapTx . modify ( updateIt , update_descendant_state ( modifySize , modifyFee , modifyCount ) ) ;
return true ;
}
}
// vHashesToUpdate is the set of transaction hashes from a disconnected block
// vHashesToUpdate is the set of transaction hashes from a disconnected block
@ -167,10 +147,7 @@ void CTxMemPool::UpdateTransactionsFromBlock(const std::vector<uint256> &vHashes
UpdateParent ( childIter , it , true ) ;
UpdateParent ( childIter , it , true ) ;
}
}
}
}
if ( ! UpdateForDescendants ( it , 100 , mapMemPoolDescendantsToUpdate , setAlreadyIncluded ) ) {
UpdateForDescendants ( it , mapMemPoolDescendantsToUpdate , setAlreadyIncluded ) ;
// Mark as dirty if we can't do the calculation.
mapTx . modify ( it , set_dirty ( ) ) ;
}
}
}
}
}
@ -301,22 +278,13 @@ void CTxMemPool::UpdateForRemoveFromMempool(const setEntries &entriesToRemove)
}
}
}
}
void CTxMemPoolEntry : : SetDirty ( )
{
nCountWithDescendants = 0 ;
nSizeWithDescendants = nTxSize ;
nModFeesWithDescendants = GetModifiedFee ( ) ;
}
void CTxMemPoolEntry : : UpdateState ( int64_t modifySize , CAmount modifyFee , int64_t modifyCount )
void CTxMemPoolEntry : : UpdateState ( int64_t modifySize , CAmount modifyFee , int64_t modifyCount )
{
{
if ( ! IsDirty ( ) ) {
nSizeWithDescendants + = modifySize ;
nSizeWithDescendants + = modifySize ;
assert ( int64_t ( nSizeWithDescendants ) > 0 ) ;
assert ( int64_t ( nSizeWithDescendants ) > 0 ) ;
nModFeesWithDescendants + = modifyFee ;
nModFeesWithDescendants + = modifyFee ;
nCountWithDescendants + = modifyCount ;
nCountWithDescendants + = modifyCount ;
assert ( int64_t ( nCountWithDescendants ) > 0 ) ;
assert ( int64_t ( nCountWithDescendants ) > 0 ) ;
}
}
}
CTxMemPool : : CTxMemPool ( const CFeeRate & _minReasonableRelayFee ) :
CTxMemPool : : CTxMemPool ( const CFeeRate & _minReasonableRelayFee ) :
@ -658,12 +626,7 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const
assert ( setChildrenCheck = = GetMemPoolChildren ( it ) ) ;
assert ( setChildrenCheck = = GetMemPoolChildren ( it ) ) ;
// Also check to make sure size is greater than sum with immediate children.
// Also check to make sure size is greater than sum with immediate children.
// just a sanity check, not definitive that this calc is correct...
// just a sanity check, not definitive that this calc is correct...
if ( ! it - > IsDirty ( ) ) {
assert ( it - > GetSizeWithDescendants ( ) > = childSizes + it - > GetTxSize ( ) ) ;
assert ( it - > GetSizeWithDescendants ( ) > = childSizes + it - > GetTxSize ( ) ) ;
} else {
assert ( it - > GetSizeWithDescendants ( ) = = it - > GetTxSize ( ) ) ;
assert ( it - > GetModFeesWithDescendants ( ) = = it - > GetModifiedFee ( ) ) ;
}
if ( fDependsWait )
if ( fDependsWait )
waitingOnDependants . push_back ( & ( * it ) ) ;
waitingOnDependants . push_back ( & ( * it ) ) ;