@@ -71,7 +71,7 @@ use crate::offers::parse::Bolt12SemanticError;
71
71
use crate::offers::refund::{Refund, RefundBuilder};
72
72
use crate::offers::signer;
73
73
use crate::onion_message::async_payments::{AsyncPaymentsMessage, HeldHtlcAvailable, ReleaseHeldHtlc, AsyncPaymentsMessageHandler};
74
- use crate::onion_message::messenger::{new_pending_onion_message, Destination, MessageRouter, PendingOnionMessage, Responder, ResponseInstruction};
74
+ use crate::onion_message::messenger::{Destination, MessageRouter, Responder, ResponseInstruction, MessageSendInstructions };
75
75
use crate::onion_message::offers::{OffersMessage, OffersMessageHandler};
76
76
use crate::sign::{EntropySource, NodeSigner, Recipient, SignerProvider};
77
77
use crate::sign::ecdsa::EcdsaChannelSigner;
@@ -2277,9 +2277,9 @@ where
2277
2277
needs_persist_flag: AtomicBool,
2278
2278
2279
2279
#[cfg(not(any(test, feature = "_test_utils")))]
2280
- pending_offers_messages: Mutex<Vec<PendingOnionMessage< OffersMessage> >>,
2280
+ pending_offers_messages: Mutex<Vec<( OffersMessage, MessageSendInstructions) >>,
2281
2281
#[cfg(any(test, feature = "_test_utils"))]
2282
- pub(crate) pending_offers_messages: Mutex<Vec<PendingOnionMessage< OffersMessage> >>,
2282
+ pub(crate) pending_offers_messages: Mutex<Vec<( OffersMessage, MessageSendInstructions) >>,
2283
2283
2284
2284
/// Tracks the message events that are to be broadcasted when we are connected to some peer.
2285
2285
pending_broadcast_messages: Mutex<Vec<MessageSendEvent>>,
@@ -9068,21 +9068,21 @@ where
9068
9068
.flat_map(|reply_path| offer.paths().iter().map(move |path| (path, reply_path)))
9069
9069
.take(OFFERS_MESSAGE_REQUEST_LIMIT)
9070
9070
.for_each(|(path, reply_path)| {
9071
- let message = new_pending_onion_message(
9072
- OffersMessage::InvoiceRequest(invoice_request .clone()),
9073
- Destination::BlindedPath(path .clone() ),
9074
- Some(reply_path.clone()),
9075
- );
9076
- pending_offers_messages.push(message);
9071
+ let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
9072
+ destination: Destination::BlindedPath(path .clone()),
9073
+ reply_path: reply_path .clone(),
9074
+ };
9075
+ let message = OffersMessage::InvoiceRequest(invoice_request.clone() );
9076
+ pending_offers_messages.push(( message, instructions) );
9077
9077
});
9078
9078
} else if let Some(signing_pubkey) = offer.signing_pubkey() {
9079
9079
for reply_path in reply_paths {
9080
- let message = new_pending_onion_message(
9081
- OffersMessage::InvoiceRequest(invoice_request.clone() ),
9082
- Destination::Node(signing_pubkey) ,
9083
- Some(reply_path),
9084
- );
9085
- pending_offers_messages.push(message);
9080
+ let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
9081
+ destination: Destination::Node(signing_pubkey ),
9082
+ reply_path ,
9083
+ };
9084
+ let message = OffersMessage::InvoiceRequest(invoice_request.clone() );
9085
+ pending_offers_messages.push(( message, instructions) );
9086
9086
}
9087
9087
} else {
9088
9088
debug_assert!(false);
@@ -9162,25 +9162,25 @@ where
9162
9162
let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
9163
9163
if refund.paths().is_empty() {
9164
9164
for reply_path in reply_paths {
9165
- let message = new_pending_onion_message(
9166
- OffersMessage::Invoice(invoice.clone ()),
9167
- Destination::Node(refund.payer_id()) ,
9168
- Some(reply_path),
9169
- );
9170
- pending_offers_messages.push(message);
9165
+ let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
9166
+ destination: Destination::Node(refund.payer_id ()),
9167
+ reply_path ,
9168
+ };
9169
+ let message = OffersMessage::Invoice(invoice.clone() );
9170
+ pending_offers_messages.push(( message, instructions) );
9171
9171
}
9172
9172
} else {
9173
9173
reply_paths
9174
9174
.iter()
9175
9175
.flat_map(|reply_path| refund.paths().iter().map(move |path| (path, reply_path)))
9176
9176
.take(OFFERS_MESSAGE_REQUEST_LIMIT)
9177
9177
.for_each(|(path, reply_path)| {
9178
- let message = new_pending_onion_message(
9179
- OffersMessage::Invoice(invoice .clone()),
9180
- Destination::BlindedPath(path .clone() ),
9181
- Some(reply_path.clone()),
9182
- );
9183
- pending_offers_messages.push(message);
9178
+ let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
9179
+ destination: Destination::BlindedPath(path .clone()),
9180
+ reply_path: reply_path .clone(),
9181
+ };
9182
+ let message = OffersMessage::Invoice(invoice.clone() );
9183
+ pending_offers_messages.push(( message, instructions) );
9184
9184
});
9185
9185
}
9186
9186
@@ -10749,41 +10749,41 @@ where
10749
10749
{
10750
10750
fn handle_message(
10751
10751
&self, message: OffersMessage, context: Option<OffersContext>, responder: Option<Responder>,
10752
- ) -> ResponseInstruction< OffersMessage> {
10752
+ ) -> Option<( OffersMessage, ResponseInstruction) > {
10753
10753
let secp_ctx = &self.secp_ctx;
10754
10754
let expanded_key = &self.inbound_payment_key;
10755
10755
10756
10756
match message {
10757
10757
OffersMessage::InvoiceRequest(invoice_request) => {
10758
10758
let responder = match responder {
10759
10759
Some(responder) => responder,
10760
- None => return ResponseInstruction::NoResponse ,
10760
+ None => return None ,
10761
10761
};
10762
10762
10763
10763
let nonce = match context {
10764
10764
None if invoice_request.metadata().is_some() => None,
10765
10765
Some(OffersContext::InvoiceRequest { nonce }) => Some(nonce),
10766
- _ => return ResponseInstruction::NoResponse ,
10766
+ _ => return None ,
10767
10767
};
10768
10768
10769
10769
let invoice_request = match nonce {
10770
10770
Some(nonce) => match invoice_request.verify_using_recipient_data(
10771
10771
nonce, expanded_key, secp_ctx,
10772
10772
) {
10773
10773
Ok(invoice_request) => invoice_request,
10774
- Err(()) => return ResponseInstruction::NoResponse ,
10774
+ Err(()) => return None ,
10775
10775
},
10776
10776
None => match invoice_request.verify_using_metadata(expanded_key, secp_ctx) {
10777
10777
Ok(invoice_request) => invoice_request,
10778
- Err(()) => return ResponseInstruction::NoResponse ,
10778
+ Err(()) => return None ,
10779
10779
},
10780
10780
};
10781
10781
10782
10782
let amount_msats = match InvoiceBuilder::<DerivedSigningPubkey>::amount_msats(
10783
10783
&invoice_request.inner
10784
10784
) {
10785
10785
Ok(amount_msats) => amount_msats,
10786
- Err(error) => return responder.respond( OffersMessage::InvoiceError(error.into())),
10786
+ Err(error) => return Some(( OffersMessage::InvoiceError(error.into()), responder.respond ())),
10787
10787
};
10788
10788
10789
10789
let relative_expiry = DEFAULT_RELATIVE_EXPIRY.as_secs() as u32;
@@ -10793,7 +10793,7 @@ where
10793
10793
Ok((payment_hash, payment_secret)) => (payment_hash, payment_secret),
10794
10794
Err(()) => {
10795
10795
let error = Bolt12SemanticError::InvalidAmount;
10796
- return responder.respond( OffersMessage::InvoiceError(error.into()));
10796
+ return Some(( OffersMessage::InvoiceError(error.into()), responder.respond ()));
10797
10797
},
10798
10798
};
10799
10799
@@ -10807,7 +10807,7 @@ where
10807
10807
Ok(payment_paths) => payment_paths,
10808
10808
Err(()) => {
10809
10809
let error = Bolt12SemanticError::MissingPaths;
10810
- return responder.respond( OffersMessage::InvoiceError(error.into()));
10810
+ return Some(( OffersMessage::InvoiceError(error.into()), responder.respond ()));
10811
10811
},
10812
10812
};
10813
10813
@@ -10852,14 +10852,14 @@ where
10852
10852
};
10853
10853
10854
10854
match response {
10855
- Ok(invoice) => responder.respond( OffersMessage::Invoice(invoice)),
10856
- Err(error) => responder.respond( OffersMessage::InvoiceError(error.into())),
10855
+ Ok(invoice) => Some(( OffersMessage::Invoice(invoice), responder.respond() )),
10856
+ Err(error) => Some(( OffersMessage::InvoiceError(error.into()), responder.respond ())),
10857
10857
}
10858
10858
},
10859
10859
OffersMessage::Invoice(invoice) => {
10860
10860
let payment_id = match self.verify_bolt12_invoice(&invoice, context.as_ref()) {
10861
10861
Ok(payment_id) => payment_id,
10862
- Err(()) => return ResponseInstruction::NoResponse ,
10862
+ Err(()) => return None ,
10863
10863
};
10864
10864
10865
10865
let logger = WithContext::from(
@@ -10871,7 +10871,7 @@ where
10871
10871
payment_id, invoice, context, responder,
10872
10872
};
10873
10873
self.pending_events.lock().unwrap().push_back((event, None));
10874
- return ResponseInstruction::NoResponse ;
10874
+ return None ;
10875
10875
}
10876
10876
10877
10877
let error = match self.send_payment_for_verified_bolt12_invoice(
@@ -10890,26 +10890,26 @@ where
10890
10890
},
10891
10891
Err(Bolt12PaymentError::UnexpectedInvoice)
10892
10892
| Err(Bolt12PaymentError::DuplicateInvoice)
10893
- | Ok(()) => return ResponseInstruction::NoResponse ,
10893
+ | Ok(()) => return None ,
10894
10894
};
10895
10895
10896
10896
match responder {
10897
- Some(responder) => responder.respond( OffersMessage::InvoiceError(error)),
10897
+ Some(responder) => Some(( OffersMessage::InvoiceError(error), responder.respond() )),
10898
10898
None => {
10899
10899
log_trace!(logger, "No reply path to send error: {:?}", error);
10900
- ResponseInstruction::NoResponse
10900
+ None
10901
10901
},
10902
10902
}
10903
10903
},
10904
10904
#[cfg(async_payments)]
10905
10905
OffersMessage::StaticInvoice(_invoice) => {
10906
10906
match responder {
10907
10907
Some(responder) => {
10908
- responder.respond (OffersMessage::InvoiceError(
10909
- InvoiceError::from_string("Static invoices not yet supported".to_string())
10910
- ))
10908
+ return Some( (OffersMessage::InvoiceError(
10909
+ InvoiceError::from_string("Static invoices not yet supported".to_string())
10910
+ ), responder.respond()));
10911
10911
},
10912
- None => return ResponseInstruction::NoResponse ,
10912
+ None => return None ,
10913
10913
}
10914
10914
},
10915
10915
OffersMessage::InvoiceError(invoice_error) => {
@@ -10932,12 +10932,12 @@ where
10932
10932
_ => {},
10933
10933
}
10934
10934
10935
- ResponseInstruction::NoResponse
10935
+ None
10936
10936
},
10937
10937
}
10938
10938
}
10939
10939
10940
- fn release_pending_messages(&self) -> Vec<PendingOnionMessage< OffersMessage> > {
10940
+ fn release_pending_messages(&self) -> Vec<( OffersMessage, MessageSendInstructions) > {
10941
10941
core::mem::take(&mut self.pending_offers_messages.lock().unwrap())
10942
10942
}
10943
10943
}
@@ -10956,13 +10956,13 @@ where
10956
10956
{
10957
10957
fn held_htlc_available(
10958
10958
&self, _message: HeldHtlcAvailable, _responder: Option<Responder>
10959
- ) -> ResponseInstruction< ReleaseHeldHtlc> {
10960
- ResponseInstruction::NoResponse
10959
+ ) -> Option<( ReleaseHeldHtlc, ResponseInstruction) > {
10960
+ None
10961
10961
}
10962
10962
10963
10963
fn release_held_htlc(&self, _message: ReleaseHeldHtlc) {}
10964
10964
10965
- fn release_pending_messages(&self) -> Vec<PendingOnionMessage< AsyncPaymentsMessage> > {
10965
+ fn release_pending_messages(&self) -> Vec<( AsyncPaymentsMessage, MessageSendInstructions) > {
10966
10966
Vec::new()
10967
10967
}
10968
10968
}
0 commit comments