Skip to content

Commit a2bfac8

Browse files
committed
refactor: use GenTxid in tx request functions
1 parent e65d115 commit a2bfac8

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/net_processing.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -751,34 +751,34 @@ static void FindNextBlocksToDownload(NodeId nodeid, unsigned int count, std::vec
751751
}
752752
}
753753

754-
void EraseTxRequest(const uint256& txid) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
754+
void EraseTxRequest(const GenTxid& gtxid) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
755755
{
756-
g_already_asked_for.erase(txid);
756+
g_already_asked_for.erase(gtxid.GetHash());
757757
}
758758

759-
std::chrono::microseconds GetTxRequestTime(const uint256& txid) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
759+
std::chrono::microseconds GetTxRequestTime(const GenTxid& gtxid) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
760760
{
761-
auto it = g_already_asked_for.find(txid);
761+
auto it = g_already_asked_for.find(gtxid.GetHash());
762762
if (it != g_already_asked_for.end()) {
763763
return it->second;
764764
}
765765
return {};
766766
}
767767

768-
void UpdateTxRequestTime(const uint256& txid, std::chrono::microseconds request_time) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
768+
void UpdateTxRequestTime(const GenTxid& gtxid, std::chrono::microseconds request_time) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
769769
{
770-
auto it = g_already_asked_for.find(txid);
770+
auto it = g_already_asked_for.find(gtxid.GetHash());
771771
if (it == g_already_asked_for.end()) {
772-
g_already_asked_for.insert(std::make_pair(txid, request_time));
772+
g_already_asked_for.insert(std::make_pair(gtxid.GetHash(), request_time));
773773
} else {
774774
g_already_asked_for.update(it, request_time);
775775
}
776776
}
777777

778-
std::chrono::microseconds CalculateTxGetDataTime(const uint256& txid, std::chrono::microseconds current_time, bool use_inbound_delay, bool use_txid_delay) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
778+
std::chrono::microseconds CalculateTxGetDataTime(const GenTxid& gtxid, std::chrono::microseconds current_time, bool use_inbound_delay, bool use_txid_delay) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
779779
{
780780
std::chrono::microseconds process_time;
781-
const auto last_request_time = GetTxRequestTime(txid);
781+
const auto last_request_time = GetTxRequestTime(gtxid);
782782
// First time requesting this tx
783783
if (last_request_time.count() == 0) {
784784
process_time = current_time;
@@ -811,7 +811,7 @@ void RequestTx(CNodeState* state, const GenTxid& gtxid, std::chrono::microsecond
811811

812812
// Calculate the time to try requesting this transaction. Use
813813
// fPreferredDownload as a proxy for outbound peers.
814-
const auto process_time = CalculateTxGetDataTime(gtxid.GetHash(), current_time, !state->fPreferredDownload, !state->m_wtxid_relay && g_wtxid_relay_peers > 0);
814+
const auto process_time = CalculateTxGetDataTime(gtxid, current_time, !state->fPreferredDownload, !state->m_wtxid_relay && g_wtxid_relay_peers > 0);
815815

816816
peer_download_state.m_tx_process_time.emplace(process_time, gtxid);
817817
}
@@ -2933,10 +2933,10 @@ void ProcessMessage(
29332933

29342934
TxValidationState state;
29352935

2936-
for (uint256 hash : {txid, wtxid}) {
2937-
nodestate->m_tx_download.m_tx_announced.erase(hash);
2938-
nodestate->m_tx_download.m_tx_in_flight.erase(hash);
2939-
EraseTxRequest(hash);
2936+
for (const GenTxid& gtxid : {GenTxid(false, txid), GenTxid(true, wtxid)}) {
2937+
nodestate->m_tx_download.m_tx_announced.erase(gtxid.GetHash());
2938+
nodestate->m_tx_download.m_tx_in_flight.erase(gtxid.GetHash());
2939+
EraseTxRequest(gtxid);
29402940
}
29412941

29422942
std::list<CTransactionRef> lRemovedTxn;
@@ -4539,15 +4539,15 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
45394539
if (!AlreadyHave(inv, m_mempool)) {
45404540
// If this transaction was last requested more than 1 minute ago,
45414541
// then request.
4542-
const auto last_request_time = GetTxRequestTime(gtxid.GetHash());
4542+
const auto last_request_time = GetTxRequestTime(gtxid);
45434543
if (last_request_time <= current_time - GETDATA_TX_INTERVAL) {
45444544
LogPrint(BCLog::NET, "Requesting %s peer=%d\n", inv.ToString(), pto->GetId());
45454545
vGetData.push_back(inv);
45464546
if (vGetData.size() >= MAX_GETDATA_SZ) {
45474547
connman->PushMessage(pto, msgMaker.Make(NetMsgType::GETDATA, vGetData));
45484548
vGetData.clear();
45494549
}
4550-
UpdateTxRequestTime(gtxid.GetHash(), current_time);
4550+
UpdateTxRequestTime(gtxid, current_time);
45514551
state.m_tx_download.m_tx_in_flight.emplace(gtxid.GetHash(), current_time);
45524552
} else {
45534553
// This transaction is in flight from someone else; queue
@@ -4562,7 +4562,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
45624562
// would open us up to an attacker using inbound
45634563
// wtxid-relay to prevent us from requesting transactions
45644564
// from outbound txid-relay peers).
4565-
const auto next_process_time = CalculateTxGetDataTime(gtxid.GetHash(), current_time, !state.fPreferredDownload, false);
4565+
const auto next_process_time = CalculateTxGetDataTime(gtxid, current_time, !state.fPreferredDownload, false);
45664566
tx_process_time.emplace(next_process_time, gtxid);
45674567
}
45684568
} else {

0 commit comments

Comments
 (0)