Skip to content

Commit

Permalink
Only check entire mempool if consensus TX fails
Browse files Browse the repository at this point in the history
  • Loading branch information
Bushstar committed Dec 11, 2020
1 parent 4bfda3e commit fed3155
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions src/txmempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,25 +582,42 @@ void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigne
std::set<CTransactionRef> txsToRemove;
CCoinsViewCache mempoolDuplicate(const_cast<CCoinsViewCache*>(&::ChainstateActive().CoinsTip()));
CAmount txfee = 0;
bool accountConflict{false};

// Check custom TX consensus types are now not in conflict with account layer
// Check if any custom TXs are in mempool with conflict
for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); ++it) {
CValidationState state;
if (!Consensus::CheckTxInputs(it->GetTx(), state, mempoolDuplicate, pcustomcsview.get(), nBlockHeight, txfee, Params())) {
LogPrintf("%s: Remove conflicting TX: %s\n", __func__, it->GetTx().GetHash().GetHex());
txsToRemove.insert(it->GetSharedTx());
std::vector<unsigned char> metadata;
CustomTxType txType = GuessCustomTxType(it->GetTx(), metadata);
if (NotAllowedToFail(txType)) {
auto res = ApplyCustomTx(*pcustomcsview, g_chainstate->CoinsTip(), it->GetTx(), Params().GetConsensus(), nBlockHeight, 0, true);
if (!res.ok && (res.code & CustomTxErrCodes::Fatal)) {
accountConflict = true;
break;
}
}
}

for (auto& tx : txsToRemove) {
txiter it = mapTx.find(tx->GetHash());
if (it != mapTx.end()) {
setEntries stage;
stage.insert(it);
RemoveStaged(stage, true, MemPoolRemovalReason::CONFLICT);
// Account conflict, check entire mempool
if (accountConflict) {
// Check custom TX consensus types are now not in conflict with account layer
for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); ++it) {
CValidationState state;
if (!Consensus::CheckTxInputs(it->GetTx(), state, mempoolDuplicate, pcustomcsview.get(), nBlockHeight, txfee, Params())) {
LogPrintf("%s: Remove conflicting TX: %s\n", __func__, it->GetTx().GetHash().GetHex());
txsToRemove.insert(it->GetSharedTx());
}
}

for (auto& tx : txsToRemove) {
txiter it = mapTx.find(tx->GetHash());
if (it != mapTx.end()) {
setEntries stage;
stage.insert(it);
RemoveStaged(stage, true, MemPoolRemovalReason::CONFLICT);
}
removeConflicts(*tx);
ClearPrioritisation(tx->GetHash());
}
removeConflicts(*tx);
ClearPrioritisation(tx->GetHash());
}

lastRollingFeeUpdate = GetTime();
Expand Down

0 comments on commit fed3155

Please sign in to comment.