diff --git a/src/txmempool.cpp b/src/txmempool.cpp index d65005fc645..a4216d678bb 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -962,9 +962,9 @@ const CTransaction* CTxMemPool::GetConflictTx(const COutPoint& prevout) const std::optional CTxMemPool::GetIter(const Txid& txid) const { + AssertLockHeld(cs); auto it = mapTx.find(txid.ToUint256()); - if (it != mapTx.end()) return it; - return std::nullopt; + return it != mapTx.end() ? std::make_optional(it) : std::nullopt; } std::optional CTxMemPool::GetIter(const Wtxid& wtxid) const diff --git a/src/txrequest.cpp b/src/txrequest.cpp index 37496614129..4d7240bee0d 100644 --- a/src/txrequest.cpp +++ b/src/txrequest.cpp @@ -595,7 +595,7 @@ public: //! Find the GenTxids to request now from peer. std::vector GetRequestable(NodeId peer, std::chrono::microseconds now, - std::vector>* expired) + std::vector>* expired) { // Move time. SetTimePoint(now, expired); @@ -746,7 +746,7 @@ void TxRequestTracker::ReceivedResponse(NodeId peer, const uint256& txhash) } std::vector TxRequestTracker::GetRequestable(NodeId peer, std::chrono::microseconds now, - std::vector>* expired) + std::vector>* expired) { return m_impl->GetRequestable(peer, now, expired); } diff --git a/src/txrequest.h b/src/txrequest.h index 084c5ffffea..894fc674693 100644 --- a/src/txrequest.h +++ b/src/txrequest.h @@ -164,7 +164,7 @@ public: * simultaneously by one peer, and end up being requested from them, the requests will happen in announcement order. */ std::vector GetRequestable(NodeId peer, std::chrono::microseconds now, - std::vector>* expired = nullptr); + std::vector>* expired = nullptr); /** Marks a transaction as requested, with a specified expiry. * diff --git a/src/util/transaction_identifier.h b/src/util/transaction_identifier.h index 02e8ec077db..30302f061f2 100644 --- a/src/util/transaction_identifier.h +++ b/src/util/transaction_identifier.h @@ -98,7 +98,8 @@ public: friend auto operator<=>(const GenTxid& a, const GenTxid& b) { - return std::tuple(a.IsWtxid(), a.ToUint256()) <=> std::tuple(b.IsWtxid(), b.ToUint256()); + // Use a reference for read-only access to the hash, avoiding a copy that might not be optimized away. + return std::tuple(a.IsWtxid(), a.ToUint256()) <=> std::tuple(b.IsWtxid(), b.ToUint256()); } };