Skip to content

Commit dd8e16d

Browse files
committed
Update rust lightning version to include trampoline changes
1 parent 804f00f commit dd8e16d

File tree

3 files changed

+135
-92
lines changed

3 files changed

+135
-92
lines changed

Cargo.toml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ default = []
3939
#lightning-liquidity = { version = "0.2.0", features = ["std"] }
4040
#lightning-macros = { version = "0.2.0" }
4141

42-
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204", features = ["std"] }
43-
lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204" }
44-
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204", features = ["std"] }
45-
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204" }
46-
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204", features = ["tokio"] }
47-
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204" }
48-
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204" }
49-
lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204", features = ["rest-client", "rpc-client", "tokio"] }
50-
lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
51-
lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204", features = ["std"] }
52-
lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204" }
42+
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "128ead25e8d62b0262b71711631220983c48756a", features = ["std"] }
43+
lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "128ead25e8d62b0262b71711631220983c48756a" }
44+
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "128ead25e8d62b0262b71711631220983c48756a", features = ["std"] }
45+
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "128ead25e8d62b0262b71711631220983c48756a" }
46+
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "128ead25e8d62b0262b71711631220983c48756a", features = ["tokio"] }
47+
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "128ead25e8d62b0262b71711631220983c48756a" }
48+
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "128ead25e8d62b0262b71711631220983c48756a" }
49+
lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "128ead25e8d62b0262b71711631220983c48756a", features = ["rest-client", "rpc-client", "tokio"] }
50+
lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "128ead25e8d62b0262b71711631220983c48756a", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
51+
lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "128ead25e8d62b0262b71711631220983c48756a", features = ["std"] }
52+
lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "128ead25e8d62b0262b71711631220983c48756a" }
5353

5454
bdk_chain = { version = "0.23.0", default-features = false, features = ["std"] }
5555
bdk_esplora = { version = "0.22.0", default-features = false, features = ["async-https-rustls", "tokio"]}
@@ -79,13 +79,13 @@ async-trait = { version = "0.1", default-features = false }
7979
vss-client = { package = "vss-client-ng", version = "0.5" }
8080
prost = { version = "0.11.6", default-features = false}
8181
#bitcoin-payment-instructions = { version = "0.6" }
82-
bitcoin-payment-instructions = { git = "https://github.com/jkczyz/bitcoin-payment-instructions", rev = "0138feb7acefb1e49102a6fb46d7b776bf43265e" }
82+
bitcoin-payment-instructions = { git = "https://github.com/carlaKC/bitcoin-payment-instructions", rev = "c22c9b836b70d4c915dd28701e11083a8b558d56" }
8383

8484
[target.'cfg(windows)'.dependencies]
8585
winapi = { version = "0.3", features = ["winbase"] }
8686

8787
[dev-dependencies]
88-
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204", features = ["std", "_test_utils"] }
88+
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "128ead25e8d62b0262b71711631220983c48756a", features = ["std", "_test_utils"] }
8989
rand = { version = "0.9.2", default-features = false, features = ["std", "thread_rng", "os_rng"] }
9090
proptest = "1.0.0"
9191
regex = "1.5.6"

src/event.rs

