Skip to content

Commit 85eada6

Browse files
f move consts out of struct
We're gonna expose these for testing later so move them
1 parent 4cdac3b commit 85eada6

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

lightning/src/offers/async_receive_offer_cache.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,21 @@ impl AsyncReceiveOfferCache {
7878
}
7979
}
8080

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;
8688

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);
9093

94+
#[cfg(async_payments)]
95+
impl AsyncReceiveOfferCache {
9196
/// Remove expired offers from the cache.
9297
pub(super) fn prune_expired_offers(&mut self, duration_since_epoch: Duration) {
9398
// Remove expired offers from the cache.
@@ -113,7 +118,7 @@ impl AsyncReceiveOfferCache {
113118
/// Checks whether we should request new offer paths from the always-online static invoice server.
114119
pub(super) fn should_request_offer_paths(&self, duration_since_epoch: Duration) -> bool {
115120
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
117122
}
118123

119124
/// Returns a bool indicating whether new offers are needed in the cache.
@@ -135,7 +140,7 @@ impl AsyncReceiveOfferCache {
135140
})
136141
.count();
137142

138-
num_unexpiring_offers < Self::NUM_CACHED_OFFERS_TARGET
143+
num_unexpiring_offers < NUM_CACHED_OFFERS_TARGET
139144
}
140145

141146
// Indicates that onion messages requesting new offer paths have been sent to the static invoice
@@ -149,9 +154,8 @@ impl AsyncReceiveOfferCache {
149154
/// If we haven't sent an offer paths request in a long time, reset the limit to allow more
150155
/// requests to be sent out if/when needed.
151156
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);
153157
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)
155159
< duration_since_epoch;
156160
if should_reset {
157161
self.reset_offer_paths_request_attempts();

0 commit comments

Comments
 (0)