Skip to content

Update to rust-lightning:0.0.117#176

Open
luckysori wants to merge 1 commit into
feature/ln-dlc-channelsfrom
chore/upgrade-ldk-117
Open

Update to rust-lightning:0.0.117#176
luckysori wants to merge 1 commit into
feature/ln-dlc-channelsfrom
chore/upgrade-ldk-117

Conversation

@luckysori

@luckysori luckysori commented Nov 22, 2023

Copy link
Copy Markdown
Collaborator

The highlight in terms of code changes in rust-dlc is:

Use new LDK Channel ID struct

Start to use newly introduced ChannelId struct. With a stronger type we are less likely to mix up LN ChannelIds, DLC channel IDs and contract IDs. To that end, we've renamed the old ChannelId type alias to DlcChannelId since it is now only supposed to be used for (temporary or final) DLC channel IDs. We should consider introducing a struct at some point.

To ensure backwards-compatibility we're still serialising the LN channel IDs into bytes, but we now have to use the serialize_with attribute since LDK's ChannelId doesn't implement serde itself. The same applies to deserialisation.

@luckysori luckysori added the ln label Nov 22, 2023
@luckysori luckysori requested review from Tibo-lg and holzeis November 22, 2023 06:13
@luckysori luckysori self-assigned this Nov 22, 2023
@Tibo-lg

Tibo-lg commented Nov 24, 2023

Copy link
Copy Markdown
Contributor

Use new LDK Channel ID struct

Start to use newly introduced ChannelId struct. With a stronger type we are less likely to mix up LN ChannelIds, DLC channel IDs and contract IDs. To that end, we've renamed the old ChannelId type alias to DlcChannelId since it is now only supposed to be used for (temporary or final) DLC channel IDs. We should consider introducing a struct at some point.

To ensure backwards-compatibility we're still serialising the LN channel IDs into bytes, but we now have to use the serialize_with attribute since LDK's ChannelId doesn't implement serde itself. The same applies to deserialisation.

I feel it'd be cleaner to just define our own structs, and implement From<ldk::ChannelId> for the SubChannelId one. Then we could derive the serde::Serialize, and also have a more consistent naming. I feel it can be confusing that Channel structs use DlcChannelId while SubChannel use ChannelId. Unless there is some advantage that I'm not seeing?

@luckysori luckysori force-pushed the chore/upgrade-ldk-117 branch 2 times, most recently from 65b6bce to 61e33c8 Compare November 28, 2023 20:57
@luckysori

Copy link
Copy Markdown
Collaborator Author

Use new LDK Channel ID struct

Start to use newly introduced ChannelId struct. With a stronger type we are less likely to mix up LN ChannelIds, DLC channel IDs and contract IDs. To that end, we've renamed the old ChannelId type alias to DlcChannelId since it is now only supposed to be used for (temporary or final) DLC channel IDs. We should consider introducing a struct at some point.
To ensure backwards-compatibility we're still serialising the LN channel IDs into bytes, but we now have to use the serialize_with attribute since LDK's ChannelId doesn't implement serde itself. The same applies to deserialisation.

I feel it'd be cleaner to just define our own structs, and implement From<ldk::ChannelId> for the SubChannelId one. Then we could derive the serde::Serialize, and also have a more consistent naming. I feel it can be confusing that Channel structs use DlcChannelId while SubChannel use ChannelId. Unless there is some advantage that I'm not seeing?

I think what you propose is even better, but I wasn't sure if you wanted to go that far since before this PR we were just using type aliases everywhere. I can work on adding a couple of newtypes like you suggest.

@luckysori luckysori force-pushed the chore/upgrade-ldk-117 branch 2 times, most recently from cb6964f to 1fe6ab5 Compare November 29, 2023 10:13
@holzeis holzeis force-pushed the chore/upgrade-ldk-117 branch 3 times, most recently from 07d1fe3 to b7721f9 Compare November 29, 2023 14:38
@luckysori luckysori force-pushed the chore/upgrade-ldk-117 branch 2 times, most recently from 1fe6ab5 to 745717d Compare December 1, 2023 05:01
@luckysori luckysori force-pushed the chore/upgrade-ldk-117 branch from 745717d to de1af07 Compare December 20, 2023 06:35
@luckysori

luckysori commented Dec 20, 2023

Copy link
Copy Markdown
Collaborator Author

@Tibo-lg: I've tried to address your comment.

It's probably not perfect because it was a pretty painful process, so let me know if I can make it better.

