Skip to content
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

feat(lsp): Add support for lsp in lampo #277

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Harshit933
Copy link
Collaborator

@Harshit933 Harshit933 commented Jul 18, 2024

This project aims to configure lampo to be able to act as a lightning liquidity provider and be able to act both as a client and as a server.

Changes done:

  1. lampo-common/src/conf.rs: Configure lampo config to be able to act as provider or client based on the input we give.
  2. lampo-common/src/event/liquidity.rs: Created a new event file where we handle all the incoming events from the lightning-liquidity
  3. lampod/src/actions/handler.rs: Made changes to emit different events while we act as a server, events could be: HTLCIntercepted, PaymentForwarded, HTLCHandlingFailed etc.
  4. lampod/src/lib.rs: Made suitable changes to spin up our node with different configs for message_handler.
  5. lampod/src/ln/message_handler.rs: This was mostly copied from the https://github.com/tnull/ldk-node-hack as it serves two different handlers for peer manager, when we are not acting as a LSP we handle the messages via LampoCustomMessageHandler::Liquidity and LampoCustomMessageHandler::Ignoring is basically a dummy handler.
  6. tests/tests/src/lampo_tests.rs: Created two new tests for the LSPs.

lampod/src/liquidity.rs Outdated Show resolved Hide resolved
lampod/src/liquidity.rs Outdated Show resolved Hide resolved
lampod/src/liquidity.rs Outdated Show resolved Hide resolved
lampod/src/liquidity.rs Outdated Show resolved Hide resolved
lampod/src/liquidity.rs Outdated Show resolved Hide resolved
lampod/src/lib.rs Outdated Show resolved Hide resolved
lampod/src/liquidity.rs Outdated Show resolved Hide resolved
lampod/src/liquidity.rs Outdated Show resolved Hide resolved
lampod/src/liquidity.rs Outdated Show resolved Hide resolved
lampod/src/liquidity.rs Outdated Show resolved Hide resolved
lampod/src/liquidity.rs Outdated Show resolved Hide resolved
This commit allows our node to act as a server to provide
liquidity to other nodes.
@Harshit933 Harshit933 marked this pull request as ready for review August 20, 2024 01:49
Comment on lines +130 to +134
// Must be used when we act as a liquidity provider
conf.ldk_conf = UserConfig {
accept_intercept_htlcs: true,
..Default::default()
};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think this is the correct place

// These functions should be called when we get something like
// liquidity=consumer of liquidity=provider inside lampo.conf
pub fn configure_as_liquidity_consumer(&mut self) {
self.liquidity = Some("Consumer".to_string())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.liquidity = Some("Consumer".to_string())
self.liquidity = Some("Consumer".to_string())

use an enum like LiquisityProvider::Consumer

lampo-common/src/event.rs Outdated Show resolved Hide resolved
use lightning_liquidity::{lsps0::ser::RequestId, lsps2::msgs::OpeningFeeParams};

#[derive(Debug, Clone)]
pub enum LiquidityEvent {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure that this is the correct place where to put the event, but maybe this can be moved later in another crate

@@ -48,3 +48,7 @@ pub mod btc_rpc {
pub mempoolminfee: f32,
}
}

pub mod chrono {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not understand why we need this

@@ -44,27 +46,33 @@ pub type SimpleArcPeerManager<M, T, L> = PeerManager<
Arc<P2PGossipSync<Arc<NetworkGraph<Arc<L>>>, Arc<T>, Arc<L>>>,
Arc<LampoArcOnionMessenger<L>>,
Arc<L>,
IgnoringMessageHandler,
LampoCustomMessageHandler,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LampoCustomMessageHandler,
LampoMessageHandler,

Renaming

Arc<LampoKeysManager>,
>;

type InnerLampoPeerManager =
pub type InnerLampoPeerManager =
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

node3.fund_wallet(6).unwrap();
Err(())
});
// This would return a timeout as json_pay will continue to wait till it get an
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is the code where you are calling accept_inbound_channel_from_trusted_peer_0conf?

Comment on lines 140 to 155
if let Some(_) = liquidity_manager {
let _ = self.channel_manager.channeld().accept_inbound_channel_from_trusted_peer_0conf(&temporary_channel_id, &counterparty_node_id, 0);
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think this is called at any point. We should keep the error here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is being called when we specifically accepting the channels with 0conf, which would be used when we are a client requesting for in bound liquidity. This would come handy when the payer pays the JIT invoice and the LSP on the go creates a channel with the client.

}
ldk::events::Event::ChannelReady {
channel_id,
user_channel_id,
counterparty_node_id,
channel_type,
} => {
let liquidity_manager = self.liquidity_manager.clone();
if let Some(ref liq_manager) = liquidity_manager {
let _ = liquidity_manager.unwrap().channel_ready(user_channel_id, &channel_id, &counterparty_node_id);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should do this only with the LSP not with any nodes

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we are doing this when we have some liquidity config inside the lampo.conf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants