mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-14 12:43:40 +02:00
Keep mempool consistent after conflicting withdraw-spent
This commit is contained in:
parent
bde5c0a819
commit
eebbfb84b6
5 changed files with 25 additions and 11 deletions
|
|
@ -417,7 +417,8 @@ BOOST_AUTO_TEST_CASE(MempoolAncestorIndexingTest)
|
|||
/* after tx6 is mined, tx7 should move up in the sort */
|
||||
std::vector<CTransactionRef> vtx;
|
||||
vtx.push_back(MakeTransactionRef(tx6));
|
||||
pool.removeForBlock(vtx, 1);
|
||||
std::set<std::pair<uint256, COutPoint> > setWithdrawsSpent;
|
||||
pool.removeForBlock(vtx, 1, setWithdrawsSpent);
|
||||
|
||||
sortedOrder.erase(sortedOrder.begin()+1);
|
||||
// Ties are broken by hash
|
||||
|
|
@ -560,7 +561,8 @@ BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest)
|
|||
SetMockTime(42 + CTxMemPool::ROLLING_FEE_HALFLIFE);
|
||||
BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), maxFeeRateRemoved.GetFeePerK() + 1000);
|
||||
// ... we should keep the same min fee until we get a block
|
||||
pool.removeForBlock(vtx, 1);
|
||||
std::set<std::pair<uint256, COutPoint> > setWithdrawsSpent;
|
||||
pool.removeForBlock(vtx, 1, setWithdrawsSpent);
|
||||
SetMockTime(42 + 2*CTxMemPool::ROLLING_FEE_HALFLIFE);
|
||||
BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), (maxFeeRateRemoved.GetFeePerK() + 1000)/2);
|
||||
// ... then feerate should drop 1/2 each halflife
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
|
|||
for (unsigned int i = 0; i < 128; i++)
|
||||
garbage.push_back('X');
|
||||
CMutableTransaction tx;
|
||||
std::set<std::pair<uint256, COutPoint> > dummyWithdraws;
|
||||
tx.vin.resize(1);
|
||||
tx.vin[0].scriptSig = garbage;
|
||||
tx.vout.resize(1);
|
||||
|
|
@ -72,7 +73,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
|
|||
txHashes[9-h].pop_back();
|
||||
}
|
||||
}
|
||||
mpool.removeForBlock(block, ++blocknum);
|
||||
mpool.removeForBlock(block, ++blocknum, dummyWithdraws);
|
||||
block.clear();
|
||||
if (blocknum == 30) {
|
||||
// At this point we should need to combine 5 buckets to get enough data points
|
||||
|
|
@ -116,7 +117,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
|
|||
// Mine 50 more blocks with no transactions happening, estimates shouldn't change
|
||||
// We haven't decayed the moving average enough so we still have enough data points in every bucket
|
||||
while (blocknum < 250)
|
||||
mpool.removeForBlock(block, ++blocknum);
|
||||
mpool.removeForBlock(block, ++blocknum, dummyWithdraws);
|
||||
|
||||
BOOST_CHECK(mpool.estimateFee(1) == CFeeRate(0));
|
||||
for (int i = 2; i < 10;i++) {
|
||||
|
|
@ -136,7 +137,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
|
|||
txHashes[j].push_back(hash);
|
||||
}
|
||||
}
|
||||
mpool.removeForBlock(block, ++blocknum);
|
||||
mpool.removeForBlock(block, ++blocknum, dummyWithdraws);
|
||||
}
|
||||
|
||||
int answerFound;
|
||||
|
|
@ -155,7 +156,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
|
|||
txHashes[j].pop_back();
|
||||
}
|
||||
}
|
||||
mpool.removeForBlock(block, 265);
|
||||
mpool.removeForBlock(block, 265, dummyWithdraws);
|
||||
block.clear();
|
||||
BOOST_CHECK(mpool.estimateFee(1) == CFeeRate(0));
|
||||
for (int i = 2; i < 10;i++) {
|
||||
|
|
@ -176,7 +177,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
|
|||
|
||||
}
|
||||
}
|
||||
mpool.removeForBlock(block, ++blocknum);
|
||||
mpool.removeForBlock(block, ++blocknum, dummyWithdraws);
|
||||
block.clear();
|
||||
}
|
||||
BOOST_CHECK(mpool.estimateFee(1) == CFeeRate(0));
|
||||
|
|
|
|||
|
|
@ -601,7 +601,8 @@ void CTxMemPool::removeConflicts(const CTransaction &tx)
|
|||
/**
|
||||
* Called when a block is connected. Removes from mempool and updates the miner fee estimator.
|
||||
*/
|
||||
void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight)
|
||||
void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight,
|
||||
const std::set<std::pair<uint256, COutPoint> >& setWithdrawsSpent)
|
||||
{
|
||||
LOCK(cs);
|
||||
std::vector<const CTxMemPoolEntry*> entries;
|
||||
|
|
@ -626,6 +627,16 @@ void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigne
|
|||
removeConflicts(*tx);
|
||||
ClearPrioritisation(tx->GetHash());
|
||||
}
|
||||
for (std::set<std::pair<uint256, COutPoint> >::const_iterator it = setWithdrawsSpent.begin(); it != setWithdrawsSpent.end(); it++) {
|
||||
std::map<std::pair<uint256, COutPoint>, uint256>::const_iterator it2 = mapWithdrawsSpentToTxid.find(*it);
|
||||
if (it2 != mapWithdrawsSpentToTxid.end()) {
|
||||
txiter txit = mapTx.find(it2->second);
|
||||
assert(txit != mapTx.end());
|
||||
setEntries stage;
|
||||
stage.insert(txit);
|
||||
RemoveStaged(stage, true);
|
||||
}
|
||||
}
|
||||
lastRollingFeeUpdate = GetTime();
|
||||
blockSinceLastRollingFeeBump = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -543,8 +543,8 @@ public:
|
|||
void removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason = MemPoolRemovalReason::UNKNOWN);
|
||||
void removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight, int flags);
|
||||
void removeConflicts(const CTransaction &tx);
|
||||
void removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight);
|
||||
|
||||
void removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight,
|
||||
const std::set<std::pair<uint256, COutPoint> >& setWithdrawsSpent);
|
||||
void clear();
|
||||
void _clear(); //lock free
|
||||
bool CompareDepthAndScore(const uint256& hasha, const uint256& hashb);
|
||||
|
|
|
|||
|
|
@ -2347,7 +2347,7 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
|
|||
int64_t nTime5 = GetTimeMicros(); nTimeChainState += nTime5 - nTime4;
|
||||
LogPrint("bench", " - Writing chainstate: %.2fms [%.2fs]\n", (nTime5 - nTime4) * 0.001, nTimeChainState * 0.000001);
|
||||
// Remove conflicting transactions from the mempool.;
|
||||
mempool.removeForBlock(blockConnecting.vtx, pindexNew->nHeight);
|
||||
mempool.removeForBlock(blockConnecting.vtx, pindexNew->nHeight, setWithdrawsSpent);
|
||||
// Update chainActive & related variables.
|
||||
UpdateTip(pindexNew, chainparams);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue