| 358 | } |
| 359 | |
| 360 | static void handle_localpay(struct htlc_in *hin, |
| 361 | struct amount_msat amt_to_forward, |
| 362 | u32 outgoing_cltv_value, |
| 363 | struct amount_msat total_msat, |
| 364 | const struct secret *payment_secret, |
| 365 | const u8 *payment_metadata) |
| 366 | { |
| 367 | const u8 *failmsg; |
| 368 | struct lightningd *ld = hin->key.channel->peer->ld; |
| 369 | |
| 370 | /* BOLT #4: |
| 371 | * |
| 372 | * For the final node, this value MUST be exactly equal to the |
| 373 | * incoming htlc amount, otherwise the HTLC should be rejected. |
| 374 | */ |
| 375 | if (!amount_msat_eq(amt_to_forward, hin->msat)) { |
| 376 | log_debug(hin->key.channel->log, |
| 377 | "HTLC %"PRIu64" final incorrect amount:" |
| 378 | " %s in, %s expected", |
| 379 | hin->key.id, |
| 380 | type_to_string(tmpctx, struct amount_msat, &hin->msat), |
| 381 | type_to_string(tmpctx, struct amount_msat, |
| 382 | &amt_to_forward)); |
| 383 | /* BOLT #4: |
| 384 | * |
| 385 | * 1. type: 19 (`final_incorrect_htlc_amount`) |
| 386 | * 2. data: |
| 387 | * * [`u64`:`incoming_htlc_amt`] |
| 388 | * |
| 389 | * The amount in the HTLC doesn't match the value in the onion. |
| 390 | */ |
| 391 | failmsg = towire_final_incorrect_htlc_amount(NULL, hin->msat); |
| 392 | goto fail; |
| 393 | } |
| 394 | |
| 395 | /* BOLT #4: |
| 396 | * |
| 397 | * 1. type: 18 (`final_incorrect_cltv_expiry`) |
| 398 | * 2. data: |
| 399 | * * [`u32`:`cltv_expiry`] |
| 400 | * |
| 401 | * The CLTV expiry in the HTLC doesn't match the value in the onion. |
| 402 | */ |
| 403 | if (!check_cltv(hin, hin->cltv_expiry, outgoing_cltv_value, 0)) { |
| 404 | failmsg = towire_final_incorrect_cltv_expiry(NULL, |
| 405 | hin->cltv_expiry); |
| 406 | goto fail; |
| 407 | } |
| 408 | |
| 409 | /* BOLT #4: |
| 410 | * |
| 411 | * - if the `cltv_expiry` value is unreasonably near the present: |
| 412 | * - MUST fail the HTLC. |
| 413 | * - MUST return an `incorrect_or_unknown_payment_details` error. |
| 414 | */ |
| 415 | if (get_block_height(ld->topology) + ld->config.cltv_final |
| 416 | > hin->cltv_expiry) { |
| 417 | log_debug(hin->key.channel->log, |
no test coverage detected