Skip to content

Commit 6a3e37c

Browse files
Fill in top-level docs for onion message offline peer interception.
1 parent f542c2b commit 6a3e37c

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lightning/src/events/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,14 +1036,25 @@ pub enum Event {
10361036
///
10371037
/// [`ChannelHandshakeConfig::negotiate_anchors_zero_fee_htlc_tx`]: crate::util::config::ChannelHandshakeConfig::negotiate_anchors_zero_fee_htlc_tx
10381038
BumpTransaction(BumpTransactionEvent),
1039+
/// We received an onion message that is intended to be forwarded to a peer
1040+
/// that is currently offline. This event will only be generated if the
1041+
/// `OnionMessenger` was initialized with
1042+
/// [`OnionMessenger::new_with_offline_peer_interception`], see its docs.
10391043
///
1044+
/// [`OnionMessenger::new_with_offline_peer_interception`]: crate::onion_message::messenger::OnionMessenger::new_with_offline_peer_interception
10401045
OnionMessageForOfflinePeer {
10411046
/// The node id of the offline peer.
10421047
peer_node_id: PublicKey,
10431048
/// The onion message intended to be forwarded to `peer_node_id`.
10441049
message: msgs::OnionMessage,
10451050
},
1051+
/// Indicates that an onion message supporting peer has come online and it may
1052+
/// be time to forward any onion messages that were previously intercepted for
1053+
/// them. This event will only be generated if the `OnionMessenger` was
1054+
/// initialized with
1055+
/// [`OnionMessenger::new_with_offline_peer_interception`], see its docs.
10461056
///
1057+
/// [`OnionMessenger::new_with_offline_peer_interception`]: crate::onion_message::messenger::OnionMessenger::new_with_offline_peer_interception
10471058
OnionMessagePeerConnected {
10481059
/// The node id of the peer we just connected to, who advertises support for
10491060
/// onion messages.

lightning/src/onion_message/messenger.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,27 @@ where
722722
)
723723
}
724724

725+
/// Similar to [`Self::new`], but rather than dropping onion messages that are
726+
/// intended to be forwarded to offline peers, we will intercept them for
727+
/// later forwarding.
725728
///
729+
/// Interception flow:
730+
/// 1. If an onion message for an offline peer is received, `OnionMessenger` will
731+
/// generate an [`Event::OnionMessageForOfflinePeer`]. Event handlers can
732+
/// then choose to persist this onion message for later forwarding, or drop
733+
/// it.
734+
/// 2. When the offline peer later comes back online, `OnionMessenger` will
735+
/// generate an [`Event::OnionMessagePeerConnected`]. Event handlers will
736+
/// then fetch all previously intercepted onion messages for this peer.
737+
/// 3. Once the stored onion messages are fetched, they can finally be
738+
/// forwarded to the now-online peer via [`Self::forward_onion_message`].
739+
///
740+
/// # Note
741+
///
742+
/// LDK will not rate limit how many [`Event::OnionMessageForOfflinePeer`]s
743+
/// are generated, so it is the caller's responsibility to limit how many
744+
/// onion messages are persisted and only persist onion messages for relevant
745+
/// peers.
726746
pub fn new_with_offline_peer_interception(
727747
entropy_source: ES, node_signer: NS, logger: L, message_router: MR, offers_handler: OMH,
728748
custom_handler: CMH

0 commit comments

Comments
 (0)