From 4fdcee9a115203794f1b9c2dce857d5794b267e6 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 21 Mar 2022 11:28:28 +1030 Subject: [PATCH] channeld: generalize specific_feerates mesage into config_channel. 1. Add the htlc_max param. 2. Allow parameters to be unset, meaning "don't change". Signed-off-by: Rusty Russell --- channeld/channeld.c | 33 ++++++++++++++------- channeld/channeld_wire.csv | 9 +++--- lightningd/channel_control.c | 2 +- lightningd/peer_control.c | 3 +- lightningd/test/run-invoice-select-inchan.c | 6 ++-- wallet/test/run-wallet.c | 6 ++-- 6 files changed, 37 insertions(+), 22 deletions(-) diff --git a/channeld/channeld.c b/channeld/channeld.c index 65cf9d5e1..262cb387f 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -3426,18 +3426,31 @@ static void handle_blockheight(struct peer *peer, const u8 *inmsg) } } -static void handle_specific_feerates(struct peer *peer, const u8 *inmsg) +static void handle_config_channel(struct peer *peer, const u8 *inmsg) { - u32 base_old = peer->fee_base; - u32 per_satoshi_old = peer->fee_per_satoshi; + u32 *base, *ppm; + struct amount_msat *htlc_max; + bool changed; - if (!fromwire_channeld_specific_feerates(inmsg, - &peer->fee_base, - &peer->fee_per_satoshi)) - master_badmsg(WIRE_CHANNELD_SPECIFIC_FEERATES, inmsg); + if (!fromwire_channeld_config_channel(inmsg, inmsg, &base, &ppm, &htlc_max)) + master_badmsg(WIRE_CHANNELD_CONFIG_CHANNEL, inmsg); /* only send channel updates if values actually changed */ - if (peer->fee_base != base_old || peer->fee_per_satoshi != per_satoshi_old) + changed = false; + if (base && *base != peer->fee_base) { + peer->fee_base = *base; + changed = true; + } + if (ppm && *ppm != peer->fee_per_satoshi) { + peer->fee_per_satoshi = *ppm; + changed = true; + } + if (htlc_max && !amount_msat_eq(*htlc_max, peer->htlc_maximum_msat)) { + peer->htlc_maximum_msat = *htlc_max; + changed = true; + } + + if (changed) send_channel_update(peer, 0); } @@ -3627,10 +3640,10 @@ static void req_in(struct peer *peer, const u8 *msg) return; handle_fail(peer, msg); return; - case WIRE_CHANNELD_SPECIFIC_FEERATES: + case WIRE_CHANNELD_CONFIG_CHANNEL: if (handle_master_request_later(peer, msg)) return; - handle_specific_feerates(peer, msg); + handle_config_channel(peer, msg); return; case WIRE_CHANNELD_SEND_SHUTDOWN: handle_shutdown_cmd(peer, msg); diff --git a/channeld/channeld_wire.csv b/channeld/channeld_wire.csv index f0d9f9e9c..df54a26b7 100644 --- a/channeld/channeld_wire.csv +++ b/channeld/channeld_wire.csv @@ -216,10 +216,11 @@ msgtype,channeld_fail_fallen_behind,1028 # This is NULL if option_static_remotekey. msgdata,channeld_fail_fallen_behind,remote_per_commitment_point,?pubkey, -# Handle a channel specific feerate base ppm configuration -msgtype,channeld_specific_feerates,1029 -msgdata,channeld_specific_feerates,feerate_base,u32, -msgdata,channeld_specific_feerates,feerate_ppm,u32, +# Handle a channel-specific configuration change +msgtype,channeld_config_channel,1029 +msgdata,channeld_config_channel,feerate_base,?u32, +msgdata,channeld_config_channel,feerate_ppm,?u32, +msgdata,channeld_config_channel,htlc_maximum,?amount_msat, # When we receive announcement_signatures for channel announce msgtype,channeld_got_announcement,1017 diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index 390320e72..2b21d5241 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -548,7 +548,7 @@ static unsigned channel_msg(struct subd *sd, const u8 *msg, const int *fds) case WIRE_CHANNELD_DEV_REENABLE_COMMIT: case WIRE_CHANNELD_FEERATES: case WIRE_CHANNELD_BLOCKHEIGHT: - case WIRE_CHANNELD_SPECIFIC_FEERATES: + case WIRE_CHANNELD_CONFIG_CHANNEL: case WIRE_CHANNELD_CHANNEL_UPDATE: case WIRE_CHANNELD_DEV_MEMLEAK: case WIRE_CHANNELD_DEV_QUIESCE: diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index e3aff6408..38809d433 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -2028,7 +2028,8 @@ static void set_channel_fees(struct command *cmd, struct channel *channel, /* tell channeld to make a send_channel_update */ if (channel->owner && streq(channel->owner->name, "channeld")) subd_send_msg(channel->owner, - take(towire_channeld_specific_feerates(NULL, base, ppm))); + take(towire_channeld_config_channel(NULL, &base, &ppm, + NULL))); /* save values to database */ wallet_channel_save(cmd->ld->wallet, channel); diff --git a/lightningd/test/run-invoice-select-inchan.c b/lightningd/test/run-invoice-select-inchan.c index 9e95ca3e0..1f7db910b 100644 --- a/lightningd/test/run-invoice-select-inchan.c +++ b/lightningd/test/run-invoice-select-inchan.c @@ -625,15 +625,15 @@ void towire_bigsize(u8 **pptr UNNEEDED, const bigsize_t val UNNEEDED) /* Generated stub for towire_channel_id */ void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED) { fprintf(stderr, "towire_channel_id called!\n"); abort(); } +/* Generated stub for towire_channeld_config_channel */ +u8 *towire_channeld_config_channel(const tal_t *ctx UNNEEDED, u32 *feerate_base UNNEEDED, u32 *feerate_ppm UNNEEDED, struct amount_msat *htlc_maximum UNNEEDED) +{ fprintf(stderr, "towire_channeld_config_channel called!\n"); abort(); } /* Generated stub for towire_channeld_dev_memleak */ u8 *towire_channeld_dev_memleak(const tal_t *ctx UNNEEDED) { fprintf(stderr, "towire_channeld_dev_memleak called!\n"); abort(); } /* Generated stub for towire_channeld_dev_reenable_commit */ u8 *towire_channeld_dev_reenable_commit(const tal_t *ctx UNNEEDED) { fprintf(stderr, "towire_channeld_dev_reenable_commit called!\n"); abort(); } -/* Generated stub for towire_channeld_specific_feerates */ -u8 *towire_channeld_specific_feerates(const tal_t *ctx UNNEEDED, u32 feerate_base UNNEEDED, u32 feerate_ppm UNNEEDED) -{ fprintf(stderr, "towire_channeld_specific_feerates called!\n"); abort(); } /* Generated stub for towire_connectd_peer_final_msg */ u8 *towire_connectd_peer_final_msg(const tal_t *ctx UNNEEDED, const struct node_id *id UNNEEDED, const u8 *msg UNNEEDED) { fprintf(stderr, "towire_connectd_peer_final_msg called!\n"); abort(); } diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index c1ce3a94b..d6573857e 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -693,6 +693,9 @@ void topology_add_sync_waiter_(const tal_t *ctx UNNEEDED, /* Generated stub for towire_channel_disabled */ u8 *towire_channel_disabled(const tal_t *ctx UNNEEDED) { fprintf(stderr, "towire_channel_disabled called!\n"); abort(); } +/* Generated stub for towire_channeld_config_channel */ +u8 *towire_channeld_config_channel(const tal_t *ctx UNNEEDED, u32 *feerate_base UNNEEDED, u32 *feerate_ppm UNNEEDED, struct amount_msat *htlc_maximum UNNEEDED) +{ fprintf(stderr, "towire_channeld_config_channel called!\n"); abort(); } /* Generated stub for towire_channeld_dev_memleak */ u8 *towire_channeld_dev_memleak(const tal_t *ctx UNNEEDED) { fprintf(stderr, "towire_channeld_dev_memleak called!\n"); abort(); } @@ -717,9 +720,6 @@ u8 *towire_channeld_offer_htlc(const tal_t *ctx UNNEEDED, struct amount_msat amo /* Generated stub for towire_channeld_sending_commitsig_reply */ u8 *towire_channeld_sending_commitsig_reply(const tal_t *ctx UNNEEDED) { fprintf(stderr, "towire_channeld_sending_commitsig_reply called!\n"); abort(); } -/* Generated stub for towire_channeld_specific_feerates */ -u8 *towire_channeld_specific_feerates(const tal_t *ctx UNNEEDED, u32 feerate_base UNNEEDED, u32 feerate_ppm UNNEEDED) -{ fprintf(stderr, "towire_channeld_specific_feerates called!\n"); abort(); } /* Generated stub for towire_connectd_peer_disconnected */ u8 *towire_connectd_peer_disconnected(const tal_t *ctx UNNEEDED, const struct node_id *id UNNEEDED) { fprintf(stderr, "towire_connectd_peer_disconnected called!\n"); abort(); }