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

Function channel_fail_htlc

channeld/full_channel.c:952–992  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

950}
951
952enum channel_remove_err channel_fail_htlc(struct channel *channel,
953 enum side owner, u64 id,
954 struct htlc **htlcp)
955{
956 struct htlc *htlc;
957
958 htlc = channel_get_htlc(channel, owner, id);
959 if (!htlc)
960 return CHANNEL_ERR_NO_SUCH_ID;
961
962 /* BOLT #2:
963 *
964 * A receiving node:
965 * - if the `id` does not correspond to an HTLC in its current
966 * commitment transaction:
967 * - MUST send a `warning` and close the connection, or send an
968 * `error` and fail the channel.
969 */
970 if (!htlc_has(htlc, HTLC_FLAG(!htlc_owner(htlc), HTLC_F_COMMITTED))) {
971 status_unusual("channel_fail_htlc: %"PRIu64" in state %s",
972 htlc->id, htlc_state_name(htlc->state));
973 return CHANNEL_ERR_HTLC_UNCOMMITTED;
974 }
975
976 /* FIXME: Technically, they can fail this before we're committed to
977 * it. This implies a non-linear state machine. */
978 if (htlc->state == SENT_ADD_ACK_REVOCATION)
979 htlc->state = RCVD_REMOVE_HTLC;
980 else if (htlc->state == RCVD_ADD_ACK_REVOCATION)
981 htlc->state = SENT_REMOVE_HTLC;
982 else {
983 status_unusual("channel_fail_htlc: %"PRIu64" in state %s",
984 htlc->id, htlc_state_name(htlc->state));
985 return CHANNEL_ERR_HTLC_NOT_IRREVOCABLE;
986 }
987
988 dump_htlc(htlc, "FAIL:");
989 if (htlcp)
990 *htlcp = htlc;
991 return CHANNEL_ERR_REMOVE_OK;
992}
993
994static void htlc_incstate(struct channel *channel,
995 struct htlc *htlc,

Callers 3

handle_peer_fail_htlcFunction · 0.85
handle_failFunction · 0.85

Calls 5

channel_get_htlcFunction · 0.85
htlc_hasFunction · 0.85
htlc_ownerFunction · 0.85
dump_htlcFunction · 0.85
htlc_state_nameFunction · 0.50

Tested by

no test coverage detected