Skip to content

Commit 9e0f2da

Browse files
Persist cached async receive offer in ChannelManager
In future commits, as part of being an async recipient, we will interactively build an offer and static invoice with an always-online node that will serve static invoices on our behalf. Once the offer is built and the static invoice is confirmed as persisted by the server, we will use this struct to cache the offer in ChannelManager.
1 parent 890ce7d commit 9e0f2da

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

lightning/src/ln/channelmanager.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,22 @@ struct PendingInboundPayment {
15011501
min_value_msat: Option<u64>,
15021502
}
15031503

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+
15041520
/// [`SimpleArcChannelManager`] is useful when you need a [`ChannelManager`] with a static lifetime, e.g.
15051521
/// when you're using `lightning-net-tokio` (since `tokio::spawn` requires parameters with static
15061522
/// lifetimes). Other times you can afford a reference, which is more efficient, in which case
@@ -2660,6 +2676,7 @@ where
26602676
#[cfg(any(test, feature = "_test_utils"))]
26612677
pub(crate) pending_offers_messages: Mutex<Vec<(OffersMessage, MessageSendInstructions)>>,
26622678
pending_async_payments_messages: Mutex<Vec<(AsyncPaymentsMessage, MessageSendInstructions)>>,
2679+
async_receive_offer_cache: Mutex<AsyncReceiveOffer>,
26632680

26642681
/// Tracks the message events that are to be broadcasted when we are connected to some peer.
26652682
pending_broadcast_messages: Mutex<Vec<MessageSendEvent>>,
@@ -3614,6 +3631,7 @@ where
36143631

36153632
pending_offers_messages: Mutex::new(Vec::new()),
36163633
pending_async_payments_messages: Mutex::new(Vec::new()),
3634+
async_receive_offer_cache: Mutex::new(AsyncReceiveOffer { offer: None, offer_paths_request_attempts: 0 }),
36173635
pending_broadcast_messages: Mutex::new(Vec::new()),
36183636

36193637
last_days_feerates: Mutex::new(VecDeque::new()),
@@ -13402,6 +13420,7 @@ where
1340213420
(15, self.inbound_payment_id_secret, required),
1340313421
(17, in_flight_monitor_updates, required),
1340413422
(19, peer_storage_dir, optional_vec),
13423+
(21, *self.async_receive_offer_cache.lock().unwrap(), required),
1340513424
});
1340613425

1340713426
Ok(())
@@ -13931,6 +13950,7 @@ where
1393113950
let mut decode_update_add_htlcs: Option<HashMap<u64, Vec<msgs::UpdateAddHTLC>>> = None;
1393213951
let mut inbound_payment_id_secret = None;
1393313952
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 };
1393413954
read_tlv_fields!(reader, {
1393513955
(1, pending_outbound_payments_no_retry, option),
1393613956
(2, pending_intercepted_htlcs, option),
@@ -13948,6 +13968,7 @@ where
1394813968
(15, inbound_payment_id_secret, option),
1394913969
(17, in_flight_monitor_updates, required),
1395013970
(19, peer_storage_dir, optional_vec),
13971+
(21, async_receive_offer_cache, (default_value, AsyncReceiveOffer { offer: None, offer_paths_request_attempts: 0 })),
1395113972
});
1395213973
let mut decode_update_add_htlcs = decode_update_add_htlcs.unwrap_or_else(|| new_hash_map());
1395313974
let peer_storage_dir: Vec<(PublicKey, Vec<u8>)> = peer_storage_dir.unwrap_or_else(Vec::new);
@@ -14643,6 +14664,7 @@ where
1464314664

1464414665
pending_offers_messages: Mutex::new(Vec::new()),
1464514666
pending_async_payments_messages: Mutex::new(Vec::new()),
14667+
async_receive_offer_cache: Mutex::new(async_receive_offer_cache),
1464614668

1464714669
pending_broadcast_messages: Mutex::new(Vec::new()),
1464814670

@@ -15070,8 +15092,8 @@ mod tests {
1507015092
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
1507115093

1507215094
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
1507515097
// `PeerStorage` from the channel partner.
1507615098
nodes[0].node.handle_peer_storage(nodes[1].node.get_our_node_id(), msgs::PeerStorage{data: vec![0; 100]});
1507715099

lightning/src/util/ser.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,7 @@ impl_for_vec!(crate::chain::channelmonitor::ChannelMonitorUpdate);
10571057
impl_for_vec!(crate::ln::channelmanager::MonitorUpdateCompletionAction);
10581058
impl_for_vec!(crate::ln::channelmanager::PaymentClaimDetails);
10591059
impl_for_vec!(crate::ln::msgs::SocketAddress);
1060+
impl_for_vec!(crate::blinded_path::message::BlindedMessagePath);
10601061
impl_for_vec!((A, B), A, B);
10611062
impl_writeable_for_vec!(&crate::routing::router::BlindedTail);
10621063
impl_readable_for_vec!(crate::routing::router::BlindedTail);

0 commit comments

Comments
 (0)