Skip to content

Commit ffe7497

Browse files
committed
[blocked-4507]: Update rust-lightning to use default_value_vec
Update to be able to write vectors of HTLCLocator for PaymentForwarded. Note that we still don't expect to receive multiple outgoing HTLCs because trampoline has not yet been enabled, but we lay the groundwork here.
1 parent bf7713d commit ffe7497

File tree

2 files changed

+76
-53
lines changed

2 files changed

+76
-53
lines changed

Cargo.toml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,15 @@ harness = false
172172
#vss-client-ng = { path = "../vss-client" }
173173
#vss-client-ng = { git = "https://github.com/lightningdevkit/vss-client", branch = "main" }
174174
#
175-
#[patch."https://github.com/lightningdevkit/rust-lightning"]
176-
#lightning = { path = "../rust-lightning/lightning" }
177-
#lightning-types = { path = "../rust-lightning/lightning-types" }
178-
#lightning-invoice = { path = "../rust-lightning/lightning-invoice" }
179-
#lightning-net-tokio = { path = "../rust-lightning/lightning-net-tokio" }
180-
#lightning-persister = { path = "../rust-lightning/lightning-persister" }
181-
#lightning-background-processor = { path = "../rust-lightning/lightning-background-processor" }
182-
#lightning-rapid-gossip-sync = { path = "../rust-lightning/lightning-rapid-gossip-sync" }
183-
#lightning-block-sync = { path = "../rust-lightning/lightning-block-sync" }
184-
#lightning-transaction-sync = { path = "../rust-lightning/lightning-transaction-sync" }
185-
#lightning-liquidity = { path = "../rust-lightning/lightning-liquidity" }
186-
#lightning-macros = { path = "../rust-lightning/lightning-macros" }
175+
[patch."https://github.com/lightningdevkit/rust-lightning"]
176+
lightning = { git = "https://github.com/carlakc/rust-lightning", rev = "62fde7a019b2d6a696efb7120be1d548efb031cc", features = ["std"] }
177+
lightning-types = { git = "https://github.com/carlakc/rust-lightning", rev = "62fde7a019b2d6a696efb7120be1d548efb031cc" }
178+
lightning-invoice = { git = "https://github.com/carlakc/rust-lightning", rev = "62fde7a019b2d6a696efb7120be1d548efb031cc", features = ["std"] }
179+
lightning-net-tokio = { git = "https://github.com/carlakc/rust-lightning", rev = "62fde7a019b2d6a696efb7120be1d548efb031cc" }
180+
lightning-persister = { git = "https://github.com/carlakc/rust-lightning", rev = "62fde7a019b2d6a696efb7120be1d548efb031cc", features = ["tokio"] }
181+
lightning-background-processor = { git = "https://github.com/carlakc/rust-lightning", rev = "62fde7a019b2d6a696efb7120be1d548efb031cc" }
182+
lightning-rapid-gossip-sync = { git = "https://github.com/carlakc/rust-lightning", rev = "62fde7a019b2d6a696efb7120be1d548efb031cc" }
183+
lightning-block-sync = { git = "https://github.com/carlakc/rust-lightning", rev = "62fde7a019b2d6a696efb7120be1d548efb031cc", features = ["rest-client", "rpc-client", "tokio"] }
184+
lightning-transaction-sync = { git = "https://github.com/carlakc/rust-lightning", rev = "62fde7a019b2d6a696efb7120be1d548efb031cc", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
185+
lightning-liquidity = { git = "https://github.com/carlakc/rust-lightning", rev = "62fde7a019b2d6a696efb7120be1d548efb031cc", features = ["std"] }
186+
lightning-macros = { git = "https://github.com/carlakc/rust-lightning", rev = "62fde7a019b2d6a696efb7120be1d548efb031cc" }

src/event.rs

Lines changed: 64 additions & 41 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,40 @@ 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+
6498
/// An event emitted by [`Node`], which should be handled by the user.
6599
///
66100
/// [`Node`]: [`crate::Node`]
@@ -128,29 +162,14 @@ pub enum Event {
128162
},
129163
/// A payment has been forwarded.
130164
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>,
165+
/// The set of incoming HTLCs that were forwarded to our node. Contains a single HTLC for
166+
/// source-routed payments, and may contain multiple HTLCs when we acted as a trampoline
167+
/// router.
168+
prev_htlcs: Vec<HTLCLocator>,
169+
/// The set of outgoing HTLCs forwarded by our node. Contains a single HTLC for regular
170+
/// source-routed payments, and may contain multiple HTLCs when we acted as a trampoline
171+
/// router.
172+
next_htlcs: Vec<HTLCLocator>,
154173
/// The total fee, in milli-satoshis, which was earned as a result of the payment.
155174
///
156175
/// Note that if we force-closed the channel over which we forwarded an HTLC while the HTLC
@@ -323,16 +342,27 @@ impl_writeable_tlv_based_enum!(Event,
323342
(7, custom_records, optional_vec),
324343
},
325344
(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),
345+
// Legacy fields: read from old data, never written.
346+
(0, legacy_prev_channel_id, (legacy, ChannelId, |_| Ok(()), |_: &Event| None::<Option<ChannelId>>)),
347+
(1, legacy_prev_node_id, (legacy, PublicKey, |_| Ok(()), |_: &Event| None::<Option<PublicKey>>)),
348+
(2, legacy_next_channel_id, (legacy, ChannelId, |_| Ok(()), |_: &Event| None::<Option<ChannelId>>)),
349+
(3, legacy_next_node_id, (legacy, PublicKey, |_| Ok(()), |_: &Event| None::<Option<PublicKey>>)),
350+
(4, legacy_prev_user_channel_id, (legacy, u128, |_| Ok(()), |_: &Event| None::<Option<u128>>)),
351+
(6, legacy_next_user_channel_id, (legacy, u128, |_| Ok(()), |_: &Event| None::<Option<u128>>)),
332352
(8, total_fee_earned_msat, option),
333353
(10, skimmed_fee_msat, option),
334354
(12, claim_from_onchain_tx, required),
335355
(14, outbound_amount_forwarded_msat, option),
356+
(15, prev_htlcs, (default_value_vec, vec![HTLCLocator {
357+
channel_id: legacy_prev_channel_id.ok_or(lightning::ln::msgs::DecodeError::InvalidValue)?,
358+
user_channel_id: legacy_prev_user_channel_id.map(UserChannelId),
359+
node_id: legacy_prev_node_id,
360+
}])),
361+
(17, next_htlcs, (default_value_vec, vec![HTLCLocator {
362+
channel_id: legacy_next_channel_id.ok_or(lightning::ln::msgs::DecodeError::InvalidValue)?,
363+
user_channel_id: legacy_next_user_channel_id.map(UserChannelId),
364+
node_id: legacy_next_node_id,
365+
}])),
336366
},
337367
(8, SplicePending) => {
338368
(1, channel_id, required),
@@ -1400,9 +1430,6 @@ where
14001430
// reporting the first HTLC in each vec.
14011431
debug_assert_eq!(prev_htlcs.len(), 1, "unexpected number of prev_htlcs");
14021432
debug_assert_eq!(next_htlcs.len(), 1, "unexpected number of next_htlcs");
1403-
let prev_htlc = prev_htlcs
1404-
.first()
1405-
.expect("we expect at least one prev_htlc for PaymentForwarded");
14061433
let next_htlc = next_htlcs
14071434
.first()
14081435
.expect("we expect at least one next_htlc for PaymentForwarded");
@@ -1415,12 +1442,8 @@ where
14151442
}
14161443

14171444
let event = Event::PaymentForwarded {
1418-
prev_channel_id: prev_htlc.channel_id,
1419-
next_channel_id: next_htlc.channel_id,
1420-
prev_user_channel_id: prev_htlc.user_channel_id.map(UserChannelId),
1421-
next_user_channel_id: next_htlc.user_channel_id.map(UserChannelId),
1422-
prev_node_id: prev_htlc.node_id,
1423-
next_node_id: next_htlc.node_id,
1445+
prev_htlcs: prev_htlcs.into_iter().map(HTLCLocator::from).collect(),
1446+
next_htlcs: next_htlcs.into_iter().map(HTLCLocator::from).collect(),
14241447
total_fee_earned_msat,
14251448
skimmed_fee_msat,
14261449
claim_from_onchain_tx,

0 commit comments

Comments
 (0)