Skip to content

Commit 85e07a8

Browse files
f just send paths requests bursts once per minute
1 parent 3e461a8 commit 85e07a8

File tree

3 files changed

+21
-29
lines changed

3 files changed

+21
-29
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5140,9 +5140,9 @@ where
51405140
}
51415141

51425142
#[cfg(async_payments)]
5143-
fn check_refresh_async_receive_offers(&self) {
5143+
fn check_refresh_async_receive_offers(&self, timer_tick_occurred: bool) {
51445144
let peers = self.get_peers_for_blinded_path();
5145-
match self.flow.check_refresh_async_receive_offers(peers) {
5145+
match self.flow.check_refresh_async_receive_offers(peers, timer_tick_occurred) {
51465146
Err(()) => {
51475147
log_error!(
51485148
self.logger,
@@ -7148,7 +7148,7 @@ where
71487148
);
71497149

71507150
#[cfg(async_payments)]
7151-
self.check_refresh_async_receive_offers();
7151+
self.check_refresh_async_receive_offers(true);
71527152

71537153
// Technically we don't need to do this here, but if we have holding cell entries in a
71547154
// channel that need freeing, it's better to do that here and block a background task
@@ -11688,7 +11688,7 @@ where
1168811688
// until we have some peer connection(s) to send onion messages over, so as a minor optimization
1168911689
// refresh the cache when a peer connects.
1169011690
#[cfg(async_payments)]
11691-
self.check_refresh_async_receive_offers();
11691+
self.check_refresh_async_receive_offers(false);
1169211692
res
1169311693
}
1169411694

lightning/src/offers/async_receive_offer_cache.rs

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,14 @@ const OFFER_REFRESH_THRESHOLD: Duration = Duration::from_secs(2 * 60 * 60);
161161
#[cfg(async_payments)]
162162
impl AsyncReceiveOfferCache {
163163
/// Remove expired offers from the cache, returning whether new offers are needed.
164-
pub(super) fn prune_expired_offers(&mut self, duration_since_epoch: Duration) -> bool {
164+
pub(super) fn prune_expired_offers(
165+
&mut self, duration_since_epoch: Duration, timer_tick_occurred: bool,
166+
) -> bool {
167+
// Allow more offer paths requests to be sent out in a burst roughly once per minute.
168+
if timer_tick_occurred {
169+
self.reset_offer_paths_request_attempts();
170+
}
171+
165172
// Remove expired offers from the cache.
166173
let mut offer_was_removed = false;
167174
self.offers.retain(|offer| {
@@ -172,15 +179,6 @@ impl AsyncReceiveOfferCache {
172179
true
173180
});
174181

175-
// If we just removed a newly expired offer, force allowing more paths request attempts.
176-
if offer_was_removed {
177-
self.reset_offer_paths_request_attempts();
178-
} else {
179-
// If we haven't attempted to request new paths in a long time, allow more requests to go out
180-
// if/when needed.
181-
self.check_reset_offer_paths_request_attempts(duration_since_epoch);
182-
}
183-
184182
self.needs_new_offers(duration_since_epoch)
185183
&& self.offer_paths_request_attempts < MAX_UPDATE_ATTEMPTS
186184
}
@@ -217,17 +215,8 @@ impl AsyncReceiveOfferCache {
217215
self.last_offer_paths_request_timestamp = duration_since_epoch;
218216
}
219217

220-
/// If we haven't sent an offer paths request in a long time, reset the limit to allow more
221-
/// requests to be sent out if/when needed.
222-
fn check_reset_offer_paths_request_attempts(&mut self, duration_since_epoch: Duration) {
223-
let should_reset =
224-
self.last_offer_paths_request_timestamp.saturating_add(PATHS_REQUESTS_RESET_INTERVAL)
225-
< duration_since_epoch;
226-
if should_reset {
227-
self.reset_offer_paths_request_attempts();
228-
}
229-
}
230-
218+
/// Called on timer tick (roughly once per minute) to allow another MAX_UPDATE_ATTEMPTS offer
219+
/// paths requests to go out.
231220
fn reset_offer_paths_request_attempts(&mut self) {
232221
self.offer_paths_request_attempts = 0;
233222
self.last_offer_paths_request_timestamp = Duration::from_secs(0);

lightning/src/offers/flow.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,13 +1127,16 @@ where
11271127
///
11281128
/// # Usage
11291129
///
1130-
/// This method should be called on peer connection and every few minutes or so, to keep the
1131-
/// offers cache updated.
1130+
/// This method should be called on peer connection and once per minute or so, to keep the offers
1131+
/// cache updated.
1132+
///
1133+
/// SHOULD NOT be called much more than once per minute or too many messages may be sent to the
1134+
/// server node.
11321135
///
11331136
/// Errors if we failed to create blinded reply paths when sending an [`OfferPathsRequest`] message.
11341137
#[cfg(async_payments)]
11351138
pub(crate) fn check_refresh_async_receive_offers(
1136-
&self, peers: Vec<MessageForwardNode>,
1139+
&self, peers: Vec<MessageForwardNode>, timer_tick_occurred: bool,
11371140
) -> Result<(), ()> {
11381141
// Terminate early if this node does not intend to receive async payments.
11391142
if self.paths_to_static_invoice_server.is_empty() {
@@ -1148,7 +1151,7 @@ where
11481151
.async_receive_offer_cache
11491152
.lock()
11501153
.unwrap()
1151-
.prune_expired_offers(duration_since_epoch);
1154+
.prune_expired_offers(duration_since_epoch, timer_tick_occurred);
11521155

11531156
// If we need new offers, send out offer paths request messages to the static invoice server.
11541157
if needs_new_offers {

0 commit comments

Comments
 (0)