mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-08 16:44:22 +01:00
common: support opt_shutdown_anysegwit checks (EXPERIMENTAL_FEATURES).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -78,6 +78,10 @@ static const struct feature_style feature_styles[] = {
|
||||
.copy_style = { [INIT_FEATURE] = FEATURE_REPRESENT,
|
||||
[NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT,
|
||||
[CHANNEL_FEATURE] = FEATURE_DONT_REPRESENT } },
|
||||
{ OPT_SHUTDOWN_ANYSEGWIT,
|
||||
.copy_style = { [INIT_FEATURE] = FEATURE_REPRESENT,
|
||||
[NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT,
|
||||
[CHANNEL_FEATURE] = FEATURE_DONT_REPRESENT } },
|
||||
{ OPT_DUAL_FUND,
|
||||
.copy_style = { [INIT_FEATURE] = FEATURE_REPRESENT,
|
||||
[NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT,
|
||||
@@ -385,9 +389,12 @@ static const char *feature_name(const tal_t *ctx, size_t f)
|
||||
"option_basic_mpp",
|
||||
"option_support_large_channel",
|
||||
"option_anchor_outputs",
|
||||
"option_anchors_zero_fee_htlc_tx",
|
||||
NULL,
|
||||
"option_shutdown_anysegwit",
|
||||
};
|
||||
|
||||
if (f / 2 >= ARRAY_SIZE(fnames))
|
||||
if (f / 2 >= ARRAY_SIZE(fnames) || !fnames[f / 2])
|
||||
return tal_fmt(ctx, "option_unknown_%zu/%s",
|
||||
COMPULSORY_FEATURE(f), (f & 1) ? "odd" : "even");
|
||||
|
||||
|
||||
@@ -113,6 +113,12 @@ u8 *featurebits_or(const tal_t *ctx, const u8 *f1 TAKES, const u8 *f2 TAKES);
|
||||
#define OPT_LARGE_CHANNELS 18
|
||||
#define OPT_ANCHOR_OUTPUTS 20
|
||||
|
||||
/* BOLT-4e329271a358ee52bf43ddbd96776943c5d74508 #9:
|
||||
*
|
||||
* | 26/27 | `option_shutdown_anysegwit` |... IN ...
|
||||
*/
|
||||
#define OPT_SHUTDOWN_ANYSEGWIT 26
|
||||
|
||||
/* BOLT-7b04b1461739c5036add61782d58ac490842d98b #9:
|
||||
* | 222/223 | `option_dual_fund` | ... IN9 ...
|
||||
*/
|
||||
|
||||
@@ -1,10 +1,63 @@
|
||||
#include <bitcoin/script.h>
|
||||
#include <common/shutdown_scriptpubkey.h>
|
||||
|
||||
bool valid_shutdown_scriptpubkey(const u8 *scriptpubkey)
|
||||
#include <stdio.h>
|
||||
|
||||
/* BOLT-4e329271a358ee52bf43ddbd96776943c5d74508 #2:
|
||||
* 5. if (and only if) `option_shutdown_anysegwit` is negotiated:
|
||||
* * `OP_1` through `OP_16` inclusive, followed by a single
|
||||
* push of 2 to 40 bytes
|
||||
* (witness program versions 1 through 16)
|
||||
*/
|
||||
static bool is_valid_witnessprog(const u8 *scriptpubkey)
|
||||
{
|
||||
size_t pushlen;
|
||||
|
||||
if (tal_bytelen(scriptpubkey) < 2)
|
||||
return false;
|
||||
|
||||
switch (scriptpubkey[0]) {
|
||||
case OP_1:
|
||||
case OP_2:
|
||||
case OP_3:
|
||||
case OP_4:
|
||||
case OP_5:
|
||||
case OP_6:
|
||||
case OP_7:
|
||||
case OP_8:
|
||||
case OP_9:
|
||||
case OP_10:
|
||||
case OP_11:
|
||||
case OP_12:
|
||||
case OP_13:
|
||||
case OP_14:
|
||||
case OP_15:
|
||||
case OP_16:
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "op = %u (invalid)\n", scriptpubkey[0]);
|
||||
return false;
|
||||
}
|
||||
|
||||
pushlen = scriptpubkey[1];
|
||||
/* Must be all of the rest of scriptpubkey */
|
||||
if (2 + pushlen != tal_bytelen(scriptpubkey)) {
|
||||
fprintf(stderr, "2 + %zu != %zu\n", pushlen, tal_bytelen(scriptpubkey));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(pushlen >= 2 && pushlen <= 40))
|
||||
fprintf(stderr, "pushlen == %zu\n", pushlen);
|
||||
|
||||
return pushlen >= 2 && pushlen <= 40;
|
||||
}
|
||||
|
||||
bool valid_shutdown_scriptpubkey(const u8 *scriptpubkey,
|
||||
bool anysegwit)
|
||||
{
|
||||
return is_p2pkh(scriptpubkey, NULL)
|
||||
|| is_p2sh(scriptpubkey, NULL)
|
||||
|| is_p2wpkh(scriptpubkey, NULL)
|
||||
|| is_p2wsh(scriptpubkey, NULL);
|
||||
|| is_p2wsh(scriptpubkey, NULL)
|
||||
|| (anysegwit && is_valid_witnessprog(scriptpubkey));
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
* - if the `scriptpubkey` is not in one of the above forms:
|
||||
* - SHOULD fail the connection.
|
||||
*/
|
||||
bool valid_shutdown_scriptpubkey(const u8 *scriptpubkey);
|
||||
bool valid_shutdown_scriptpubkey(const u8 *scriptpubkey,
|
||||
bool anysegwit);
|
||||
|
||||
#endif /* LIGHTNING_COMMON_SHUTDOWN_SCRIPTPUBKEY_H */
|
||||
|
||||
Reference in New Issue
Block a user