From aab989366158fc57a6b8a0467795a20b4b4ef9b1 Mon Sep 17 00:00:00 2001 From: lisa neigut Date: Tue, 14 Apr 2020 14:02:46 -0500 Subject: [PATCH] coins: have `we_fulfilled` be fully 'ternary' note that 'null' 'we_fulfilled's are going to be legacy from this release forward. --- lightningd/htlc_end.c | 2 +- lightningd/htlc_end.h | 2 +- lightningd/htlc_set.c | 3 ++- lightningd/peer_htlcs.c | 16 +++++++++++----- wallet/wallet.c | 10 +++++++--- wallet/wallet.h | 2 +- 6 files changed, 23 insertions(+), 12 deletions(-) diff --git a/lightningd/htlc_end.c b/lightningd/htlc_end.c index 5ed0937d1..d2b3c8a1e 100644 --- a/lightningd/htlc_end.c +++ b/lightningd/htlc_end.c @@ -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(); diff --git a/lightningd/htlc_end.h b/lightningd/htlc_end.h index ce090f2ca..0673260fc 100644 --- a/lightningd/htlc_end.h +++ b/lightningd/htlc_end.h @@ -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 { diff --git a/lightningd/htlc_set.c b/lightningd/htlc_set.c index a3c8308ab..1bcb4e1f2 100644 --- a/lightningd/htlc_set.c +++ b/lightningd/htlc_set.c @@ -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); diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index 186d1387f..731da6e1a 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -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); diff --git a/wallet/wallet.c b/wallet/wallet.c index 7c79812da..466b0a94e 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -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; } diff --git a/wallet/wallet.h b/wallet/wallet.h index bc8d0c323..88dda612c 100644 --- a/wallet/wallet.h +++ b/wallet/wallet.h @@ -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.