Skip to content

Commit

Permalink
tests: Starting working on pay_a_jit_invoice integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
Harshit933 committed Aug 21, 2024
1 parent 7257d8c commit df33e5d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
4 changes: 4 additions & 0 deletions lampo-testing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ impl LampoTesting {
.ldk_conf
.channel_handshake_limits
.force_announced_channel_preference = false;
// This option is used when we want to configure the 0 conf channel for the LSP.
// OpenChannelRequest is received in the handler if this is set to true then we
// manually accept the channel having 0 confirmations of ChannelPending state.
lampo_conf.ldk_conf.manually_accept_inbound_channels = true;
let (wallet, mnemonic) = CoreWalletManager::new(Arc::new(lampo_conf.clone()))?;
let wallet = Arc::new(wallet);
let mut lampo = LampoDaemon::new(lampo_conf.clone(), wallet.clone());
Expand Down
1 change: 0 additions & 1 deletion lampod-cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ impl TryInto<LampoConf> for LampoCliArgs {

let path = self.data_dir.unwrap_or(conf.root_path);
// FIXME: this override the full configuration, we should merge the two
// FIXME: Make this configurable
conf = LampoConf::new(Some(path), Some(conf.network), None)?;
conf.prepare_dirs()?;

Expand Down
16 changes: 14 additions & 2 deletions lampod/src/actions/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ impl Handler for LampoHandler {
push_msat,
channel_type,
} => {
Err(error::anyhow!("Request for open a channel received, unfortunatly we do not support this feature yet."))
log::info!("Recieved open channel request!");
let liquidity_manager = self.liquidity_manager.clone();
if let Some(_) = liquidity_manager {
let _ = self.channel_manager.channeld().accept_inbound_channel_from_trusted_peer_0conf(&temporary_channel_id, &counterparty_node_id, 0);
}
Ok(())
}
ldk::events::Event::ChannelReady {
channel_id,
Expand Down Expand Up @@ -305,17 +310,24 @@ impl Handler for LampoHandler {
},
ldk::events::Event::HTLCHandlingFailed { prev_channel_id, failed_next_destination } => {
log::info!("HTLC Handling failed");
let liquidity_manager = self.liquidity_manager.clone();
if let Some(ref liq_manager) = liquidity_manager {
let _ = liquidity_manager.unwrap().htlc_handling_failed(failed_next_destination.clone());
}
let event = LiquidityEvent::HTLCHandlingFailed { prev_channel_id, failed_next_destination };
self.emit(Event::Liquidity(event));
Ok(())
}
ldk::events::Event::PaymentForwarded { prev_channel_id, next_channel_id, prev_user_channel_id, next_user_channel_id, total_fee_earned_msat, skimmed_fee_msat, claim_from_onchain_tx, outbound_amount_forwarded_msat } => {
log::info!("Payment Forwarded");
let liquidity_manager = self.liquidity_manager.clone();
if let Some(ref liq_manager) = liquidity_manager {
let _ = liquidity_manager.unwrap().payment_forwarded(next_channel_id.unwrap());
}
let event = LiquidityEvent::PaymentForwarded { prev_channel_id, next_channel_id, prev_user_channel_id, next_user_channel_id, total_fee_earned_msat, skimmed_fee_msat, claim_from_onchain_tx, outbound_amount_forwarded_msat };
self.emit(Event::Liquidity(event));
Ok(())
}

_ => Err(error::anyhow!("unexpected ldk event: {:?}", event)),
}
}
Expand Down
24 changes: 23 additions & 1 deletion lampod/src/ln/liquidity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use lampo_common::event::liquidity::LiquidityEvent;
use lampo_common::event::Event;
use lampo_common::handler::Handler;
use lampo_common::keys::LampoKeysManager;
use lampo_common::ldk::events::HTLCDestination;
use lampo_common::ldk::invoice::Bolt11Invoice;
use lampo_common::ldk::invoice::InvoiceBuilder;
use lampo_common::ldk::invoice::RouteHint;
Expand Down Expand Up @@ -106,6 +107,18 @@ impl LampoLiquidityManager {
}
}

pub fn htlc_handling_failed(&self, failed_next_destination: HTLCDestination) -> error::Result<()>{
self.liquidity_manager()
.lsps2_service_handler()
.unwrap()
.htlc_handling_failed(
failed_next_destination,
)
.map_err(|e| error::anyhow!("Error : {:?}", e))?;

Ok(())
}

fn has_some_provider(&self) -> Option<LSPManager> {
self.lsp_manager.clone()
}
Expand Down Expand Up @@ -135,6 +148,15 @@ impl LampoLiquidityManager {
Ok(())
}

pub fn payment_forwarded(&self, next_channel_id: ChannelId) -> error::Result<()> {
self.liquidity_manager()
.lsps2_service_handler()
.unwrap()
.payment_forwarded(next_channel_id)
.map_err(|e| error::anyhow!("Error : {:?}", e))?;
Ok(())
}

pub fn channel_ready(
&self,
user_channel_id: u128,
Expand Down Expand Up @@ -429,7 +451,7 @@ impl LampoLiquidityManager {
// TODO: This needs to be configurable
let expiry_seconds = 300;

let min_final_cltv_expiry_delta = MIN_FINAL_CLTV_EXPIRY_DELTA + 2;
let min_final_cltv_expiry_delta = MIN_FINAL_CLTV_EXPIRY_DELTA + 4;

let res = self
.channel_manager
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/src/lampo_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ pub fn test_pay_a_jit_invoice() -> error::Result<()> {
// The Provider needs to pay this invoice
let result = node2
.liquidity()
.create_jit_invoice(10000, "A new desc".to_string())?;
.create_jit_invoice(1000000, "A new desc".to_string())?;

log::info!("This is the invoice: {}", result.clone().to_string());

Expand Down

0 comments on commit df33e5d

Please sign in to comment.