-
Notifications
You must be signed in to change notification settings - Fork 407
Rename ChannelKeys -> Sign and generic it consistently #799
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
Rename ChannelKeys -> Sign and generic it consistently #799
Conversation
Codecov Report
@@ Coverage Diff @@
## main #799 +/- ##
==========================================
+ Coverage 90.80% 90.82% +0.02%
==========================================
Files 45 45
Lines 24548 24547 -1
==========================================
+ Hits 22290 22294 +4
+ Misses 2258 2253 -5
Continue to review full report at Codecov.
|
lightning/src/chain/mod.rs
Outdated
type Keys: ChannelKeys; | ||
type ChanSigner: ChannelSigner; |
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 if you're warming to the using verbs for traits and nouns for types, but consider trait Sign
and type ChannelSigner: Sign
for consistency. Then you could dispense with abbreviated ChanSigner
.
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.
Considering the options in more detail:
N | Trait | Type | Type Param |
---|---|---|---|
1 | ChannelSigner | InMemoryChannelSigner | ChanSigner |
2 | Sign | InMemoryChannelSigner | ChannelSigner |
3 | ChannelSign | InMemoryChannelSigner | ChannelSigner |
4 | Sign | InMemorySigner | Signer |
So 1 is this PR in its current state, 2 is what @jkczyz proposed. 3 seems to be a more consistent version of 2 which doesn't drop the word Channel
on the trait. We could go for 4 given that signing at the channel level is such a fundamental aspect of a Lightning node, so might as well be a bit less verbose.
I prefer 4 somewhat, but I don't feel strongly.
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.
Hmm, the problem I have with Sign is it doesn't really fully capture what's going on - it's a channel-specific thing that signs. If we moved it to channel::Sign it'd be more like chain::Watch but I'm not sure it makes sense there.
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 tend to agree with @devrandom in that "channel" is fundamental so could be dropped. I'd favor (4) but with slight variation.
IMO, it is redundant when used as the type parameter to Channel
.
pub(super) struct Channel<ChanSigner: ChannelSigner> {
}
impl<ChanSigner: ChannelSigner> Channel<ChanSigner> {
}
That it is for a specific channel could be made clear in the documentation and is enforced by it being a type parameter for Channel
and ChannelMonitor
.
However, for parameterizing types where what signing pertains to isn't clear, the type parameter could be the more specific ChannelSigner
instead Signer
(e.g., in Watch
).
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.
Ok, I think I did this everywhere, let me know if I missed any cases.
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.
ACK, but consider some variations on naming
lightning/src/chain/mod.rs
Outdated
type Keys: ChannelKeys; | ||
type ChanSigner: ChannelSigner; |
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.
Considering the options in more detail:
N | Trait | Type | Type Param |
---|---|---|---|
1 | ChannelSigner | InMemoryChannelSigner | ChanSigner |
2 | Sign | InMemoryChannelSigner | ChannelSigner |
3 | ChannelSign | InMemoryChannelSigner | ChannelSigner |
4 | Sign | InMemorySigner | Signer |
So 1 is this PR in its current state, 2 is what @jkczyz proposed. 3 seems to be a more consistent version of 2 which doesn't drop the word Channel
on the trait. We could go for 4 given that signing at the channel level is such a fundamental aspect of a Lightning node, so might as well be a bit less verbose.
I prefer 4 somewhat, but I don't feel strongly.
ba6121b
to
2d4d20e
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.
I'd prefer ChannelSigner
over ChanSigner
as the shortened version was introduced primarily to avoid conflicting with the trait name. But that is no longer a problem. I also find the "chan" is a little too close to "chain" when reading.
lightning-persister/src/lib.rs
Outdated
@@ -130,7 +130,7 @@ impl FilesystemPersister { | |||
} | |||
} | |||
|
|||
impl<ChanSigner: ChannelKeys + Send + Sync> channelmonitor::Persist<ChanSigner> for FilesystemPersister { | |||
impl<ChanSigner: Sign + Send + Sync> channelmonitor::Persist<ChanSigner> for FilesystemPersister { |
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.
Maybe here too?
Tangentially, I wonder if this type parameter should really be moved to the functions where it is clearer. Is it required at the struct level in order to work with another struct that is parameterized by this? Or is the compiler smart enough to make the determination?
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.
Hmm, this seems to not have any other Channel context.
As to the question about functions, I believe its required in this context because ChannelMonitor
stores a signer in the struct, not just accepting it as a parameter to a function.
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.
For the context, I was seeing the module qualifier channelmonitor
and the use below parameterizing ChannelMonitor
. I don't feel too strongly about this, though.
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.
Ah. Yea, I see your point. I don't care either way now, and its more work to change it :).
@@ -2253,7 +2253,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> { | |||
/// transaction and losing money. This is a risk because previous channel states | |||
/// are toxic, so it's important that whatever channel state is persisted is | |||
/// kept up-to-date. | |||
pub trait Persist<Keys: ChannelKeys>: Send + Sync { | |||
pub trait Persist<Keys: Sign>: Send + Sync { |
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.
What should we do for cases where Keys
was used as a type parameter? Maybe best to standardize as Signer
.
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.
Oops, my regexes missed those ones.
lightning/src/chain/mod.rs
Outdated
@@ -69,7 +69,7 @@ pub trait Access: Send + Sync { | |||
/// [`PermanentFailure`]: channelmonitor/enum.ChannelMonitorUpdateErr.html#variant.PermanentFailure | |||
pub trait Watch: Send + Sync { | |||
/// Keys needed by monitors for creating and signing transactions. | |||
type Keys: ChannelKeys; | |||
type ChanSigner: Sign; |
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.
Similarly here only for using an associated type vs function type parameter.
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.
Hmm, so this doesn't make sense as a function parameter - users don't ever want to receive arbitrary ChannelMonitor
s with unknown signer while serializing. That said, this probably shouldn't be an associated type - a Watch<A>
is a different type from a Watch<B>
and a single struct could (though probably won't) implement both.
40f1115
to
3298f43
Compare
If it's not too much trouble, changing this only touches a few files mostly where "chain" is used. |
ad705c0
to
6072707
Compare
The `ChannelKeys` object really isn't about keys at all anymore, its all about signing. At the same time, we rename the type aliases used in traits from both `ChanKeySigner` and `Keys` to just `Signer` (or, in contexts where Channel isnt clear, `ChanSigner`).
6072707
to
813f117
Compare
Rebased. |
813f117
to
aa127f5
Compare
Also threw in bindings updates cause they are trivial. |
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.
Getting some errors when running genbindings.sh
:
++ rustc --version --verbose
++ grep host:
+ HOST_PLATFORM='host: x86_64-apple-darwin'
+ '[' 'host: x86_64-apple-darwin' = 'host: x86_64-apple-darwin' ']'
+ sed -i '' 's/typedef LDKnative.*Import.*LDKnative.*;//g' include/lightning.h
+ CFLAGS='-Wall -Wno-nullability-completeness -pthread'
+ gcc -Wall -Wno-nullability-completeness -pthread -Wall -g -pthread demo.c target/debug/libldk.a -ldl
In file included from demo.c:2:
./include/lightning.h:1605:18: error: expected member name or ';' after declaration specifiers
LDKHTLCUpdate 0;
~~~~~~~~~~~~~ ^
./include/lightning.h:1605:17: error: expected ';' at end of declaration list
LDKHTLCUpdate 0;
^
;
./include/lightning.h:1609:16: error: expected member name or ';' after declaration specifiers
LDKOutPoint 0;
~~~~~~~~~~~ ^
./include/lightning.h:1609:15: error: expected ';' at end of declaration list
LDKOutPoint 0;
^
;
./include/lightning.h:1724:38: error: expected member name or ';' after declaration specifiers
LDKDelayedPaymentOutputDescriptor 0;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
./include/lightning.h:1724:37: error: expected ';' at end of declaration list
LDKDelayedPaymentOutputDescriptor 0;
^
;
./include/lightning.h:1728:37: error: expected member name or ';' after declaration specifiers
LDKStaticPaymentOutputDescriptor 0;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
./include/lightning.h:1728:36: error: expected ';' at end of declaration list
LDKStaticPaymentOutputDescriptor 0;
^
;
./include/lightning.h:2385:16: error: expected member name or ';' after declaration specifiers
LDKAPIError 0;
~~~~~~~~~~~ ^
./include/lightning.h:2385:15: error: expected ';' at end of declaration list
LDKAPIError 0;
^
;
./include/lightning.h:2389:35: error: expected member name or ';' after declaration specifiers
LDKCVec_CResult_NoneAPIErrorZZ 0;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
./include/lightning.h:2389:34: error: expected ';' at end of declaration list
LDKCVec_CResult_NoneAPIErrorZZ 0;
^
;
./include/lightning.h:2393:22: error: expected member name or ';' after declaration specifiers
LDKCVec_APIErrorZ 0;
~~~~~~~~~~~~~~~~~ ^
./include/lightning.h:2393:21: error: expected ';' at end of declaration list
LDKCVec_APIErrorZ 0;
^
;
./include/lightning.h:2397:35: error: expected member name or ';' after declaration specifiers
LDKCVec_CResult_NoneAPIErrorZZ 0;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
./include/lightning.h:2397:34: error: expected ';' at end of declaration list
LDKCVec_CResult_NoneAPIErrorZZ 0;
^
;
16 errors generated.
Hmm, that isnt how the header looks for me. Can you try updating your cbindgen (or maybe I need to update mine?) |
c31f30d
to
b0d02bb
Compare
Working on 0.17.0. I was on 0.14.4. |
Perhaps also rename Similarly for Also, we might consider renaming Or if you want, I can do all this in a followup. ACK on current |
b0d02bb
to
4b6f0a3
Compare
Squashed earlier fixup commits and added a commit to rename the missing |
ACK 4b6f0a3 |
ACK 4b6f0a3 |
Based on #789, this has really upset my OCD for some time, so needs fixing.
The
ChannelKeys
object really isn't about keys at all anymore,its all about signing. At the same time, we rename the type aliases
used in traits from both
ChanKeySigner
andKeys
to justChanSigner