From c07e1aae3b479c79a1c8ea8b9af0c716c8b81fda Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 21 Feb 2020 15:40:44 +1030 Subject: [PATCH] lightningd: rename htlc_in field from failcode to badonion. That's all it's used for now. And remove unreferenced failoutchannel. Signed-off-by: Rusty Russell --- lightningd/htlc_end.c | 26 +++++++++++++------------- lightningd/htlc_end.h | 10 +++------- lightningd/peer_htlcs.c | 14 +++++++------- wallet/wallet.c | 14 ++++++++------ 4 files changed, 31 insertions(+), 33 deletions(-) diff --git a/lightningd/htlc_end.c b/lightningd/htlc_end.c index f2fe2b0de20d..7489976ce5bd 100644 --- a/lightningd/htlc_end.c +++ b/lightningd/htlc_end.c @@ -100,9 +100,9 @@ struct htlc_in *htlc_in_check(const struct htlc_in *hin, const char *abortstr) htlc_state_name(hin->hstate)); else if (hin->failonion && hin->preimage) return corrupt(abortstr, "Both failonion and succeeded"); - else if (hin->failcode != 0 && hin->preimage) - return corrupt(abortstr, "Both failcode and succeeded"); - else if (hin->failonion && (hin->failcode & BADONION)) + else if (hin->badonion != 0 && hin->preimage) + return corrupt(abortstr, "Both badonion and succeeded"); + else if (hin->failonion && hin->badonion) return corrupt(abortstr, "Both failed and malformed"); /* Can't have a resolution while still being added. */ @@ -112,11 +112,11 @@ struct htlc_in *htlc_in_check(const struct htlc_in *hin, const char *abortstr) return corrupt(abortstr, "Still adding, has preimage"); if (hin->failonion) return corrupt(abortstr, "Still adding, has failmsg"); - if (hin->failcode) - return corrupt(abortstr, "Still adding, has failcode"); + if (hin->badonion) + return corrupt(abortstr, "Still adding, has badonion"); } else if (hin->hstate >= SENT_REMOVE_HTLC && hin->hstate <= SENT_REMOVE_ACK_REVOCATION) { - if (!hin->preimage && !hin->failonion && !hin->failcode) + if (!hin->preimage && !hin->failonion && !hin->badonion) return corrupt(abortstr, "Removing, no resolution"); } else return corrupt(abortstr, "Bad state %s", @@ -148,7 +148,7 @@ struct htlc_in *new_htlc_in(const tal_t *ctx, sizeof(hin->onion_routing_packet)); hin->hstate = RCVD_ADD_COMMIT; - hin->failcode = 0; + hin->badonion = 0; hin->failonion = NULL; hin->preimage = NULL; @@ -186,9 +186,9 @@ struct htlc_out *htlc_out_check(const struct htlc_out *hout, /* If output is resolved, input must be resolved same * way (or not resolved yet). */ if (hout->failonion) { - if (hout->in->failcode) + if (hout->in->badonion) return corrupt(abortstr, - "Output failmsg, input failcode"); + "Output failmsg, input badonion"); if (hout->in->preimage) return corrupt(abortstr, "Output failmsg, input preimage"); @@ -203,9 +203,9 @@ struct htlc_out *htlc_out_check(const struct htlc_out *hout, if (hout->in->failonion) return corrupt(abortstr, "Output preimage, input failonion"); - if (hout->in->failcode) + if (hout->in->badonion) return corrupt(abortstr, - "Output preimage, input failcode"); + "Output preimage, input badonion"); } else { if (hout->in->preimage) return corrupt(abortstr, @@ -213,9 +213,9 @@ struct htlc_out *htlc_out_check(const struct htlc_out *hout, if (hout->in->failonion) return corrupt(abortstr, "Output unresovled, input failmsg"); - if (hout->in->failcode) + if (hout->in->badonion) return corrupt(abortstr, - "Output unresolved, input failcode"); + "Output unresolved, input badonion"); } } diff --git a/lightningd/htlc_end.h b/lightningd/htlc_end.h index fdb07e8ffa0a..c25f0625aa60 100644 --- a/lightningd/htlc_end.h +++ b/lightningd/htlc_end.h @@ -36,16 +36,12 @@ struct htlc_in { /* Shared secret for us to send any failure message (NULL if malformed) */ struct secret *shared_secret; - /* FIXME: Use failed_htlc here */ - /* If a local error, this is non-zero. */ - enum onion_type failcode; + /* If we couldn't decode the onion, this contains the error code.. */ + enum onion_type badonion; - /* For a remote error. */ + /* Otherwise, this contains the failure message to send. */ const struct onionreply *failonion; - /* If failcode & UPDATE, this is the channel which failed. */ - struct short_channel_id failoutchannel; - /* If they fulfilled, here's the preimage. */ struct preimage *preimage; diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index 0b70c00c66c5..0357e4efbe36 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -76,7 +76,7 @@ static bool htlc_in_update_state(struct channel *channel, wallet_htlc_update(channel->peer->ld->wallet, hin->dbid, newstate, hin->preimage, - hin->failcode, hin->failonion, NULL); + hin->badonion, hin->failonion, NULL); hin->hstate = newstate; return true; @@ -161,7 +161,7 @@ static void local_fail_in_htlc_badonion(struct htlc_in *hin, assert(!hin->preimage); assert(badonion & BADONION); - hin->failcode = badonion; + hin->badonion = badonion; /* We update state now to signal it's in progress, for persistence. */ htlc_in_update_state(hin->key.channel, hin, SENT_REMOVE_HTLC); htlc_in_check(hin, __func__); @@ -714,7 +714,7 @@ static void channel_resolve_reply(struct subd *gossip, const u8 *msg, wallet_forwarded_payment_add(gr->hin->key.channel->peer->ld->wallet, gr->hin, &gr->next_channel, NULL, FORWARD_LOCAL_FAILED, - gr->hin->failcode); + WIRE_UNKNOWN_NEXT_PEER); tal_free(gr); return; } @@ -1293,12 +1293,12 @@ void onchain_failed_our_htlc(const struct channel *channel, static void remove_htlc_in(struct channel *channel, struct htlc_in *hin) { htlc_in_check(hin, __func__); - assert(hin->failonion || hin->preimage || hin->failcode); + assert(hin->failonion || hin->preimage || hin->badonion); log_debug(channel->log, "Removing in HTLC %"PRIu64" state %s %s", hin->key.id, htlc_state_name(hin->hstate), hin->preimage ? "FULFILLED" - : hin->failcode ? onion_type_name(hin->failcode) + : hin->badonion ? onion_type_name(hin->badonion) : "REMOTEFAIL"); /* If we fulfilled their HTLC, credit us. */ @@ -2019,8 +2019,8 @@ void peer_htlcs(const tal_t *ctx, hin->cltv_expiry, hin->onion_routing_packet, hin->hstate); - if (hin->failcode) - add_fail_badonion(hin, hin->failcode, failed_in); + if (hin->badonion) + add_fail_badonion(hin, hin->badonion, failed_in); if (hin->failonion) add_fail(hin, hin->failonion, failed_in); if (hin->preimage) diff --git a/wallet/wallet.c b/wallet/wallet.c index df52e340aa2a..65c0e4469507 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -1828,7 +1828,7 @@ static bool wallet_stmt2htlc_in(struct channel *channel, in->failonion = NULL; else in->failonion = db_column_onionreply(in, stmt, 8); - in->failcode = db_column_int(stmt, 9); + in->badonion = db_column_int(stmt, 9); if (db_column_is_null(stmt, 11)) { in->shared_secret = NULL; } else { @@ -1853,12 +1853,12 @@ static bool wallet_stmt2htlc_in(struct channel *channel, #ifdef COMPAT_V080 /* This field is now reserved for badonion codes: the rest should * use the failonion field. */ - if (in->failcode && !(in->failcode & BADONION)) { + if (in->badonion && !(in->badonion & BADONION)) { log_broken(channel->log, "Replacing incoming HTLC %"PRIu64" error " "%s with WIRE_TEMPORARY_NODE_FAILURE", - in->key.id, onion_type_name(in->failcode)); - in->failcode = 0; + in->key.id, onion_type_name(in->badonion)); + in->badonion = 0; in->failonion = create_onionreply(in, in->shared_secret, towire_temporary_node_failure(tmpctx)); @@ -1947,10 +1947,12 @@ static void fixup_hin(struct wallet *wallet, struct htlc_in *hin) return; /* Failed ones (only happens after db fixed!) OK. */ - if (hin->failcode || hin->failonion) + if (hin->badonion || hin->failonion) return; - hin->failcode = WIRE_TEMPORARY_NODE_FAILURE; + hin->failonion = create_onionreply(hin, + hin->shared_secret, + towire_temporary_node_failure(tmpctx)); log_broken(wallet->log, "HTLC #%"PRIu64" (%s) " " for amount %s"