MCPcopy Create free account
hub / github.com/ElementsProject/lightning / handle

Method handle

plugins/lsps-plugin/src/core/lsps2/handler.rs:420–577  ·  view source on GitHub ↗
(&self, req: HtlcAcceptedRequest)

Source from the content-addressed store, hash-verified

418
419impl<A: DatastoreProvider + Lsps2OfferProvider + LightningProvider> HtlcAcceptedHookHandler<A> {
420 pub async fn handle(&self, req: HtlcAcceptedRequest) -> AnyResult<HtlcAcceptedResponse> {
421 let scid = match req.onion.short_channel_id {
422 Some(scid) => scid,
423 None => {
424 // We are the final destination of this htlc.
425 return Ok(HtlcAcceptedResponse::continue_(None, None, None));
426 }
427 };
428
429 // A) Is this SCID one that we care about?
430 let ds_rec = match self.api.get_buy_request(&scid).await {
431 Ok(rec) => rec,
432 Err(_) => {
433 return Ok(HtlcAcceptedResponse::continue_(None, None, None));
434 }
435 };
436
437 // Fixme: Check that we don't have a channel yet with the peer that we await to
438 // become READY to use.
439 // ---
440
441 // Fixme: We only accept no-mpp for now, mpp and other flows will be added later on
442 // Fixme: We continue mpp for now to let the test mock handle the htlc, as we need
443 // to test the client implementation for mpp payments.
444 if ds_rec.expected_payment_size.is_some() {
445 warn!("mpp payments are not implemented yet");
446 return Ok(HtlcAcceptedResponse::continue_(None, None, None));
447 // return Ok(HtlcAcceptedResponse::fail(
448 // Some(UNKNOWN_NEXT_PEER.to_string()),
449 // None,
450 // ));
451 }
452
453 // B) Is the fee option menu still valid?
454 let now = Utc::now();
455 if now >= ds_rec.opening_fee_params.valid_until {
456 // Not valid anymore, remove from DS and fail HTLC.
457 let _ = self.api.del_buy_request(&scid).await;
458 return Ok(HtlcAcceptedResponse::fail(
459 Some(TEMPORARY_CHANNEL_FAILURE.to_string()),
460 None,
461 ));
462 }
463
464 // C) Is the amount in the boundaries of the fee menu?
465 if req.htlc.amount_msat.msat() < ds_rec.opening_fee_params.min_fee_msat.msat()
466 || req.htlc.amount_msat.msat() > ds_rec.opening_fee_params.max_payment_size_msat.msat()
467 {
468 // No! reject the HTLC.
469 debug!("amount_msat for scid: {}, was too low or to high", scid);
470 return Ok(HtlcAcceptedResponse::fail(
471 Some(UNKNOWN_NEXT_PEER.to_string()),
472 None,
473 ));
474 }
475
476 // D) Check that the amount_msat covers the opening fee (only for non-mpp right now)
477 let opening_fee = if let Some(opening_fee) = compute_opening_fee(

Calls 15

failFunction · 0.85
compute_opening_feeFunction · 0.85
ppmMethod · 0.80
set_tu64Method · 0.80
set_u64Method · 0.80
to_vecMethod · 0.80
get_buy_requestMethod · 0.45
del_buy_requestMethod · 0.45
to_stringMethod · 0.45
msatMethod · 0.45
get_channel_capacityMethod · 0.45
fund_jit_channelMethod · 0.45