From 5f6a2c05bd561bc3aedea6b30a6d23df51f83ea9 Mon Sep 17 00:00:00 2001 From: niftynei Date: Thu, 3 Sep 2020 13:16:25 -0500 Subject: [PATCH] dualopend: check that we're not exceeding max allowable capacity --- openingd/dualopend.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/openingd/dualopend.c b/openingd/dualopend.c index fca4594bb..6e5396e2b 100644 --- a/openingd/dualopend.c +++ b/openingd/dualopend.c @@ -985,6 +985,23 @@ static u8 *accepter_start(struct state *state, const u8 *oc2_msg) type_to_string(tmpctx, struct amount_sat, &state->opener_funding)); + /* Check that total funding doesn't exceed allowed channel capacity */ + /* BOLT #2: + * + * The receiving node MUST fail the channel if: + *... + * - `funding_satoshis` is greater than or equal to 2^24 and the receiver does not support + * `option_support_large_channel`. */ + /* We choose to require *negotiation*, not just support! */ + if (!feature_negotiated(state->our_features, state->their_features, + OPT_LARGE_CHANNELS) + && amount_sat_greater(total, chainparams->max_funding)) { + negotiation_failed(state, false, + "total funding_satoshis %s too large", + type_to_string(tmpctx, struct amount_sat, + &total)); + return NULL; + } /* Add all of our inputs/outputs to the changeset */ init_changeset(state, psbt);