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

Function wallet_htlc_update

wallet/wallet.c:2511–2575  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

2509
2510/* input htlcs use failcode & failonion & we_filled, output htlcs use failmsg & failonion */
2511void wallet_htlc_update(struct wallet *wallet, const u64 htlc_dbid,
2512 const enum htlc_state new_state,
2513 const struct preimage *payment_key,
2514 u64 max_commit_num,
2515 enum onion_wire badonion,
2516 const struct onionreply *failonion,
2517 const u8 *failmsg,
2518 bool *we_filled)
2519{
2520 struct db_stmt *stmt;
2521 bool terminal = (new_state == RCVD_REMOVE_ACK_REVOCATION
2522 || new_state == SENT_REMOVE_ACK_REVOCATION);
2523
2524 /* We should only use this for badonion codes */
2525 assert(!badonion || (badonion & BADONION));
2526
2527 /* The database ID must be set by a previous call to
2528 * `wallet_htlc_save_*` */
2529 assert(htlc_dbid);
2530 stmt = db_prepare_v2(
2531 wallet->db, SQL("UPDATE channel_htlcs SET hstate=?, payment_key=?, "
2532 "malformed_onion=?, failuremsg=?, localfailmsg=?, "
2533 "we_filled=?, max_commit_num=?"
2534 " WHERE id=?"));
2535
2536 db_bind_int(stmt, 0, htlc_state_in_db(new_state));
2537 db_bind_u64(stmt, 7, htlc_dbid);
2538
2539 if (payment_key)
2540 db_bind_preimage(stmt, 1, payment_key);
2541 else
2542 db_bind_null(stmt, 1);
2543
2544 db_bind_int(stmt, 2, badonion);
2545
2546 if (failonion)
2547 db_bind_onionreply(stmt, 3, failonion);
2548 else
2549 db_bind_null(stmt, 3);
2550
2551 db_bind_talarr(stmt, 4, failmsg);
2552
2553 if (we_filled)
2554 db_bind_int(stmt, 5, *we_filled);
2555 else
2556 db_bind_null(stmt, 5);
2557
2558 /* Set max_commit_num iff we're in final state. */
2559 if (terminal)
2560 db_bind_u64(stmt, 6, max_commit_num);
2561 else
2562 db_bind_null(stmt, 6);
2563
2564 db_exec_prepared_v2(take(stmt));
2565
2566 if (terminal) {
2567 /* If it's terminal, remove the data we needed for re-xmission. */
2568 stmt = db_prepare_v2(

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 8

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

Tested by 1

test_htlc_crudFunction · 0.68