Skip to content

Commit d0795d8

Browse files
authored
Merge pull request #2679 from TheBlueMatt/2023-10-116-bindings-1
Small bindings tweaks for 0.0.118
2 parents 3f416bc + 35eb38d commit d0795d8

File tree

5 files changed

+64
-24
lines changed

5 files changed

+64
-24
lines changed

ci/ci-tests.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ popd
100100

101101
echo -e "\n\nTesting no-std flags in various combinations"
102102
for DIR in lightning lightning-invoice lightning-rapid-gossip-sync; do
103-
cargo test -p $DIR --verbose --color always --no-default-features --features no-std
103+
[ "$RUSTC_MINOR_VERSION" -gt 50 ] && cargo test -p $DIR --verbose --color always --no-default-features --features no-std
104104
# check if there is a conflict between no-std and the default std feature
105-
cargo test -p $DIR --verbose --color always --features no-std
105+
[ "$RUSTC_MINOR_VERSION" -gt 50 ] && cargo test -p $DIR --verbose --color always --features no-std
106106
done
107107
for DIR in lightning lightning-invoice lightning-rapid-gossip-sync; do
108108
# check if there is a conflict between no-std and the c_bindings cfg
109-
RUSTFLAGS="--cfg=c_bindings" cargo test -p $DIR --verbose --color always --no-default-features --features=no-std
109+
[ "$RUSTC_MINOR_VERSION" -gt 50 ] && RUSTFLAGS="--cfg=c_bindings" cargo test -p $DIR --verbose --color always --no-default-features --features=no-std
110110
done
111111
RUSTFLAGS="--cfg=c_bindings" cargo test --verbose --color always
112112

lightning/src/ln/channelmanager.rs

+21-21
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ use crate::offers::merkle::SignError;
6363
use crate::offers::offer::{DerivedMetadata, Offer, OfferBuilder};
6464
use crate::offers::parse::Bolt12SemanticError;
6565
use crate::offers::refund::{Refund, RefundBuilder};
66-
use crate::onion_message::{Destination, OffersMessage, OffersMessageHandler, PendingOnionMessage};
66+
use crate::onion_message::{Destination, OffersMessage, OffersMessageHandler, PendingOnionMessage, new_pending_onion_message};
6767
use crate::sign::{EntropySource, KeysManager, NodeSigner, Recipient, SignerProvider, WriteableEcdsaChannelSigner};
6868
use crate::util::config::{UserConfig, ChannelConfig, ChannelConfigUpdate};
6969
use crate::util::wakers::{Future, Notifier};
@@ -7505,23 +7505,23 @@ where
75057505

75067506
let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
75077507
if offer.paths().is_empty() {
7508-
let message = PendingOnionMessage {
7509-
contents: OffersMessage::InvoiceRequest(invoice_request),
7510-
destination: Destination::Node(offer.signing_pubkey()),
7511-
reply_path: Some(reply_path),
7512-
};
7508+
let message = new_pending_onion_message(
7509+
OffersMessage::InvoiceRequest(invoice_request),
7510+
Destination::Node(offer.signing_pubkey()),
7511+
Some(reply_path),
7512+
);
75137513
pending_offers_messages.push(message);
75147514
} else {
75157515
// Send as many invoice requests as there are paths in the offer (with an upper bound).
75167516
// Using only one path could result in a failure if the path no longer exists. But only
75177517
// one invoice for a given payment id will be paid, even if more than one is received.
75187518
const REQUEST_LIMIT: usize = 10;
75197519
for path in offer.paths().into_iter().take(REQUEST_LIMIT) {
7520-
let message = PendingOnionMessage {
7521-
contents: OffersMessage::InvoiceRequest(invoice_request.clone()),
7522-
destination: Destination::BlindedPath(path.clone()),
7523-
reply_path: Some(reply_path.clone()),
7524-
};
7520+
let message = new_pending_onion_message(
7521+
OffersMessage::InvoiceRequest(invoice_request.clone()),
7522+
Destination::BlindedPath(path.clone()),
7523+
Some(reply_path.clone()),
7524+
);
75257525
pending_offers_messages.push(message);
75267526
}
75277527
}
@@ -7574,19 +7574,19 @@ where
75747574

75757575
let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
75767576
if refund.paths().is_empty() {
7577-
let message = PendingOnionMessage {
7578-
contents: OffersMessage::Invoice(invoice),
7579-
destination: Destination::Node(refund.payer_id()),
7580-
reply_path: Some(reply_path),
7581-
};
7577+
let message = new_pending_onion_message(
7578+
OffersMessage::Invoice(invoice),
7579+
Destination::Node(refund.payer_id()),
7580+
Some(reply_path),
7581+
);
75827582
pending_offers_messages.push(message);
75837583
} else {
75847584
for path in refund.paths() {
7585-
let message = PendingOnionMessage {
7586-
contents: OffersMessage::Invoice(invoice.clone()),
7587-
destination: Destination::BlindedPath(path.clone()),
7588-
reply_path: Some(reply_path.clone()),
7589-
};
7585+
let message = new_pending_onion_message(
7586+
OffersMessage::Invoice(invoice.clone()),
7587+
Destination::BlindedPath(path.clone()),
7588+
Some(reply_path.clone()),
7589+
);
75907590
pending_offers_messages.push(message);
75917591
}
75927592
}

