From ad1893f83f644ba4ae68703dd744bfe838510832 Mon Sep 17 00:00:00 2001 From: niftynei Date: Wed, 19 Oct 2022 12:09:41 -0500 Subject: [PATCH] opening: helper for anchor flagged, use in dualopend also There's two anchor flags, we should check both. Also have dualopend check this as well! --- openingd/common.c | 17 +++++++++++------ openingd/common.h | 3 +++ openingd/dualopend.c | 12 ++++++++---- openingd/openingd.c | 10 ++++------ 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/openingd/common.c b/openingd/common.c index 7ee1f34e1..33e5a4df8 100644 --- a/openingd/common.c +++ b/openingd/common.c @@ -211,6 +211,16 @@ u8 *no_upfront_shutdown_script(const tal_t *ctx, return NULL; } +bool anchors_negotiated(struct feature_set *our_features, + const u8 *their_features) +{ + return feature_negotiated(our_features, their_features, + OPT_ANCHOR_OUTPUTS) + || feature_negotiated(our_features, + their_features, + OPT_ANCHORS_ZERO_FEE_HTLC_TX); +} + char *validate_remote_upfront_shutdown(const tal_t *ctx, struct feature_set *our_features, const u8 *their_features, @@ -220,13 +230,8 @@ char *validate_remote_upfront_shutdown(const tal_t *ctx, bool anysegwit = feature_negotiated(our_features, their_features, OPT_SHUTDOWN_ANYSEGWIT); - bool anchors = feature_negotiated(our_features, - their_features, - OPT_ANCHOR_OUTPUTS) - || feature_negotiated(our_features, - their_features, - OPT_ANCHORS_ZERO_FEE_HTLC_TX); + bool anchors = anchors_negotiated(our_features, their_features); /* BOLT #2: * * - MUST include `upfront_shutdown_script` with either a valid diff --git a/openingd/common.h b/openingd/common.h index 86a2be41d..09be918ae 100644 --- a/openingd/common.h +++ b/openingd/common.h @@ -19,6 +19,9 @@ bool check_config_bounds(const tal_t *ctx, bool option_anchor_outputs, char **err_reason); +bool anchors_negotiated(struct feature_set *our_features, + const u8 *their_features); + u8 *no_upfront_shutdown_script(const tal_t *ctx, struct feature_set *our_features, const u8 *their_features); diff --git a/openingd/dualopend.c b/openingd/dualopend.c index 42ff89717..295fa0487 100644 --- a/openingd/dualopend.c +++ b/openingd/dualopend.c @@ -2265,7 +2265,8 @@ static void accepter_start(struct state *state, const u8 *oc2_msg) state->min_effective_htlc_capacity, &tx_state->remoteconf, &tx_state->localconf, - true, /* v2 means we use anchor outputs */ + anchors_negotiated(state->our_features, + state->their_features), &err_reason)) { negotiation_failed(state, "%s", err_reason); return; @@ -2968,7 +2969,8 @@ static void opener_start(struct state *state, u8 *msg) state->min_effective_htlc_capacity, &tx_state->remoteconf, &tx_state->localconf, - true, /* v2 means we use anchor outputs */ + anchors_negotiated(state->our_features, + state->their_features), &err_reason)) { negotiation_failed(state, "%s", err_reason); return; @@ -3255,7 +3257,8 @@ static void rbf_local_start(struct state *state, u8 *msg) state->min_effective_htlc_capacity, &tx_state->remoteconf, &tx_state->localconf, - true, /* v2 means we use anchor outputs */ + anchors_negotiated(state->our_features, + state->their_features), &err_reason)) { open_err_warn(state, "%s", err_reason); goto free_rbf_ctx; @@ -3386,7 +3389,8 @@ static void rbf_remote_start(struct state *state, const u8 *rbf_msg) state->min_effective_htlc_capacity, &tx_state->remoteconf, &tx_state->localconf, - true, /* v2 means we use anchor outputs */ + anchors_negotiated(state->our_features, + state->their_features), &err_reason)) { negotiation_failed(state, "%s", err_reason); goto free_rbf_ctx; diff --git a/openingd/openingd.c b/openingd/openingd.c index 33f886aee..fd23fbd93 100644 --- a/openingd/openingd.c +++ b/openingd/openingd.c @@ -504,9 +504,8 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags) state->min_effective_htlc_capacity, &state->remoteconf, &state->localconf, - feature_negotiated(state->our_features, - state->their_features, - OPT_ANCHOR_OUTPUTS), + anchors_negotiated(state->our_features, + state->their_features), &err_reason)) { negotiation_failed(state, "%s", err_reason); return NULL; @@ -1012,9 +1011,8 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg) state->min_effective_htlc_capacity, &state->remoteconf, &state->localconf, - feature_negotiated(state->our_features, - state->their_features, - OPT_ANCHOR_OUTPUTS), + anchors_negotiated(state->our_features, + state->their_features), &err_reason)) { negotiation_failed(state, "%s", err_reason); return NULL;