Update to rust-lightning:0.0.117#176
Conversation
I feel it'd be cleaner to just define our own structs, and implement |
65b6bce to
61e33c8
Compare
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. |
cb6964f to
1fe6ab5
Compare
07d1fe3 to
b7721f9
Compare
1fe6ab5 to
745717d
Compare
745717d to
de1af07
Compare
|
@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 |
de1af07 to
7fdc4db
Compare
As part of this update `rust-lightning` introduced a `ChannelId` struct, which motivated us to also introduce the `DlcChannelId` and `SubChannelId` structs.
7fdc4db to
86e2000
Compare
Tibo-lg
left a comment
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I agree, we need to print this as hex. I'll fix it.
| let channel_id = crate::utils::get_new_temporary_id(); | ||
| let channel_id = DlcChannelId::from_bytes(channel_id); |
There was a problem hiding this comment.
It'd be nice to have some wrapper within the type for this (can do it later as well).
There was a problem hiding this comment.
Yeah, I agree. I will do that.
| prev_tx_id, | ||
| ChannelInfo { | ||
| channel_id: signed_channel.channel_id, | ||
| channel_id: signed_channel.channel_id.inner(), |
There was a problem hiding this comment.
Would it make sense to implement Deref or into (really just a suggestion, not sure it'd be much better).
There was a problem hiding this comment.
Yep. I think From/Into makes sense. Can do that.
| dlc_channel_manager, | ||
| actions: Mutex::new(actions), | ||
| phantom: PhantomData, | ||
| phantom_cs: PhantomData, |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Feels like this would be better as a method on the type.
| _: u64, | ||
| _: &NodeId, | ||
| _: &NodeId, | ||
| _: ChannelUsage, |
There was a problem hiding this comment.
not sure why you changed these and not the last one :D (I feel not changing them is also fine)
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
I think there are the same methods in dlc::serde_utils, maybe easier to just reference that?
There was a problem hiding this comment.
Yep, will do that!
| 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"] } |
There was a problem hiding this comment.
I think serde is supposed to be feature gated (not 100% sure it's correctly setup but at least that was the goal)
There was a problem hiding this comment.
You are right. We want to only enable serde for the dlc crate if the serde feature flag is passed. I'll fix that.
|
|
||
| [dependencies] | ||
| bitcoin = {version = "0.29.2"} | ||
| lightning = {version = "0.0.117"} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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>>, |
There was a problem hiding this comment.
Is there a reason for not using the types here?
There was a problem hiding this comment.
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.
The highlight in terms of code changes in
rust-dlcis:Use new LDK Channel ID struct
Start to use newly introduced
ChannelIdstruct. With a stronger type we are less likely to mix up LNChannelIds, DLC channel IDs and contract IDs. To that end, we've renamed the oldChannelIdtype alias toDlcChannelIdsince 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_withattribute since LDK'sChannelIddoesn't implement serde itself. The same applies to deserialisation.