Skip to content

Commit

Permalink
lightningd: use explicit accessor to get channel_update for errors.
Browse files Browse the repository at this point in the history
We want this later, so do the prep work now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Jan 31, 2024
1 parent 1093b43 commit 3e1d34f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
5 changes: 4 additions & 1 deletion lightningd/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
11 changes: 8 additions & 3 deletions lightningd/gossip_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 9 additions & 7 deletions lightningd/peer_htlcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down
7 changes: 4 additions & 3 deletions wallet/test/run-wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(); }
Expand Down

0 comments on commit 3e1d34f

Please sign in to comment.