@@ -1501,6 +1501,22 @@ struct PendingInboundPayment {
1501
1501
min_value_msat: Option<u64>,
1502
1502
}
1503
1503
1504
+ /// If we are an async recipient, on startup we interactively build an offer and static invoice with
1505
+ /// an always-online node that will serve static invoices on our behalf. Once the offer is built and
1506
+ /// the static invoice is confirmed as persisted by the server, use this struct to cache the offer
1507
+ /// in `ChannelManager`.
1508
+ struct AsyncReceiveOffer {
1509
+ offer: Option<Offer>,
1510
+ /// Used to limit the number of times we request paths for our offer from the static invoice
1511
+ /// server.
1512
+ offer_paths_request_attempts: u8,
1513
+ }
1514
+
1515
+ impl_writeable_tlv_based!(AsyncReceiveOffer, {
1516
+ (0, offer, option),
1517
+ (2, offer_paths_request_attempts, (static_value, 0)),
1518
+ });
1519
+
1504
1520
/// [`SimpleArcChannelManager`] is useful when you need a [`ChannelManager`] with a static lifetime, e.g.
1505
1521
/// when you're using `lightning-net-tokio` (since `tokio::spawn` requires parameters with static
1506
1522
/// lifetimes). Other times you can afford a reference, which is more efficient, in which case
@@ -2660,6 +2676,7 @@ where
2660
2676
#[cfg(any(test, feature = "_test_utils"))]
2661
2677
pub(crate) pending_offers_messages: Mutex<Vec<(OffersMessage, MessageSendInstructions)>>,
2662
2678
pending_async_payments_messages: Mutex<Vec<(AsyncPaymentsMessage, MessageSendInstructions)>>,
2679
+ async_receive_offer_cache: Mutex<AsyncReceiveOffer>,
2663
2680
2664
2681
/// Tracks the message events that are to be broadcasted when we are connected to some peer.
2665
2682
pending_broadcast_messages: Mutex<Vec<MessageSendEvent>>,
@@ -3614,6 +3631,7 @@ where
3614
3631
3615
3632
pending_offers_messages: Mutex::new(Vec::new()),
3616
3633
pending_async_payments_messages: Mutex::new(Vec::new()),
3634
+ async_receive_offer_cache: Mutex::new(AsyncReceiveOffer { offer: None, offer_paths_request_attempts: 0 }),
3617
3635
pending_broadcast_messages: Mutex::new(Vec::new()),
3618
3636
3619
3637
last_days_feerates: Mutex::new(VecDeque::new()),
@@ -13402,6 +13420,7 @@ where
13402
13420
(15, self.inbound_payment_id_secret, required),
13403
13421
(17, in_flight_monitor_updates, required),
13404
13422
(19, peer_storage_dir, optional_vec),
13423
+ (21, *self.async_receive_offer_cache.lock().unwrap(), required),
13405
13424
});
13406
13425
13407
13426
Ok(())
@@ -13931,6 +13950,7 @@ where
13931
13950
let mut decode_update_add_htlcs: Option<HashMap<u64, Vec<msgs::UpdateAddHTLC>>> = None;
13932
13951
let mut inbound_payment_id_secret = None;
13933
13952
let mut peer_storage_dir: Option<Vec<(PublicKey, Vec<u8>)>> = None;
13953
+ let mut async_receive_offer_cache = AsyncReceiveOffer { offer: None, offer_paths_request_attempts: 0 };
13934
13954
read_tlv_fields!(reader, {
13935
13955
(1, pending_outbound_payments_no_retry, option),
13936
13956
(2, pending_intercepted_htlcs, option),
@@ -13948,6 +13968,7 @@ where
13948
13968
(15, inbound_payment_id_secret, option),
13949
13969
(17, in_flight_monitor_updates, required),
13950
13970
(19, peer_storage_dir, optional_vec),
13971
+ (21, async_receive_offer_cache, (default_value, AsyncReceiveOffer { offer: None, offer_paths_request_attempts: 0 })),
13951
13972
});
13952
13973
let mut decode_update_add_htlcs = decode_update_add_htlcs.unwrap_or_else(|| new_hash_map());
13953
13974
let peer_storage_dir: Vec<(PublicKey, Vec<u8>)> = peer_storage_dir.unwrap_or_else(Vec::new);
@@ -14643,6 +14664,7 @@ where
14643
14664
14644
14665
pending_offers_messages: Mutex::new(Vec::new()),
14645
14666
pending_async_payments_messages: Mutex::new(Vec::new()),
14667
+ async_receive_offer_cache: Mutex::new(async_receive_offer_cache),
14646
14668
14647
14669
pending_broadcast_messages: Mutex::new(Vec::new()),
14648
14670
@@ -15070,8 +15092,8 @@ mod tests {
15070
15092
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
15071
15093
15072
15094
create_announced_chan_between_nodes(&nodes, 0, 1);
15073
-
15074
- // Since we do not send peer storage, we manually simulate receiving a dummy
15095
+
15096
+ // Since we do not send peer storage, we manually simulate receiving a dummy
15075
15097
// `PeerStorage` from the channel partner.
15076
15098
nodes[0].node.handle_peer_storage(nodes[1].node.get_our_node_id(), msgs::PeerStorage{data: vec![0; 100]});
15077
15099
0 commit comments