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

Function send_commit

channeld/channeld.c:1223–1405  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1221}
1222
1223static void send_commit(struct peer *peer)
1224{
1225 u8 *msg;
1226 const struct htlc **changed_htlcs;
1227 struct bitcoin_signature commit_sig, *htlc_sigs;
1228 struct bitcoin_tx **txs;
1229 const u8 *funding_wscript;
1230 const struct htlc **htlc_map;
1231 struct wally_tx_output *direct_outputs[NUM_SIDES];
1232 struct penalty_base *pbase;
1233 u32 our_blockheight;
1234 u32 feerate_target;
1235
1236#if DEVELOPER
1237 if (peer->dev_disable_commit && !*peer->dev_disable_commit) {
1238 peer->commit_timer = NULL;
1239 return;
1240 }
1241#endif
1242
1243 /* FIXME: Document this requirement in BOLT 2! */
1244 /* We can't send two commits in a row. */
1245 if (peer->revocations_received != peer->next_index[REMOTE] - 1) {
1246 assert(peer->revocations_received
1247 == peer->next_index[REMOTE] - 2);
1248 peer->commit_timer_attempts++;
1249 /* Only report this in extreme cases */
1250 if (peer->commit_timer_attempts % 100 == 0)
1251 status_debug("Can't send commit:"
1252 " waiting for revoke_and_ack with %"
1253 PRIu64" attempts",
1254 peer->commit_timer_attempts);
1255 /* Mark this as done and try again. */
1256 peer->commit_timer = NULL;
1257 start_commit_timer(peer);
1258 return;
1259 }
1260
1261 /* BOLT #2:
1262 *
1263 * - if no HTLCs remain in either commitment transaction (including dust HTLCs)
1264 * and neither side has a pending `revoke_and_ack` to send:
1265 * - MUST NOT send any `update` message after that point.
1266 */
1267 if (peer->shutdown_sent[LOCAL] && !num_channel_htlcs(peer->channel)) {
1268 status_debug("Can't send commit: final shutdown phase");
1269
1270 peer->commit_timer = NULL;
1271 return;
1272 }
1273
1274 /* If we wanted to update fees, do it now. */
1275 if (want_fee_update(peer, &feerate_target)) {
1276 /* FIXME: We occasionally desynchronize with LND here, so
1277 * don't stress things by having more than one feerate change
1278 * in-flight! */
1279 if (feerate_changes_done(peer->channel->fee_states, false)) {
1280 /* BOLT-919 #2:

Callers

nothing calls this directly

Calls 15

start_commit_timerFunction · 0.85
num_channel_htlcsFunction · 0.85
want_fee_updateFunction · 0.85
feerate_changes_doneFunction · 0.85
htlc_dust_okFunction · 0.85
peer_failed_warnFunction · 0.85
channel_update_feerateFunction · 0.85
approx_max_feerateFunction · 0.85
peer_writeFunction · 0.85
want_blockheight_updateFunction · 0.85
blockheight_changes_doneFunction · 0.85

Tested by

no test coverage detected