# Design Document for Importing RGB on Lampo ## Pre-condition - Understand the changes in the Lightning Network protocol with RGB. See [RGB Over Lightning Network Compatibility](https://docs.rgb.info/rgb-over-lightning-network/lightning-network-compatibility) - Missing swaps! So for now, we do not care about this part. - Heavily rely on [rgb-lib](https://github.com/RGB-Tools/rgb-lib) and [rgb-lightning-node](https://github.com/RGB-Tools/rgb-lightning-node). If there are any missing parts, ping @vincenzopalazzo for clarification. - Try using [easy-rgb](https://github.com/vincenzopalazzo/easy-rgb), but do not rely on it because the persistence is currently a bit different from [rgb-lightning-node](https://github.com/RGB-Tools/rgb-lightning-node). ## Next Steps 1. Create a new [wallet interface inside Lampo](https://github.com/vincenzopalazzo/lampo.rs/blob/main/lampo-common/src/wallet.rs) - Identify the required changes, but it should be quite straightforward to implement. 2. Make the LDK version of Lampo compatible with the LDK that rgb-lib is using through conditional compilation. - Clone LDK with Git. See [Specifying Dependencies from Git Repositories](https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#specifying-dependencies-from-git-repositories). - Compile Lampo with an RGB feature flag. See [Platform-Specific Dependencies](https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#platform-specific-dependencies). If this is not possible, we should fork Lampo and revert to a previous version of LDK. ```toml! [dependencies] # how to manage the collision? https://stackoverflow.com/a/58739076/10854225 vanilla-lightning = { git = "https://github.com/lightningdevkit/rust-lightning.git", optional = true } rgb-lightning = { git = "https://github.com/RGB-Tools/rust-lightning.git", optional = true } [features] default = ["vanilla-lightning"] rgb = ["rgb-lightning"] ### When you go to import `lampo-common` [dependencies] lampo-common = { path = "../lampo-common", default-features = false, features = ["rgb"] } ``` 3. Identify the changes that [easy-rgb](https://github.com/vincenzopalazzo/easy-rgb) requires to be compatible with [rgb-lightning-node](https://github.com/RGB-Tools/rgb-lightning-node). ---- Please work on a `macros/rgb` branch! All your change and PR need to be done to the `macros/rgb` branch --- Just as podcast look at Greg Kroah-Hartman talk https://www.youtube.com/watch?v=vyenmLqJQjs --- ## Meeting June 10th 2024 - Look at my PR https://github.com/vincenzopalazzo/lampo.rs/pull/112/files Errors regarding `onion_messsage` ``` warning: `lampo-common` (lib) generated 1 warning (run `cargo fix --lib -p lampo-common` to apply 1 suggestion) Compiling lampod v0.0.1 (/home/doom/Desktop/lampo.rs/lampod) error[E0603]: module `messenger` is private --> lampod/src/ln/onion_message.rs:25:43 | 25 | rgb_lampo_common::ldk::onion_message::messenger::OnionMessagePath, | ^^^^^^^^^ private module | note: the module `messenger` is defined here --> /home/doom/.cargo/git/checkouts/rust-lightning-80885787907c2cbb/deb9485/lightning/src/onion_message/mod.rs:23:1 | 23 | mod messenger; | ^^^^^^^^^^^^^ error[E0603]: module `messenger` is private --> lampod/src/ln/onion_message.rs:30:43 | 30 | rgb_lampo_common::ldk::onion_message::messenger, | ^^^^^^^^^ private module | note: the module `messenger` is defined here --> /home/doom/.cargo/git/checkouts/rust-lightning-80885787907c2cbb/deb9485/lightning/src/onion_message/mod.rs:23:1 | 23 | mod messenger; | ^^^^^^^^^^^^^ error[E0603]: module `messenger` is private --> lampod/src/ln/peer_manager.rs:34:43 | 34 | rgb_lampo_common::ldk::onion_message::messenger::OnionMessenger, | ^^^^^^^^^ private module | note: the module `messenger` is defined here --> /home/doom/.cargo/git/checkouts/rust-lightning-80885787907c2cbb/deb9485/lightning/src/onion_message/mod.rs:23:1 | 23 | mod messenger; | ^^^^^^^^^^^^^ error[E0603]: module `messenger` is private --> lampod/src/ln/route.rs:54:43 | 54 | rgb_lampo_common::ldk::onion_message::messenger::MessageRouter, | ^^^^^^^^^ private module | note: the module `messenger` is defined here --> /home/doom/.cargo/git/checkouts/rust-lightning-80885787907c2cbb/deb9485/lightning/src/onion_message/mod.rs:23:1 | 23 | mod messenger; | ^^^^^^^^^^^^^ help: consider importing one of these items instead | 54 | crate::MessageRouter, | ~~~~~~~~~~~~~~~~~~~~ 54 | rgb_lampo_common::ldk::onion_message::MessageRouter, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error[E0603]: module `messenger` is private --> lampod/src/ln/route.rs:63:43 | 63 | rgb_lampo_common::ldk::onion_message::messenger, | ^^^^^^^^^ private module | note: the module `messenger` is defined here --> /home/doom/.cargo/git/checkouts/rust-lightning-80885787907c2cbb/deb9485/lightning/src/onion_message/mod.rs:23:1 | 23 | mod messenger; | ^^^^^^^^^^^^^ For more information about this error, try `rustc --explain E0603`. error: could not compile `lampod` (lib) due to 5 previous errors ``` ---- # Your todo-list for next week - [x] Create a new branch with what we have learn from rgb feature with cargo - With a single commit - [x] work only in `lampo-common`, `lampod`, `lampo-testing`, and `tests/` (just the rust test) - [ ] when you get all this working, (cargo build --feature vanilla/ cargo build --feature rgb) - [ ] Wait on me that I rebase `next` - [ ] and then you work on the branch reworking. - [ ] Open a PR on lampo on the rgb branch `rgb` - [ ] Start working on the wallet (this required experimenting easy-rgb) ## Your commit for the next week Link for the first step - https://github.com/Harshit933/lampo.rs/tree/macros/rgb-v2 ## Meeting June 17th 2024 What I did on the remaining week : - Observed that most of the `lightning v0.0.118` depends on the `bitcoin 0.29.2`, check it [here](https://github.com/Harshit933/rust-lightning/blob/deb9485ddcbf49820ff3a36f4a5f31d701eb83e8/lightning/Cargo.toml#L44) So, I was getting various `errors` which are based on the `bitcoin` version while implementing another `ChannelManager` for the `rgb` version of `lampo`(as our default `channelmanager` can't be used, see errors as mentioned below ) Some of them : ``` error[E0053]: method `broadcast_transactions` has an incompatible type for trait --> lampod/src/chain/blockchain.rs:101:42 | 101 | fn broadcast_transactions(&self, tx: &[&Transaction]) { | ^^^^^^^^^^^^^^^ | | | expected `Transaction`, found `lampo_common::backend::Transaction` | help: change the parameter type to match the trait: `&[&bitcoin::blockdata::transaction::Transaction]` | = note: expected signature `fn(&LampoChainManager, &[&bitcoin::blockdata::transaction::Transaction])` found signature `fn(&LampoChainManager, &[&lampo_common::backend::Transaction])` error[E0053]: method `register_tx` has an incompatible type for trait --> lampod/src/chain/blockchain.rs:112:33 | 112 | fn register_tx(&self, txid: &bitcoin::Txid, script_pubkey: &bitcoin::Script) { | ^^^^^^^^^^^^^^ | | | expected `Txid`, found `lampo_common::backend::Txid` | help: change the parameter type to match the trait: `&bitcoin::hash_types::newtypes::Txid` | = note: expected signature `fn(&LampoChainManager, &bitcoin::hash_types::newtypes::Txid, &bitcoin::blockdata::script::Script)` found signature `fn(&LampoChainManager, &lampo_common::backend::Txid, &lampo_common::backend::Script)` ``` Errors related to `ChannelManager`: ``` warning: `lampo-common` (lib) generated 1 warning (run `cargo fix --lib -p lampo-common` to apply 1 suggestion) error[E0107]: struct takes 5 generic arguments but 6 generic arguments were supplied --> lampod/src/ln/channel_manager.rs:66:24 | 66 | pub type LampoRouter = DefaultRouter< | ^^^^^^^^^^^^^ expected 5 generic arguments ... 72 | LampoScorer, | ----------- help: remove this generic argument | note: struct defined here, with 5 generic parameters: `G`, `L`, `S`, `SP`, `Sc` --> /home/doom/.cargo/git/checkouts/rust-lightning-80885787907c2cbb/c36fd74/lightning/src/routing/router.rs:38:12 | 38 | pub struct DefaultRouter<G: Deref<Target = NetworkGraph<L>>, L: Deref, S: Deref, SP: Sized, Sc: ScoreLookUp<ScoreParams = SP>> where | ^^^^^^^^^^^^^ - - - -- -- error[E0107]: struct takes 5 generic arguments but 6 generic arguments were supplied --> lampod/src/ln/channel_manager.rs:256:9 | 256 | DefaultRouter< | ^^^^^^^^^^^^^ expected 5 generic arguments ... 262 | LampoScorer, | ----------- help: remove this generic argument | note: struct defined here, with 5 generic parameters: `G`, `L`, `S`, `SP`, `Sc` --> /home/doom/.cargo/git/checkouts/rust-lightning-80885787907c2cbb/c36fd74/lightning/src/routing/router.rs:38:12 | 38 | pub struct DefaultRouter<G: Deref<Target = NetworkGraph<L>>, L: Deref, S: Deref, SP: Sized, Sc: ScoreLookUp<ScoreParams = SP>> w... | ^^^^^^^^^^^^^ - - - -- -- Some errors have detailed explanations: E0107, E0425, E0432, E0603. For more information about an error, try `rustc --explain E0107`. error: could not compile `lampod` (lib) due to 6 previous errors ``` So what I did is I re-exported the bitcoin 0.29.2 to be used with `rgb` version of lightning. But it still has some challenges(asked inside the code). - Created a seperate branch where I tried to implement a different `ChannelManager` than the version we are using (need review). Link to the new branch : https://github.com/Harshit933/lampo.rs/tree/macros/rgb-v2-call-review ### vincent ```rust! #[cfg(vanilla)] pub mod bitcoin { // import the type here Define the type here! pub use bitcoin::ScriptBuff; pub use bitcoin::hash::ShiBuff; } #[cfg(rgb)] pub mod bitcoin { // import the type but call them like the vanilla type pub use bitcoin::Script as ScriptBuff; pub use bitcoin::ShiBuff; } // Use everywhere the type as use lampo_common::bitcoin::ScirptBuff; ``` Make a trait for all the functions inside the `actions/handler.rs`. Then implement the trait for vanilla inside `lampod` and for rgb inside lampo-rgb. ## Your question for the next - As we see the code I have put up various questions and put up TODOs and FIXME there. ## TODO list for next time (Compiles for all the packages seperately) - [x] when you get all this working, (cargo build --feature vanilla/ cargo build --feature rgb) - [ ] Wait on me that I rebase `next` - [ ] and then you work on the branch reworking. - [ ] Open a PR on lampo on the rgb branch `rgb` - [ ] Start working on the wallet (this required experimenting easy-rgb) (in-progress) - [x] Make a trait for all the functions inside the actions/handler.rs. Then implement the trait for vanilla inside lampod and for rgb inside lampo-rgb. (in-progress Link: https://github.com/Harshit933/lampo.rs/commits/macros/rgb-v2-call-review/) - [ ] Implement a `visitor` pattern for `json_pay`. See inside `coffee` (in-progress) ## Meeting this week (8-7-24): - Things that I tried this week: **Implement a `visitor` pattern for `json_pay`.** - Visitor pattern is supposed to to work different algorithms/functions based on the object that we pass through. Here, we also need to do the same but at one time we have to compile only one version of the function!. This is different as ultimately we need to bind the functionality of the `Rgb` pay function with `#[cfg(feature = "rgb")]` and vanilla one with `#[cfg(feature = "vanilla")]` - Implement a facade pattern inside `lampo-rgb`? - While implementing the handler trait, i did something like this https://github.com/Harshit933/lampo.rs/commit/545042fb778f9035c7badff46f66f43962fa7d46 . Two things: If we take trait `handler` from `lampod` and implement this inside `lampo-rgb`, I have a cyclic dependency as we need to take `lampo-rgb` inside lampod also. ## **Meeting this week (15-7-2024)** - What function do we use between these three to get the events from `LiquidityManager`, What is the difference between implementing these three functions : `next_event`, `next_async_event` and `get_and_clear_pending_events`? https://docs.rs/lightning-liquidity/0.1.0-alpha.4/lightning_liquidity/struct.LiquidityManager.html# - Implement a different handler for `LampoLiquidity` that handles all the events from `lightning_liquidity::LiquidityManager`, link - https://github.com/tnull/ldk-node-hack/blob/fbad621a89b298d9bc7e8a56badddb2094284d2a/src/liquidity.rs#L146 - How do we test this? - Should we configure this to provide `lsp-apis` only when we pass a certain flag? Link:https://github.com/vincenzopalazzo/lampo.rs/commit/7cc4c854234364b7855ec969c756a0fa24b327d2