| 2034 | } |
| 2035 | |
| 2036 | static 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); |
no test coverage detected