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

Function handle_localpay

lightningd/peer_htlcs.c:435–552  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

433}
434
435static void handle_localpay(struct htlc_in *hin,
436 struct amount_msat amt_to_forward,
437 u32 outgoing_cltv_value,
438 struct amount_msat total_msat,
439 const struct amount_msat *invoice_msat_override,
440 const struct secret *payment_secret,
441 const u8 *payment_metadata)
442{
443 const u8 *failmsg;
444 struct lightningd *ld = hin->key.channel->peer->ld;
445
446 /* BOLT #4:
447 * - If it is the final node:
448 * - MUST treat `total_msat` as if it were equal to `amt_to_forward` if it
449 * is not present.
450 * - MUST return an error if:
451 * - incoming `amount_msat` < `amt_to_forward`.
452 */
453 if (amount_msat_less(hin->msat, amt_to_forward)) {
454 log_debug(hin->key.channel->log,
455 "HTLC %"PRIu64" final incorrect amount:"
456 " %s in, %s expected",
457 hin->key.id,
458 fmt_amount_msat(tmpctx, hin->msat),
459 fmt_amount_msat(tmpctx, amt_to_forward));
460 /* BOLT #4:
461 * 1. type: 19 (`final_incorrect_htlc_amount`)
462 * 2. data:
463 * * [`u64`:`incoming_htlc_amt`]
464 *
465 * The amount in the HTLC is less than the value in the onion.
466 */
467 failmsg = towire_final_incorrect_htlc_amount(NULL, hin->msat);
468 goto fail;
469 }
470
471 /* BOLT #4:
472 * - If it is the final node:
473 * - MUST treat `total_msat` as if it were equal to `amt_to_forward` if it
474 * is not present.
475 * - MUST return an error if:
476 *...
477 * - incoming `cltv_expiry` < `outgoing_cltv_value`.
478 */
479 if (!check_cltv(hin, hin->cltv_expiry, outgoing_cltv_value, 0)) {
480 /* BOLT #4:
481 *
482 * 1. type: 18 (`final_incorrect_cltv_expiry`)
483 * 2. data:
484 * * [`u32`:`cltv_expiry`]
485 *
486 * The CLTV expiry in the HTLC is less than the value in the onion.
487 */
488 failmsg = towire_final_incorrect_cltv_expiry(NULL,
489 hin->cltv_expiry);
490 goto fail;
491 }
492

Callers 1

htlc_accepted_hook_finalFunction · 0.85

Calls 7

check_cltvFunction · 0.85
tal_hexFunction · 0.85
get_block_heightFunction · 0.70
local_fail_in_htlcFunction · 0.70
amount_msat_lessFunction · 0.50
fmt_amount_msatFunction · 0.50

Tested by

no test coverage detected