Skip to content

Commit

Permalink
Avoid caching iterators
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Correa Casablanca <andres@thirdhash.com>
  • Loading branch information
Andres Correa Casablanca committed Jan 17, 2019
1 parent fc96297 commit 0e73a6b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
15 changes: 10 additions & 5 deletions src/txmempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,10 +568,11 @@ void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigne
DisconnectedBlockTransactions disconnectpool;
disconnectpool.addForBlock(vtx);

auto begin_it = disconnectpool.GetQueuedTx().get<insertion_order>().rbegin();
auto end_it = disconnectpool.GetQueuedTx().get<insertion_order>().rend();

for (auto ptx = begin_it; ptx != end_it; ptx++) {
for (
auto ptx = disconnectpool.GetQueuedTx().get<insertion_order>().rbegin();
ptx != disconnectpool.GetQueuedTx().get<insertion_order>().rend();
ptx++
) {
uint256 hash = (*ptx)->GetHash();

indexed_transaction_set::iterator i = mapTx.find(hash);
Expand All @@ -586,7 +587,11 @@ void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigne
minerPolicyEstimator->processBlock(nBlockHeight, entries);
}

for (auto ptx = begin_it; ptx != end_it; ptx++) {
for (
auto ptx = disconnectpool.GetQueuedTx().get<insertion_order>().rbegin();
ptx != disconnectpool.GetQueuedTx().get<insertion_order>().rend();
ptx++
) {
auto tx = *ptx;
txiter it = mapTx.find(tx->GetHash());
if (it != mapTx.end()) {
Expand Down
4 changes: 2 additions & 2 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1739,7 +1739,7 @@ DisconnectResult CChainState::DisconnectBlock(const CBlock& block, const CBlockI
}

// First, restore inputs
for (size_t i = 1; i < block.vtx.size(); i++) {
for (size_t i = 1; i < block.vtx.size(); ++i) {
const CTransaction &tx = *(block.vtx[i]);
CTxUndo &txundo = blockUndo.vtxundo[i - 1];

Expand All @@ -1748,7 +1748,7 @@ DisconnectResult CChainState::DisconnectBlock(const CBlock& block, const CBlockI
return DISCONNECT_FAILED;
}

for (size_t j = 0; j < tx.vin.size(); j++) {
for (size_t j = 0; j < tx.vin.size(); ++j) {
const COutPoint &out = tx.vin[j].prevout;
DisconnectResult res = (DisconnectResult)ApplyTxInUndo(
std::move(txundo.vprevout[j]), view, out
Expand Down

0 comments on commit 0e73a6b

Please sign in to comment.