@@ -78,16 +78,21 @@ impl AsyncReceiveOfferCache {
78
78
}
79
79
}
80
80
81
- #[ cfg( async_payments) ]
82
- impl AsyncReceiveOfferCache {
83
- // The target number of offers we want to have cached at any given time, to mitigate too much
84
- // reuse of the same offer.
85
- const NUM_CACHED_OFFERS_TARGET : usize = 3 ;
81
+ // The target number of offers we want to have cached at any given time, to mitigate too much
82
+ // reuse of the same offer.
83
+ const NUM_CACHED_OFFERS_TARGET : usize = 3 ;
84
+
85
+ // The max number of times we'll attempt to request offer paths or attempt to refresh a static
86
+ // invoice before giving up.
87
+ const MAX_UPDATE_ATTEMPTS : u8 = 3 ;
86
88
87
- // The max number of times we'll attempt to request offer paths or attempt to refresh a static
88
- // invoice before giving up.
89
- const MAX_UPDATE_ATTEMPTS : u8 = 3 ;
89
+ // If we run out of attempts to request offer paths from the static invoice server, we'll stop
90
+ // sending requests for some time. After this amount of time has passed, more requests are allowed
91
+ // to be sent out.
92
+ const PATHS_REQUESTS_BUFFER : Duration = Duration :: from_secs ( 3 * 60 * 60 ) ;
90
93
94
+ #[ cfg( async_payments) ]
95
+ impl AsyncReceiveOfferCache {
91
96
/// Remove expired offers from the cache.
92
97
pub ( super ) fn prune_expired_offers ( & mut self , duration_since_epoch : Duration ) {
93
98
// Remove expired offers from the cache.
@@ -113,7 +118,7 @@ impl AsyncReceiveOfferCache {
113
118
/// Checks whether we should request new offer paths from the always-online static invoice server.
114
119
pub ( super ) fn should_request_offer_paths ( & self , duration_since_epoch : Duration ) -> bool {
115
120
self . needs_new_offers ( duration_since_epoch)
116
- && self . offer_paths_request_attempts < Self :: MAX_UPDATE_ATTEMPTS
121
+ && self . offer_paths_request_attempts < MAX_UPDATE_ATTEMPTS
117
122
}
118
123
119
124
/// Returns a bool indicating whether new offers are needed in the cache.
@@ -135,7 +140,7 @@ impl AsyncReceiveOfferCache {
135
140
} )
136
141
. count ( ) ;
137
142
138
- num_unexpiring_offers < Self :: NUM_CACHED_OFFERS_TARGET
143
+ num_unexpiring_offers < NUM_CACHED_OFFERS_TARGET
139
144
}
140
145
141
146
// Indicates that onion messages requesting new offer paths have been sent to the static invoice
@@ -149,9 +154,8 @@ impl AsyncReceiveOfferCache {
149
154
/// If we haven't sent an offer paths request in a long time, reset the limit to allow more
150
155
/// requests to be sent out if/when needed.
151
156
fn check_reset_offer_paths_request_attempts ( & mut self , duration_since_epoch : Duration ) {
152
- const REQUESTS_TIME_BUFFER : Duration = Duration :: from_secs ( 3 * 60 * 60 ) ;
153
157
let should_reset =
154
- self . last_offer_paths_request_timestamp . saturating_add ( REQUESTS_TIME_BUFFER )
158
+ self . last_offer_paths_request_timestamp . saturating_add ( PATHS_REQUESTS_BUFFER )
155
159
< duration_since_epoch;
156
160
if should_reset {
157
161
self . reset_offer_paths_request_attempts ( ) ;
0 commit comments