channeld: get htlc_maximum_msat from lightningd.

We used to calculate it ourselves.  Unfortunately this needs to
be done in several places, since new_channel() isn't used to fully
create a channel in the case of dual funding :(

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2022-03-21 11:28:27 +10:30
parent 6fdcc86f9d
commit 3217dbe17f
6 changed files with 12 additions and 38 deletions

View File

@@ -119,8 +119,12 @@ struct peer {
/* CLTV delta to announce to peers */ /* CLTV delta to announce to peers */
u16 cltv_delta; u16 cltv_delta;
/* We only really know these because we're the ones who create
* the channel_updates. */
u32 fee_base; u32 fee_base;
u32 fee_per_satoshi; u32 fee_per_satoshi;
struct amount_msat htlc_maximum_msat;
/* The scriptpubkey to use for shutting down. */ /* The scriptpubkey to use for shutting down. */
u32 *final_index; u32 *final_index;
@@ -212,42 +216,6 @@ const u8 *hsm_req(const tal_t *ctx, const u8 *req TAKES)
return msg; 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 #if EXPERIMENTAL_FEATURES
static void maybe_send_stfu(struct peer *peer) 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->channel->config[REMOTE].htlc_minimum,
peer->fee_base, peer->fee_base,
peer->fee_per_satoshi, peer->fee_per_satoshi,
advertized_htlc_max(peer->channel)); peer->htlc_maximum_msat);
wire_sync_write(MASTER_FD, take(msg)); wire_sync_write(MASTER_FD, take(msg));
} }
@@ -3774,6 +3742,7 @@ static void init_channel(struct peer *peer)
&opener, &opener,
&peer->fee_base, &peer->fee_base,
&peer->fee_per_satoshi, &peer->fee_per_satoshi,
&peer->htlc_maximum_msat,
&local_msat, &local_msat,
&points[LOCAL], &points[LOCAL],
&funding_pubkey[LOCAL], &funding_pubkey[LOCAL],

View File

@@ -35,6 +35,7 @@ msgdata,channeld_init,old_remote_per_commit,pubkey,
msgdata,channeld_init,opener,enum side, msgdata,channeld_init,opener,enum side,
msgdata,channeld_init,fee_base,u32, msgdata,channeld_init,fee_base,u32,
msgdata,channeld_init,fee_proportional,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,local_msatoshi,amount_msat,
msgdata,channeld_init,our_basepoints,basepoints, msgdata,channeld_init,our_basepoints,basepoints,
msgdata,channeld_init,our_funding_pubkey,pubkey, msgdata,channeld_init,our_funding_pubkey,pubkey,
Can't render this file because it has a wrong number of fields in line 14.

View File

@@ -317,7 +317,7 @@ struct channel *new_unsaved_channel(struct peer *peer,
* capacity the reserve we have to keep. * capacity the reserve we have to keep.
* FIXME: does this need fuzz? * 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_sat lower_bound;
struct amount_msat lower_bound_msat; struct amount_msat lower_bound_msat;

View File

@@ -481,4 +481,5 @@ struct htlc_out *channel_has_htlc_out(struct channel *channel);
const u8 *get_channel_update(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 */ #endif /* LIGHTNING_LIGHTNINGD_CHANNEL_H */

View File

@@ -702,6 +702,7 @@ void peer_start_channeld(struct channel *channel,
channel->opener, channel->opener,
channel->feerate_base, channel->feerate_base,
channel->feerate_ppm, channel->feerate_ppm,
channel->htlc_maximum_msat,
channel->our_msat, channel->our_msat,
&channel->local_basepoints, &channel->local_basepoints,
&channel->local_funding_pubkey, &channel->local_funding_pubkey,

View File

@@ -1110,6 +1110,7 @@ wallet_update_channel(struct lightningd *ld,
channel->msat_to_us_min = our_msat; channel->msat_to_us_min = our_msat;
channel->msat_to_us_max = our_msat; channel->msat_to_us_max = our_msat;
channel->lease_expiry = lease_expiry; channel->lease_expiry = lease_expiry;
channel->htlc_maximum_msat = htlc_max_possible_send(channel);
tal_free(channel->lease_commit_sig); tal_free(channel->lease_commit_sig);
channel->lease_commit_sig = tal_steal(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_msat = lease_chan_max_msat;
channel->lease_chan_max_ppt = lease_chan_max_ppt; 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. */ /* Now we finally put it in the database. */
wallet_channel_insert(ld->wallet, channel); wallet_channel_insert(ld->wallet, channel);