Skip to content

Commit 49dfa5a

Browse files
authored
Merge pull request #3263 from TheBlueMatt/2024-08-bindings-om
Remove message type bound on `ResponseInstruction`
2 parents 0d7ae86 + 47b527a commit 49dfa5a

File tree

8 files changed

+274
-307
lines changed

8 files changed

+274
-307
lines changed

fuzz/src/onion_message.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use lightning::onion_message::async_payments::{
1616
AsyncPaymentsMessageHandler, HeldHtlcAvailable, ReleaseHeldHtlc,
1717
};
1818
use lightning::onion_message::messenger::{
19-
CustomOnionMessageHandler, Destination, MessageRouter, OnionMessagePath, OnionMessenger,
20-
PendingOnionMessage, Responder, ResponseInstruction,
19+
CustomOnionMessageHandler, Destination, MessageRouter, MessageSendInstructions,
20+
OnionMessagePath, OnionMessenger, Responder, ResponseInstruction,
2121
};
2222
use lightning::onion_message::offers::{OffersMessage, OffersMessageHandler};
2323
use lightning::onion_message::packet::OnionMessageContents;
@@ -109,8 +109,8 @@ impl OffersMessageHandler for TestOffersMessageHandler {
109109
fn handle_message(
110110
&self, _message: OffersMessage, _context: Option<OffersContext>,
111111
_responder: Option<Responder>,
112-
) -> ResponseInstruction<OffersMessage> {
113-
ResponseInstruction::NoResponse
112+
) -> Option<(OffersMessage, ResponseInstruction)> {
113+
None
114114
}
115115
}
116116

@@ -119,13 +119,15 @@ struct TestAsyncPaymentsMessageHandler {}
119119
impl AsyncPaymentsMessageHandler for TestAsyncPaymentsMessageHandler {
120120
fn held_htlc_available(
121121
&self, message: HeldHtlcAvailable, responder: Option<Responder>,
122-
) -> ResponseInstruction<ReleaseHeldHtlc> {
122+
) -> Option<(ReleaseHeldHtlc, ResponseInstruction)> {
123123
let responder = match responder {
124124
Some(resp) => resp,
125-
None => return ResponseInstruction::NoResponse,
125+
None => return None,
126126
};
127-
responder
128-
.respond(ReleaseHeldHtlc { payment_release_secret: message.payment_release_secret })
127+
Some((
128+
ReleaseHeldHtlc { payment_release_secret: message.payment_release_secret },
129+
responder.respond(),
130+
))
129131
}
130132
fn release_held_htlc(&self, _message: ReleaseHeldHtlc) {}
131133
}
@@ -158,10 +160,10 @@ impl CustomOnionMessageHandler for TestCustomMessageHandler {
158160
fn handle_custom_message(
159161
&self, message: Self::CustomMessage, _context: Option<Vec<u8>>,
160162
responder: Option<Responder>,
161-
) -> ResponseInstruction<Self::CustomMessage> {
163+
) -> Option<(Self::CustomMessage, ResponseInstruction)> {
162164
match responder {
163-
Some(responder) => responder.respond(message),
164-
None => ResponseInstruction::NoResponse,
165+
Some(responder) => Some((message, responder.respond())),
166+
None => None,
165167
}
166168
}
167169
fn read_custom_message<R: io::Read>(
@@ -171,7 +173,7 @@ impl CustomOnionMessageHandler for TestCustomMessageHandler {
171173
buffer.read_to_limit(&mut buf, u64::MAX)?;
172174
return Ok(Some(TestCustomMessage {}));
173175
}
174-
fn release_pending_custom_messages(&self) -> Vec<PendingOnionMessage<Self::CustomMessage>> {
176+
fn release_pending_custom_messages(&self) -> Vec<(TestCustomMessage, MessageSendInstructions)> {
175177
vec![]
176178
}
177179
}

lightning/src/ln/channelmanager.rs

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ use crate::offers::parse::Bolt12SemanticError;
7171
use crate::offers::refund::{Refund, RefundBuilder};
7272
use crate::offers::signer;
7373
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};
7575
use crate::onion_message::offers::{OffersMessage, OffersMessageHandler};
7676
use crate::sign::{EntropySource, NodeSigner, Recipient, SignerProvider};
7777
use crate::sign::ecdsa::EcdsaChannelSigner;
@@ -2277,9 +2277,9 @@ where
22772277
needs_persist_flag: AtomicBool,
22782278

22792279
#[cfg(not(any(test, feature = "_test_utils")))]
2280-
pending_offers_messages: Mutex<Vec<PendingOnionMessage<OffersMessage>>>,
2280+
pending_offers_messages: Mutex<Vec<(OffersMessage, MessageSendInstructions)>>,
22812281
#[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)>>,
22832283

22842284
/// Tracks the message events that are to be broadcasted when we are connected to some peer.
22852285
pending_broadcast_messages: Mutex<Vec<MessageSendEvent>>,
@@ -9068,21 +9068,21 @@ where
90689068
.flat_map(|reply_path| offer.paths().iter().map(move |path| (path, reply_path)))
90699069
.take(OFFERS_MESSAGE_REQUEST_LIMIT)
90709070
.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));
90779077
});
90789078
} else if let Some(signing_pubkey) = offer.signing_pubkey() {
90799079
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));
90869086
}
90879087
} else {
90889088
debug_assert!(false);
@@ -9162,25 +9162,25 @@ where
91629162
let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
91639163
if refund.paths().is_empty() {
91649164
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));
91719171
}
91729172
} else {
91739173
reply_paths
91749174
.iter()
91759175
.flat_map(|reply_path| refund.paths().iter().map(move |path| (path, reply_path)))
91769176
.take(OFFERS_MESSAGE_REQUEST_LIMIT)
91779177
.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));
91849184
});
91859185
}
91869186

