From 88d55441c5bfe5052545874fba36be137ce2cbee Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 8 Sep 2021 09:36:14 +0930 Subject: [PATCH] channeld: allow large HTLCs if peer offers option_support_large_channel This check is going away anyway (only Electrum enforced it), but we know that all wumbo peers expect large HTLCs to work today. Signed-off-by: Rusty Russell Changelog-Added: Protocol: Allow sending large HTLCs if peer offers option_support_large_channel (> 4294967295msat) --- channeld/channeld.c | 2 ++ channeld/full_channel.c | 5 ++++- channeld/full_channel.h | 2 ++ channeld/test/run-full_channel.c | 4 ++-- common/initial_channel.c | 2 ++ common/initial_channel.h | 5 +++++ openingd/dualopend.c | 11 ++++++++++- openingd/openingd.c | 4 ++++ 8 files changed, 31 insertions(+), 4 deletions(-) diff --git a/channeld/channeld.c b/channeld/channeld.c index 38d73afb7..4102ddf77 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -3789,6 +3789,8 @@ static void init_channel(struct peer *peer) &funding_pubkey[REMOTE], option_static_remotekey, option_anchor_outputs, + feature_offered(peer->their_features, + OPT_LARGE_CHANNELS), opener); if (!channel_force_htlcs(peer->channel, diff --git a/channeld/full_channel.c b/channeld/full_channel.c index f9291a8d7..be6f0de87 100644 --- a/channeld/full_channel.c +++ b/channeld/full_channel.c @@ -109,6 +109,7 @@ struct channel *new_full_channel(const tal_t *ctx, const struct pubkey *remote_funding_pubkey, bool option_static_remotekey, bool option_anchor_outputs, + bool option_wumbo, enum side opener) { struct channel *channel = new_initial_channel(ctx, @@ -128,6 +129,7 @@ struct channel *new_full_channel(const tal_t *ctx, remote_funding_pubkey, option_static_remotekey, option_anchor_outputs, + option_wumbo, opener); if (channel) { @@ -584,7 +586,8 @@ static enum channel_add_err add_htlc(struct channel *channel, * - MUST set the four most significant bytes of `amount_msat` to 0. */ if (sender == LOCAL - && amount_msat_greater(htlc->amount, chainparams->max_payment)) { + && amount_msat_greater(htlc->amount, chainparams->max_payment) + && !channel->option_wumbo) { return CHANNEL_ERR_MAX_HTLC_VALUE_EXCEEDED; } diff --git a/channeld/full_channel.h b/channeld/full_channel.h index 56b7c1514..689a873c3 100644 --- a/channeld/full_channel.h +++ b/channeld/full_channel.h @@ -30,6 +30,7 @@ struct existing_htlc; * @remote_fundingkey: remote funding key * @option_static_remotekey: use `option_static_remotekey`. * @option_anchor_outputs: use `option_anchor_outputs`. + * @option_wumbo: large channel negotiated. * @opener: which side initiated it. * * Returns state, or NULL if malformed. @@ -52,6 +53,7 @@ struct channel *new_full_channel(const tal_t *ctx, const struct pubkey *remote_funding_pubkey, bool option_static_remotekey, bool option_anchor_outputs, + bool option_wumbo, enum side opener); /** diff --git a/channeld/test/run-full_channel.c b/channeld/test/run-full_channel.c index b889358a8..a9cb50362 100644 --- a/channeld/test/run-full_channel.c +++ b/channeld/test/run-full_channel.c @@ -493,7 +493,7 @@ int main(int argc, const char *argv[]) &localbase, &remotebase, &local_funding_pubkey, &remote_funding_pubkey, - false, false, LOCAL); + false, false, false, LOCAL); rchannel = new_full_channel(tmpctx, &cid, &funding_txid, funding_output_index, 0, take(new_height_states(NULL, REMOTE, &blockheight)), @@ -506,7 +506,7 @@ int main(int argc, const char *argv[]) &remotebase, &localbase, &remote_funding_pubkey, &local_funding_pubkey, - false, false, REMOTE); + false, false, false, REMOTE); /* BOLT #3: * diff --git a/common/initial_channel.c b/common/initial_channel.c index 2b1cafc98..19e6291cb 100644 --- a/common/initial_channel.c +++ b/common/initial_channel.c @@ -35,6 +35,7 @@ struct channel *new_initial_channel(const tal_t *ctx, const struct pubkey *remote_funding_pubkey, bool option_static_remotekey, bool option_anchor_outputs, + bool option_wumbo, enum side opener) { struct channel *channel = tal(ctx, struct channel); @@ -83,6 +84,7 @@ struct channel *new_initial_channel(const tal_t *ctx, channel->option_static_remotekey = option_static_remotekey; channel->option_anchor_outputs = option_anchor_outputs; + channel->option_wumbo = option_wumbo; if (option_anchor_outputs) assert(option_static_remotekey); return channel; diff --git a/common/initial_channel.h b/common/initial_channel.h index 13dcb5e49..dde829e68 100644 --- a/common/initial_channel.h +++ b/common/initial_channel.h @@ -75,6 +75,9 @@ struct channel { /* Is this using option_anchor_outputs? */ bool option_anchor_outputs; + /* Are we using big channels? */ + bool option_wumbo; + /* When the lease expires for the funds in this channel */ u32 lease_expiry; }; @@ -99,6 +102,7 @@ struct channel { * @remote_fundingkey: remote funding key * @option_static_remotekey: was this created with option_static_remotekey? * @option_anchor_outputs: was this created with option_anchor_outputs? + * @option_wumbo: has peer currently negotiated wumbo? * @opener: which side initiated it. * * Returns channel, or NULL if malformed. @@ -121,6 +125,7 @@ struct channel *new_initial_channel(const tal_t *ctx, const struct pubkey *remote_funding_pubkey, bool option_static_remotekey, bool option_anchor_outputs, + bool option_wumbo, enum side opener); /** diff --git a/openingd/dualopend.c b/openingd/dualopend.c index 45eee1019..55da00598 100644 --- a/openingd/dualopend.c +++ b/openingd/dualopend.c @@ -1726,6 +1726,8 @@ static void revert_channel_state(struct state *state) &state->our_funding_pubkey, &state->their_funding_pubkey, true, true, + feature_offered(state->their_features, + OPT_LARGE_CHANNELS), opener); } @@ -1828,6 +1830,8 @@ static u8 *accepter_commits(struct state *state, &state->our_funding_pubkey, &state->their_funding_pubkey, true, true, + feature_offered(state->their_features, + OPT_LARGE_CHANNELS), REMOTE); local_commit = initial_channel_tx(state, &wscript, state->channel, @@ -2436,6 +2440,8 @@ static u8 *opener_commits(struct state *state, &state->our_funding_pubkey, &state->their_funding_pubkey, true, true, + feature_offered(state->their_features, + OPT_LARGE_CHANNELS), /* Opener is local */ LOCAL); @@ -3858,7 +3864,10 @@ int main(int argc, char *argv[]) &state->their_points, &state->our_funding_pubkey, &state->their_funding_pubkey, - true, true, opener); + true, true, + feature_offered(state->their_features, + OPT_LARGE_CHANNELS), + opener); if (opener == LOCAL) state->our_role = TX_INITIATOR; diff --git a/openingd/openingd.c b/openingd/openingd.c index 864a3698a..5d03b6153 100644 --- a/openingd/openingd.c +++ b/openingd/openingd.c @@ -533,6 +533,8 @@ static bool funder_finalize_channel_setup(struct state *state, &state->their_funding_pubkey, state->option_static_remotekey, state->option_anchor_outputs, + feature_offered(state->their_features, + OPT_LARGE_CHANNELS), /* Opener is local */ LOCAL); /* We were supposed to do enough checks above, but just in case, @@ -1023,6 +1025,8 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg) &their_funding_pubkey, state->option_static_remotekey, state->option_anchor_outputs, + feature_offered(state->their_features, + OPT_LARGE_CHANNELS), REMOTE); /* We don't expect this to fail, but it does do some additional * internal sanity checks. */