htlc: rename local flag to am_origin, add FIXME.

Noted by @cdecker, the term 'local' is grossly overused, and the hout
preimage is basically only used as a sanity check (though I've just put
a FIXME there for now).

Also eliminated spurious blank line which crept into wallet.c.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2018-10-10 06:51:31 +10:30
parent 6c96bcacd7
commit 0226ef0572
4 changed files with 15 additions and 15 deletions

View File

@@ -143,8 +143,8 @@ struct htlc_out *htlc_out_check(const struct htlc_out *hout,
else if (hout->failuremsg && hout->preimage)
return corrupt(abortstr, "Both failed and succeeded");
if (hout->local && hout->in)
return corrupt(abortstr, "Both local and incoming");
if (hout->am_origin && hout->in)
return corrupt(abortstr, "Both origin and incoming");
if (hout->in) {
if (hout->in->msatoshi < hout->msatoshi)
@@ -240,7 +240,7 @@ struct htlc_out *new_htlc_out(const tal_t *ctx,
u64 msatoshi, u32 cltv_expiry,
const struct sha256 *payment_hash,
const u8 *onion_routing_packet,
bool local,
bool am_origin,
struct htlc_in *in)
{
struct htlc_out *hout = tal(ctx, struct htlc_out);
@@ -261,7 +261,7 @@ struct htlc_out *new_htlc_out(const tal_t *ctx,
hout->failuremsg = NULL;
hout->preimage = NULL;
hout->local = local;
hout->am_origin = am_origin;
hout->in = NULL;
if (in)
htlc_out_connect_htlc_in(hout, in);

View File

@@ -71,10 +71,11 @@ struct htlc_out {
const u8 *failuremsg;
/* If we fulfilled, here's the preimage. */
/* FIXME: This is basically unused, except as a bool! */
struct preimage *preimage;
/* Is this local? Implies ->in is NULL. */
bool local;
/* Is this a locally-generated payment? Implies ->in is NULL. */
bool am_origin;
/* Where it's from, if not going to us. */
struct htlc_in *in;
@@ -132,7 +133,7 @@ struct htlc_out *new_htlc_out(const tal_t *ctx,
u64 msatoshi, u32 cltv_expiry,
const struct sha256 *payment_hash,
const u8 *onion_routing_packet,
bool local,
bool am_origin,
struct htlc_in *in);
void connect_htlc_in(struct htlc_in_map *map, struct htlc_in *hin);

View File

@@ -139,7 +139,7 @@ static void fail_out_htlc(struct htlc_out *hout, const char *localfail)
{
htlc_out_check(hout, __func__);
assert(hout->failcode || hout->failuremsg);
if (hout->local) {
if (hout->am_origin) {
payment_failed(hout->key.channel->peer->ld, hout, localfail);
} else if (hout->in) {
fail_in_htlc(hout->in, hout->failcode, hout->failuremsg,
@@ -381,7 +381,7 @@ static void rcvd_htlc_reply(struct subd *subd, const u8 *msg, const int *fds UNU
if (failure_code) {
hout->failcode = (enum onion_type) failure_code;
if (hout->local) {
if (hout->am_origin) {
char *localfail = tal_fmt(msg, "%s: %.*s",
onion_type_name(failure_code),
(int)tal_count(failurestr),
@@ -733,7 +733,7 @@ static void fulfill_our_htlc_out(struct channel *channel, struct htlc_out *hout,
channel->dbid,
hout->msatoshi);
if (hout->local)
if (hout->am_origin)
payment_succeeded(ld, hout, preimage);
else if (hout->in)
fulfill_htlc(hout->in, preimage);
@@ -872,7 +872,7 @@ void onchain_failed_our_htlc(const struct channel *channel,
wallet_htlc_update(channel->peer->ld->wallet, hout->dbid, hout->hstate,
hout->preimage, hout->failcode, hout->failuremsg);
if (hout->local) {
if (hout->am_origin) {
assert(why != NULL);
char *localfail = tal_fmt(channel, "%s: %s",
onion_type_name(WIRE_PERMANENT_CHANNEL_FAILURE),
@@ -1746,7 +1746,7 @@ void htlcs_reconnect(struct lightningd *ld,
for (hout = htlc_out_map_first(htlcs_out, &outi); hout;
hout = htlc_out_map_next(htlcs_out, &outi)) {
if (hout->local) {
if (hout->am_origin) {
continue;
}

View File

@@ -1349,10 +1349,10 @@ static bool wallet_stmt2htlc_out(struct channel *channel,
if (sqlite3_column_type(stmt, 10) != SQLITE_NULL) {
out->origin_htlc_id = sqlite3_column_int64(stmt, 10);
out->local = false;
out->am_origin = false;
} else {
out->origin_htlc_id = 0;
out->local = true;
out->am_origin = true;
}
/* Need to defer wiring until we can look up all incoming
@@ -1399,7 +1399,6 @@ static void fixup_hin(struct wallet *wallet, struct htlc_in *hin)
#endif
}
bool wallet_htlcs_load_for_channel(struct wallet *wallet,
struct channel *chan,
struct htlc_in_map *htlcs_in,