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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lampo-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ crossbeam-channel = "0.5.8"
anyhow = "1.0.70"
colored = "1.9"
log = { version = "0.4", features = ["std"] }
chrono = { version = "0.4", features = ["std"], default-features = false }
chrono = { version = "0.4", features = ["std", "clock"], default-features = false }
serde_json = "1.0"
serde = "1.0"
hex = "0.4.3"
lightning-liquidity = "0.1.0-alpha.4"
41 changes: 41 additions & 0 deletions lampo-common/src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ pub struct LampoConf {
pub log_level: String,
pub alias: Option<String>,
pub announce_addr: Option<String>,
// Should be something like liquidity=consumer, liquidity=provider or none
pub liquidity: Option<Liquidity>,
pub lsp_node_id: Option<String>,
pub lsp_socket_addr: Option<String>,
}

impl Default for LampoConf {
Expand Down Expand Up @@ -51,6 +55,9 @@ impl Default for LampoConf {
log_file: None,
alias: None,
announce_addr: None,
liquidity: None,
lsp_node_id: None,
lsp_socket_addr: None,
}
}
}
Expand Down Expand Up @@ -120,6 +127,11 @@ impl LampoConf {
let input_path = path;
let path = Self::normalize_root_dir(&conf.root_path, conf.network);
conf.root_path = path.clone();
// Must be used when we act as a liquidity provider
conf.ldk_conf = UserConfig {
accept_intercept_htlcs: true,
..Default::default()
};
Comment on lines +130 to +134
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


let lampo_file = format!("{}/lampo.conf", conf.path());

Expand All @@ -133,6 +145,22 @@ impl LampoConf {

Ok(conf)
}

// 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(Liquidity::Consumer);
}

pub fn configure_as_liquidity_provider(&mut self) {
self.liquidity = Some(Liquidity::Provider);
}
}

#[derive(Debug, Clone)]
pub enum Liquidity {
Consumer,
Provider,
}

impl TryFrom<String> for LampoConf {
Expand Down Expand Up @@ -220,6 +248,16 @@ impl TryFrom<String> for LampoConf {
let log_file = conf.get_conf("log-file").unwrap_or(None);
let alias = conf.get_conf("alias").unwrap_or(None);
let announce_addr = conf.get_conf("announce-addr").unwrap_or(None);
let liquidity = conf
.get_conf("liquidity")
.unwrap_or(None)
.map(|liq| match liq.as_str() {
"Provider" => Liquidity::Provider,
"Consumer" => Liquidity::Consumer,
_ => panic!(),
});
let lsp_node_id = conf.get_conf("lsp-node-id").unwrap_or(None);
let lsp_socket_addr = conf.get_conf("lsp-socket-addr").unwrap_or(None);

Ok(Self {
inner: Some(conf),
Expand All @@ -237,6 +275,9 @@ impl TryFrom<String> for LampoConf {
log_level: level,
alias,
announce_addr,
liquidity,
lsp_node_id,
lsp_socket_addr,
})
}
}
Expand Down
3 changes: 3 additions & 0 deletions lampo-common/src/event.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
//! Events commands
pub mod liquidity;
pub mod ln;
pub mod onchain;

use std::sync::{Arc, Mutex};

use crate::chan;
use crate::event::liquidity::LiquidityEvent;
use crate::event::ln::LightningEvent;
use crate::event::onchain::OnChainEvent;

Expand Down Expand Up @@ -64,5 +66,6 @@ impl<T: Clone> Subscriber<T> {
pub enum Event {
Lightning(LightningEvent),
OnChain(OnChainEvent),
Liquidity(LiquidityEvent),
Inventory,
}
56 changes: 56 additions & 0 deletions lampo-common/src/event/liquidity.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use bitcoin::secp256k1::PublicKey;
use lightning::events::HTLCDestination;
use lightning::ln::{channelmanager::InterceptId, ChannelId, PaymentHash};
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

OpenParamsReady {
counterparty_node_id: PublicKey,
opening_fee_params_menu: Vec<OpeningFeeParams>,
},
InvoiceparamsReady {
counterparty_node_id: PublicKey,
intercept_scid: u64,
cltv_expiry_delta: u32,
},
BuyRequest {
request_id: RequestId,
counterparty_node_id: PublicKey,
opening_fee_params: OpeningFeeParams,
payment_size_msat: Option<u64>,
},
Geinfo {
request_id: RequestId,
counterparty_node_id: PublicKey,
token: Option<String>,
},
OpenChannel {
their_network_key: PublicKey,
amt_to_forward_msat: u64,
opening_fee_msat: u64,
user_channel_id: u128,
intercept_scid: u64,
},
HTLCHandlingFailed {
prev_channel_id: ChannelId,
failed_next_destination: HTLCDestination,
},
HTLCIntercepted {
intercept_id: InterceptId,
requested_next_hop_scid: u64,
payment_hash: PaymentHash,
inbound_amount_msat: u64,
expected_outbound_amount_msat: u64,
},
PaymentForwarded {
prev_channel_id: Option<ChannelId>,
next_channel_id: Option<ChannelId>,
prev_user_channel_id: Option<u128>,
next_user_channel_id: Option<u128>,
total_fee_earned_msat: Option<u64>,
skimmed_fee_msat: Option<u64>,
claim_from_onchain_tx: bool,
outbound_amount_forwarded_msat: Option<u64>,
},
}
4 changes: 4 additions & 0 deletions lampo-common/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ impl LampoKeysManager {
self.htlc_base_secret = Some(SecretKey::from_str(&htlc_base_secret).unwrap());
self.shachain_seed = Some(self.inner.get_secure_random_bytes())
}

pub fn get_node_secret_key(&self) -> SecretKey {
self.inner.get_node_secret_key()
}
}

impl EntropySource for LampoKeysManager {
Expand Down
4 changes: 4 additions & 0 deletions lampo-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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

pub use chrono::*;
}
4 changes: 2 additions & 2 deletions lampo-common/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::time::SystemTime;
// FIXME: this is not async we should modify it
use std::fs::File;

use chrono::prelude::*;
use crate::chrono::prelude::*;
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
use crate::chrono::prelude::*;
use chrono::prelude::*;

use colored::*;

pub use log::{Level, Log, Metadata, Record, SetLoggerError};
Expand Down Expand Up @@ -53,7 +53,7 @@ impl Log for Logger {
writeln!(
stream,
"{} {}",
DateTime::from(SystemTime::now())
DateTime::<Utc>::from(SystemTime::now())
.to_rfc3339_opts(SecondsFormat::Millis, true)
.white(),
message,
Expand Down
Loading
Loading