Skip to content

Commit d588575

Browse files
committed
refactor: miscellaneous GenTxid followups
Addresses a few comments from #32631: bitcoin/bitcoin#32631 (comment) bitcoin/bitcoin#32631 (comment) bitcoin/bitcoin#32631 (comment)
1 parent 184159e commit d588575

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

src/txmempool.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -962,9 +962,9 @@ const CTransaction* CTxMemPool::GetConflictTx(const COutPoint& prevout) const
962962

963963
std::optional<CTxMemPool::txiter> CTxMemPool::GetIter(const Txid& txid) const
964964
{
965+
AssertLockHeld(cs);
965966
auto it = mapTx.find(txid.ToUint256());
966-
if (it != mapTx.end()) return it;
967-
return std::nullopt;
967+
return it != mapTx.end() ? std::make_optional(it) : std::nullopt;
968968
}
969969

970970
std::optional<CTxMemPool::txiter> CTxMemPool::GetIter(const Wtxid& wtxid) const

src/txrequest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ class TxRequestTracker::Impl {
595595

596596
//! Find the GenTxids to request now from peer.
597597
std::vector<GenTxid> GetRequestable(NodeId peer, std::chrono::microseconds now,
598-
std::vector<std::pair<NodeId, GenTxid>>* expired)
598+
std::vector<std::pair<NodeId, GenTxid>>* expired)
599599
{
600600
// Move time.
601601
SetTimePoint(now, expired);
@@ -746,7 +746,7 @@ void TxRequestTracker::ReceivedResponse(NodeId peer, const uint256& txhash)
746746
}
747747

748748
std::vector<GenTxid> TxRequestTracker::GetRequestable(NodeId peer, std::chrono::microseconds now,
749-
std::vector<std::pair<NodeId, GenTxid>>* expired)
749+
std::vector<std::pair<NodeId, GenTxid>>* expired)
750750
{
751751
return m_impl->GetRequestable(peer, now, expired);
752752
}

src/txrequest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class TxRequestTracker {
164164
* simultaneously by one peer, and end up being requested from them, the requests will happen in announcement order.
165165
*/
166166
std::vector<GenTxid> GetRequestable(NodeId peer, std::chrono::microseconds now,
167-
std::vector<std::pair<NodeId, GenTxid>>* expired = nullptr);
167+
std::vector<std::pair<NodeId, GenTxid>>* expired = nullptr);
168168

169169
/** Marks a transaction as requested, with a specified expiry.
170170
*

src/util/transaction_identifier.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ class GenTxid : public std::variant<Txid, Wtxid>
9898

9999
friend auto operator<=>(const GenTxid& a, const GenTxid& b)
100100
{
101-
return std::tuple(a.IsWtxid(), a.ToUint256()) <=> std::tuple(b.IsWtxid(), b.ToUint256());
101+
// Use a reference for read-only access to the hash, avoiding a copy that might not be optimized away.
102+
return std::tuple<bool, const uint256&>(a.IsWtxid(), a.ToUint256()) <=> std::tuple<bool, const uint256&>(b.IsWtxid(), b.ToUint256());
102103
}
103104
};
104105

0 commit comments

Comments
 (0)