@@ -10749,41 +10749,41 @@ where
1074910749
{
1075010750
fn handle_message(
1075110751
&self, message: OffersMessage, context: Option<OffersContext>, responder: Option<Responder>,
10752-
) -> ResponseInstruction<OffersMessage> {
10752+
) -> Option<(OffersMessage, ResponseInstruction)> {
1075310753
let secp_ctx = &self.secp_ctx;
1075410754
let expanded_key = &self.inbound_payment_key;
1075510755

1075610756
match message {
1075710757
OffersMessage::InvoiceRequest(invoice_request) => {
1075810758
let responder = match responder {
1075910759
Some(responder) => responder,
10760-
None => return ResponseInstruction::NoResponse,
10760+
None => return None,
1076110761
};
1076210762

1076310763
let nonce = match context {
1076410764
None if invoice_request.metadata().is_some() => None,
1076510765
Some(OffersContext::InvoiceRequest { nonce }) => Some(nonce),
10766-
_ => return ResponseInstruction::NoResponse,
10766+
_ => return None,
1076710767
};
1076810768

1076910769
let invoice_request = match nonce {
1077010770
Some(nonce) => match invoice_request.verify_using_recipient_data(
1077110771
nonce, expanded_key, secp_ctx,
1077210772
) {
1077310773
Ok(invoice_request) => invoice_request,
10774-
Err(()) => return ResponseInstruction::NoResponse,
10774+
Err(()) => return None,
1077510775
},
1077610776
None => match invoice_request.verify_using_metadata(expanded_key, secp_ctx) {
1077710777
Ok(invoice_request) => invoice_request,
10778-
Err(()) => return ResponseInstruction::NoResponse,
10778+
Err(()) => return None,
1077910779
},
1078010780
};
1078110781

1078210782
let amount_msats = match InvoiceBuilder::<DerivedSigningPubkey>::amount_msats(
1078310783
&invoice_request.inner
1078410784
) {
1078510785
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())),
1078710787
};
1078810788

1078910789
let relative_expiry = DEFAULT_RELATIVE_EXPIRY.as_secs() as u32;
@@ -10793,7 +10793,7 @@ where
1079310793
Ok((payment_hash, payment_secret)) => (payment_hash, payment_secret),
1079410794
Err(()) => {
1079510795
let error = Bolt12SemanticError::InvalidAmount;
10796-
return responder.respond(OffersMessage::InvoiceError(error.into()));
10796+
return Some((OffersMessage::InvoiceError(error.into()), responder.respond()));
1079710797
},
1079810798
};
1079910799

@@ -10807,7 +10807,7 @@ where
1080710807
Ok(payment_paths) => payment_paths,
1080810808
Err(()) => {
1080910809
let error = Bolt12SemanticError::MissingPaths;
10810-
return responder.respond(OffersMessage::InvoiceError(error.into()));
10810+
return Some((OffersMessage::InvoiceError(error.into()), responder.respond()));
1081110811
},
1081210812
};
1081310813

