Skip to content
Open
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
30 changes: 23 additions & 7 deletions plugins/lsps-plugin/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ use cln_lsps::{
},
core::{
lsps2::{
htlc::{Htlc, HtlcAcceptedHookHandler, HtlcDecision, Onion, RejectReason},
htlc::{Htlc, HtlcAcceptedHookHandler, HtlcDecision, HtlcError, Onion, RejectReason},
service::Lsps2ServiceHandler,
},
server::LspsService,
},
proto::lsps0::{Msat, LSPS0_MESSAGE_TYPE},
proto::lsps2::failure_codes::TEMPORARY_CHANNEL_FAILURE,
};
use cln_plugin::{options, HookBuilder, HookFilter, Plugin};
use log::{debug, error, trace};
use log::{debug, error, trace, warn};
use std::path::{Path, PathBuf};
use std::sync::Arc;

Expand Down Expand Up @@ -190,16 +191,31 @@ async fn handle_htlc_inner(
log_decision(&dec);
decision_to_response(dec)?
}
Err(e) => {
// Fixme: Should we log **BROKEN** here?
debug!("Htlc handler failed (continuing): {:#}", e);
return Ok(json_continue());
}
Err(e) => return Ok(handle_htlc_error(e)),
};

Ok(serde_json::to_value(&response)?)
}

fn handle_htlc_error(e: HtlcError) -> serde_json::Value {
match e {
HtlcError::FundChannel(ref cause) => {
warn!(
"LSPS2: Failed to open JIT channel (likely insufficient on-chain balance): {:#}. \
Operator action required.",
cause
);
}
HtlcError::ChannelReadyCheck(ref cause) => {
warn!("LSPS2: Channel ready check failed: {:#}", cause);
}
HtlcError::CapacityQuery(ref cause) => {
error!("LSPS2: Capacity query failed: {:#}", cause);
}
}
json_fail(TEMPORARY_CHANNEL_FAILURE)
}

fn decision_to_response(decision: HtlcDecision) -> Result<serde_json::Value, anyhow::Error> {
Ok(match decision {
HtlcDecision::NotOurs => json_continue(),
Expand Down