@@ -700,6 +700,24 @@ void UpdateTxRequestTime(const uint256& txid, int64_t request_time) EXCLUSIVE_LO
700
700
}
701
701
}
702
702
703
+ int64_t CalculateTxGetDataTime (const uint256& txid, int64_t current_time, bool use_inbound_delay) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
704
+ {
705
+ int64_t process_time;
706
+ int64_t last_request_time = GetTxRequestTime (txid);
707
+ // First time requesting this tx
708
+ if (last_request_time == 0 ) {
709
+ process_time = current_time;
710
+ } else {
711
+ // Randomize the delay to avoid biasing some peers over others (such as due to
712
+ // fixed ordering of peer processing in ThreadMessageHandler)
713
+ process_time = last_request_time + GETDATA_TX_INTERVAL + GetRand (MAX_GETDATA_RANDOM_DELAY);
714
+ }
715
+
716
+ // We delay processing announcements from inbound peers
717
+ if (use_inbound_delay) process_time += INBOUND_PEER_TX_DELAY;
718
+
719
+ return process_time;
720
+ }
703
721
704
722
void RequestTx (CNodeState* state, const uint256& txid, int64_t nNow) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
705
723
{
@@ -713,19 +731,9 @@ void RequestTx(CNodeState* state, const uint256& txid, int64_t nNow) EXCLUSIVE_L
713
731
}
714
732
peer_download_state.m_tx_announced .insert (txid);
715
733
716
- int64_t process_time;
717
- int64_t last_request_time = GetTxRequestTime (txid);
718
- // First time requesting this tx
719
- if (last_request_time == 0 ) {
720
- process_time = nNow;
721
- } else {
722
- // Randomize the delay to avoid biasing some peers over others (such as due to
723
- // fixed ordering of peer processing in ThreadMessageHandler)
724
- process_time = last_request_time + GETDATA_TX_INTERVAL + GetRand (MAX_GETDATA_RANDOM_DELAY);
725
- }
726
-
727
- // We delay processing announcements from non-preferred (eg inbound) peers
728
- if (!state->fPreferredDownload ) process_time += INBOUND_PEER_TX_DELAY;
734
+ // Calculate the time to try requesting this transaction. Use
735
+ // fPreferredDownload as a proxy for outbound peers.
736
+ int64_t process_time = CalculateTxGetDataTime (txid, nNow, !state->fPreferredDownload );
729
737
730
738
peer_download_state.m_tx_process_time .emplace (process_time, txid);
731
739
}
@@ -3967,7 +3975,10 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
3967
3975
3968
3976
auto & tx_process_time = state.m_tx_download .m_tx_process_time ;
3969
3977
while (!tx_process_time.empty () && tx_process_time.begin ()->first <= nNow && state.m_tx_download .m_tx_in_flight .size () < MAX_PEER_TX_IN_FLIGHT) {
3970
- const uint256& txid = tx_process_time.begin ()->second ;
3978
+ const uint256 txid = tx_process_time.begin ()->second ;
3979
+ // Erase this entry from tx_process_time (it may be added back for
3980
+ // processing at a later time, see below)
3981
+ tx_process_time.erase (tx_process_time.begin ());
3971
3982
CInv inv (MSG_TX | GetFetchFlags (pto), txid);
3972
3983
if (!AlreadyHave (inv)) {
3973
3984
// If this transaction was last requested more than 1 minute ago,
@@ -3987,14 +3998,14 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
3987
3998
// up processing to happen after the download times out
3988
3999
// (with a slight delay for inbound peers, to prefer
3989
4000
// requests to outbound peers).
3990
- RequestTx (&state, txid, nNow);
4001
+ int64_t next_process_time = CalculateTxGetDataTime (txid, nNow, !state.fPreferredDownload );
4002
+ tx_process_time.emplace (next_process_time, txid);
3991
4003
}
3992
4004
} else {
3993
4005
// We have already seen this transaction, no need to download.
3994
4006
state.m_tx_download .m_tx_announced .erase (inv.hash );
3995
4007
state.m_tx_download .m_tx_in_flight .erase (inv.hash );
3996
4008
}
3997
- tx_process_time.erase (tx_process_time.begin ());
3998
4009
}
3999
4010
4000
4011
0 commit comments