coins: have `we_fulfilled` be fully 'ternary'

note that 'null' 'we_fulfilled's are going to be legacy from this
release forward.
This commit is contained in:
lisa neigut 2020-04-14 14:02:46 -05:00 committed by Rusty Russell
parent 8537e77ac7
commit aab9893661
6 changed files with 23 additions and 12 deletions

View File

@ -158,7 +158,7 @@ struct htlc_in *new_htlc_in(const tal_t *ctx,
hin->badonion = 0;
hin->failonion = NULL;
hin->preimage = NULL;
hin->we_filled = false;
hin->we_filled = NULL;
hin->received_time = time_now();

View File

@ -54,7 +54,7 @@ struct htlc_in {
/* Only set if blinding != NULL */
struct secret blinding_ss;
/* true if we supplied the preimage */
bool we_filled;
bool *we_filled;
};
struct htlc_out {

View File

@ -59,7 +59,8 @@ void htlc_set_fulfill(struct htlc_set *set, const struct preimage *preimage)
tal_del_destructor2(set->htlcs[i], htlc_set_hin_destroyed, set);
/* mark that we filled -- needed for tagging coin mvt */
set->htlcs[i]->we_filled = true;
set->htlcs[i]->we_filled = tal(set->htlcs[i], bool);
*set->htlcs[i]->we_filled = true;
fulfill_htlc(set->htlcs[i], preimage);
}
tal_free(set);

View File

@ -95,9 +95,10 @@ static bool htlc_out_update_state(struct channel *channel,
"out"))
return false;
bool we_filled = false;
wallet_htlc_update(channel->peer->ld->wallet, hout->dbid, newstate,
hout->preimage, 0, hout->failonion,
hout->failmsg, false);
hout->failmsg, &we_filled);
hout->hstate = newstate;
return true;
@ -186,11 +187,12 @@ static void failmsg_update_reply(struct subd *gossipd,
cbdata->hin->shared_secret,
failmsg);
bool we_filled = false;
wallet_htlc_update(gossipd->ld->wallet,
cbdata->hin->dbid, cbdata->hin->hstate,
cbdata->hin->preimage,
cbdata->hin->badonion,
cbdata->hin->failonion, NULL, false);
cbdata->hin->failonion, NULL, &we_filled);
failed_htlc = mk_failed_htlc(tmpctx,
cbdata->hin, cbdata->hin->failonion);
@ -853,7 +855,8 @@ htlc_accepted_hook_try_resolve(struct htlc_accepted_hook_payload *request,
towire_u16(&unknown_details, 0x400f);
local_fail_in_htlc(hin, take(unknown_details));
} else {
hin->we_filled = true;
hin->we_filled = tal(hin, bool);
*hin->we_filled = true;
fulfill_htlc(hin, payment_preimage);
}
}
@ -1244,6 +1247,7 @@ static void fulfill_our_htlc_out(struct channel *channel, struct htlc_out *hout,
const struct preimage *preimage)
{
struct lightningd *ld = channel->peer->ld;
bool we_filled = false;
assert(!hout->preimage);
hout->preimage = tal_dup(hout, struct preimage, preimage);
@ -1251,7 +1255,7 @@ static void fulfill_our_htlc_out(struct channel *channel, struct htlc_out *hout,
wallet_htlc_update(ld->wallet, hout->dbid, hout->hstate,
hout->preimage, 0, hout->failonion,
hout->failmsg, false);
hout->failmsg, &we_filled);
/* Update channel stats */
wallet_channel_stats_incr_out_fulfilled(ld->wallet,
channel->dbid,
@ -1418,9 +1422,11 @@ void onchain_failed_our_htlc(const struct channel *channel,
/* Force state to something which expects a failure, and save to db */
hout->hstate = RCVD_REMOVE_HTLC;
htlc_out_check(hout, __func__);
bool we_filled = false;
wallet_htlc_update(ld->wallet, hout->dbid, hout->hstate,
hout->preimage, 0, hout->failonion,
hout->failmsg, false);
hout->failmsg, &we_filled);
if (hout->am_origin) {
assert(why != NULL);

View File

@ -1844,7 +1844,7 @@ void wallet_htlc_update(struct wallet *wallet, const u64 htlc_dbid,
enum onion_type badonion,
const struct onionreply *failonion,
const u8 *failmsg,
bool we_filled)
bool *we_filled)
{
struct db_stmt *stmt;
@ -1882,7 +1882,7 @@ void wallet_htlc_update(struct wallet *wallet, const u64 htlc_dbid,
db_bind_null(stmt, 4);
if (we_filled)
db_bind_int(stmt, 5, 1);
db_bind_int(stmt, 5, *we_filled);
else
db_bind_null(stmt, 5);
@ -1956,7 +1956,11 @@ static bool wallet_stmt2htlc_in(struct channel *channel,
}
#endif
in->we_filled = !db_column_is_null(stmt, 13);
if (!db_column_is_null(stmt, 13)) {
in->we_filled = tal(in, bool);
*in->we_filled = db_column_int(stmt, 13);
} else
in->we_filled = NULL;
return ok;
}

View File

@ -616,7 +616,7 @@ void wallet_htlc_update(struct wallet *wallet, const u64 htlc_dbid,
enum onion_type badonion,
const struct onionreply *failonion,
const u8 *failmsg,
bool we_filled);
bool *we_filled);
/**
* wallet_htlcs_load_in_for_channel - Load incoming HTLCs associated with chan from DB.