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