-
Notifications
You must be signed in to change notification settings - Fork 382
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
Refactor ChannelTransactionParameters
into FundingScope
#3604
base: main
Are you sure you want to change the base?
Refactor ChannelTransactionParameters
into FundingScope
#3604
Conversation
@wpaulino This primarily moves fields from The drawback is we'd be duplicating fields that wouldn't change. But this seems better than duplicating fields that would change and risk having inconsistent data. Also, it could prevent us from needing to worry about changing other uses of What are your thoughts? |
I was thinking we could deprecate the funding scope related fields from |
Yeah, this PR takes that approach. But when removing the fields we'd need to update all uses to take both For instance, writing an There's also I haven't looked exhaustively to see all usages, but it seems simpler to keep |
Hm, I'm not opposed to always writing As for |
Here's the alternative approach: https://github.com/jkczyz/rust-lightning/tree/2025-02-channel-funding-pubkeys-alt |
Yeah this looks pretty simple, and would also allow us to handle transitioning to new channel types in a splice since it already tracks the channel type features. I don't think the duplicate data is all that bad here once we have multiple scopes since it will eventually go away when the splice confirms. We should at least be able to avoid persisting the duplicate data, if we choose to, by cloning it from the "main" (currently confirmed) scope when reading. Thoughts on either of these approaches @TheBlueMatt? |
@TheBlueMatt Added some more commits to the alternative branch after pairing with @wpaulino yesterday. They move |
Discussed this being supersceded by an alternative that tries to keep signer operations (across many splice versions) together as one call. |
e788ac1
to
df840cb
Compare
Rather than moving relevant fields of ChannelTransactionParameters to FundingScope, move the entire struct there instead. This prevents API churn wherever ChannelTransactionParameters is used, which otherwise would need a FundingScope in addition.
Since the funding transactions changes for each new FudningScope, include it there instead of ChannelContext.
Since channel_value_satoshis is needed by the signer and may change for each new FundingScope, included it in ChannelTransactionParameters so it can be passed to each signer call in the upcoming commits.
Now that ChannelTransactionParameters are in FundingScope, channel_value_satoshis can be dropped from the latter.
Now that channel_value_satoshis has been moved to ChannelTransactionParameters, pass the entire parameters when calling each method on EcdsaChannelSigner. This will remove the need for ChannelSigner::provide_channel_parameters. Instead, the parameters from the FundingScope will be passed in to each method. This simplifies the interaction with a ChannelSigner when needing to be called for more than one FundingScope, which will be the case for pending splices and RBF attempts.
Now that channel_value_satoshis has been moved to ChannelTransactionParameters, pass the entire parameters when calling each method on EcdsaChannelSigner. This will remove the need for ChannelSigner::provide_channel_parameters. Instead, the parameters from the FundingScope will be passed in to each method. This simplifies the interaction with a ChannelSigner when needing to be called for more than one FundingScope, which will be the case for pending splices and RBF attempts.
Now that channel_value_satoshis has been moved to ChannelTransactionParameters, pass the entire parameters when calling each method on EcdsaChannelSigner. This will remove the need for ChannelSigner::provide_channel_parameters. Instead, the parameters from the FundingScope will be passed in to each method. This simplifies the interaction with a ChannelSigner when needing to be called for more than one FundingScope, which will be the case for pending splices and RBF attempts.
Now that channel_value_satoshis has been moved to ChannelTransactionParameters, pass the entire parameters when calling each method on EcdsaChannelSigner. This will remove the need for ChannelSigner::provide_channel_parameters. Instead, the parameters from the FundingScope will be passed in to each method. This simplifies the interaction with a ChannelSigner when needing to be called for more than one FundingScope, which will be the case for pending splices and RBF attempts.
Now that channel_value_satoshis has been moved to ChannelTransactionParameters, pass the entire parameters when calling each method on EcdsaChannelSigner. This will remove the need for ChannelSigner::provide_channel_parameters. Instead, the parameters from the FundingScope will be passed in to each method. This simplifies the interaction with a ChannelSigner when needing to be called for more than one FundingScope, which will be the case for pending splices and RBF attempts.
Now that channel_value_satoshis has been moved to ChannelTransactionParameters, pass the entire parameters when calling each method on EcdsaChannelSigner. This will remove the need for ChannelSigner::provide_channel_parameters. Instead, the parameters from the FundingScope will be passed in to each method. This simplifies the interaction with a ChannelSigner when needing to be called for more than one FundingScope, which will be the case for pending splices and RBF attempts.
Now that channel_value_satoshis has been moved to ChannelTransactionParameters, pass the entire parameters when calling each method on EcdsaChannelSigner. This will remove the need for ChannelSigner::provide_channel_parameters. Instead, the parameters from the FundingScope will be passed in to each method. This simplifies the interaction with a ChannelSigner when needing to be called for more than one FundingScope, which will be the case for pending splices and RBF attempts.
df840cb
to
aff70ae
Compare
FundingScope
ChannelTransactionParameters
into FundingScope
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3604 +/- ##
==========================================
- Coverage 88.60% 88.59% -0.02%
==========================================
Files 151 151
Lines 118409 118404 -5
Branches 118409 118404 -5
==========================================
- Hits 104918 104900 -18
+ Misses 10972 10968 -4
- Partials 2519 2536 +17 ☔ View full report in Codecov by Sentry. |
Updated the branch to use the alternative version. See updated PR description for details. |
|
||
/// The transaction which funds this channel. Note that for manually-funded channels (i.e., | ||
/// [`ChannelContext::is_manual_broadcast`] is true) this will be a dummy empty transaction. | ||
funding_transaction: Option<Transaction>, |
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 be possible to have just the transaction ID here? it's not so good to carry around the funding transaction for every signing operation in memory limited environments.
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.
This won't be given to the signer, only ChannelTransactionParameters
will
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, of course, thank you
lightning/src/sign/ecdsa.rs
Outdated
@@ -238,7 +238,8 @@ pub trait EcdsaChannelSigner: ChannelSigner { | |||
/// | |||
/// [`NodeSigner::sign_gossip_message`]: crate::sign::NodeSigner::sign_gossip_message | |||
fn sign_channel_announcement_with_funding_key( | |||
&self, msg: &UnsignedChannelAnnouncement, secp_ctx: &Secp256k1<secp256k1::All>, | |||
&self, channel_parameters: &ChannelTransactionParameters, |
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.
We can probably omit this one, instead we'd just have to pass the optional funding pubkey tweak once that's implemented.
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, I assumed we'd get it from ChannelTransactionParameters
. Happy to drop this if you'd prefer.
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 let's drop it for now, one less thing to break
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.
Dropped
lightning/src/sign/mod.rs
Outdated
// TODO: Is this ok? | ||
let channel_parameters = | ||
descriptor.channel_transaction_parameters.as_ref().expect(MISSING_PARAMS_ERR); |
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.
Only if the descriptor was produced in v0.0.117 or later. Probably best to err on the safe side and keep the handling as before.
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 about for the payment point? The earlier version was using self.pubkeys()
. I figured we get rid of this since it's duplicative with channel_parameters.holder_pubkeys
. But maybe we use that as a fallback instead when looking up the payment point. Will add a fixup doing so.
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 say just keep using self.pubkeys()
since it doesn't depend on the channel parameters. It might get removed eventually with some of the custom commitment work to be done, so we can worry about it then.
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.
Done.
@@ -1804,7 +1734,7 @@ impl Writeable for InMemorySigner { | |||
self.delayed_payment_base_key.write(writer)?; | |||
self.htlc_base_key.write(writer)?; | |||
self.commitment_seed.write(writer)?; | |||
self.channel_parameters.write(writer)?; |
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 we can remove all serialization code for the signer now, it hasn't been used for many releases.
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.
Looks like deserialization is indirectly used via read_chan_signer
called when a deserialized FundedChannel
doesn't contain channel_keys_id
:
rust-lightning/lightning/src/ln/channel.rs
Line 10592 in 1610854
let holder_signer = signer_provider.read_chan_signer(&keys_data)?; |
Isn't clear to me when that wouldn't be present, though. If that's old, maybe we should error instead?
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 channel_keys_id
can be expected on now. keys_data
is only Some
for versions <= 2 (we're on 4 now), so someone upgrading from back then would be pretty rare. And if they are, they can just upgrade to an older version first.
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.
Gotcha. Removed this now.
@@ -1684,7 +1684,7 @@ impl FundingScope { | |||
/// pays to get_funding_redeemscript().to_p2wsh()). | |||
/// Panics if called before accept_channel/InboundV1Channel::new | |||
pub fn get_funding_redeemscript(&self) -> ScriptBuf { | |||
make_funding_redeemscript(&self.get_holder_pubkeys().funding_pubkey, self.counterparty_funding_pubkey()) | |||
self.channel_transaction_parameters.make_funding_redeemscript() |
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.
Any reason this was done? Seems fine to keep it as it was
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 had a note from our meeting to move this to ChannelTransactionParameters
. I ended up keeping the method on FundingScope
but moving the body.
ad8ddcb
to
339e0ca
Compare
Now that channel_value_satoshis has been moved to ChannelTransactionParameters, pass the entire parameters when calling each method on EcdsaChannelSigner. This will remove the need for ChannelSigner::provide_channel_parameters. Instead, the parameters from the FundingScope will be passed in to each method. This simplifies the interaction with a ChannelSigner when needing to be called for more than one FundingScope, which will be the case for pending splices and RBF attempts.
Now that channel_value_satoshis has been moved to ChannelTransactionParameters, InMemorySigner no longer needs a copy. Remove uses of the copy from sign_counterparty_payment_input.
Now that channel_value_satoshis has been moved to ChannelTransactionParameters, InMemorySigner no longer needs a copy. Remove indirect uses of the copy from TestChannelSigner.
InMemorySigner no longer holds channel_value_satoshis and channel_parameters. Instead of writing 0 and None, respectively, drop (de-)serialization support entirely since InMemorySigner hasn't been serialized since SERIALIZATION_VERSION 2.
Now that the copy of ChannelTransactionParameters is no longer used by InMemorySigner, remove it and all remaining uses. Since it was set by ChannelSigner::provide_channel_parameters, this method is no longer needed and can also be removed.
Now that channel_value_satoshis has been moved to ChannelTransactionParameters, it no longer needs to be used when deriving a signer. This is a breaking API change, though InMemorySigner did not make use of channel_value_satoshis when being derived.
The custom derive_channel_signer methods on AnchorDescriptor and HTLCDescriptor simply delegate to the passed SignerProvider now that providing ChannelTransactionParameters is no longer needed. Drop these methods and replace them with the method bodies at the call sites.
339e0ca
to
a55149f
Compare
Continues the work of #3592 by moving fields related to the funding transaction into
FundingScope
.This includes fields fromChannelContext
for the funding transaction andChannelTransactionParameters
for the funding outpoint and pubkeys.This primarily involves moving the entire
ChannelTransactionParameters
intoFundingScope
andchannel_value_satoshis
intoChannelTransactionParameters
. The latter result in less API churn at the cost of duplicating parameters that don't change across eachFundingScope
. To that end, this PR also updates theEcdsaChannelSigner
to takeChannelTransactionParameters
which removes the need forChannelSigner::provide_channel_parameters
.Since
ChannelTransactionParameters
containschannel_value_satoshis
, implementation likeInMemorySigner
no longer need it. Thus, theNodeSigner
trait is updated to no longer take the value when deriving signers, which is a breaking change.