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

Function wallet_forwarded_payment_update

wallet/wallet.c:5349–5411  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5347}
5348
5349static bool wallet_forwarded_payment_update(struct wallet *w,
5350 const struct htlc_in *in,
5351 const struct htlc_out *out,
5352 enum forward_status state,
5353 enum onion_wire failcode,
5354 struct timeabs *resolved_time,
5355 enum forward_style forward_style)
5356{
5357 struct db_stmt *stmt;
5358 bool changed;
5359
5360 /* We update based solely on the htlc_in since an HTLC cannot be
5361 * associated with more than one forwarded payment. This saves us from
5362 * having to have two versions of the update statement (one with and
5363 * one without the htlc_out restriction).*/
5364 stmt = db_prepare_v2(w->db,
5365 SQL("UPDATE forwards SET"
5366 " updated_index=?"
5367 ", in_msatoshi=?"
5368 ", out_msatoshi=?"
5369 ", state=?"
5370 ", resolved_time=?"
5371 ", failcode=?"
5372 ", forward_style=?"
5373 " WHERE in_htlc_id=? AND in_channel_scid=?"));
5374 /* This may not work so don't increment index yet! */
5375 db_bind_u64(stmt, w->ld->indexes[WAIT_SUBSYSTEM_FORWARD].i[WAIT_INDEX_UPDATED] + 1);
5376 db_bind_amount_msat(stmt, in->msat);
5377
5378 if (out) {
5379 db_bind_amount_msat(stmt, out->msat);
5380 } else {
5381 db_bind_null(stmt);
5382 }
5383
5384 db_bind_int(stmt, wallet_forward_status_in_db(state));
5385
5386 if (resolved_time != NULL) {
5387 db_bind_timeabs(stmt, *resolved_time);
5388 } else {
5389 db_bind_null(stmt);
5390 }
5391
5392 if (failcode != 0) {
5393 assert(state == FORWARD_FAILED || state == FORWARD_LOCAL_FAILED);
5394 db_bind_int(stmt, (int)failcode);
5395 } else {
5396 db_bind_null(stmt);
5397 }
5398
5399 /* This can happen for malformed onions, reload from db. */
5400 if (forward_style == FORWARD_STYLE_UNKNOWN)
5401 db_bind_null(stmt);
5402 else
5403 db_bind_int(stmt, forward_style_in_db(forward_style));
5404 db_bind_u64(stmt, in->key.id);
5405 db_bind_short_channel_id(stmt, channel_scid_or_local_alias(in->key.channel));
5406 db_exec_prepared_v2(stmt);

Callers 1

Calls 12

db_bind_u64Function · 0.85
db_bind_amount_msatFunction · 0.85
db_bind_nullFunction · 0.85
db_bind_intFunction · 0.85
db_bind_timeabsFunction · 0.85
forward_style_in_dbFunction · 0.85
db_bind_short_channel_idFunction · 0.85
db_exec_prepared_v2Function · 0.85
db_count_changesFunction · 0.85
tal_freeFunction · 0.85

Tested by

no test coverage detected