diff --git a/channeld/channeld.c b/channeld/channeld.c index edf4c7215..65cf9d5e1 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -119,8 +119,12 @@ struct peer { /* CLTV delta to announce to peers */ u16 cltv_delta; + + /* We only really know these because we're the ones who create + * the channel_updates. */ u32 fee_base; u32 fee_per_satoshi; + struct amount_msat htlc_maximum_msat; /* The scriptpubkey to use for shutting down. */ u32 *final_index; @@ -212,42 +216,6 @@ const u8 *hsm_req(const tal_t *ctx, const u8 *req TAKES) return msg; } -/* - * The maximum msat that this node will accept for an htlc. - * It's flagged as an optional field in `channel_update`. - * - * We advertize the maximum value possible, defined as the smaller - * of the remote's maximum in-flight HTLC or the total channel - * capacity the reserve we have to keep. - * FIXME: does this need fuzz? - */ -static struct amount_msat advertized_htlc_max(const struct channel *channel) -{ - struct amount_sat lower_bound; - struct amount_msat lower_bound_msat; - - /* This shouldn't fail */ - if (!amount_sat_sub(&lower_bound, channel->funding_sats, - channel->config[REMOTE].channel_reserve)) { - status_failed(STATUS_FAIL_INTERNAL_ERROR, - "funding %s - remote reserve %s?", - type_to_string(tmpctx, struct amount_sat, - &channel->funding_sats), - type_to_string(tmpctx, struct amount_sat, - &channel->config[REMOTE] - .channel_reserve)); - } - - if (!amount_sat_to_msat(&lower_bound_msat, lower_bound)) { - status_failed(STATUS_FAIL_INTERNAL_ERROR, - "lower_bound %s invalid?", - type_to_string(tmpctx, struct amount_sat, - &lower_bound)); - } - - return lower_bound_msat; -} - #if EXPERIMENTAL_FEATURES static void maybe_send_stfu(struct peer *peer) { @@ -396,7 +364,7 @@ static void send_channel_update(struct peer *peer, int disable_flag) peer->channel->config[REMOTE].htlc_minimum, peer->fee_base, peer->fee_per_satoshi, - advertized_htlc_max(peer->channel)); + peer->htlc_maximum_msat); wire_sync_write(MASTER_FD, take(msg)); } @@ -3774,6 +3742,7 @@ static void init_channel(struct peer *peer) &opener, &peer->fee_base, &peer->fee_per_satoshi, + &peer->htlc_maximum_msat, &local_msat, &points[LOCAL], &funding_pubkey[LOCAL], diff --git a/channeld/channeld_wire.csv b/channeld/channeld_wire.csv index b84ca73c4..f0d9f9e9c 100644 --- a/channeld/channeld_wire.csv +++ b/channeld/channeld_wire.csv @@ -35,6 +35,7 @@ msgdata,channeld_init,old_remote_per_commit,pubkey, msgdata,channeld_init,opener,enum side, msgdata,channeld_init,fee_base,u32, msgdata,channeld_init,fee_proportional,u32, +msgdata,channeld_init,htlc_maximum_msat,amount_msat, msgdata,channeld_init,local_msatoshi,amount_msat, msgdata,channeld_init,our_basepoints,basepoints, msgdata,channeld_init,our_funding_pubkey,pubkey, diff --git a/lightningd/channel.c b/lightningd/channel.c index ff68376ee..3bb5ad027 100644 --- a/lightningd/channel.c +++ b/lightningd/channel.c @@ -317,7 +317,7 @@ struct channel *new_unsaved_channel(struct peer *peer, * capacity the reserve we have to keep. * FIXME: does this need fuzz? */ -static struct amount_msat htlc_max_possible_send(const struct channel *channel) +struct amount_msat htlc_max_possible_send(const struct channel *channel) { struct amount_sat lower_bound; struct amount_msat lower_bound_msat; diff --git a/lightningd/channel.h b/lightningd/channel.h index 98953fbe7..867f8208d 100644 --- a/lightningd/channel.h +++ b/lightningd/channel.h @@ -481,4 +481,5 @@ struct htlc_out *channel_has_htlc_out(struct channel *channel); const u8 *get_channel_update(struct channel *channel); +struct amount_msat htlc_max_possible_send(const struct channel *channel); #endif /* LIGHTNING_LIGHTNINGD_CHANNEL_H */ diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index e07db69d0..390320e72 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -702,6 +702,7 @@ void peer_start_channeld(struct channel *channel, channel->opener, channel->feerate_base, channel->feerate_ppm, + channel->htlc_maximum_msat, channel->our_msat, &channel->local_basepoints, &channel->local_funding_pubkey, diff --git a/lightningd/dual_open_control.c b/lightningd/dual_open_control.c index 3aa4f98ad..d2fa86f4a 100644 --- a/lightningd/dual_open_control.c +++ b/lightningd/dual_open_control.c @@ -1110,6 +1110,7 @@ wallet_update_channel(struct lightningd *ld, channel->msat_to_us_min = our_msat; channel->msat_to_us_max = our_msat; channel->lease_expiry = lease_expiry; + channel->htlc_maximum_msat = htlc_max_possible_send(channel); tal_free(channel->lease_commit_sig); channel->lease_commit_sig = tal_steal(channel, lease_commit_sig); @@ -1252,6 +1253,7 @@ wallet_commit_channel(struct lightningd *ld, channel->lease_chan_max_msat = lease_chan_max_msat; channel->lease_chan_max_ppt = lease_chan_max_ppt; + channel->htlc_maximum_msat = htlc_max_possible_send(channel); /* Now we finally put it in the database. */ wallet_channel_insert(ld->wallet, channel);