Skip to content

Commit 95446cc

Browse files
committed
fixup! Update ldk-node dependency
Remove redundant payment patterns. Expose incoming and outgoing HTLC amounts while preserving field numbers and the distinction between unknown amounts and zero. AI assistance: OpenAI Codex was used for this change.
1 parent 3aadad5 commit 95446cc

5 files changed

Lines changed: 67 additions & 14 deletions

File tree

ldk-server-grpc/src/proto/types.proto

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,11 @@ message HtlcLocator {
319319
// The node id of the counterparty for this HTLC.
320320
// This can be unset for older serialized events.
321321
optional string node_id = 3;
322+
323+
// The amount in millisatoshis of the HTLC that was sent or received, if known.
324+
// This can be unset for events serialized by LDK Node v0.7.0 and prior,
325+
// or forwarding records stored by LDK Server before this field was added.
326+
optional uint64 amount_msat = 4;
322327
}
323328

324329
// A forwarded payment through our node.

ldk-server-grpc/src/types.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,11 @@ pub struct HtlcLocator {
453453
/// This can be unset for older serialized events.
454454
#[prost(string, optional, tag = "3")]
455455
pub node_id: ::core::option::Option<::prost::alloc::string::String>,
456+
/// The amount in millisatoshis of the HTLC that was sent or received, if known.
457+
/// This can be unset for events serialized by LDK Node v0.7.0 and prior,
458+
/// or forwarding records stored by LDK Server before this field was added.
459+
#[prost(uint64, optional, tag = "4")]
460+
pub amount_msat: ::core::option::Option<u64>,
456461
}
457462
/// A forwarded payment through our node.
458463
///
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// This file is Copyright its original authors, visible in version control
2+
// history.
3+
//
4+
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
5+
// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
7+
// You may not use this file except in accordance with one or both of these
8+
// licenses.
9+
10+
use ldk_server_grpc::types::HtlcLocator;
11+
use prost::Message;
12+
13+
// Encoded with the original schema: channel_id = 1, user_channel_id = 2, node_id = 3.
14+
const LEGACY_LOCATOR: &[u8] = b"\x0a\x07channel\x12\x04user\x1a\x04node";
15+
16+
#[test]
17+
fn legacy_locator_preserves_ids_and_unknown_amount() {
18+
let locator = HtlcLocator::decode(LEGACY_LOCATOR).unwrap();
19+
20+
assert_eq!(locator.channel_id, "channel");
21+
assert_eq!(locator.user_channel_id.as_deref(), Some("user"));
22+
assert_eq!(locator.node_id.as_deref(), Some("node"));
23+
assert_eq!(locator.amount_msat, None);
24+
assert_eq!(locator.encode_to_vec(), LEGACY_LOCATOR);
25+
}
26+
27+
#[test]
28+
fn locator_amount_uses_field_four_and_preserves_zero() {
29+
for amount_msat in [0, 42] {
30+
let mut encoded = LEGACY_LOCATOR.to_vec();
31+
// Field 4 has varint wire type 0. Both test amounts use a single byte.
32+
encoded.extend_from_slice(&[0x20, amount_msat]);
33+
let locator = HtlcLocator::decode(encoded.as_slice()).unwrap();
34+
35+
assert_eq!(locator.channel_id, "channel");
36+
assert_eq!(locator.user_channel_id.as_deref(), Some("user"));
37+
assert_eq!(locator.node_id.as_deref(), Some("node"));
38+
assert_eq!(locator.amount_msat, Some(u64::from(amount_msat)));
39+
assert_eq!(locator.encode_to_vec(), encoded);
40+
}
41+
}

ldk-server/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ fn main() {
599599
channel_id: htlc.channel_id.to_string(),
600600
user_channel_id: htlc.user_channel_id.map(|u| u.0.to_string()),
601601
node_id: htlc.node_id.map(|n| n.to_string()),
602+
amount_msat: htlc.amount_msat,
602603
})
603604
.collect();
604605
let next_htlcs = next_htlcs
@@ -607,6 +608,7 @@ fn main() {
607608
channel_id: htlc.channel_id.to_string(),
608609
user_channel_id: htlc.user_channel_id.map(|u| u.0.to_string()),
609610
node_id: htlc.node_id.map(|n| n.to_string()),
611+
amount_msat: htlc.amount_msat,
610612
})
611613
.collect();
612614

ldk-server/src/util/proto_adapter.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ pub(crate) fn payment_kind_to_proto(
266266
tx_type: tx_type.map(transaction_type_to_proto),
267267
})),
268268
},
269-
PaymentKind::Bolt11 { hash, preimage, secret, counterparty_skimmed_fee_msat, .. } => {
269+
PaymentKind::Bolt11 { hash, preimage, secret, counterparty_skimmed_fee_msat } => {
270270
ldk_server_grpc::types::PaymentKind {
271271
kind: Some(Bolt11(ldk_server_grpc::types::Bolt11 {
272272
hash: hash.to_string(),
@@ -276,19 +276,19 @@ pub(crate) fn payment_kind_to_proto(
276276
})),
277277
}
278278
},
279-
PaymentKind::Bolt12Offer {
280-
hash, preimage, secret, offer_id, payer_note, quantity, ..
281-
} => ldk_server_grpc::types::PaymentKind {
282-
kind: Some(Bolt12Offer(ldk_server_grpc::types::Bolt12Offer {
283-
hash: hash.map(|h| h.to_string()),
284-
preimage: preimage.map(|p| p.to_string()),
285-
secret: secret.map(|s| Bytes::copy_from_slice(&s.0)),
286-
offer_id: offer_id.0.to_lower_hex_string(),
287-
payer_note: payer_note.map(|s| s.to_string()),
288-
quantity,
289-
})),
279+
PaymentKind::Bolt12Offer { hash, preimage, secret, offer_id, payer_note, quantity } => {
280+
ldk_server_grpc::types::PaymentKind {
281+
kind: Some(Bolt12Offer(ldk_server_grpc::types::Bolt12Offer {
282+
hash: hash.map(|h| h.to_string()),
283+
preimage: preimage.map(|p| p.to_string()),
284+
secret: secret.map(|s| Bytes::copy_from_slice(&s.0)),
285+
offer_id: offer_id.0.to_lower_hex_string(),
286+
payer_note: payer_note.map(|s| s.to_string()),
287+
quantity,
288+
})),
289+
}
290290
},
291-
PaymentKind::Bolt12Refund { hash, preimage, secret, payer_note, quantity, .. } => {
291+
PaymentKind::Bolt12Refund { hash, preimage, secret, payer_note, quantity } => {
292292
ldk_server_grpc::types::PaymentKind {
293293
kind: Some(Bolt12Refund(ldk_server_grpc::types::Bolt12Refund {
294294
hash: hash.map(|h| h.to_string()),
@@ -299,7 +299,7 @@ pub(crate) fn payment_kind_to_proto(
299299
})),
300300
}
301301
},
302-
PaymentKind::Spontaneous { hash, preimage, .. } => ldk_server_grpc::types::PaymentKind {
302+
PaymentKind::Spontaneous { hash, preimage } => ldk_server_grpc::types::PaymentKind {
303303
kind: Some(Spontaneous(ldk_server_grpc::types::Spontaneous {
304304
hash: hash.to_string(),
305305
preimage: preimage.map(|p| p.to_string()),

0 commit comments

Comments
 (0)