@@ -10852,14 +10852,14 @@ where
1085210852
};
1085310853

1085410854
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())),
1085710857
}
1085810858
},
1085910859
OffersMessage::Invoice(invoice) => {
1086010860
let payment_id = match self.verify_bolt12_invoice(&invoice, context.as_ref()) {
1086110861
Ok(payment_id) => payment_id,
10862-
Err(()) => return ResponseInstruction::NoResponse,
10862+
Err(()) => return None,
1086310863
};
1086410864

1086510865
let logger = WithContext::from(
@@ -10871,7 +10871,7 @@ where
1087110871
payment_id, invoice, context, responder,
1087210872
};
1087310873
self.pending_events.lock().unwrap().push_back((event, None));
10874-
return ResponseInstruction::NoResponse;
10874+
return None;
1087510875
}
1087610876

1087710877
let error = match self.send_payment_for_verified_bolt12_invoice(
@@ -10890,26 +10890,26 @@ where
1089010890
},
1089110891
Err(Bolt12PaymentError::UnexpectedInvoice)
1089210892
| Err(Bolt12PaymentError::DuplicateInvoice)
10893-
| Ok(()) => return ResponseInstruction::NoResponse,
10893+
| Ok(()) => return None,
1089410894
};
1089510895

1089610896
match responder {
10897-
Some(responder) => responder.respond(OffersMessage::InvoiceError(error)),
10897+
Some(responder) => Some((OffersMessage::InvoiceError(error), responder.respond())),
1089810898
None => {
1089910899
log_trace!(logger, "No reply path to send error: {:?}", error);
10900-
ResponseInstruction::NoResponse
10900+
None
1090110901
},
1090210902
}
1090310903
},
1090410904
#[cfg(async_payments)]
1090510905
OffersMessage::StaticInvoice(_invoice) => {
1090610906
match responder {
1090710907
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()));
1091110911
},
10912-
None => return ResponseInstruction::NoResponse,
10912+
None => return None,
1091310913
}
1091410914
},
1091510915
OffersMessage::InvoiceError(invoice_error) => {
@@ -10932,12 +10932,12 @@ where
1093210932
_ => {},
1093310933
}
1093410934

10935-
ResponseInstruction::NoResponse
10935+
None
1093610936
},
1093710937
}
1093810938
}
1093910939

10940-
fn release_pending_messages(&self) -> Vec<PendingOnionMessage<OffersMessage>> {
10940+
fn release_pending_messages(&self) -> Vec<(OffersMessage, MessageSendInstructions)> {
1094110941
core::mem::take(&mut self.pending_offers_messages.lock().unwrap())
1094210942
}
1094310943
}
@@ -10956,13 +10956,13 @@ where
1095610956
{
1095710957
fn held_htlc_available(
1095810958
&self, _message: HeldHtlcAvailable, _responder: Option<Responder>
10959-
) -> ResponseInstruction<ReleaseHeldHtlc> {
10960-
ResponseInstruction::NoResponse
10959+
) -> Option<(ReleaseHeldHtlc, ResponseInstruction)> {
10960+
None
1096110961
}
1096210962

1096310963
fn release_held_htlc(&self, _message: ReleaseHeldHtlc) {}
1096410964

10965-
fn release_pending_messages(&self) -> Vec<PendingOnionMessage<AsyncPaymentsMessage>> {
10965+
fn release_pending_messages(&self) -> Vec<(AsyncPaymentsMessage, MessageSendInstructions)> {
1096610966
Vec::new()
1096710967
}
1096810968
}

0 commit comments

Comments
 (0)