lightningdevkit / rust-lightning

A highly modular Bitcoin Lightning library written in Rust. It's rust-lightning, not Rusty's Lightning!
Other
1.11k stars 342 forks source link

[RFC] keysmanager: allow to inject custom channels keys #3133

Closed vincenzopalazzo closed 2 weeks ago

vincenzopalazzo commented 2 weeks ago

I have been going back and forth with @TheBlueMatt for a couple of years now, and I am still unable to find a solution to work around the LDK KeyManager.

Context

LNprototest is injecting the channel keys inside the node to predict the signature (see the lampo runner code here).

This RFC proposes to extend the code of the KeyManager to inject the dev keys into the main KeyManager. However, it involves a lot of code that I would like to avoid keeping inside LDK. I am trying to use an adapted pattern to work around this by using the LDK KeyManager as an inner type and then changing only the methods that I need.

My experimentation with the lampo codebase is failing because the adapter pattern works only if we have some sort of trait that defines the methods KeyManager is implementing.

See the lampo code here: https://github.com/vincenzopalazzo/lampo.rs/pull/255.

So the solutions that I see are twofold:

  1. Polish the following RFC and keep the code inside LDK;
  2. Abstract the KeyManager into a trait and allow lampo (and other LDK implementations) to implement the trait and use a DefaultKeyManager that implements the KeyManager trait as the current code does. In this way, I can use the adapter pattern without any problems because I can use dynamic dispatch to inject my channel keys. However, this could add a pointer indirection, but I am not sure without writing the code.

Please note that this is not ready for review, but it is more of a discussion on how to move forward.

TheBlueMatt commented 2 weeks ago

Abstract the KeyManager into a trait

This is already true, see the SignerProvider trait.

vincenzopalazzo commented 2 weeks ago

You are right @TheBlueMatt, we discuss it a little bit on discord https://discord.com/channels/915026692102316113/915026887066132481/1252677517240959109 for people interested to follow