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

Function peer_accepted_htlc

lightningd/peer_htlcs.c:1495–1659  ·  view source on GitHub ↗

* Everyone is committed to this htlc of theirs * * @param ctx: context for failmsg, if any. * @param channel: The channel this HTLC was accepted from. * @param id: the ID of the HTLC we accepted * @param replay: Are we loading from the database and therefore should not * perform the transition to RCVD_ADD_ACK_REVOCATION? * @param[out] badonion: Set non-zero if the onion was bad. * @

Source from the content-addressed store, hash-verified

1493 * If this returns false, exactly one of @badonion or @failmsg is set.
1494 */
1495static bool peer_accepted_htlc(const tal_t *ctx,
1496 struct channel *channel, u64 id,
1497 bool replay,
1498 enum onion_wire *badonion,
1499 u8 **failmsg)
1500{
1501 struct htlc_in *hin;
1502 struct route_step *rs;
1503 struct onionpacket *op;
1504 struct lightningd *ld = channel->peer->ld;
1505 struct htlc_accepted_hook_payload *hook_payload;
1506
1507
1508 *failmsg = NULL;
1509 *badonion = 0;
1510
1511 hin = find_htlc_in(ld->htlcs_in, channel, id);
1512 if (!hin) {
1513 channel_internal_error(channel,
1514 "peer_got_revoke unknown htlc %"PRIu64, id);
1515 *failmsg = towire_temporary_node_failure(ctx);
1516 goto fail;
1517 }
1518
1519 if (hin->fail_immediate && htlc_in_update_state(channel, hin, RCVD_ADD_ACK_REVOCATION)) {
1520 log_debug(channel->log, "failing immediately, as requested");
1521 /* Failing the htlc, typically done because of htlc dust */
1522 *failmsg = towire_temporary_node_failure(ctx);
1523 goto fail;
1524 }
1525
1526 if (!replay && !htlc_in_update_state(channel, hin, RCVD_ADD_ACK_REVOCATION)) {
1527 *failmsg = towire_temporary_node_failure(ctx);
1528 goto fail;
1529 }
1530
1531 htlc_in_check(hin, __func__);
1532
1533 if (channel->peer->dev_ignore_htlcs) {
1534 log_debug(channel->log, "their htlc %"PRIu64" dev_ignore_htlcs",
1535 id);
1536 return true;
1537 }
1538
1539 /* BOLT #2:
1540 *
1541 * - SHOULD fail to route any HTLC added after it has sent `shutdown`.
1542 */
1543 if (!replay && !channel_state_can_add_htlc(channel->state)) {
1544 *failmsg = towire_permanent_channel_failure(ctx);
1545 log_debug(channel->log,
1546 "Rejecting their htlc %"PRIu64
1547 " since we're shutting down",
1548 id);
1549 goto fail;
1550 }
1551
1552 /* BOLT #2:

Callers 2

peer_got_revokeFunction · 0.85
htlcs_resubmitFunction · 0.85

Calls 15

find_htlc_inFunction · 0.85
htlc_in_update_stateFunction · 0.85
parse_onionpacketFunction · 0.85
process_onionpacketFunction · 0.85
fmt_secretFunction · 0.85
onion_decodeFunction · 0.85
serialize_onionpacketFunction · 0.85
blinding_hash_e_and_ssFunction · 0.85
blinding_next_path_keyFunction · 0.85
calc_forwarding_channelFunction · 0.85
towire_tlvstream_rawFunction · 0.85

Tested by

no test coverage detected