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

Function handle_localpay

lightningd/peer_htlcs.c:479–596  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

477}
478
479static void handle_localpay(struct htlc_in *hin,
480 struct amount_msat amt_to_forward,
481 u32 outgoing_cltv_value,
482 struct amount_msat total_msat,
483 const struct amount_msat *invoice_msat_override,
484 const struct secret *payment_secret,
485 const u8 *payment_metadata)
486{
487 const u8 *failmsg;
488 struct lightningd *ld = hin->key.channel->peer->ld;
489
490 /* BOLT #4:
491 * - If it is the final node:
492 * - MUST treat `total_msat` as if it were equal to `amt_to_forward` if it
493 * is not present.
494 * - MUST return an error if:
495 * - incoming `amount_msat` < `amt_to_forward`.
496 */
497 if (amount_msat_less(hin->msat, amt_to_forward)) {
498 log_debug(hin->key.channel->log,
499 "HTLC %"PRIu64" final incorrect amount:"
500 " %s in, %s expected",
501 hin->key.id,
502 fmt_amount_msat(tmpctx, hin->msat),
503 fmt_amount_msat(tmpctx, amt_to_forward));
504 /* BOLT #4:
505 * 1. type: 19 (`final_incorrect_htlc_amount`)
506 * 2. data:
507 * * [`u64`:`incoming_htlc_amt`]
508 *
509 * The amount in the HTLC is less than the value in the onion.
510 */
511 failmsg = towire_final_incorrect_htlc_amount(NULL, hin->msat);
512 goto fail;
513 }
514
515 /* BOLT #4:
516 * - If it is the final node:
517 * - MUST treat `total_msat` as if it were equal to `amt_to_forward` if it
518 * is not present.
519 * - MUST return an error if:
520 *...
521 * - incoming `cltv_expiry` < `outgoing_cltv_value`.
522 */
523 if (!check_cltv(hin, hin->cltv_expiry, outgoing_cltv_value, 0)) {
524 /* BOLT #4:
525 *
526 * 1. type: 18 (`final_incorrect_cltv_expiry`)
527 * 2. data:
528 * * [`u32`:`cltv_expiry`]
529 *
530 * The CLTV expiry in the HTLC is less than the value in the onion.
531 */
532 failmsg = towire_final_incorrect_cltv_expiry(NULL,
533 hin->cltv_expiry);
534 goto fail;
535 }
536

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