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

Function change_htlcs

channeld/full_channel.c:1092–1147  ·  view source on GitHub ↗

Returns flags which were changed. */

Source from the content-addressed store, hash-verified

1090
1091/* Returns flags which were changed. */
1092static int change_htlcs(struct channel *channel,
1093 enum side sidechanged,
1094 const enum htlc_state *htlc_states,
1095 size_t n_hstates,
1096 const struct htlc ***htlcs,
1097 const char *prefix)
1098{
1099 struct htlc_map_iter it;
1100 struct htlc *h;
1101 int cflags = 0;
1102 int i;
1103 struct balance owed[NUM_SIDES];
1104
1105 for (i = 0; i < NUM_SIDES; i++)
1106 to_balance(&owed[i], channel->view[sidechanged].owed[i]);
1107
1108 for (h = htlc_map_first(channel->htlcs, &it);
1109 h;
1110 h = htlc_map_next(channel->htlcs, &it)) {
1111 for (i = 0; i < n_hstates; i++) {
1112 if (h->state == htlc_states[i]) {
1113 htlc_incstate(channel, h, sidechanged, owed);
1114 dump_htlc(h, prefix);
1115 htlc_arr_append(htlcs, h);
1116 cflags |= (htlc_state_flags(htlc_states[i])
1117 ^ htlc_state_flags(h->state));
1118 }
1119 }
1120 }
1121
1122 for (i = 0; i < NUM_SIDES; i++) {
1123 if (!balance_ok(&owed[i], &channel->view[sidechanged].owed[i])) {
1124 status_failed(STATUS_FAIL_INTERNAL_ERROR,
1125 "%s: %s balance underflow: %s -> %"PRId64,
1126 side_to_str(sidechanged),
1127 side_to_str(i),
1128 type_to_string(tmpctx, struct amount_msat,
1129 &channel->view[sidechanged].owed[i]),
1130 owed[i].msat);
1131 }
1132 }
1133
1134 /* Update fees and blockheight (do backwards, to avoid
1135 * double-increment!). */
1136 for (i = n_hstates - 1; i >= 0; i--) {
1137 if (fee_incstate(channel, sidechanged, htlc_states[i]))
1138 cflags |= (htlc_state_flags(htlc_states[i])
1139 ^ htlc_state_flags(htlc_states[i]+1));
1140
1141 if (blockheight_incstate(channel, sidechanged, htlc_states[i]))
1142 cflags |= (htlc_state_flags(htlc_states[i])
1143 ^ htlc_state_flags(htlc_states[i]+1));
1144 }
1145
1146 return cflags;
1147}
1148
1149/* FIXME: The sender's requirements are *implied* by this, not stated! */

Callers 4

channel_sending_commitFunction · 0.85
channel_rcvd_commitFunction · 0.85

Calls 11

to_balanceFunction · 0.85
htlc_incstateFunction · 0.85
dump_htlcFunction · 0.85
htlc_arr_appendFunction · 0.85
balance_okFunction · 0.85
side_to_strFunction · 0.85
fee_incstateFunction · 0.85
blockheight_incstateFunction · 0.85
htlc_state_flagsFunction · 0.50
status_failedFunction · 0.50
type_to_stringClass · 0.50

Tested by

no test coverage detected