Implement struct wrappers for channel key types to avoid confusion.
authorolegkubrakov <oleg@lightspark.com>
Tue, 14 Nov 2023 18:08:25 +0000 (10:08 -0800)
committerMatt Corallo <git@bluematt.me>
Mon, 27 Nov 2023 17:52:12 +0000 (17:52 +0000)
commit935a716cc6c4fada075e2b740a70bb1b7b349d49
tree5abf5792265bc9d82d461145205e4c83cfcfef51
parent70ea1108646468335d085a862e18bca774632bf3
Implement struct wrappers for channel key types to avoid confusion.

Currently all channel keys and their basepoints exist uniformly as
`PublicKey` type, which not only makes in harder for a developer to
distinguish those entities, but also does not engage the language
type system to check if the correct key is being used in any
particular function.

Having struct wrappers around keys also enables more nuanced
semantics allowing to express Lightning Protocol rules in language.
For example, the code allows to derive `HtlcKey` from
`HtlcBasepoint` and not from `PaymentBasepoint`.

This change is transparent for channel monitors that will use the
internal public key of a wrapper.

Payment, DelayedPayment, HTLC and Revocation basepoints and their
derived keys are now wrapped into a specific struct that make it
distinguishable for the Rust type system. Functions that require a
specific key or basepoint should not use generic Public Key, but
require a specific key wrapper struct to engage Rust type
verification system and make it more clear for developers which
key is used.
lightning/src/chain/channelmonitor.rs
lightning/src/chain/package.rs
lightning/src/ln/chan_utils.rs
lightning/src/ln/channel.rs
lightning/src/ln/channel_keys.rs [new file with mode: 0644]
lightning/src/ln/mod.rs
lightning/src/sign/mod.rs
lightning/src/util/test_channel_signer.rs