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

Enable Creation of Offers and Refunds Without Blinded Path #3246

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4174d39
Introduce `message_received` in Offer/OnionMessageHandler
shaavan Nov 12, 2024
c2f2e08
Move `message_received` out of `ChannelMessageHandler`
shaavan Nov 12, 2024
0f3e875
Remove async BOLT12 handling support
shaavan Dec 4, 2024
d7c47af
Introduce `OffersMessageFlow`
shaavan Nov 15, 2024
7f7a1fe
Introduce `OffersMessageCommons` Trait and Implementation
shaavan Nov 15, 2024
c9cc372
f: Move initiate_async_payments to commons
shaavan Dec 11, 2024
8240983
Refactor `OffersMessageHandler` Implementation to `OffersMessageFlow`
shaavan Nov 15, 2024
85794cf
Introduce `AnOffersMessageFlow`
shaavan Nov 15, 2024
ada31ae
Move `create_offer_builder` to `OffersMessageFlow`
shaavan Nov 15, 2024
8543117
Move create_refund_builder to OffersMessageFlow
shaavan Nov 15, 2024
03a69e4
Move pay_for_offer to OffersMessageFlow
shaavan Nov 16, 2024
abf34ec
Move request_refund_payment to OffersMessageFlow
shaavan Nov 16, 2024
f49930b
f: Remove spurious _persistence_guard check
shaavan Dec 11, 2024
0d0732c
Move pay_for_offer_human_readable to OffersMessageFlow
shaavan Nov 27, 2024
7b44fe0
Move DNSResolverMessageHandler impl to OffersMessageFlow
shaavan Nov 27, 2024
a24579a
Move create_blinded_path_using_absolute_expiry to flow.rs
shaavan Nov 27, 2024
f12c835
Introduce create_blinded_paths in flow.rs
shaavan Dec 12, 2024
dd177d2
Move pending_offers_message to flows.rs
shaavan Nov 27, 2024
defec29
Move pending_dns_onion_messages to flow.rs
shaavan Nov 27, 2024
4818efe
Move send_payment_for_bolt12_invoice to flow.rs
shaavan Nov 27, 2024
18f6738
Introduce RouterConfig for DefaultMessageRouter
shaavan Dec 13, 2024
e18898b
Allow create_blinded_paths to take `Vec<MessageForwardNode>` as input
shaavan Dec 13, 2024
1db5eca
Update DefaultMessageRouter's MessageRouter Implementation
shaavan Dec 13, 2024
1f17e34
Update create_offer_builder to Take Router as Parameter
shaavan Dec 13, 2024
45bcd4c
Update create_refund_builder to Take Router as Parameter
shaavan Dec 13, 2024
6e0c973
Remove Redundant Variants of create_blinded_paths
shaavan Dec 13, 2024
ee51aed
Introduce Tests for Offers and Refunds Without Blinded Paths
shaavan Oct 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions fuzz/src/chanmon_consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use bitcoin::hashes::sha256d::Hash as Sha256dHash;
use bitcoin::hashes::Hash as TraitImport;
use bitcoin::WPubkeyHash;

