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

Function wallet_htlc_update

wallet/wallet.c:3521–3601  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

3519
3520/* input htlcs use failcode & failonion & we_filled, output htlcs use failmsg & failonion */
3521void wallet_htlc_update(struct wallet *wallet, const u64 htlc_dbid,
3522 const enum htlc_state new_state,
3523 const struct preimage *payment_key,
3524 u64 max_commit_num,
3525 enum onion_wire badonion,
3526 const struct onionreply *failonion,
3527 const u8 *failmsg,
3528 const bool *we_filled,
3529 u64 htlc_id,
3530 const struct channel *channel,
3531 enum side owner,
3532 const struct sha256 *payment_hash,
3533 u32 expiry,
3534 struct amount_msat amount)
3535{
3536 struct db_stmt *stmt;
3537 bool terminal = (new_state == RCVD_REMOVE_ACK_REVOCATION
3538 || new_state == SENT_REMOVE_ACK_REVOCATION);
3539
3540 /* We should only use this for badonion codes */
3541 assert(!badonion || (badonion & BADONION));
3542
3543 /* The database ID must be set by a previous call to
3544 * `wallet_htlc_save_*` */
3545 assert(htlc_dbid);
3546 stmt = db_prepare_v2(
3547 wallet->db, SQL("UPDATE channel_htlcs SET hstate=?, payment_key=?, "
3548 "malformed_onion=?, failuremsg=?, localfailmsg=?, "
3549 "we_filled=?, max_commit_num=?, updated_index=? "
3550 " WHERE id=?"));
3551
3552 db_bind_int(stmt, htlc_state_in_db(new_state));
3553
3554 if (payment_key)
3555 db_bind_preimage(stmt, payment_key);
3556 else
3557 db_bind_null(stmt);
3558
3559 db_bind_int(stmt, badonion);
3560
3561 if (failonion)
3562 db_bind_onionreply(stmt, failonion);
3563 else
3564 db_bind_null(stmt);
3565
3566 db_bind_talarr(stmt, failmsg);
3567
3568 if (we_filled)
3569 db_bind_int(stmt, *we_filled);
3570 else
3571 db_bind_null(stmt);
3572
3573 /* Set max_commit_num iff we're in final state. */
3574 if (terminal)
3575 db_bind_u64(stmt, max_commit_num);
3576 else
3577 db_bind_null(stmt);
3578 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