Bump rust-lightning to include trampoline changes#825
Bump rust-lightning to include trampoline changes#825carlaKC wants to merge 1 commit intolightningdevkit:mainfrom
Conversation
|
👋 Thanks for assigning @tnull as a reviewer! |
src/event.rs
Outdated
| /// A set of multiple htlcs all associated with same forward. | ||
| #[derive(Debug, Clone, PartialEq, Eq)] | ||
| #[cfg_attr(feature = "uniffi", derive(uniffi::Record))] | ||
| pub struct HTLCSet(Vec<HTLCLocator>); |
There was a problem hiding this comment.
Interested in some feedback here 🙏
To use default_value to fill in legacy fields when the new field isn't present, we need to implement Readable/Writeable for Vec<HTLCLocator>. We can't do this because we don't own the trait or the type (orphan rule).
The solution I've gone with here is to use a wrapper struct and pull in the code we have in impl_for_vec in LDK.
Alternatives would be:
- Don't use
default_value, and write manualReadable/Writeableimpls forEventso that we can manually fill the legacy values (I can't find a way to do it within macros). - Just use
required_vecand don't fill legacy values (seems bad).
src/event.rs
Outdated
| // For backwards compatibility, write the first prev/next_htlc to our legacy fields. This | ||
| // allows use to downgrade with some information loss about the remaining htlcs. |
There was a problem hiding this comment.
Not sure what the project's philosophy is for backwards compatibility, so just gone with what I would have done in LDK - happy to do something else if it's preferred!
There was a problem hiding this comment.
Yeah, while we def. want to get to support downgrades at some point, we currently don't. So we can just drop this extra logic as long as we're positive backwards compatibility during upgrades is ensured.
76e3d44 to
dd42f5f
Compare
Cargo.toml
Outdated
| # TODO: need to push branch to Jeff's fork? | ||
| bitcoin-payment-instructions = { git = "https://github.com/carlaKC/bitcoin-payment-instructions", rev = "c22c9b836b70d4c915dd28701e11083a8b558d56" } |
There was a problem hiding this comment.
@tnull had been doing most of the updates until recently when my PRs (and others) started breaking LDK Node. I ended up setting up a remote to his branch and based mine off of it. Personally, I'd be fine if you want to do something similar, as that at least gives us a common history for bitcoin-payment-instructions bumps.
Cargo.toml
Outdated
| #lightning-transaction-sync = { path = "../rust-lightning/lightning-transaction-sync" } | ||
| #lightning-liquidity = { path = "../rust-lightning/lightning-liquidity" } | ||
| #lightning-macros = { path = "../rust-lightning/lightning-macros" } | ||
| lightning-macros = { path = "../rust-lightning/lightning-macros" } |
| pub node_id: Option<PublicKey>, | ||
| } | ||
|
|
||
| impl_writeable_tlv_based!(HTLCLocator, { |
There was a problem hiding this comment.
Hmm, I'd really like to avoid duplicating upstream's serialization logic, which always risks to get out-of-sync. Can we rather also impl From<Vec<HTLCLocator>> for Vec<LdkHTLCLocator> and use upstream's write? I admit that is also not great, but maybe preferable to duplicating even more logic?
There was a problem hiding this comment.
I admit that is also not great, but maybe preferable to duplicating even more logic?
Given this a shot, it's a little unwieldy but I agree probably preferable to duplication.
There was a problem hiding this comment.
Indeed unwieldy and not loving the reallocation either, but oh well...
But we can now remove the impl_writeable_tlv_based here, right?
src/event.rs
Outdated
|
|
||
| /// A set of multiple htlcs all associated with same forward. | ||
| #[derive(Debug, Clone, PartialEq, Eq)] | ||
| pub struct HTLCSet(pub Vec<HTLCLocator>); |
There was a problem hiding this comment.
Why do we need this additional newtype? I think even for bindings we should be able to leave it as Vec<HTLCLocator>?
There was a problem hiding this comment.
This was to get around the orphan rule for serialization (we can't implement a trait we don't own - Readable/Writeable - for a type we don't own - Vec<T>).
If we don't need backwards compat, then we don't need default_value and can clean up a whole bunch of things including this 👌
src/event.rs
Outdated
| (5, node_id, option), | ||
| }); | ||
|
|
||
| impl From<lightning::events::HTLCLocator> for HTLCLocator { |
There was a problem hiding this comment.
nit: Please import the upstream type as LdkHTLCLocator, which is the usual pattern.
src/event.rs
Outdated
| // For backwards compatibility, write the first prev/next_htlc to our legacy fields. This | ||
| // allows use to downgrade with some information loss about the remaining htlcs. |
There was a problem hiding this comment.
Yeah, while we def. want to get to support downgrades at some point, we currently don't. So we can just drop this extra logic as long as we're positive backwards compatibility during upgrades is ensured.
dd42f5f to
e60ce2e
Compare
tnull
left a comment
There was a problem hiding this comment.
Hmm, I do wonder if we could improve things and reuse the upstream struct entirely if we introduced UserChannelId there.
| pub node_id: Option<PublicKey>, | ||
| } | ||
|
|
||
| impl_writeable_tlv_based!(HTLCLocator, { |
There was a problem hiding this comment.
Indeed unwieldy and not loving the reallocation either, but oh well...
But we can now remove the impl_writeable_tlv_based here, right?
| .await; | ||
| for next_htlc in next_htlcs.iter() { | ||
| liquidity_source | ||
| .handle_payment_forwarded(Some(next_htlc.channel_id), skimmed_fee_msat) |
There was a problem hiding this comment.
Hmm, wouldn't this have us / the accounting logic believe that we withheld the skimmed amount multiple times?
| if claim_from_onchain_tx { | ||
| log_info!( | ||
| self.logger, | ||
| "Forwarded payment{}{} of {}msat, earning {}msat in fees from claiming onchain.", |
There was a problem hiding this comment.
Does this also need adjustments?
| // We cannot implement Readable/Writeable for Vec<HTLCLocator> because we do not own the | ||
| // trait or the type (Vec). To work around this, and prevent duplicating serialization code, | ||
| // we map to the underlying LdkHTLCLocator type for serialization. | ||
| (15, prev_htlcs, (custom, Vec<LdkHTLCLocator>, |
There was a problem hiding this comment.
Can we try to streamline this a bit? Maybe introduce a helper method to dedup the code? At the very least it seems we can drop a few lines:
diff --git a/src/event.rs b/src/event.rs
index 417f5941..0505a870 100644
--- a/src/event.rs
+++ b/src/event.rs
@@ -369,16 +369,14 @@ impl_writeable_tlv_based_enum!(Event,
// we map to the underlying LdkHTLCLocator type for serialization.
(15, prev_htlcs, (custom, Vec<LdkHTLCLocator>,
|v: Option<Vec<LdkHTLCLocator>>| {
- let res: Result<Vec<HTLCLocator>, lightning::ln::msgs::DecodeError> =
- Ok(v.map(|ldk_vec| ldk_vec.into_iter().map(HTLCLocator::from).collect())
+ Ok(v.map(|ldk_vec| ldk_vec.into_iter().map(HTLCLocator::from).collect())
.unwrap_or_else(|| {
legacy_prev_channel_id.map(|ch| vec![HTLCLocator {
channel_id: ch,
user_channel_id: legacy_prev_user_channel_id.map(UserChannelId),
node_id: legacy_prev_node_id,
}]).unwrap_or_default()
- }));
- res
+ }))
},
|us: &Event| {
if let Event::PaymentForwarded { ref prev_htlcs, .. } = us {
@@ -390,7 +388,6 @@ impl_writeable_tlv_based_enum!(Event,
)),
(17, next_htlcs, (custom, Vec<LdkHTLCLocator>,
|v: Option<Vec<LdkHTLCLocator>>| {
- let res: Result<Vec<HTLCLocator>, lightning::ln::msgs::DecodeError> =
Ok(v.map(|ldk_vec| ldk_vec.into_iter().map(HTLCLocator::from).collect())
.unwrap_or_else(|| {
legacy_next_channel_id.map(|ch| vec![HTLCLocator {
@@ -398,8 +395,7 @@ impl_writeable_tlv_based_enum!(Event,
user_channel_id: legacy_next_user_channel_id.map(UserChannelId),
node_id: legacy_next_node_id,
}]).unwrap_or_default()
- }));
- res
+ }))
},
|us: &Event| {
if let Event::PaymentForwarded { ref next_htlcs, .. } = us {| } | ||
|
|
||
| impl_writeable_tlv_based!(HTLCLocator, { | ||
| (1, channel_id, required), |
There was a problem hiding this comment.
Should we make these even, given its a new struct?
Depends on #824.
Also needs the following patch on top of 2026-02-ldk-node-base in
bitcoin-payment-instructions.