lightning/src/onion_message/messenger.rs

+31
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ where
159159
///
160160
/// These are obtained when released from [`OnionMessenger`]'s handlers after which they are
161161
/// enqueued for sending.
162+
#[cfg(not(c_bindings))]
162163
pub struct PendingOnionMessage<T: OnionMessageContents> {
163164
/// The message contents to send in an [`OnionMessage`].
164165
pub contents: T,
@@ -170,6 +171,22 @@ pub struct PendingOnionMessage<T: OnionMessageContents> {
170171
pub reply_path: Option<BlindedPath>,
171172
}
172173

174+
#[cfg(c_bindings)]
175+
/// An [`OnionMessage`] for [`OnionMessenger`] to send.
176+
///
177+
/// These are obtained when released from [`OnionMessenger`]'s handlers after which they are
178+
/// enqueued for sending.
179+
pub type PendingOnionMessage<T: OnionMessageContents> = (T, Destination, Option<BlindedPath>);
180+
181+
pub(crate) fn new_pending_onion_message<T: OnionMessageContents>(
182+
contents: T, destination: Destination, reply_path: Option<BlindedPath>
183+
) -> PendingOnionMessage<T> {
184+
#[cfg(not(c_bindings))]
185+
return PendingOnionMessage { contents, destination, reply_path };
186+
#[cfg(c_bindings)]
187+
return (contents, destination, reply_path);
188+
}
189+
173190
/// A trait defining behavior for routing an [`OnionMessage`].
174191
pub trait MessageRouter {
175192
/// Returns a route for sending an [`OnionMessage`] to the given [`Destination`].
@@ -286,7 +303,15 @@ pub trait CustomOnionMessageHandler {
286303
///
287304
/// Typically, this is used for messages initiating a message flow rather than in response to
288305
/// another message. The latter should use the return value of [`Self::handle_custom_message`].
306+
#[cfg(not(c_bindings))]
289307
fn release_pending_custom_messages(&self) -> Vec<PendingOnionMessage<Self::CustomMessage>>;
308+
309+
/// Releases any [`Self::CustomMessage`]s that need to be sent.
310+
///
311+
/// Typically, this is used for messages initiating a message flow rather than in response to
312+
/// another message. The latter should use the return value of [`Self::handle_custom_message`].
313+
#[cfg(c_bindings)]
314+
fn release_pending_custom_messages(&self) -> Vec<(Self::CustomMessage, Destination, Option<BlindedPath>)>;
290315
}
291316

292317
/// A processed incoming onion message, containing either a Forward (another onion message)
@@ -686,15 +711,21 @@ where
686711
fn next_onion_message_for_peer(&self, peer_node_id: PublicKey) -> Option<OnionMessage> {
687712
// Enqueue any initiating `OffersMessage`s to send.
688713
for message in self.offers_handler.release_pending_messages() {
714+
#[cfg(not(c_bindings))]
689715
let PendingOnionMessage { contents, destination, reply_path } = message;
716+
#[cfg(c_bindings)]
717+
let (contents, destination, reply_path) = message;
690718
self.find_path_and_enqueue_onion_message(
691719
contents, destination, reply_path, format_args!("when sending OffersMessage")
692720
);
693721
}
694722

695723
// Enqueue any initiating `CustomMessage`s to send.
696724
for message in self.custom_handler.release_pending_custom_messages() {
725+
#[cfg(not(c_bindings))]
697726
let PendingOnionMessage { contents, destination, reply_path } = message;
727+
#[cfg(c_bindings)]
728+
let (contents, destination, reply_path) = message;
698729
self.find_path_and_enqueue_onion_message(
699730
contents, destination, reply_path, format_args!("when sending CustomMessage")
700731
);

lightning/src/onion_message/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ pub use self::messenger::{SimpleArcOnionMessenger, SimpleRefOnionMessenger};
3333
pub use self::offers::{OffersMessage, OffersMessageHandler};
3434
pub use self::packet::{Packet, ParsedOnionMessageContents};
3535
pub(crate) use self::packet::ControlTlvs;
36+
pub(crate) use self::messenger::new_pending_onion_message;

lightning/src/onion_message/offers.rs

+8
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,15 @@ pub trait OffersMessageHandler {
4444
///
4545
/// Typically, this is used for messages initiating a payment flow rather than in response to
4646
/// another message. The latter should use the return value of [`Self::handle_message`].
47+
#[cfg(not(c_bindings))]
4748
fn release_pending_messages(&self) -> Vec<PendingOnionMessage<OffersMessage>> { vec![] }
49+
50+
/// Releases any [`OffersMessage`]s that need to be sent.
51+
///
52+
/// Typically, this is used for messages initiating a payment flow rather than in response to
53+
/// another message. The latter should use the return value of [`Self::handle_message`].
54+
#[cfg(c_bindings)]
55+
fn release_pending_messages(&self) -> Vec<(OffersMessage, crate::onion_message::Destination, Option<crate::blinded_path::BlindedPath>)> { vec![] }
4856
}
4957

5058
/// Possible BOLT 12 Offers messages sent and received via an [`OnionMessage`].

0 commit comments

Comments
 (0)