Changeset View
Changeset View
Standalone View
Standalone View
src/txmempool.cpp
| Show All 19 Lines | |||||
| #include <util/moneystr.h> | #include <util/moneystr.h> | ||||
| #include <util/time.h> | #include <util/time.h> | ||||
| #include <validationinterface.h> | #include <validationinterface.h> | ||||
| #include <version.h> | #include <version.h> | ||||
| #include <algorithm> | #include <algorithm> | ||||
| #include <cmath> | #include <cmath> | ||||
| #include <limits> | #include <limits> | ||||
| #include <vector> | |||||
| bool CTxMemPool::CalculateAncestors( | bool CTxMemPool::CalculateAncestors( | ||||
| setEntries &setAncestors, | setEntries &setAncestors, | ||||
| CTxMemPoolEntry::Parents &staged_ancestors) const { | CTxMemPoolEntry::Parents &staged_ancestors) const { | ||||
| while (!staged_ancestors.empty()) { | while (!staged_ancestors.empty()) { | ||||
| const auto stage = staged_ancestors.begin()->get(); | const auto stage = staged_ancestors.begin()->get(); | ||||
| txiter stageit = mapTx.find(stage->GetTx().GetId()); | txiter stageit = mapTx.find(stage->GetTx().GetId()); | ||||
| ▲ Show 20 Lines • Show All 470 Lines • ▼ Show 20 Lines | std::vector<TxMempoolInfo> CTxMemPool::infoAll() const { | ||||
| const auto &index = mapTx.get<entry_id>(); | const auto &index = mapTx.get<entry_id>(); | ||||
| for (auto it = index.begin(); it != index.end(); ++it) { | for (auto it = index.begin(); it != index.end(); ++it) { | ||||
| ret.push_back(GetInfo(mapTx.project<0>(it))); | ret.push_back(GetInfo(mapTx.project<0>(it))); | ||||
| } | } | ||||
| return ret; | return ret; | ||||
| } | } | ||||
| bool CTxMemPool::setAvalancheFinalized(const CTxMemPoolEntryRef &tx) { | bool CTxMemPool::setAvalancheFinalized(const CTxMemPoolEntryRef &tx, | ||||
| std::vector<TxId> &finalizedTxIds) { | |||||
| AssertLockHeld(cs); | AssertLockHeld(cs); | ||||
| auto it = mapTx.find(tx->GetTx().GetId()); | auto it = mapTx.find(tx->GetTx().GetId()); | ||||
| if (it == mapTx.end()) { | if (it == mapTx.end()) { | ||||
| // Trying to finalize a tx that is not in the mempool ! | // Trying to finalize a tx that is not in the mempool ! | ||||
| return false; | return false; | ||||
| } | } | ||||
| setEntries setAncestors; | setEntries setAncestors; | ||||
| setAncestors.insert(it); | setAncestors.insert(it); | ||||
| if (!CalculateMemPoolAncestors(tx, setAncestors, | if (!CalculateMemPoolAncestors(tx, setAncestors, | ||||
| /*fSearchForParents=*/false)) { | /*fSearchForParents=*/false)) { | ||||
| // Failed to get a list of parents for this tx. If we finalize it we | // Failed to get a list of parents for this tx. If we finalize it we | ||||
| // might be missing a parent and generate an invalid block. | // might be missing a parent and generate an invalid block. | ||||
| return false; | return false; | ||||
| } | } | ||||
| finalizedTxIds.clear(); | |||||
PiRK: I find this behavior a bit surprising. Shouldn't it be the caller's responsibility to provide… | |||||
FabienAuthorUnsubmitted Done Inline Actionsyou want to return the vector if finalized ids, so you need to clear it to fulfill this expectation Fabien: you want to return the vector if finalized ids, so you need to clear it to fulfill this… | |||||
| for (txiter ancestor_it : setAncestors) { | for (txiter ancestor_it : setAncestors) { | ||||
| // It is possible (and normal) that an ancestor is already finalized. | // It is possible (and normal) that an ancestor is already finalized. | ||||
| // Beware to not account for it in this case. | // Beware to not account for it in this case. | ||||
| if (finalizedTxs.insert(*ancestor_it)) { | if (finalizedTxs.insert(*ancestor_it)) { | ||||
| totalFinalizedTxSize += (*ancestor_it)->GetTxSize(); | totalFinalizedTxSize += (*ancestor_it)->GetTxSize(); | ||||
| totalFinalizedTxSigchecks += (*ancestor_it)->GetSigChecks(); | totalFinalizedTxSigchecks += (*ancestor_it)->GetSigChecks(); | ||||
| finalizedTxIds.push_back((*ancestor_it)->GetTx().GetId()); | |||||
| } | } | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| CTransactionRef CTxMemPool::get(const TxId &txid) const { | CTransactionRef CTxMemPool::get(const TxId &txid) const { | ||||
| LOCK(cs); | LOCK(cs); | ||||
| ▲ Show 20 Lines • Show All 329 Lines • Show Last 20 Lines | |||||
I find this behavior a bit surprising. Shouldn't it be the caller's responsibility to provide an empty output vector?
In the current state of the code the vector is always passed empty anyway.