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

Function channel_added_their_htlc

lightningd/peer_htlcs.c:2036–2098  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2034}
2035
2036static bool channel_added_their_htlc(struct channel *channel,
2037 const struct added_htlc *added)
2038{
2039 struct lightningd *ld = channel->peer->ld;
2040 struct htlc_in *hin;
2041 struct secret shared_secret;
2042 struct onionpacket *op;
2043 enum onion_wire failcode;
2044
2045 /* BOLT #2:
2046 *
2047 * - receiving an `amount_msat` equal to 0, OR less than its own `htlc_minimum_msat`:
2048 * - SHOULD send a `warning` and close the connection, or send an
2049 * `error` and fail the channel.
2050 */
2051 if (amount_msat_eq(added->amount, AMOUNT_MSAT(0))
2052 || amount_msat_less(added->amount, channel->our_config.htlc_minimum)) {
2053 channel_internal_error(channel,
2054 "trying to add HTLC amount %s"
2055 " but minimum is %s",
2056 type_to_string(tmpctx,
2057 struct amount_msat,
2058 &added->amount),
2059 type_to_string(tmpctx,
2060 struct amount_msat,
2061 &channel->our_config.htlc_minimum));
2062 return false;
2063 }
2064
2065 /* Do the work of extracting shared secret now if possible. */
2066 /* FIXME: We do this *again* in peer_accepted_htlc! */
2067 op = parse_onionpacket(tmpctx, added->onion_routing_packet,
2068 sizeof(added->onion_routing_packet),
2069 &failcode);
2070 if (op) {
2071 if (!ecdh_maybe_blinding(&op->ephemeralkey,
2072 added->blinding, &added->blinding_ss,
2073 &shared_secret)) {
2074 log_debug(channel->log, "htlc %"PRIu64
2075 ": can't tweak pubkey", added->id);
2076 return false;
2077 }
2078 }
2079
2080 /* This stays around even if we fail it immediately: it *is*
2081 * part of the current commitment. */
2082 hin = new_htlc_in(channel, channel, added->id, added->amount,
2083 added->cltv_expiry, &added->payment_hash,
2084 op ? &shared_secret : NULL,
2085 added->blinding, &added->blinding_ss,
2086 added->onion_routing_packet,
2087 added->fail_immediate);
2088
2089 /* Save an incoming htlc to the wallet */
2090 wallet_htlc_save_in(ld->wallet, channel, hin);
2091 /* Update channel stats */
2092 wallet_channel_stats_incr_in_offered(ld->wallet, channel->dbid,
2093 added->amount);

Callers 1

peer_got_commitsigFunction · 0.85

Calls 10

amount_msat_lessFunction · 0.85
ecdh_maybe_blindingFunction · 0.85
new_htlc_inFunction · 0.85
wallet_htlc_save_inFunction · 0.85
connect_htlc_inFunction · 0.85
channel_internal_errorFunction · 0.70
amount_msat_eqFunction · 0.50
type_to_stringClass · 0.50
parse_onionpacketFunction · 0.50

Tested by

no test coverage detected