diff --git a/lightningd/channel.h b/lightningd/channel.h index bf70c249ae9d..c2893fc09d89 100644 --- a/lightningd/channel.h +++ b/lightningd/channel.h @@ -788,7 +788,10 @@ void channel_set_billboard(struct channel *channel, bool perm, struct htlc_in *channel_has_htlc_in(struct channel *channel); struct htlc_out *channel_has_htlc_out(struct channel *channel); -const u8 *get_channel_update(struct channel *channel); +const u8 *channel_update_for_error(const tal_t *ctx, + struct channel *channel); struct amount_msat htlc_max_possible_send(const struct channel *channel); + + #endif /* LIGHTNING_LIGHTNINGD_CHANNEL_H */ diff --git a/lightningd/gossip_control.c b/lightningd/gossip_control.c index b4083c29ad6b..6e2df87ffb20 100644 --- a/lightningd/gossip_control.c +++ b/lightningd/gossip_control.c @@ -162,15 +162,20 @@ static void handle_local_channel_update(struct lightningd *ld, const u8 *msg) channel_replace_update(channel, take(update)); } -const u8 *get_channel_update(struct channel *channel) +const u8 *channel_update_for_error(const tal_t *ctx, + struct channel *channel) { + if (!channel->channel_update) + return NULL; + /* Tell gossipd we're using it (if shutting down, might be NULL) */ - if (channel->channel_update && channel->peer->ld->gossip) { + if (channel->peer->ld->gossip && channel->scid) { subd_send_msg(channel->peer->ld->gossip, take(towire_gossipd_used_local_channel_update (NULL, channel->scid))); } - return channel->channel_update; + + return tal_dup_talarr(ctx, u8, channel->channel_update); } static void set_channel_remote_update(struct lightningd *ld, diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index 36b81760915c..2cd4e289f428 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -491,7 +491,8 @@ static void destroy_hout_subd_died(struct htlc_out *hout) hout->key.id); hout->failmsg = towire_temporary_channel_failure(hout, - get_channel_update(hout->key.channel)); + channel_update_for_error(tmpctx, + hout->key.channel)); /* Assign a temporary state (we're about to free it!) so checks * are happy that it has a failure message */ @@ -529,7 +530,7 @@ static void rcvd_htlc_reply(struct subd *subd, const u8 *msg, const int *fds UNU if (tal_count(failmsg)) { /* It's our job to append the channel_update */ if (fromwire_peektype(failmsg) & UPDATE) { - const u8 *update = get_channel_update(hout->key.channel); + const u8 *update = channel_update_for_error(tmpctx, hout->key.channel); towire(&failmsg, update, tal_bytelen(update)); } hout->failmsg = tal_steal(hout, failmsg); @@ -626,7 +627,7 @@ const u8 *send_htlc_out(const tal_t *ctx, log_info(out->log, "Attempt to send HTLC but unowned (%s)", channel_state_name(out)); return towire_temporary_channel_failure(ctx, - get_channel_update(out)); + channel_update_for_error(tmpctx, out)); } if (!topology_synced(out->peer->ld->topology)) { @@ -749,7 +750,8 @@ static void forward_htlc(struct htlc_in *hin, next->old_feerate_base, next->old_feerate_ppm)) { failmsg = towire_fee_insufficient(tmpctx, hin->msat, - get_channel_update(next)); + channel_update_for_error(tmpctx, + next)); goto fail; } log_info(hin->key.channel->log, @@ -763,7 +765,7 @@ static void forward_htlc(struct htlc_in *hin, || amount_msat_less(amt_to_forward, next->old_htlc_minimum_msat) || amount_msat_greater(amt_to_forward, next->old_htlc_maximum_msat)) { failmsg = towire_temporary_channel_failure(tmpctx, - get_channel_update(next)); + channel_update_for_error(tmpctx, next)); goto fail; } log_info(hin->key.channel->log, @@ -773,7 +775,7 @@ static void forward_htlc(struct htlc_in *hin, if (!check_cltv(hin, cltv_expiry, outgoing_cltv_value, ld->config.cltv_expiry_delta)) { failmsg = towire_incorrect_cltv_expiry(tmpctx, cltv_expiry, - get_channel_update(next)); + channel_update_for_error(tmpctx, next)); goto fail; } @@ -792,7 +794,7 @@ static void forward_htlc(struct htlc_in *hin, outgoing_cltv_value, get_block_height(ld->topology)); failmsg = towire_expiry_too_soon(tmpctx, - get_channel_update(next)); + channel_update_for_error(tmpctx, next)); goto fail; } diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index 1ef36ffb6705..b7a87c10d3ac 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -88,6 +88,10 @@ void channel_unsaved_close_conn(struct channel *channel UNNEEDED, const char *wh /* Generated stub for channel_update_feerates */ void channel_update_feerates(struct lightningd *ld UNNEEDED, const struct channel *channel UNNEEDED) { fprintf(stderr, "channel_update_feerates called!\n"); abort(); } +/* Generated stub for channel_update_for_error */ +const u8 *channel_update_for_error(const tal_t *ctx UNNEEDED, + struct channel *channel UNNEEDED) +{ fprintf(stderr, "channel_update_for_error called!\n"); abort(); } /* Generated stub for channel_update_reserve */ void channel_update_reserve(struct channel *channel UNNEEDED, struct channel_config *their_config UNNEEDED, @@ -296,9 +300,6 @@ bool fromwire_openingd_dev_memleak_reply(const void *p UNNEEDED, bool *leak UNNE /* Generated stub for get_block_height */ u32 get_block_height(const struct chain_topology *topo UNNEEDED) { fprintf(stderr, "get_block_height called!\n"); abort(); } -/* Generated stub for get_channel_update */ -const u8 *get_channel_update(struct channel *channel UNNEEDED) -{ fprintf(stderr, "get_channel_update called!\n"); abort(); } /* Generated stub for hsmd_wire_name */ const char *hsmd_wire_name(int e UNNEEDED) { fprintf(stderr, "hsmd_wire_name called!\n"); abort(); }