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

Function wallet_htlc_update

wallet/wallet.c:3539–3619  ·  view source on GitHub ↗

input htlcs use failcode & failonion & we_filled, output htlcs use failmsg & failonion */

Source from the content-addressed store, hash-verified

3537
3538/* input htlcs use failcode & failonion & we_filled, output htlcs use failmsg & failonion */
3539void wallet_htlc_update(struct wallet *wallet, const u64 htlc_dbid,
3540 const enum htlc_state new_state,
3541 const struct preimage *payment_key,
3542 u64 max_commit_num,
3543 enum onion_wire badonion,
3544 const struct onionreply *failonion,
3545 const u8 *failmsg,
3546 const bool *we_filled,
3547 u64 htlc_id,
3548 const struct channel *channel,
3549 enum side owner,
3550 const struct sha256 *payment_hash,
3551 u32 expiry,
3552 struct amount_msat amount)
3553{
3554 struct db_stmt *stmt;
3555 bool terminal = (new_state == RCVD_REMOVE_ACK_REVOCATION
3556 || new_state == SENT_REMOVE_ACK_REVOCATION);
3557
3558 /* We should only use this for badonion codes */
3559 assert(!badonion || (badonion & BADONION));
3560
3561 /* The database ID must be set by a previous call to
3562 * `wallet_htlc_save_*` */
3563 assert(htlc_dbid);
3564 stmt = db_prepare_v2(
3565 wallet->db, SQL("UPDATE channel_htlcs SET hstate=?, payment_key=?, "
3566 "malformed_onion=?, failuremsg=?, localfailmsg=?, "
3567 "we_filled=?, max_commit_num=?, updated_index=? "
3568 " WHERE id=?"));
3569
3570 db_bind_int(stmt, htlc_state_in_db(new_state));
3571
3572 if (payment_key)
3573 db_bind_preimage(stmt, payment_key);
3574 else
3575 db_bind_null(stmt);
3576
3577 db_bind_int(stmt, badonion);
3578
3579 if (failonion)
3580 db_bind_onionreply(stmt, failonion);
3581 else
3582 db_bind_null(stmt);
3583
3584 db_bind_talarr(stmt, failmsg);
3585
3586 if (we_filled)
3587 db_bind_int(stmt, *we_filled);
3588 else
3589 db_bind_null(stmt);
3590
3591 /* Set max_commit_num iff we're in final state. */
3592 if (terminal)
3593 db_bind_u64(stmt, max_commit_num);
3594 else
3595 db_bind_null(stmt);
3596 db_bind_u64(stmt, htlcs_index_update_status(wallet->ld,

Callers 6

test_htlc_crudFunction · 0.85
htlc_in_update_stateFunction · 0.85
htlc_out_update_stateFunction · 0.85
fail_in_htlcFunction · 0.85
fulfill_our_htlc_outFunction · 0.85
onchain_failed_our_htlcFunction · 0.85

Calls 11

db_bind_intFunction · 0.85
htlc_state_in_dbFunction · 0.85
db_bind_preimageFunction · 0.85
db_bind_nullFunction · 0.85
db_bind_onionreplyFunction · 0.85
db_bind_talarrFunction · 0.85
db_bind_u64Function · 0.85
db_exec_prepared_v2Function · 0.85
db_count_changesFunction · 0.85
tal_freeFunction · 0.85

Tested by 1

test_htlc_crudFunction · 0.68