-
Notifications
You must be signed in to change notification settings - Fork 366
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
Make payment_key
derivation deterministic
#3391
base: main
Are you sure you want to change the base?
Make payment_key
derivation deterministic
#3391
Conversation
b8c5f77
to
5b17762
Compare
... which we haven't been using since 0.0.119 / commit 7a951b1.
.. as it doesn't use the actual signer's `payment_key`, but the associated public key.
.. to make the name more clear and since before we `clone` it in `derive_channel_keys` anyways.
5b17762
to
a7db955
Compare
After discussion this offline I now reverted this to simply use the first byte of Furthermore, this change will of course prohibit downgrading channel monitors to use the older derivation version. This is also the reason why currently |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3391 +/- ##
==========================================
+ Coverage 89.66% 89.72% +0.05%
==========================================
Files 128 128
Lines 104887 105577 +690
Branches 104887 105577 +690
==========================================
+ Hits 94052 94734 +682
- Misses 8126 8140 +14
+ Partials 2709 2703 -6 ☔ View full report in Codecov by Sentry. |
f9619b8
to
0c26baf
Compare
.. to align the field everywhere.
.. to align the field naming with the spec for clarity.
Previously, `KeysManager::derive_channel_keys` would derive the channel's `payment_key` uniquely on a per-channel basis which would disallow users losing their `channel_keys_id` to recover funds. As it's no real necessity to have `payment_key` derivation depend on `channel_keys_id` we can allow for easier recovery of any non-HTLC encumbered funds if we make `payment_key` derivation deterministic. To this end, we use the first byte of `channel_keys_id` as a versioning byte indicating the version of the used channel keys derivation scheme. Note that Previously `KeysManager::generate_channel_keys_id` would with very high likelyhood never have generated a `channel_keys_id` with a non-null first byte, which makes this a backwards-compatible change for any users that didn't run custom implementations of `SignerProvider::generate_channel_keys_id` conflicting with this assumption.
Some test cases have hard-coded values which we change here (to be squashed in after review).
0c26baf
to
57cadf2
Compare
.. to allow users to return specific scripts per channel.
57cadf2
to
c70f7ec
Compare
In 6a55dcc we fixed an issue where we'd just `unwrap` `InMemorySigner`'s `channel_parameters` field and added a comment explaining why we can't do that. However, in particular as related APIs were also changed in follow-up commits to return `Option`s, the introduced comment is now outdated and doesn't really make sense anymore without that historical context present. As it's more or less misleading by now, we just drop it.
Previously,
KeysManager::derive_channel_keys
would derive the channel'spayment_key
uniquely on a per-channel basis which would disallow users losing theirchannel_keys_id
to recover funds. As there is no necessity to havepayment_key
derivation depend onchannel_keys_id
we can allow for easier recovery of any non-HTLC encumbered funds if we makepayment_key
derivation deterministic.Here we do just this but also include a larger refactor introducing aChannelKeysDerivationParameters
struct holding a versioning field to be able to express this change in the derivation scheme. To this end we ensure that legacy channels will continue to use the old derivation scheme after upgrade, while new channels will derive thepayment_key
deterministicly.
To this end, we use the first byte of
channel_keys_id
as a versioning byte indicating the version of the used channel keys derivation scheme. Note that PreviouslyKeysManager::generate_channel_keys_id
would withvery high likelyhood never have generated a
channel_keys_id
with a non-null first byte, which makes this a backwards-compatible change for any users that didn't run custom implementations ofSignerProvider::generate_channel_keys_id
conflicting with this assumption.Apart from this, we add some refactoring commits that drop unused logic (
Writeable
forInMemorySigner
) and rename fields to align them with the BOLTs for clarity.We previously also discussed abusing the first byte ofchannel_keys_id
as a version byte, which wouldn't require the overhead of introducingChannelKeysDerivationParameters
and serializing thechannel_keys_derivation_version
field independently everywhere. However, as discussed I now chose to go with the latter approach as it seems cleaner and more future-proof.That said, looking for an approach ACK here before continuing. Will be draft until then.Should be good for review
TODO:
channel_keys_id
argument toget_shutdown_scriptpubkey
, just as for the destination case. (cc @alecchendev)