From bbd9b10d47d7448986015c32b5145a213c40be8b Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Tue, 29 Oct 2019 21:37:54 +0300 Subject: [PATCH] Refactor nonLockedTxsByInputs (#3178) --- src/llmq/quorums_instantsend.cpp | 22 +++++----------------- src/llmq/quorums_instantsend.h | 2 +- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/llmq/quorums_instantsend.cpp b/src/llmq/quorums_instantsend.cpp index 306d247201..32f418e683 100644 --- a/src/llmq/quorums_instantsend.cpp +++ b/src/llmq/quorums_instantsend.cpp @@ -1052,7 +1052,7 @@ void CInstantSendManager::AddNonLockedTx(const CTransactionRef& tx, const CBlock if (res.second) { for (auto& in : tx->vin) { - nonLockedTxsByInputs.emplace(in.prevout.hash, std::make_pair(in.prevout.n, tx->GetHash())); + nonLockedTxsByOutpoints.emplace(in.prevout, tx->GetHash()); } } @@ -1088,16 +1088,7 @@ void CInstantSendManager::RemoveNonLockedTx(const uint256& txid, bool retryChild nonLockedTxs.erase(jt); } } - - auto its = nonLockedTxsByInputs.equal_range(in.prevout.hash); - for (auto kt = its.first; kt != its.second; ) { - if (kt->second.first != in.prevout.n) { - ++kt; - continue; - } else { - kt = nonLockedTxsByInputs.erase(kt); - } - } + nonLockedTxsByOutpoints.erase(in.prevout); } } @@ -1237,12 +1228,9 @@ void CInstantSendManager::ResolveBlockConflicts(const uint256& islockHash, const { LOCK(cs); for (auto& in : islock.inputs) { - auto its = nonLockedTxsByInputs.equal_range(in.hash); - for (auto it = its.first; it != its.second; ++it) { - if (it->second.first != in.n) { - continue; - } - auto& conflictTxid = it->second.second; + auto it = nonLockedTxsByOutpoints.find(in); + if (it != nonLockedTxsByOutpoints.end()) { + auto& conflictTxid = it->second; if (conflictTxid == islock.txid) { continue; } diff --git a/src/llmq/quorums_instantsend.h b/src/llmq/quorums_instantsend.h index ec3b48ceb4..50d935ec1b 100644 --- a/src/llmq/quorums_instantsend.h +++ b/src/llmq/quorums_instantsend.h @@ -107,7 +107,7 @@ private: std::unordered_set children; }; std::unordered_map nonLockedTxs; - std::unordered_multimap> nonLockedTxsByInputs; + std::unordered_map nonLockedTxsByOutpoints; std::unordered_set pendingRetryTxs;