@@ -1752,6 +1752,7 @@ where
1752
1752
/// # tx_broadcaster: &dyn lightning::chain::chaininterface::BroadcasterInterface,
1753
1753
/// # router: &lightning::routing::router::DefaultRouter<&NetworkGraph<&'a L>, &'a L, &ES, &S, SP, SL>,
1754
1754
/// # message_router: &lightning::onion_message::messenger::DefaultMessageRouter<&NetworkGraph<&'a L>, &'a L, &ES>,
1755
+ /// # flow: &lightning::offers::flow::OffersMessageFlow<&ES, &lightning::onion_message::messenger::DefaultMessageRouter<&NetworkGraph<&'a L>, &'a L, &ES>>,
1755
1756
/// # logger: &L,
1756
1757
/// # entropy_source: &ES,
1757
1758
/// # node_signer: &dyn lightning::sign::NodeSigner,
@@ -1767,15 +1768,15 @@ where
1767
1768
/// };
1768
1769
/// let default_config = UserConfig::default();
1769
1770
/// let channel_manager = ChannelManager::new(
1770
- /// fee_estimator, chain_monitor, tx_broadcaster, router, message_router, logger,
1771
+ /// fee_estimator, chain_monitor, tx_broadcaster, router, message_router, flow, logger,
1771
1772
/// entropy_source, node_signer, signer_provider, default_config, params, current_timestamp,
1772
1773
/// );
1773
1774
///
1774
1775
/// // Restart from deserialized data
1775
1776
/// let mut channel_monitors = read_channel_monitors();
1776
1777
/// let args = ChannelManagerReadArgs::new(
1777
1778
/// entropy_source, node_signer, signer_provider, fee_estimator, chain_monitor, tx_broadcaster,
1778
- /// router, message_router, logger, default_config, channel_monitors.iter().collect(),
1779
+ /// router, message_router, flow, logger, default_config, channel_monitors.iter().collect(),
1779
1780
/// );
1780
1781
/// let (block_hash, channel_manager) =
1781
1782
/// <(BlockHash, ChannelManager<_, _, _, _, _, _, _, _, _, _>)>::read(&mut reader, args)?;
@@ -10122,18 +10123,15 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
10122
10123
pub fn create_offer_builder(
10123
10124
&$self, absolute_expiry: Option<Duration>
10124
10125
) -> Result<$builder, Bolt12SemanticError> {
10125
- let node_id = $self.get_our_node_id();
10126
- let expanded_key = &$self.inbound_payment_key;
10127
10126
let entropy = &*$self.entropy_source;
10128
- let secp_ctx = &$self.secp_ctx;
10129
10127
10130
10128
let nonce = Nonce::from_entropy_source(entropy);
10131
10129
let context = OffersContext::InvoiceRequest { nonce };
10132
- let path = $self.create_blinded_paths_using_absolute_expiry(context, absolute_expiry)
10130
+ let path = $self.flow. create_blinded_paths_using_absolute_expiry($self.peer_for_blinded_path(), context, absolute_expiry)
10133
10131
.and_then(|paths| paths.into_iter().next().ok_or(()))
10134
10132
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
10135
- let builder = OfferBuilder::deriving_signing_pubkey(node_id, expanded_key, nonce, secp_ctx)
10136
- .chain_hash( $self.chain_hash)
10133
+
10134
+ let builder = $self.flow.create_offer_builder(nonce)?
10137
10135
.path(path);
10138
10136
10139
10137
let builder = match absolute_expiry {
@@ -10195,23 +10193,16 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
10195
10193
&$self, amount_msats: u64, absolute_expiry: Duration, payment_id: PaymentId,
10196
10194
retry_strategy: Retry, route_params_config: RouteParametersConfig
10197
10195
) -> Result<$builder, Bolt12SemanticError> {
10198
- let node_id = $self.get_our_node_id();
10199
- let expanded_key = &$self.inbound_payment_key;
10200
10196
let entropy = &*$self.entropy_source;
10201
- let secp_ctx = &$self.secp_ctx;
10202
10197
10203
10198
let nonce = Nonce::from_entropy_source(entropy);
10204
10199
let context = OffersContext::OutboundPayment { payment_id, nonce, hmac: None };
10205
- let path = $self.create_blinded_paths_using_absolute_expiry(context, Some(absolute_expiry))
10200
+ let path = $self.flow. create_blinded_paths_using_absolute_expiry($self.peer_for_blinded_path(), context, Some(absolute_expiry))
10206
10201
.and_then(|paths| paths.into_iter().next().ok_or(()))
10207
10202
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
10208
10203
10209
- let builder = RefundBuilder::deriving_signing_pubkey(
10210
- node_id, expanded_key, nonce, secp_ctx, amount_msats, payment_id
10211
- )?
10212
- .chain_hash($self.chain_hash)
10213
- .absolute_expiry(absolute_expiry)
10214
- .path(path);
10204
+ let builder = $self.flow.create_refund_builder(amount_msats, absolute_expiry, payment_id, nonce)?
10205
+ .path(path);
10215
10206
10216
10207
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop($self);
10217
10208
@@ -10272,15 +10263,10 @@ where
10272
10263
return Err(Bolt12SemanticError::MissingPaths)
10273
10264
}
10274
10265
10275
- let node_id = self.get_our_node_id();
10276
- let expanded_key = &self.inbound_payment_key;
10277
10266
let entropy = &*self.entropy_source;
10278
- let secp_ctx = &self.secp_ctx;
10279
10267
10280
10268
let nonce = Nonce::from_entropy_source(entropy);
10281
- let mut builder = OfferBuilder::deriving_signing_pubkey(
10282
- node_id, expanded_key, nonce, secp_ctx
10283
- ).chain_hash(self.chain_hash);
10269
+ let mut builder = self.flow.create_offer_builder(nonce)?;
10284
10270
10285
10271
for path in message_paths_to_always_online_node {
10286
10272
builder = builder.path(path);
@@ -10420,44 +10406,23 @@ where
10420
10406
) -> Result<(), Bolt12SemanticError> {
10421
10407
let expanded_key = &self.inbound_payment_key;
10422
10408
let entropy = &*self.entropy_source;
10423
- let secp_ctx = &self.secp_ctx;
10424
10409
10425
10410
let nonce = Nonce::from_entropy_source(entropy);
10426
- let builder: InvoiceRequestBuilder<secp256k1::All> = offer
10427
- .request_invoice(expanded_key, nonce, secp_ctx, payment_id)?
10428
- .into();
10429
- let builder = builder.chain_hash(self.chain_hash)?;
10430
-
10431
- let builder = match quantity {
10432
- None => builder,
10433
- Some(quantity) => builder.quantity(quantity)?,
10434
- };
10435
- let builder = match amount_msats {
10436
- None => builder,
10437
- Some(amount_msats) => builder.amount_msats(amount_msats)?,
10438
- };
10439
- let builder = match payer_note {
10440
- None => builder,
10441
- Some(payer_note) => builder.payer_note(payer_note),
10442
- };
10443
- let builder = match human_readable_name {
10444
- None => builder,
10445
- Some(hrn) => builder.sourced_from_human_readable_name(hrn),
10446
- };
10411
+ let builder = self.flow.create_invoice_request_builder(offer, nonce, quantity, amount_msats, payer_note, human_readable_name, payment_id)?;
10447
10412
let invoice_request = builder.build_and_sign()?;
10448
10413
10449
10414
let hmac = payment_id.hmac_for_offer_payment(nonce, expanded_key);
10450
10415
let context = MessageContext::Offers(
10451
10416
OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) }
10452
10417
);
10453
- let reply_paths = self.create_blinded_paths(context)
10418
+ let reply_paths = self.flow. create_blinded_paths(self.peer_for_blinded_path(), context)
10454
10419
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
10455
10420
10456
10421
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
10457
10422
10458
10423
create_pending_payment(&invoice_request, nonce)?;
10459
10424
10460
- self.enqueue_invoice_request(invoice_request, reply_paths)
10425
+ self.flow. enqueue_invoice_request(invoice_request, reply_paths)
10461
10426
}
10462
10427
10463
10428
fn enqueue_invoice_request(
@@ -10542,53 +10507,18 @@ where
10542
10507
)
10543
10508
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
10544
10509
10545
- #[cfg(feature = "std")]
10546
- let builder = refund.respond_using_derived_keys(
10547
- payment_paths, payment_hash, expanded_key, entropy
10548
- )?;
10549
- #[cfg(not(feature = "std"))]
10550
- let created_at = Duration::from_secs(
10551
- self.highest_seen_timestamp.load(Ordering::Acquire) as u64
10552
- );
10553
- #[cfg(not(feature = "std"))]
10554
- let builder = refund.respond_using_derived_keys_no_std(
10555
- payment_paths, payment_hash, created_at, expanded_key, entropy
10556
- )?;
10557
- let builder: InvoiceBuilder<DerivedSigningPubkey> = builder.into();
10510
+ let builder = self.flow.create_invoice_builder(refund, payment_paths, payment_hash)?;
10558
10511
let invoice = builder.allow_mpp().build_and_sign(secp_ctx)?;
10559
10512
10560
10513
let nonce = Nonce::from_entropy_source(entropy);
10561
10514
let hmac = payment_hash.hmac_for_offer_payment(nonce, expanded_key);
10562
10515
let context = MessageContext::Offers(OffersContext::InboundPayment {
10563
10516
payment_hash: invoice.payment_hash(), nonce, hmac
10564
10517
});
10565
- let reply_paths = self.create_blinded_paths(context)
10518
+ let reply_paths = self.flow. create_blinded_paths(self.peer_for_blinded_path(), context)
10566
10519
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
10567
10520
10568
- let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
10569
- if refund.paths().is_empty() {
10570
- for reply_path in reply_paths {
10571
- let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
10572
- destination: Destination::Node(refund.payer_signing_pubkey()),
10573
- reply_path,
10574
- };
10575
- let message = OffersMessage::Invoice(invoice.clone());
10576
- pending_offers_messages.push((message, instructions));
10577
- }
10578
- } else {
10579
- reply_paths
10580
- .iter()
10581
- .flat_map(|reply_path| refund.paths().iter().map(move |path| (path, reply_path)))
10582
- .take(OFFERS_MESSAGE_REQUEST_LIMIT)
10583
- .for_each(|(path, reply_path)| {
10584
- let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
10585
- destination: Destination::BlindedPath(path.clone()),
10586
- reply_path: reply_path.clone(),
10587
- };
10588
- let message = OffersMessage::Invoice(invoice.clone());
10589
- pending_offers_messages.push((message, instructions));
10590
- });
10591
- }
10521
+ self.flow.enqueue_invoice(invoice.clone(), refund, reply_paths)?;
10592
10522
10593
10523
Ok(invoice)
10594
10524
},
@@ -10644,22 +10574,10 @@ where
10644
10574
) -> Result<(), ()> {
10645
10575
let (onion_message, context) =
10646
10576
self.hrn_resolver.resolve_name(payment_id, name, &*self.entropy_source)?;
10647
- let reply_paths = self.create_blinded_paths(MessageContext::DNSResolver(context))?;
10577
+ let reply_paths = self.flow. create_blinded_paths(self.peer_for_blinded_path(), MessageContext::DNSResolver(context))?;
10648
10578
let expiration = StaleExpiration::TimerTicks(1);
10649
10579
self.pending_outbound_payments.add_new_awaiting_offer(payment_id, expiration, retry_strategy, route_params_config, amount_msats)?;
10650
- let message_params = dns_resolvers
10651
- .iter()
10652
- .flat_map(|destination| reply_paths.iter().map(move |path| (path, destination)))
10653
- .take(OFFERS_MESSAGE_REQUEST_LIMIT);
10654
- for (reply_path, destination) in message_params {
10655
- self.pending_dns_onion_messages.lock().unwrap().push((
10656
- DNSResolverMessage::DNSSECQuery(onion_message.clone()),
10657
- MessageSendInstructions::WithSpecifiedReplyPath {
10658
- destination: destination.clone(),
10659
- reply_path: reply_path.clone(),
10660
- },
10661
- ));
10662
- }
10580
+ self.flow.enqueue_dns_onion_message(onion_message, dns_resolvers, reply_paths).map_err(|_| ())?;
10663
10581
Ok(())
10664
10582
}
10665
10583
@@ -12609,7 +12527,9 @@ where
12609
12527
}
12610
12528
12611
12529
fn release_pending_messages(&self) -> Vec<(OffersMessage, MessageSendInstructions)> {
12612
- core::mem::take(&mut self.pending_offers_messages.lock().unwrap())
12530
+ let mut messages = core::mem::take(&mut *self.pending_offers_messages.lock().unwrap());
12531
+ messages.extend(self.flow.get_and_clear_pending_offers_messages());
12532
+ messages
12613
12533
}
12614
12534
}
12615
12535
@@ -12665,7 +12585,9 @@ where
12665
12585
}
12666
12586
12667
12587
fn release_pending_messages(&self) -> Vec<(AsyncPaymentsMessage, MessageSendInstructions)> {
12668
- core::mem::take(&mut self.pending_async_payments_messages.lock().unwrap())
12588
+ let mut messages = core::mem::take(&mut *self.pending_async_payments_messages.lock().unwrap());
12589
+ messages.extend(self.flow.get_and_clear_pending_async_messages());
12590
+ messages
12669
12591
}
12670
12592
}
12671
12593
@@ -12730,7 +12652,9 @@ where
12730
12652
}
12731
12653
12732
12654
fn release_pending_messages(&self) -> Vec<(DNSResolverMessage, MessageSendInstructions)> {
12733
- core::mem::take(&mut self.pending_dns_onion_messages.lock().unwrap())
12655
+ let mut messages = core::mem::take(&mut *self.pending_dns_onion_messages.lock().unwrap());
12656
+ messages.extend(self.flow.get_and_clear_pending_dns_messages());
12657
+ messages
12734
12658
}
12735
12659
}
12736
12660
0 commit comments