-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update to rust-lightning:0.0.117
#176
base: feature/ln-dlc-channels
Are you sure you want to change the base?
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
There was a problem hiding this comment.
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.
@@ -130,8 +131,8 @@ macro_rules! check_for_timed_out_channels { | |||
if is_timed_out { | |||
let sub_channel = if channel.is_sub_channel() { | |||
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.
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.
There was a problem hiding this comment.
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.
let channel_id = crate::utils::get_new_temporary_id(); | ||
let channel_id = DlcChannelId::from_bytes(channel_id); |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
@@ -1756,7 +1763,7 @@ where | |||
self.chain_monitor.lock().unwrap().add_tx( | |||
prev_tx_id, | |||
ChannelInfo { | |||
channel_id: signed_channel.channel_id, | |||
channel_id: signed_channel.channel_id.inner(), |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
@@ -228,10 +231,11 @@ where | |||
ln_channel_manager, | |||
dlc_channel_manager, | |||
actions: Mutex::new(actions), | |||
phantom: PhantomData, | |||
phantom_cs: PhantomData, |
There was a problem hiding this comment.
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.
@@ -359,8 +363,7 @@ where | |||
let per_split_seed_pk = | |||
PublicKey::from_secret_key(self.dlc_channel_manager.get_secp(), &per_split_seed); | |||
|
|||
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.
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.
_: u64, | ||
_: &NodeId, | ||
_: &NodeId, | ||
_: ChannelUsage, |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
@@ -714,3 +715,59 @@ pub fn refresh_wallet<B: Deref, W: Deref>( | |||
retry += 1; | |||
} | |||
} | |||
|
|||
/// 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.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, will do that!
@@ -12,8 +12,8 @@ use-serde = ["serde", "secp256k1-zkp/use-serde"] | |||
|
|||
[dependencies] | |||
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.
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)
There was a problem hiding this comment.
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.
@@ -9,10 +9,11 @@ version = "0.4.0" | |||
|
|||
[dependencies] | |||
bitcoin = {version = "0.29.2"} | |||
lightning = {version = "0.0.117"} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
use secp256k1_zkp::{PublicKey, SecretKey}; | ||
use simple_wallet::WalletStorage; | ||
use std::collections::HashMap; | ||
use std::sync::{Mutex, RwLock}; | ||
|
||
pub struct MemoryStorage { | ||
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.
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?
There was a problem hiding this comment.
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.
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 LNChannelId
s, DLC channel IDs and contract IDs. To that end, we've renamed the oldChannelId
type alias toDlcChannelId
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'sChannelId
doesn't implement serde itself. The same applies to deserialisation.