Make payment_key
derivation deterministic
#3391
Open
+127
−111
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 of
channel_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.
TODO:
ChannelKeyDerivationParameters
argument toget_shutdown_scriptpubkey
, just as for the destination case. (cc @alecchendev)