Skip to content

Commit

Permalink
forward error from LND
Browse files Browse the repository at this point in the history
  • Loading branch information
lollerfirst committed Jan 28, 2025
1 parent a7b1e03 commit dc1b568
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
16 changes: 15 additions & 1 deletion crates/cdk-integration-tests/tests/regtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,12 +484,26 @@ async fn test_multimint_melt() -> Result<()> {
// Fund the wallets
let quote = wallet1.mint_quote(mint_amount, None).await?;
lnd_client.pay_invoice(quote.request.clone()).await?;
loop {
let quote_status = wallet1.mint_quote_state(&quote.id).await?;
if quote_status.state == MintQuoteState::Paid {
break;
}
tracing::debug!("Quote not yet paid");
}
wallet1
.mint(&quote.id, SplitTarget::default(), None)
.await?;

let quote = wallet2.mint_quote(mint_amount, None).await?;
lnd_client.pay_invoice(quote.request.clone()).await?;
loop {
let quote_status = wallet2.mint_quote_state(&quote.id).await?;
if quote_status.state == MintQuoteState::Paid {
break;
}
tracing::debug!("Quote not yet paid");
}
wallet2
.mint(&quote.id, SplitTarget::default(), None)
.await?;
Expand Down
7 changes: 4 additions & 3 deletions crates/cdk-lnd/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! LND Errors
use fedimint_tonic_lnd::tonic::Status;
use thiserror::Error;

/// LND Error
Expand All @@ -26,9 +27,9 @@ pub enum Error {
/// Missing last hop in route
#[error("LND missing last hop in route")]
MissingLastHop,
/// No MPP record in last hop
#[error("LND missing MPP record in last hop")]
MissingMppRecord,
/// Errors coming from the backend
#[error("LND error: `{0}`")]
LndError(Status),
}

impl From<Error> for cdk::cdk_lightning::Error {
Expand Down
22 changes: 10 additions & 12 deletions crates/cdk-lnd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use cdk::{mint, Bolt11Invoice};
use error::Error;
use fedimint_tonic_lnd::lnrpc::fee_limit::Limit;
use fedimint_tonic_lnd::lnrpc::payment::PaymentStatus;
use fedimint_tonic_lnd::lnrpc::{FeeLimit, HtlcAttempt};
use fedimint_tonic_lnd::lnrpc::{FeeLimit, Hop, HtlcAttempt, MppRecord};
use fedimint_tonic_lnd::tonic::Code;
use fedimint_tonic_lnd::Client;
use futures::{Stream, StreamExt};
Expand Down Expand Up @@ -261,9 +261,9 @@ impl MintLightning for Lnd {
.lock()
.await
.lightning()
.query_routes(fedimint_tonic_lnd::tonic::Request::new(route_req))
.query_routes(route_req)
.await
.map_err(|_| Error::PaymentFailed)?
.map_err(|e| Error::LndError(e))?
.into_inner();

let mut payment_response: HtlcAttempt = HtlcAttempt {
Expand All @@ -274,14 +274,12 @@ impl MintLightning for Lnd {
// update its MPP record,
// attempt it and check the result
for mut route in routes_response.routes.into_iter() {
let last_hop = route.hops.last_mut().ok_or(Error::MissingLastHop)?;
let mpp_record = last_hop
.mpp_record
.as_mut()
.ok_or(Error::MissingMppRecord)?;

mpp_record.payment_addr = payer_addr.clone();
mpp_record.total_amt_msat = amount_msat as i64;
let last_hop: &mut Hop = route.hops.last_mut().ok_or(Error::MissingLastHop)?;
let mpp_record = MppRecord {
payment_addr: payer_addr.clone(),
total_amt_msat: amount_msat as i64,
};
last_hop.mpp_record = Some(mpp_record);

payment_response = self
.client
Expand All @@ -294,7 +292,7 @@ impl MintLightning for Lnd {
..Default::default()
})
.await
.map_err(|_| Error::PaymentFailed)?
.map_err(|e| Error::LndError(e))?
.into_inner();

if let Some(failure) = payment_response.failure {
Expand Down

0 comments on commit dc1b568

Please sign in to comment.