Browse Source

df: use dev-env flagged upfront shutdown script

This lets the test_option_upfront_shutdown_script test pass
ppa
niftynei 4 years ago
committed by Christian Decker
parent
commit
205a7057c9
  1. 28
      openingd/common.c
  2. 3
      openingd/common.h
  3. 28
      openingd/dualopend.c
  4. 35
      openingd/openingd.c

28
openingd/common.c

@ -1,6 +1,7 @@
#include <ccan/ccan/tal/str/str.h>
#include <common/amount.h>
#include <common/channel_config.h>
#include <common/features.h>
#include <common/initial_commit_tx.h>
#include <common/type_to_string.h>
#include <openingd/common.h>
@ -194,3 +195,30 @@ bool check_config_bounds(const tal_t *ctx,
return true;
}
u8 *no_upfront_shutdown_script(const tal_t *ctx,
struct feature_set *our_features,
const u8 *their_features)
{
#if DEVELOPER
/* This is a hack, for feature testing */
const char *e = getenv("DEV_OPENINGD_UPFRONT_SHUTDOWN_SCRIPT");
if (e)
return tal_hexdata(ctx, e, strlen(e));
#endif
/* BOLT #2:
*
* - if both nodes advertised the `option_upfront_shutdown_script`
* feature:
* - MUST include `upfront_shutdown_script` with either a valid
* `shutdown_scriptpubkey` as required by `shutdown`
* `scriptpubkey`, or a zero-length `shutdown_scriptpubkey`
* (ie. `0x0000`).
*/
if (feature_negotiated(our_features, their_features,
OPT_UPFRONT_SHUTDOWN_SCRIPT))
return tal_arr(ctx, u8, 0);
return NULL;
}

3
openingd/common.h

@ -18,4 +18,7 @@ bool check_config_bounds(const tal_t *ctx,
bool option_anchor_outputs,
char **err_reason);
u8 *no_upfront_shutdown_script(const tal_t *ctx,
struct feature_set *our_features,
const u8 *their_features);
#endif /* LIGHTNING_OPENINGD_COMMON_H */

28
openingd/dualopend.c

@ -1573,12 +1573,20 @@ static void accepter_start(struct state *state, const u8 *oc2_msg)
/* If we have an upfront shutdown script, send it to our peer */
struct tlv_accept_tlvs *a_tlv = tlv_accept_tlvs_new(state);
if (state->upfront_shutdown_script[LOCAL]) {
a_tlv->option_upfront_shutdown_script = tal(a_tlv,
struct tlv_accept_tlvs_option_upfront_shutdown_script);
a_tlv->option_upfront_shutdown_script->shutdown_scriptpubkey =
tal_dup_arr(a_tlv, u8, state->upfront_shutdown_script[LOCAL],
tal_count(state->upfront_shutdown_script[LOCAL]), 0);
if (!state->upfront_shutdown_script[LOCAL])
state->upfront_shutdown_script[LOCAL]
= no_upfront_shutdown_script(state,
state->our_features,
state->their_features);
if (tal_bytelen(state->upfront_shutdown_script[LOCAL])) {
a_tlv->option_upfront_shutdown_script
= tal(a_tlv, struct tlv_accept_tlvs_option_upfront_shutdown_script);
a_tlv->option_upfront_shutdown_script->shutdown_scriptpubkey
= tal_dup_arr(a_tlv, u8,
state->upfront_shutdown_script[LOCAL],
tal_count(state->upfront_shutdown_script[LOCAL]),
0);
}
msg = towire_accept_channel2(tmpctx, &state->channel_id,
@ -1868,7 +1876,13 @@ static void opener_start(struct state *state, u8 *msg)
}
feerate_best = state->feerate_per_kw_funding;
if (state->upfront_shutdown_script[LOCAL]) {
if (!state->upfront_shutdown_script[LOCAL])
state->upfront_shutdown_script[LOCAL]
= no_upfront_shutdown_script(state,
state->our_features,
state->their_features);
if (tal_bytelen(state->upfront_shutdown_script[LOCAL])) {
open_tlv->option_upfront_shutdown_script =
tal(open_tlv,
struct tlv_opening_tlvs_option_upfront_shutdown_script);

35
openingd/openingd.c

@ -119,31 +119,6 @@ struct state {
struct feature_set *our_features;
};
static u8 *no_upfront_shutdown_script(const tal_t *ctx, struct state *state)
{
#if DEVELOPER
/* This is a hack, for feature testing */
const char *e = getenv("DEV_OPENINGD_UPFRONT_SHUTDOWN_SCRIPT");
if (e)
return tal_hexdata(ctx, e, strlen(e));
#endif
/* BOLT #2:
*
* - if both nodes advertised the `option_upfront_shutdown_script`
* feature:
* - MUST include `upfront_shutdown_script` with either a valid
* `shutdown_scriptpubkey` as required by `shutdown`
* `scriptpubkey`, or a zero-length `shutdown_scriptpubkey`
* (ie. `0x0000`).
*/
if (feature_negotiated(state->our_features, state->their_features,
OPT_UPFRONT_SHUTDOWN_SCRIPT))
return tal_arr(ctx, u8, 0);
return NULL;
}
/*~ If we can't agree on parameters, we fail to open the channel. If we're
* the opener, we need to tell lightningd, otherwise it never really notices. */
static void negotiation_aborted(struct state *state, bool am_opener,
@ -371,7 +346,10 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags)
return NULL;
if (!state->upfront_shutdown_script[LOCAL])
state->upfront_shutdown_script[LOCAL] = no_upfront_shutdown_script(state, state);
state->upfront_shutdown_script[LOCAL]
= no_upfront_shutdown_script(state,
state->our_features,
state->their_features);
open_tlvs = tlv_open_channel_tlvs_new(tmpctx);
open_tlvs->upfront_shutdown_script
@ -955,7 +933,10 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
}
if (!state->upfront_shutdown_script[LOCAL])
state->upfront_shutdown_script[LOCAL] = no_upfront_shutdown_script(state, state);
state->upfront_shutdown_script[LOCAL]
= no_upfront_shutdown_script(state,
state->our_features,
state->their_features);
/* OK, we accept! */
accept_tlvs = tlv_accept_channel_tlvs_new(tmpctx);

Loading…
Cancel
Save