Skip to content

Commit fd2f3dc

Browse files
authored
Merge pull request #3273 from TheBlueMatt/2024-08-bindings-no-static
Return owned `String`s for onion message message types
2 parents cf2fa9d + feffaf8 commit fd2f3dc

File tree

6 files changed

+62
-10
lines changed

6 files changed

+62
-10
lines changed

ci/ci-tests.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,19 @@ cargo test -p lightning --verbose --color always --no-default-features --feature
8787
cargo test -p lightning --verbose --color always --features no-std
8888

8989
echo -e "\n\nTesting c_bindings builds"
90-
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test --verbose --color always
90+
# Note that because `$RUSTFLAGS` is not passed through to doctest builds we cannot selectively
91+
# disable doctests in `c_bindings` so we skip doctests entirely here.
92+
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test --verbose --color always --lib --bins --tests
9193

9294
for DIR in lightning-invoice lightning-rapid-gossip-sync; do
9395
# check if there is a conflict between no-std and the c_bindings cfg
9496
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p $DIR --verbose --color always --no-default-features
9597
done
9698

9799
# Note that because `$RUSTFLAGS` is not passed through to doctest builds we cannot selectively
98-
# disable tests in `c_bindings` so we skip doctests entirely here.
100+
# disable doctests in `c_bindings` so we skip doctests entirely here.
99101
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning-background-processor --verbose --color always --features futures --no-default-features --lib --bins --tests
100-
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning --verbose --color always --no-default-features --features=no-std
102+
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning --verbose --color always --no-default-features --features=no-std --lib --bins --tests
101103

102104
echo -e "\n\nTesting other crate-specific builds"
103105
# Note that outbound_commitment_test only runs in this mode because of hardcoded signature values

lightning/src/ln/peer_handler.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ impl CustomOnionMessageHandler for IgnoringMessageHandler {
170170

171171
impl OnionMessageContents for Infallible {
172172
fn tlv_type(&self) -> u64 { unreachable!(); }
173+
#[cfg(c_bindings)]
174+
fn msg_type(&self) -> String { unreachable!(); }
175+
#[cfg(not(c_bindings))]
173176
fn msg_type(&self) -> &'static str { unreachable!(); }
174177
}
175178

lightning/src/onion_message/async_payments.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ impl OnionMessageContents for ReleaseHeldHtlc {
7777
fn tlv_type(&self) -> u64 {
7878
RELEASE_HELD_HTLC_TLV_TYPE
7979
}
80+
#[cfg(c_bindings)]
81+
fn msg_type(&self) -> String {
82+
"Release Held HTLC".to_string()
83+
}
84+
#[cfg(not(c_bindings))]
8085
fn msg_type(&self) -> &'static str {
8186
"Release Held HTLC"
8287
}
@@ -107,6 +112,14 @@ impl OnionMessageContents for AsyncPaymentsMessage {
107112
Self::ReleaseHeldHtlc(msg) => msg.tlv_type(),
108113
}
109114
}
115+
#[cfg(c_bindings)]
116+
fn msg_type(&self) -> String {
117+
match &self {
118+
Self::HeldHtlcAvailable(_) => "Held HTLC Available".to_string(),
119+
Self::ReleaseHeldHtlc(msg) => msg.msg_type(),
120+
}
121+
}
122+
#[cfg(not(c_bindings))]
110123
fn msg_type(&self) -> &'static str {
111124
match &self {
112125
Self::HeldHtlcAvailable(_) => "Held HTLC Available",

lightning/src/onion_message/functional_tests.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ impl OnionMessageContents for TestCustomMessage {
108108
TestCustomMessage::Pong => CUSTOM_PONG_MESSAGE_TYPE,
109109
}
110110
}
111+
#[cfg(c_bindings)]
112+
fn msg_type(&self) -> String {
113+
"Custom Message".to_string()
114+
}
115+
#[cfg(not(c_bindings))]
111116
fn msg_type(&self) -> &'static str {
112117
"Custom Message"
113118
}
@@ -656,6 +661,11 @@ fn invalid_custom_message_type() {
656661
// Onion message contents must have a TLV >= 64.
657662
63
658663
}
664+
#[cfg(c_bindings)]
665+
fn msg_type(&self) -> String {
666+
"Invalid Message".to_string()
667+
}
668+
#[cfg(not(c_bindings))]
659669
fn msg_type(&self) -> &'static str {
660670
"Invalid Message"
661671
}

lightning/src/onion_message/offers.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ impl OffersMessage {
9999
_ => Err(Bolt12ParseError::Decode(DecodeError::InvalidValue)),
100100
}
101101
}
102+
103+
fn get_msg_type(&self) -> &'static str {
104+
match &self {
105+
OffersMessage::InvoiceRequest(_) => "Invoice Request",
106+
OffersMessage::Invoice(_) => "Invoice",
107+
#[cfg(async_payments)]
108+
OffersMessage::StaticInvoice(_) => "Static Invoice",
109+
OffersMessage::InvoiceError(_) => "Invoice Error",
110+
}
111+
}
102112
}
103113

104114
impl fmt::Debug for OffersMessage {
@@ -131,14 +141,13 @@ impl OnionMessageContents for OffersMessage {
131141
OffersMessage::InvoiceError(_) => INVOICE_ERROR_TLV_TYPE,
132142
}
133143
}
144+
#[cfg(c_bindings)]
145+
fn msg_type(&self) -> String {
146+
self.get_msg_type().to_string()
147+
}
148+
#[cfg(not(c_bindings))]
134149
fn msg_type(&self) -> &'static str {
135-
match &self {
136-
OffersMessage::InvoiceRequest(_) => "Invoice Request",
137-
OffersMessage::Invoice(_) => "Invoice",
138-
#[cfg(async_payments)]
139-
OffersMessage::StaticInvoice(_) => "Static Invoice",
140-
OffersMessage::InvoiceError(_) => "Invoice Error",
141-
}
150+
self.get_msg_type()
142151
}
143152
}
144153

lightning/src/onion_message/packet.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,16 @@ impl<T: OnionMessageContents> OnionMessageContents for ParsedOnionMessageContent
148148
&ParsedOnionMessageContents::Custom(ref msg) => msg.tlv_type(),
149149
}
150150
}
151+
#[cfg(c_bindings)]
152+
fn msg_type(&self) -> String {
153+
match self {
154+
ParsedOnionMessageContents::Offers(ref msg) => msg.msg_type(),
155+
#[cfg(async_payments)]
156+
ParsedOnionMessageContents::AsyncPayments(ref msg) => msg.msg_type(),
157+
ParsedOnionMessageContents::Custom(ref msg) => msg.msg_type(),
158+
}
159+
}
160+
#[cfg(not(c_bindings))]
151161
fn msg_type(&self) -> &'static str {
152162
match self {
153163
ParsedOnionMessageContents::Offers(ref msg) => msg.msg_type(),
@@ -174,6 +184,11 @@ pub trait OnionMessageContents: Writeable + core::fmt::Debug {
174184
/// Returns the TLV type identifying the message contents. MUST be >= 64.
175185
fn tlv_type(&self) -> u64;
176186

187+
#[cfg(c_bindings)]
188+
/// Returns the message type
189+
fn msg_type(&self) -> String;
190+
191+
#[cfg(not(c_bindings))]
177192
/// Returns the message type
178193
fn msg_type(&self) -> &'static str;
179194
}

0 commit comments

Comments
 (0)