use lightning::blinded_path::message::{BlindedMessagePath, MessageContext};
use lightning::blinded_path::message::{BlindedMessagePath, MessageContext, MessageForwardNode};
use lightning::blinded_path::payment::{BlindedPaymentPath, ReceiveTlvs};
use lightning::chain;
use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
Expand All @@ -56,6 +56,7 @@ use lightning::ln::msgs::{
};
use lightning::ln::script::ShutdownScript;
use lightning::ln::types::ChannelId;
use lightning::offers::flow::OffersMessageCommons;
use lightning::offers::invoice::UnsignedBolt12Invoice;
use lightning::onion_message::messenger::{Destination, MessageRouter, OnionMessagePath};
use lightning::routing::router::{
Expand Down Expand Up @@ -147,7 +148,7 @@ impl MessageRouter for FuzzRouter {
}

fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
&self, _recipient: PublicKey, _context: MessageContext, _peers: Vec<PublicKey>,
&self, _recipient: PublicKey, _context: MessageContext, _peers: Vec<MessageForwardNode>,
_secp_ctx: &Secp256k1<T>,
) -> Result<Vec<BlindedMessagePath>, ()> {
unreachable!()
Expand Down
5 changes: 3 additions & 2 deletions fuzz/src/full_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use bitcoin::hashes::Hash as _;
use bitcoin::hex::FromHex;
use bitcoin::WPubkeyHash;

use lightning::blinded_path::message::{BlindedMessagePath, MessageContext};
use lightning::blinded_path::message::{BlindedMessagePath, MessageContext, MessageForwardNode};
use lightning::blinded_path::payment::{BlindedPaymentPath, ReceiveTlvs};
use lightning::chain;
use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
Expand All @@ -50,6 +50,7 @@ use lightning::ln::peer_handler::{
};
use lightning::ln::script::ShutdownScript;
use lightning::ln::types::ChannelId;
use lightning::offers::flow::OffersMessageCommons;
use lightning::offers::invoice::UnsignedBolt12Invoice;
use lightning::onion_message::messenger::{Destination, MessageRouter, OnionMessagePath};
use lightning::routing::gossip::{NetworkGraph, P2PGossipSync};
Expand Down Expand Up @@ -174,7 +175,7 @@ impl MessageRouter for FuzzRouter {
}

fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
&self, _recipient: PublicKey, _context: MessageContext, _peers: Vec<PublicKey>,
&self, _recipient: PublicKey, _context: MessageContext, _peers: Vec<MessageForwardNode>,
_secp_ctx: &Secp256k1<T>,
) -> Result<Vec<BlindedMessagePath>, ()> {
unreachable!()
Expand Down
4 changes: 2 additions & 2 deletions fuzz/src/onion_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bitcoin::secp256k1::schnorr;
use bitcoin::secp256k1::{self, PublicKey, Scalar, Secp256k1, SecretKey};

use lightning::blinded_path::message::{
AsyncPaymentsContext, BlindedMessagePath, MessageContext, OffersContext,
AsyncPaymentsContext, BlindedMessagePath, MessageContext, MessageForwardNode, OffersContext,
};
use lightning::blinded_path::EmptyNodeIdLookUp;
use lightning::ln::inbound_payment::ExpandedKey;
Expand Down Expand Up @@ -100,7 +100,7 @@ impl MessageRouter for TestMessageRouter {
}

fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
&self, _recipient: PublicKey, _context: MessageContext, _peers: Vec<PublicKey>,
&self, _recipient: PublicKey, _context: MessageContext, _peers: Vec<MessageForwardNode>,
_secp_ctx: &Secp256k1<T>,
) -> Result<Vec<BlindedMessagePath>, ()> {
unreachable!()
Expand Down
3 changes: 2 additions & 1 deletion lightning-background-processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,8 @@ use futures_util::{dummy_waker, OptionalSelector, Selector, SelectorOutput};
/// # type NetworkGraph = lightning::routing::gossip::NetworkGraph<Arc<Logger>>;
/// # type P2PGossipSync<UL> = lightning::routing::gossip::P2PGossipSync<Arc<NetworkGraph>, Arc<UL>, Arc<Logger>>;
/// # type ChannelManager<B, F, FE> = lightning::ln::channelmanager::SimpleArcChannelManager<ChainMonitor<B, F, FE>, B, FE, Logger>;
/// # type OnionMessenger<B, F, FE> = lightning::onion_message::messenger::OnionMessenger<Arc<lightning::sign::KeysManager>, Arc<lightning::sign::KeysManager>, Arc<Logger>, Arc<ChannelManager<B, F, FE>>, Arc<lightning::onion_message::messenger::DefaultMessageRouter<Arc<NetworkGraph>, Arc<Logger>, Arc<lightning::sign::KeysManager>>>, Arc<ChannelManager<B, F, FE>>, lightning::ln::peer_handler::IgnoringMessageHandler, lightning::ln::peer_handler::IgnoringMessageHandler, lightning::ln::peer_handler::IgnoringMessageHandler>;
/// # type OffersMessageFlow<B, F, FE> = lightning::offers::flow::OffersMessageFlow<Arc<lightning::sign::KeysManager>, Arc<ChannelManager<B, F, FE>>, Arc<lightning::onion_message::messenger::DefaultMessageRouter<Arc<NetworkGraph>, Arc<Logger>, Arc<lightning::sign::KeysManager>>>, Arc<Logger>>;
/// # type OnionMessenger<B, F, FE> = lightning::onion_message::messenger::OnionMessenger<Arc<lightning::sign::KeysManager>, Arc<lightning::sign::KeysManager>, Arc<Logger>, Arc<ChannelManager<B, F, FE>>, Arc<lightning::onion_message::messenger::DefaultMessageRouter<Arc<NetworkGraph>, Arc<Logger>, Arc<lightning::sign::KeysManager>>>, Arc<OffersMessageFlow<B, F, FE>>, lightning::ln::peer_handler::IgnoringMessageHandler, lightning::ln::peer_handler::IgnoringMessageHandler, lightning::ln::peer_handler::IgnoringMessageHandler>;
/// # type Scorer = RwLock<lightning::routing::scoring::ProbabilisticScorer<Arc<NetworkGraph>, Arc<Logger>>>;
/// # type PeerManager<B, F, FE, UL> = lightning::ln::peer_handler::SimpleArcPeerManager<SocketDescriptor, ChainMonitor<B, F, FE>, B, FE, Arc<UL>, Logger>;
/// #
Expand Down
19 changes: 13 additions & 6 deletions lightning-dns-resolver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ mod test {
use bitcoin::secp256k1::{self, PublicKey, Secp256k1};
use bitcoin::Block;

use lightning::blinded_path::message::{BlindedMessagePath, MessageContext};
use lightning::blinded_path::message::{
BlindedMessagePath, MessageContext, MessageForwardNode,
};
use lightning::blinded_path::NodeIdLookUp;
use lightning::events::{Event, PaymentPurpose};
use lightning::ln::channelmanager::{PaymentId, Retry};
Expand All @@ -168,12 +170,14 @@ mod test {
use lightning::ln::peer_handler::IgnoringMessageHandler;
use lightning::onion_message::dns_resolution::{HumanReadableName, OMNameResolver};
use lightning::onion_message::messenger::{
AOnionMessenger, Destination, MessageRouter, OnionMessagePath, OnionMessenger,
AOnionMessenger, DefaultMessageRouter, Destination, MessageRouter, OnionMessagePath,
OnionMessenger,
};
use lightning::sign::{KeysManager, NodeSigner, Recipient};
use lightning::types::features::InitFeatures;
use lightning::types::payment::PaymentHash;
use lightning::util::logger::Logger;
use lightning::util::test_utils;

use lightning::{
commitment_signed_dance, expect_payment_claimed, expect_pending_htlcs_forwardable,
Expand Down Expand Up @@ -225,7 +229,7 @@ mod test {
}

fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
&self, recipient: PublicKey, context: MessageContext, _peers: Vec<PublicKey>,
&self, recipient: PublicKey, context: MessageContext, _peers: Vec<MessageForwardNode>,
secp_ctx: &Secp256k1<T>,
) -> Result<Vec<BlindedMessagePath>, ()> {
let keys = KeysManager::new(&[0; 32], 42, 43);
Expand Down Expand Up @@ -390,10 +394,13 @@ mod test {

let name = HumanReadableName::from_encoded("[email protected]").unwrap();

let entropy = test_utils::FixedEntropy {};
// 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 router = DefaultMessageRouter::new(nodes[1].network_graph, entropy);
let bs_offer =
nodes[1].offers_handler.create_offer_builder(router).unwrap().build().unwrap();
nodes[0]
.node
.offers_handler
.testing_dnssec_proof_offer_resolution_override
.lock()
.unwrap()
Expand All @@ -404,7 +411,7 @@ mod test {
let retry = Retry::Attempts(0);
let amt = 42_000;
nodes[0]
.node
.offers_handler
.pay_for_offer_from_human_readable_name(name, amt, payment_id, retry, None, resolvers)
.unwrap();

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
72 changes: 6 additions & 66 deletions lightning/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pub mod bump_transaction;

pub use bump_transaction::BumpTransactionEvent;

use crate::blinded_path::message::OffersContext;
use crate::blinded_path::payment::{Bolt12OfferContext, Bolt12RefundContext, PaymentContext, PaymentContextRef};
use crate::chain::transaction;
use crate::ln::channelmanager::{InterceptId, PaymentId, RecipientOnionFields};
Expand All @@ -27,8 +26,6 @@ use crate::types::features::ChannelTypeFeatures;
use crate::ln::msgs;
use crate::ln::types::ChannelId;
use crate::types::payment::{PaymentPreimage, PaymentHash, PaymentSecret};
use crate::offers::invoice::Bolt12Invoice;
use crate::onion_message::messenger::Responder;
use crate::routing::gossip::NetworkUpdate;
use crate::routing::router::{BlindedTail, Path, RouteHop, RouteParameters};
use crate::sign::SpendableOutputDescriptor;
Expand Down Expand Up @@ -88,22 +85,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`],
/// [`OffersMessageCommons::create_inbound_payment`]. When handling [`Event::PaymentClaimable`],
/// this can be passed directly to [`ChannelManager::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
/// [`OffersMessageCommons::create_inbound_payment`]: crate::offers::flow::OffersMessageCommons::create_inbound_payment
/// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::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::offers::flow::OffersMessageCommons::create_inbound_payment
/// [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
payment_secret: PaymentSecret,
},
Expand Down Expand Up @@ -580,6 +577,8 @@ pub enum PaymentFailureReason {
/// An invoice was received that required unknown features.
UnknownRequiredFeatures,
/// A [`Bolt12Invoice`] was not received in a reasonable amount of time.
///
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
InvoiceRequestExpired,
/// An [`InvoiceRequest`] for the payment was rejected by the recipient.
///
Expand Down Expand Up @@ -867,39 +866,6 @@ pub enum Event {
/// Sockets for connecting to the node.
addresses: Vec<msgs::SocketAddress>,
},
/// Indicates a [`Bolt12Invoice`] in response to an [`InvoiceRequest`] or a [`Refund`] was
/// received.
///
/// This event will only be generated if [`UserConfig::manually_handle_bolt12_invoices`] is set.
/// Use [`ChannelManager::send_payment_for_bolt12_invoice`] to pay the invoice or
/// [`ChannelManager::abandon_payment`] to abandon the associated payment. See those docs for
/// further details.
///
/// # 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.
///
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
/// [`Refund`]: crate::offers::refund::Refund
/// [`UserConfig::manually_handle_bolt12_invoices`]: crate::util::config::UserConfig::manually_handle_bolt12_invoices
/// [`ChannelManager::send_payment_for_bolt12_invoice`]: crate::ln::channelmanager::ChannelManager::send_payment_for_bolt12_invoice
/// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
InvoiceReceived {
/// The `payment_id` associated with payment for the invoice.
payment_id: PaymentId,
/// The invoice to pay.
invoice: Bolt12Invoice,
/// The context of the [`BlindedMessagePath`] used to send the invoice.
///
/// [`BlindedMessagePath`]: crate::blinded_path::message::BlindedMessagePath
context: Option<OffersContext>,
/// A responder for replying with an [`InvoiceError`] if needed.
///
/// `None` if the invoice wasn't sent with a reply path.
///
/// [`InvoiceError`]: crate::offers::invoice_error::InvoiceError
responder: Option<Responder>,
},
/// Indicates an outbound payment we made succeeded (i.e. it made it all the way to its target
/// and we got back the payment preimage for it).
///
Expand Down Expand Up @@ -1803,15 +1769,6 @@ impl Writeable for Event {
(0, peer_node_id, required),
});
},
&Event::InvoiceReceived { ref payment_id, ref invoice, ref context, ref responder } => {
41u8.write(writer)?;
write_tlv_fields!(writer, {
(0, payment_id, required),
(2, invoice, required),
(4, context, option),
(6, responder, option),
});
},
&Event::FundingTxBroadcastSafe { ref channel_id, ref user_channel_id, ref funding_txo, ref counterparty_node_id, ref former_temporary_channel_id} => {
43u8.write(writer)?;
write_tlv_fields!(writer, {
Expand Down Expand Up @@ -2293,23 +2250,6 @@ impl MaybeReadable for Event {
};
f()
},
41u8 => {
let mut f = || {
_init_and_read_len_prefixed_tlv_fields!(reader, {
(0, payment_id, required),
(2, invoice, required),
(4, context, option),
(6, responder, option),
});
Ok(Some(Event::InvoiceReceived {
payment_id: payment_id.0.unwrap(),
invoice: invoice.0.unwrap(),
context,
responder,
}))
};
f()
},
43u8 => {
let mut channel_id = RequiredWrapper(None);
let mut user_channel_id = RequiredWrapper(None);
Expand Down
1 change: 1 addition & 0 deletions lightning/src/ln/async_signer_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use crate::ln::channel_state::{ChannelDetails, ChannelShutdownState};
use crate::ln::channelmanager::{PaymentId, RAACommitmentOrder, RecipientOnionFields};
use crate::ln::msgs::ChannelMessageHandler;
use crate::ln::{functional_test_utils::*, msgs};
use crate::offers::flow::OffersMessageCommons;
use crate::sign::ecdsa::EcdsaChannelSigner;
use crate::sign::SignerProvider;
use crate::util::test_channel_signer::SignerOp;
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/blinded_payment_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ fn blinded_keysend() {

let inbound_payment_key = nodes[2].keys_manager.get_inbound_payment_key();
let payment_secret = inbound_payment::create_for_spontaneous_payment(
&inbound_payment_key, None, u32::MAX, nodes[2].node.duration_since_epoch().as_secs(), None
&inbound_payment_key, None, u32::MAX, nodes[2].offers_handler.duration_since_epoch().as_secs(), None
).unwrap();

let amt_msat = 5000;
Expand Down Expand Up @@ -1277,7 +1277,7 @@ fn blinded_mpp_keysend() {

let inbound_payment_key = nodes[3].keys_manager.get_inbound_payment_key();
let payment_secret = inbound_payment::create_for_spontaneous_payment(
&inbound_payment_key, None, u32::MAX, nodes[3].node.duration_since_epoch().as_secs(), None
&inbound_payment_key, None, u32::MAX, nodes[3].offers_handler.duration_since_epoch().as_secs(), None
).unwrap();

let amt_msat = 15_000_000;
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::offers::flow::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::{PaymentId, PaymentSendFailure, RAACommitmentOrder, RecipientOnionFields};
use crate::ln::channel::{AnnouncementSigsState, ChannelPhase};
use crate::ln::msgs;
use crate::ln::types::ChannelId;
Expand Down
Loading
Loading