Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce OffersMessageFlow #3412

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
4 changes: 2 additions & 2 deletions fuzz/src/chanmon_consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ use lightning::events::MessageSendEventsProvider;
use lightning::ln::channel::FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE;
use lightning::ln::channel_state::ChannelDetails;
use lightning::ln::channelmanager::{
ChainParameters, ChannelManager, ChannelManagerReadArgs, PaymentId, PaymentSendFailure,
RecipientOnionFields,
ChainParameters, ChannelManager, ChannelManagerReadArgs, OffersMessageCommons, PaymentId,
PaymentSendFailure, RecipientOnionFields,
};
use lightning::ln::functional_test_utils::*;
use lightning::ln::msgs::{
Expand Down
3 changes: 2 additions & 1 deletion fuzz/src/full_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ use lightning::chain::{BestBlock, ChannelMonitorUpdateStatus, Confirm, Listen};
use lightning::events::Event;
use lightning::ln::channel_state::ChannelDetails;
use lightning::ln::channelmanager::{
ChainParameters, ChannelManager, InterceptId, PaymentId, RecipientOnionFields, Retry,
ChainParameters, ChannelManager, InterceptId, OffersMessageCommons, PaymentId,
RecipientOnionFields, Retry,
};
use lightning::ln::functional_test_utils::*;
use lightning::ln::msgs::{self, DecodeError};
Expand Down
4 changes: 2 additions & 2 deletions lightning-dns-resolver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ mod test {
use lightning::blinded_path::message::{BlindedMessagePath, MessageContext};
use lightning::blinded_path::NodeIdLookUp;
use lightning::events::{Event, PaymentPurpose};
use lightning::ln::channelmanager::{PaymentId, Retry};
use lightning::ln::channelmanager::{OffersMessageCommons, PaymentId, Retry};
use lightning::ln::functional_test_utils::*;
use lightning::ln::msgs::{ChannelMessageHandler, Init, OnionMessageHandler};
use lightning::ln::peer_handler::IgnoringMessageHandler;
Expand Down Expand Up @@ -391,7 +391,7 @@ mod test {
let name = HumanReadableName::from_encoded("matt@mattcorallo.com").unwrap();

// When we get the proof back, override its contents to an offer from nodes[1]
let bs_offer = nodes[1].node.create_offer_builder(None).unwrap().build().unwrap();
let bs_offer = nodes[1].offers_handler.create_offer_builder(None).unwrap().build().unwrap();
nodes[0]
.node
.testing_dnssec_proof_offer_resolution_override
Expand Down
1 change: 0 additions & 1 deletion lightning-net-tokio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,6 @@ mod tests {
fn get_chain_hashes(&self) -> Option<Vec<ChainHash>> {
Some(vec![ChainHash::using_genesis_block(Network::Testnet)])
}
fn message_received(&self) {}
}
impl MessageSendEventsProvider for MsgHandler {
fn get_and_clear_pending_msg_events(&self) -> Vec<MessageSendEvent> {
Expand Down
1 change: 1 addition & 0 deletions lightning/src/chain/chainmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,7 @@ impl<ChannelSigner: EcdsaChannelSigner, C: Deref, T: Deref, F: Deref, L: Deref,

#[cfg(test)]
mod tests {
use crate::ln::channelmanager::OffersMessageCommons;
use crate::{check_added_monitors, check_closed_event};
use crate::{expect_payment_path_successful, get_event_msg};
use crate::{get_htlc_update_msgs, get_revoke_commit_msgs};
Expand Down
40 changes: 20 additions & 20 deletions lightning/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,22 @@ pub enum PaymentPurpose {
/// A payment for a BOLT 11 invoice.
Bolt11InvoicePayment {
/// The preimage to the payment_hash, if the payment hash (and secret) were fetched via
/// [`ChannelManager::create_inbound_payment`]. When handling [`Event::PaymentClaimable`],
/// this can be passed directly to [`ChannelManager::claim_funds`] to claim the payment. No
/// [`OffersMessageCommons::create_inbound_payment`]. When handling [`Event::PaymentClaimable`],
/// this can be passed directly to [`OffersMessageCommons::claim_funds`] to claim the payment. No
/// action is needed when seen in [`Event::PaymentClaimed`].
///
/// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
/// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
/// [`OffersMessageCommons::create_inbound_payment`]: crate::ln::channelmanager::OffersMessageCommons::create_inbound_payment
/// [`OffersMessageCommons::claim_funds`]: crate::ln::channelmanager::OffersMessageCommons::claim_funds
payment_preimage: Option<PaymentPreimage>,
/// The "payment secret". This authenticates the sender to the recipient, preventing a
/// number of deanonymization attacks during the routing process.
/// It is provided here for your reference, however its accuracy is enforced directly by
/// [`ChannelManager`] using the values you previously provided to
/// [`ChannelManager::create_inbound_payment`] or
/// [`OffersMessageCommons::create_inbound_payment`] or
/// [`ChannelManager::create_inbound_payment_for_hash`].
///
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
/// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
/// [`OffersMessageCommons::create_inbound_payment`]: crate::ln::channelmanager::OffersMessageCommons::create_inbound_payment
/// [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
payment_secret: PaymentSecret,
},
Expand All @@ -112,10 +112,10 @@ pub enum PaymentPurpose {
/// [`Offer`]: crate::offers::offer::Offer
Bolt12OfferPayment {
/// The preimage to the payment hash. When handling [`Event::PaymentClaimable`], this can be
/// passed directly to [`ChannelManager::claim_funds`], if provided. No action is needed
/// passed directly to [`OffersMessageCommons::claim_funds`], if provided. No action is needed
/// when seen in [`Event::PaymentClaimed`].
///
/// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
/// [`OffersMessageCommons::claim_funds`]: crate::ln::channelmanager::OffersMessageCommons::claim_funds
payment_preimage: Option<PaymentPreimage>,
/// The secret used to authenticate the sender to the recipient, preventing a number of
/// de-anonymization attacks while routing a payment.
Expand All @@ -138,10 +138,10 @@ pub enum PaymentPurpose {
/// [`Refund`]: crate::offers::refund::Refund
Bolt12RefundPayment {
/// The preimage to the payment hash. When handling [`Event::PaymentClaimable`], this can be
/// passed directly to [`ChannelManager::claim_funds`], if provided. No action is needed
/// passed directly to [`OffersMessageCommons::claim_funds`], if provided. No action is needed
/// when seen in [`Event::PaymentClaimed`].
///
/// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
/// [`OffersMessageCommons::claim_funds`]: crate::ln::channelmanager::OffersMessageCommons::claim_funds
payment_preimage: Option<PaymentPreimage>,
/// The secret used to authenticate the sender to the recipient, preventing a number of
/// de-anonymization attacks while routing a payment.
Expand Down Expand Up @@ -678,7 +678,7 @@ pub enum Event {
former_temporary_channel_id: ChannelId,
},
/// Indicates that we've been offered a payment and it needs to be claimed via calling
/// [`ChannelManager::claim_funds`] with the preimage given in [`PaymentPurpose`].
/// [`OffersMessageCommons::claim_funds`] with the preimage given in [`PaymentPurpose`].
///
/// Note that if the preimage is not known, you should call
/// [`ChannelManager::fail_htlc_backwards`] or [`ChannelManager::fail_htlc_backwards_with_reason`]
Expand All @@ -689,9 +689,9 @@ pub enum Event {
/// [`FailureCode::InvalidOnionPayload`] if you fail to understand and handle the contents, or
/// [`ChannelManager::claim_funds_with_known_custom_tlvs`] upon successful handling.
/// If you don't intend to check for custom TLVs, you can simply use
/// [`ChannelManager::claim_funds`], which will automatically fail back even custom TLVs.
/// [`OffersMessageCommons::claim_funds`], which will automatically fail back even custom TLVs.
///
/// If you fail to call [`ChannelManager::claim_funds`],
/// If you fail to call [`OffersMessageCommons::claim_funds`],
/// [`ChannelManager::claim_funds_with_known_custom_tlvs`],
/// [`ChannelManager::fail_htlc_backwards`], or
/// [`ChannelManager::fail_htlc_backwards_with_reason`] within the HTLC's timeout, the HTLC will
Expand All @@ -710,7 +710,7 @@ pub enum Event {
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
/// returning `Err(ReplayEvent ())`) and will be persisted across restarts.
///
/// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
/// [`OffersMessageCommons::claim_funds`]: crate::ln::channelmanager::OffersMessageCommons::claim_funds
/// [`ChannelManager::claim_funds_with_known_custom_tlvs`]: crate::ln::channelmanager::ChannelManager::claim_funds_with_known_custom_tlvs
/// [`FailureCode::InvalidOnionPayload`]: crate::ln::channelmanager::FailureCode::InvalidOnionPayload
/// [`ChannelManager::fail_htlc_backwards`]: crate::ln::channelmanager::ChannelManager::fail_htlc_backwards
Expand Down Expand Up @@ -760,10 +760,10 @@ pub enum Event {
/// The block height at which this payment will be failed back and will no longer be
/// eligible for claiming.
///
/// Prior to this height, a call to [`ChannelManager::claim_funds`] is guaranteed to
/// Prior to this height, a call to [`OffersMessageCommons::claim_funds`] is guaranteed to
/// succeed, however you should wait for [`Event::PaymentClaimed`] to be sure.
///
/// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
/// [`OffersMessageCommons::claim_funds`]: crate::ln::channelmanager::OffersMessageCommons::claim_funds
claim_deadline: Option<u32>,
/// A unique ID describing this payment (derived from the list of HTLCs in the payment).
///
Expand All @@ -776,22 +776,22 @@ pub enum Event {
},
/// Indicates a payment has been claimed and we've received money!
///
/// This most likely occurs when [`ChannelManager::claim_funds`] has been called in response
/// This most likely occurs when [`OffersMessageCommons::claim_funds`] has been called in response
/// to an [`Event::PaymentClaimable`]. However, if we previously crashed during a
/// [`ChannelManager::claim_funds`] call you may see this event without a corresponding
/// [`OffersMessageCommons::claim_funds`] call you may see this event without a corresponding
/// [`Event::PaymentClaimable`] event.
///
/// # Note
/// LDK will not stop an inbound payment from being paid multiple times, so multiple
/// `PaymentClaimable` events may be generated for the same payment. If you then call
/// [`ChannelManager::claim_funds`] twice for the same [`Event::PaymentClaimable`] you may get
/// [`OffersMessageCommons::claim_funds`] twice for the same [`Event::PaymentClaimable`] you may get
/// multiple `PaymentClaimed` events.
///
/// # Failure Behavior and Persistence
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
/// returning `Err(ReplayEvent ())`) and will be persisted across restarts.
///
/// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
/// [`OffersMessageCommons::claim_funds`]: crate::ln::channelmanager::OffersMessageCommons::claim_funds
PaymentClaimed {
/// The node that received the payment.
/// This is useful to identify payments which were received via [phantom nodes].
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/blinded_payment_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::blinded_path::payment::{BlindedPaymentPath, PaymentForwardNode, Forwa
use crate::events::{Event, HTLCDestination, MessageSendEvent, MessageSendEventsProvider, PaymentFailureReason};
use crate::ln::types::ChannelId;
use crate::types::payment::{PaymentHash, PaymentSecret};
use crate::ln::channelmanager;
use crate::ln::channelmanager::{self, OffersMessageCommons};
use crate::ln::channelmanager::{HTLCFailureMsg, PaymentId, RecipientOnionFields};
use crate::types::features::{BlindedHopFeatures, ChannelFeatures, NodeFeatures};
use crate::ln::functional_test_utils::*;
Expand Down
1 change: 1 addition & 0 deletions lightning/src/ln/bolt11_payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ fn params_from_invoice(
#[cfg(test)]
mod tests {
use super::*;
use crate::ln::channelmanager::OffersMessageCommons;
use crate::routing::router::Payee;
use crate::types::payment::PaymentSecret;
use bitcoin::hashes::sha256::Hash as Sha256;
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/chanmon_update_fail_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::chain::channelmonitor::{ANTI_REORG_DELAY, ChannelMonitor};
use crate::chain::transaction::OutPoint;
use crate::chain::{ChannelMonitorUpdateStatus, Listen, Watch};
use crate::events::{Event, MessageSendEvent, MessageSendEventsProvider, PaymentPurpose, ClosureReason, HTLCDestination};
use crate::ln::channelmanager::{RAACommitmentOrder, PaymentSendFailure, PaymentId, RecipientOnionFields};
use crate::ln::channelmanager::{OffersMessageCommons, PaymentId, PaymentSendFailure, RAACommitmentOrder, RecipientOnionFields};
use crate::ln::channel::{AnnouncementSigsState, ChannelPhase};
use crate::ln::msgs;
use crate::ln::types::ChannelId;
Expand Down
Loading
Loading