Lines changed: 107 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ use lightning::events::bump_transaction::BumpTransactionEvent;
1818
#[cfg(not(feature = "uniffi"))]
1919
use lightning::events::PaidBolt12Invoice;
2020
use lightning::events::{
21-
ClosureReason, Event as LdkEvent, FundingInfo, PaymentFailureReason, PaymentPurpose,
22-
ReplayEvent,
21+
ClosureReason, Event as LdkEvent, FundingInfo, HTLCLocator as LdkHTLCLocator,
22+
PaymentFailureReason, PaymentPurpose, ReplayEvent,
2323
};
24-
use lightning::impl_writeable_tlv_based_enum;
2524
use lightning::ln::channelmanager::PaymentId;
2625
use lightning::ln::types::ChannelId;
2726
use lightning::routing::gossip::NodeId;
@@ -32,6 +31,7 @@ use lightning::util::config::{
3231
use lightning::util::errors::APIError;
3332
use lightning::util::persist::KVStore;
3433
use lightning::util::ser::{Readable, ReadableArgs, Writeable, Writer};
34+
use lightning::{impl_writeable_tlv_based, impl_writeable_tlv_based_enum};
3535
use lightning_liquidity::lsps2::utils::compute_opening_fee;
3636
use lightning_types::payment::{PaymentHash, PaymentPreimage};
3737

@@ -61,6 +61,50 @@ use crate::{
6161
UserChannelId,
6262
};
6363

64+
/// Identifies the channel and counterparty that a HTLC was processed with.
65+
#[derive(Debug, Clone, PartialEq, Eq)]
66+
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
67+
pub struct HTLCLocator {
68+
/// The channel that the HTLC was sent or received on.
69+
pub channel_id: ChannelId,
70+
/// The `user_channel_id` for the channel.
71+
///
72+
/// Will only be `None` for events serialized with LDK Node v0.3.0 or prior, or if the
73+
/// payment was settled via an on-chain transaction.
74+
pub user_channel_id: Option<UserChannelId>,
75+
/// The node id of the counterparty for this HTLC.
76+
///
77+
/// This is only `None` for HTLCs received prior to LDK Node v0.5 or for events serialized by
78+
/// versions prior to v0.5.
79+
pub node_id: Option<PublicKey>,
80+
}
81+
82+
impl_writeable_tlv_based!(HTLCLocator, {
83+
(1, channel_id, required),
84+
(3, user_channel_id, option),
85+
(5, node_id, option),
86+
});
87+
88+
impl From<LdkHTLCLocator> for HTLCLocator {
89+
fn from(value: LdkHTLCLocator) -> Self {
90+
HTLCLocator {
91+
channel_id: value.channel_id,
92+
user_channel_id: value.user_channel_id.map(|u| UserChannelId(u)),
93+
node_id: value.node_id,
94+
}
95+
}
96+
}
97+
98+
impl From<HTLCLocator> for LdkHTLCLocator {
99+
fn from(value: HTLCLocator) -> Self {
100+
LdkHTLCLocator {
101+
channel_id: value.channel_id,
102+
user_channel_id: value.user_channel_id.map(|u| u.0),
103+
node_id: value.node_id,
104+
}
105+
}
106+
}
107+
64108
/// An event emitted by [`Node`], which should be handled by the user.
65109
///
66110
/// [`Node`]: [`crate::Node`]
@@ -128,29 +172,14 @@ pub enum Event {
128172
},
129173
/// A payment has been forwarded.
130174
PaymentForwarded {
131-
/// The channel id of the incoming channel between the previous node and us.
132-
prev_channel_id: ChannelId,
133-
/// The channel id of the outgoing channel between the next node and us.
134-
next_channel_id: ChannelId,
135-
/// The `user_channel_id` of the incoming channel between the previous node and us.
136-
///
137-
/// Will only be `None` for events serialized with LDK Node v0.3.0 or prior.
138-
prev_user_channel_id: Option<UserChannelId>,
139-
/// The `user_channel_id` of the outgoing channel between the next node and us.
140-
///
141-
/// This will be `None` if the payment was settled via an on-chain transaction. See the
142-
/// caveat described for the `total_fee_earned_msat` field.
143-
next_user_channel_id: Option<UserChannelId>,
144-
/// The node id of the previous node.
145-
///
146-
/// This is only `None` for HTLCs received prior to LDK Node v0.5 or for events serialized by
147-
/// versions prior to v0.5.
148-
prev_node_id: Option<PublicKey>,
149-
/// The node id of the next node.
150-
///
151-
/// This is only `None` for HTLCs received prior to LDK Node v0.5 or for events serialized by
152-
/// versions prior to v0.5.
153-
next_node_id: Option<PublicKey>,
175+
/// The set of incoming HTLCs that were forwarded to our node. Contains a single HTLC for
176+
/// source-routed payments, and may contain multiple HTLCs when we acted as a trampoline
177+
/// router.
178+
prev_htlcs: Vec<HTLCLocator>,
179+
/// The set of outgoing HTLCs forwarded by our node. Contains a single HTLC for regular
180+
/// source-routed payments, and may contain multiple HTLCs when we acted as a trampoline
181+
/// router.
182+
next_htlcs: Vec<HTLCLocator>,
154183
/// The total fee, in milli-satoshis, which was earned as a result of the payment.
155184
///
156185
/// Note that if we force-closed the channel over which we forwarded an HTLC while the HTLC
@@ -323,16 +352,31 @@ impl_writeable_tlv_based_enum!(Event,
323352
(7, custom_records, optional_vec),
324353
},
325354
(7, PaymentForwarded) => {
326-
(0, prev_channel_id, required),
327-
(1, prev_node_id, option),
328-
(2, next_channel_id, required),
329-
(3, next_node_id, option),
330-
(4, prev_user_channel_id, option),
331-
(6, next_user_channel_id, option),
355+
// We don't write our legacy types because we don't need to support downgrades, but we do
356+
// read them so that we can forwards compatibly fill prev/next_htlcs on upgrade.
357+
(0, legacy_prev_channel_id, (legacy, ChannelId, |_| Ok(()), |_: &Event| None::<Option<ChannelId>>)),
358+
(1, legacy_prev_node_id, (legacy, PublicKey, |_| Ok(()), |_: &Event| None::<Option<PublicKey>>)),
359+
(2, legacy_next_channel_id, (legacy, ChannelId, |_| Ok(()), |_: &Event| None::<Option<ChannelId>>)),
360+
(3, legacy_next_node_id, (legacy, PublicKey, |_| Ok(()), |_: &Event| None::<Option<PublicKey>>)),
361+
(4, legacy_prev_user_channel_id, (legacy, u128, |_| Ok(()), |_: &Event| None::<Option<u128>>)),
362+
(6, legacy_next_user_channel_id, (legacy, u128, |_| Ok(()), |_: &Event| None::<Option<u128>>)),
332363
(8, total_fee_earned_msat, option),
333364
(10, skimmed_fee_msat, option),
334365
(12, claim_from_onchain_tx, required),
335366
(14, outbound_amount_forwarded_msat, option),
367+
// We cannot implement Readable/Writeable for Vec<HTLCLocator> because we do not own the
368+
// trait or the type (Vec). To work around this, and prevent duplicating serialization code,
369+
// we map to the underlying LdkHTLCLocator type for serialization.
370+
(15, prev_htlcs, (default_value_vec, vec![HTLCLocator {
371+
channel_id: legacy_prev_channel_id.ok_or(DecodeError::InvalidValue)?,
372+
user_channel_id: legacy_prev_user_channel_id.map(|v| UserChannelId(v)),
373+
node_id: legacy_prev_node_id,
374+
}])),
375+
(17, next_htlcs, (default_value_vec, vec![HTLCLocator {
376+
channel_id: legacy_next_channel_id.ok_or(DecodeError::InvalidValue)?,
377+
user_channel_id: legacy_next_user_channel_id.map(|v| UserChannelId(v)),
378+
node_id: legacy_next_node_id,
379+
}])),
336380
},
337381
(8, SplicePending) => {
338382
(1, channel_id, required),
@@ -644,7 +688,8 @@ where
644688
)
645689
.unwrap_or_else(|e| {
646690
log_error!(self.logger, "Failed to force close channel after funding generation failed: {:?}", e);
647-
debug_assert!(false,
691+
debug_assert!(
692+
false,
648693
"Failed to force close channel after funding generation failed"
649694
);
650695
});
@@ -1306,12 +1351,8 @@ where
13061351
}
13071352
},
13081353
LdkEvent::PaymentForwarded {
1309-
prev_channel_id,
1310-
next_channel_id,
1311-
prev_user_channel_id,
1312-
next_user_channel_id,
1313-
prev_node_id,
1314-
next_node_id,
1354+
prev_htlcs,
1355+
next_htlcs,
13151356
total_fee_earned_msat,
13161357
skimmed_fee_msat,
13171358
claim_from_onchain_tx,
@@ -1322,11 +1363,10 @@ where
13221363
let nodes = read_only_network_graph.nodes();
13231364
let channels = self.channel_manager.list_channels();
13241365

1325-
let node_str = |channel_id: &Option<ChannelId>| {
1326-
channel_id
1327-
.and_then(|channel_id| {
1328-
channels.iter().find(|c| c.channel_id == channel_id)
1329-
})
1366+
let node_str = |channel_id: &ChannelId| {
1367+
channels
1368+
.iter()
1369+
.find(|c| c.channel_id == *channel_id)
13301370
.and_then(|channel| {
13311371
nodes.get(&NodeId::from_pubkey(&channel.counterparty.node_id))
13321372
})
@@ -1338,21 +1378,21 @@ where
13381378
})
13391379
})
13401380
};
1341-
let channel_str = |channel_id: &Option<ChannelId>| {
1342-
channel_id
1343-
.map(|channel_id| format!(" with channel {}", channel_id))
1344-
.unwrap_or_default()
1345-
};
1346-
let from_prev_str = format!(
1347-
" from {}{}",
1348-
node_str(&prev_channel_id),
1349-
channel_str(&prev_channel_id)
1350-
);
1351-
let to_next_str = format!(
1352-
" to {}{}",
1353-
node_str(&next_channel_id),
1354-
channel_str(&next_channel_id)
1355-
);
1381+
let from_prev_str: String = prev_htlcs
1382+
.iter()
1383+
.map(|htlc| {
1384+
format!("with {} on {}", node_str(&htlc.channel_id), htlc.channel_id)
1385+
})
1386+
.collect::<Vec<_>>()
1387+
.join(", ");
1388+
1389+
let to_next_str: String = next_htlcs
1390+
.iter()
1391+
.map(|htlc| {
1392+
format!("with {} on {}", node_str(&htlc.channel_id), htlc.channel_id)
1393+
})
1394+
.collect::<Vec<_>>()
1395+
.join(", ");
13561396