I had to move some stuff around so that the new structs could be used in all the necessary places. I also left a couple of TODOs and a NOTE. Let me know what you think about those too.


Still fixing some tests

@luckysori luckysori force-pushed the chore/upgrade-ldk-117 branch from de1af07 to 7fdc4db Compare December 20, 2023 06:38
As part of this update `rust-lightning` introduced a `ChannelId`
struct, which motivated us to also introduce the `DlcChannelId` and
`SubChannelId` structs.
@luckysori luckysori force-pushed the chore/upgrade-ldk-117 branch from 7fdc4db to 86e2000 Compare December 20, 2023 06:47

@Tibo-lg Tibo-lg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM, still a couple of things that need fixing.

log::info!(
"Skipping force-closure of subchannel {}: not supported",
bitcoin::hashes::hex::ToHex::to_hex(&channel.channel_id[..])
"Skipping force-closure of subchannel {:?}: not supported",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean it will be printed as an array rather than a hex string? It'd be nice to have an easy way to print these ids.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, we need to print this as hex. I'll fix it.

Comment on lines +791 to +792
let channel_id = crate::utils::get_new_temporary_id();
let channel_id = DlcChannelId::from_bytes(channel_id);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice to have some wrapper within the type for this (can do it later as well).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree. I will do that.

prev_tx_id,
ChannelInfo {
channel_id: signed_channel.channel_id,
channel_id: signed_channel.channel_id.inner(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to implement Deref or into (really just a suggestion, not sure it'd be much better).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. I think From/Into makes sense. Can do that.

dlc_channel_manager,
actions: Mutex::new(actions),
phantom: PhantomData,
phantom_cs: PhantomData,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you don't need the CS generic parameter anymore.


let temporary_channel_id: ContractId =
subchannel::generate_temporary_channel_id(*channel_id, update_idx, 0);
let temporary_channel_id = generate_temporary_dlc_channel_id(channel_id, update_idx, 0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like this would be better as a method on the type.

Comment on lines +268 to +271
_: u64,
_: &NodeId,
_: &NodeId,
_: ChannelUsage,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why you changed these and not the last one :D (I feel not changing them is also fine)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's weird. Definitely not intentional. I'll revert it.

}

/// Serialize an hexadecimal value.
pub fn serialize_hex<S>(hex: &[u8], s: S) -> Result<S::Ok, S::Error>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are the same methods in dlc::serde_utils, maybe easier to just reference that?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, will do that!

Comment thread dlc-messages/Cargo.toml
bitcoin = {version = "0.29.2"}
dlc = {version = "0.4.0", path = "../dlc"}
lightning = {version = "0.0.116"}
dlc = {version = "0.4.0", path = "../dlc", features = ["serde"] }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think serde is supposed to be feature gated (not 100% sure it's correctly setup but at least that was the goal)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. We want to only enable serde for the dlc crate if the serde feature flag is passed. I'll fix that.

Comment thread dlc/Cargo.toml

[dependencies]
bitcoin = {version = "0.29.2"}
lightning = {version = "0.0.117"}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather this crate to stay very simple and not import lightning unless necessary. Actually is there a reason that you put ids.rs here and not in dlc-manager? It doesn't seem to be used within this crate.

@luckysori luckysori Dec 21, 2023

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually is there a reason that you put ids.rs here and not in dlc-manager? It doesn't seem to be used within this crate.

I was also hesitant about this. But it seemed to me like IDs belong in a core crate like dlc (seems to be).

The reason why I didn't want to put them in dlc-manager was because IDs are used in dlc-messages, meaning that dlc-messages would have to depend on dlc-manager which seems weird. And, more importantly, that would create a circular dependency.

I would rather this crate to stay very simple and not import lightning unless necessary.

I considered adding a feature flag to the dlc crate, but it was getting a bit tedious so I dropped it. Should I try that again?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah a circular dependency wouldn't be good. What do you think about just not using these types for the dlc-messages crate? I guess it's not that a big deal to have it in dlc though, so I'll leave it up to you.

contracts: RwLock<HashMap<ContractId, Contract>>,
channels: RwLock<HashMap<ChannelId, Channel>>,
sub_channels: RwLock<HashMap<ChannelId, SubChannel>>,
channels: RwLock<HashMap<[u8; 32], Channel>>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for not using the types here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hehe, I had the types here until the very last second, when the compiler started giving me a hard time about the types not implementing certain traits. I can give it a go again.

@luckysori luckysori removed their assignment Feb 9, 2024
@luckysori luckysori removed the request for review from holzeis February 9, 2024 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants