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

Function record_coin_movements

onchaind/onchaind.c:366–422  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

364}
365
366static void record_coin_movements(struct tracked_output *out,
367 u32 blockheight,
368 const struct bitcoin_tx *tx,
369 const struct bitcoin_txid *txid)
370{
371 /* For 'timeout' htlcs, we re-record them as a deposit
372 * before we withdraw them again. When the channel closed,
373 * we reported this as withdrawn (since we didn't know the
374 * total amount of pending htlcs that are to-them). So
375 * we have to "deposit" it again before we withdraw it.
376 * This is just to make the channel account close out nicely
377 * AND so we can accurately calculate our on-chain fee burden */
378 if (out->tx_type == OUR_HTLC_TIMEOUT_TX
379 || out->tx_type == OUR_HTLC_SUCCESS_TX)
380 record_channel_deposit(out, out->tx_blockheight, HTLC_TX);
381
382 if (out->resolved->tx_type == OUR_HTLC_TIMEOUT_TO_US)
383 record_channel_deposit(out, out->tx_blockheight, HTLC_TIMEOUT);
384
385 /* there is a case where we've fulfilled an htlc onchain,
386 * in which case we log a deposit to the channel */
387 if (out->resolved->tx_type == THEIR_HTLC_FULFILL_TO_US
388 || out->resolved->tx_type == OUR_HTLC_SUCCESS_TX)
389 record_to_us_htlc_fulfilled(out, out->tx_blockheight);
390
391 /* If it's our to-us and our close, we publish *another* tx
392 * which spends the output when the timeout ends */
393 if (out->tx_type == OUR_UNILATERAL) {
394 if (out->output_type == DELAYED_OUTPUT_TO_US)
395 record_channel_deposit(out, out->tx_blockheight,
396 CHANNEL_TO_US);
397 else if (out->output_type == OUR_HTLC) {
398 record_channel_deposit(out, out->tx_blockheight,
399 HTLC_TIMEOUT);
400 record_channel_withdrawal(txid, out, blockheight,
401 HTLC_TIMEOUT);
402 } else if (out->output_type == THEIR_HTLC)
403 record_channel_withdrawal(txid, out, blockheight,
404 HTLC_FULFILL);
405 }
406
407 if (out->tx_type == THEIR_REVOKED_UNILATERAL
408 || out->resolved->tx_type == OUR_PENALTY_TX)
409 record_channel_deposit(out, out->tx_blockheight, PENALTY);
410
411 if (out->resolved->tx_type == OUR_DELAYED_RETURN_TO_WALLET
412 || out->resolved->tx_type == THEIR_HTLC_FULFILL_TO_US
413 || out->output_type == DELAYED_OUTPUT_TO_US
414 || out->resolved->tx_type == OUR_HTLC_TIMEOUT_TO_US
415 || out->resolved->tx_type == OUR_PENALTY_TX) {
416 /* penalty rbf cases, the amount might be zero */
417 if (amount_sat_zero(out->sat))
418 record_channel_withdrawal(txid, out, blockheight, TO_MINER);
419 else
420 record_channel_withdrawal(txid, out, blockheight, TO_WALLET);
421 }
422}
423

Callers 1

output_spentFunction · 0.85

Calls 4

record_channel_depositFunction · 0.85
amount_sat_zeroFunction · 0.85

Tested by

no test coverage detected