13571397
let fee_earned = total_fee_earned_msat.unwrap_or(0);
13581398
if claim_from_onchain_tx {
@@ -1367,8 +1407,10 @@ where
13671407
} else {
13681408
log_info!(
13691409
self.logger,
1370-
"Forwarded payment{}{} of {}msat, earning {}msat in fees.",
1410+
"Forwarded payment with {} inbound HTLC(s) ({}) and {} outbound HTLC(s) ({}) of {}msat, earning {}msat in fees.",
1411+
prev_htlcs.len(),
13711412
from_prev_str,
1413+
next_htlcs.len(),
13721414
to_next_str,
13731415
outbound_amount_forwarded_msat.unwrap_or(0),
13741416
fee_earned,
@@ -1378,18 +1420,16 @@ where
13781420

13791421
if let Some(liquidity_source) = self.liquidity_source.as_ref() {
13801422
let skimmed_fee_msat = skimmed_fee_msat.unwrap_or(0);
1423+
let next_channel_ids: Vec<ChannelId> =
1424+
next_htlcs.iter().map(|htlc| htlc.channel_id).collect();
13811425
liquidity_source
1382-
.handle_payment_forwarded(next_channel_id, skimmed_fee_msat)
1426+
.handle_payment_forwarded(&next_channel_ids, skimmed_fee_msat)
13831427
.await;
13841428
}
13851429

13861430
let event = Event::PaymentForwarded {
1387-
prev_channel_id: prev_channel_id.expect("prev_channel_id expected for events generated by LDK versions greater than 0.0.107."),
1388-
next_channel_id: next_channel_id.expect("next_channel_id expected for events generated by LDK versions greater than 0.0.107."),
1389-
prev_user_channel_id: prev_user_channel_id.map(UserChannelId),
1390-
next_user_channel_id: next_user_channel_id.map(UserChannelId),
1391-
prev_node_id,
1392-
next_node_id,
1431+
prev_htlcs: prev_htlcs.into_iter().map(|h| h.into()).collect(),
1432+
next_htlcs: next_htlcs.into_iter().map(|h| h.into()).collect(),
13931433
total_fee_earned_msat,
13941434
skimmed_fee_msat,
13951435
claim_from_onchain_tx,

src/liquidity.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,19 +1386,22 @@ where
13861386
}
13871387

13881388
pub(crate) async fn handle_payment_forwarded(
1389-
&self, next_channel_id: Option<ChannelId>, skimmed_fee_msat: u64,
1389+
&self, next_channel_ids: &[ChannelId], skimmed_fee_msat: u64,
13901390
) {
1391-
if let Some(next_channel_id) = next_channel_id {
1392-
if let Some(lsps2_service_handler) = self.liquidity_manager.lsps2_service_handler() {
1393-
if let Err(e) =
1394-
lsps2_service_handler.payment_forwarded(next_channel_id, skimmed_fee_msat).await
1395-
{
1396-
log_error!(
1397-
self.logger,
1398-
"LSPS2 service failed to handle PaymentForwarded: {:?}",
1399-
e
1400-
);
1401-
}
1391+
if next_channel_ids.len() != 1 {
1392+
log_error!(
1393+
self.logger,
1394+
"Expected exactly one next channel for LSPS2 payment forwarded, got {}",
1395+
next_channel_ids.len()
1396+
);
1397+
return;
1398+
}
1399+
1400+
if let Some(lsps2_service_handler) = self.liquidity_manager.lsps2_service_handler() {
1401+
if let Err(e) =
1402+
lsps2_service_handler.payment_forwarded(next_channel_ids[0], skimmed_fee_msat).await
1403+
{
1404+
log_error!(self.logger, "LSPS2 service failed to handle PaymentForwarded: {:?}", e);
14021405
}
14031406
}
14041407
}

0 commit comments

Comments
 (0)