From 9c89184c1fc5880a90093b401237176161857675 Mon Sep 17 00:00:00 2001 From: niftynei Date: Wed, 9 Sep 2020 19:40:28 +0930 Subject: [PATCH] dualfund: add feature flag for dual-funding turn off until we're ready to test both sides --- common/features.c | 12 ++++++++ common/features.h | 5 ++++ lightningd/dual_open_control.c | 33 +++++---------------- lightningd/peer_control.c | 12 ++++++-- lightningd/test/run-invoice-select-inchan.c | 9 ++++++ wallet/db_postgres_sqlgen.c | 2 +- wallet/db_sqlite3_sqlgen.c | 2 +- wallet/statements_gettextgen.po | 4 +-- wallet/test/run-wallet.c | 9 ++++++ 9 files changed, 56 insertions(+), 32 deletions(-) diff --git a/common/features.c b/common/features.c index 6a022079d..4a423eff5 100644 --- a/common/features.c +++ b/common/features.c @@ -78,6 +78,12 @@ static const struct feature_style feature_styles[] = { [NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT, [BOLT11_FEATURE] = FEATURE_REPRESENT, [CHANNEL_FEATURE] = FEATURE_REPRESENT_AS_OPTIONAL} }, + + { OPT_DUAL_FUND, + .copy_style = { [INIT_FEATURE] = FEATURE_REPRESENT, + [NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT, + [BOLT11_FEATURE] = FEATURE_REPRESENT, + [CHANNEL_FEATURE] = FEATURE_DONT_REPRESENT} }, #endif }; @@ -106,6 +112,12 @@ static const struct dependency feature_deps[] = { */ #if EXPERIMENTAL_FEATURES { OPT_ANCHOR_OUTPUTS, OPT_STATIC_REMOTEKEY }, + /* BOLT-7b04b1461739c5036add61782d58ac490842d98b #9: + * Name | Description | Context | Dependencies | + * ... + * `option_dual_fund` | ... | ... | `option_anchor_outputs` + */ + { OPT_DUAL_FUND, OPT_ANCHOR_OUTPUTS }, #endif }; diff --git a/common/features.h b/common/features.h index a1af6b718..1ac93e100 100644 --- a/common/features.h +++ b/common/features.h @@ -115,5 +115,10 @@ u8 *featurebits_or(const tal_t *ctx, const u8 *f1 TAKES, const u8 *f2 TAKES); */ #if EXPERIMENTAL_FEATURES #define OPT_ONION_MESSAGES 102 + +/* BOLT-7b04b1461739c5036add61782d58ac490842d98b #9: + * | 222/223 | `option_dual_fund` | ... IN9 ... + */ +#define OPT_DUAL_FUND 222 #endif #endif /* LIGHTNING_COMMON_FEATURES_H */ diff --git a/lightningd/dual_open_control.c b/lightningd/dual_open_control.c index 9554aa7d9..d82858212 100644 --- a/lightningd/dual_open_control.c +++ b/lightningd/dual_open_control.c @@ -658,32 +658,13 @@ wallet_commit_channel(struct lightningd *ld, /* old_remote_per_commit not valid yet, copy valid one. */ channel_info->old_remote_per_commit = channel_info->remote_per_commit; - /* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #2: - * 1. type: 35 (`funding_signed`) - * 2. data: - * * [`channel_id`:`channel_id`] - * * [`signature`:`signature`] - * - * #### Requirements - * - * Both peers: - * - if `option_static_remotekey` or `option_anchor_outputs` was negotiated: - * - `option_static_remotekey` or `option_anchor_outputs` applies to all commitment - * transactions - * - otherwise: - * - `option_static_remotekey` or `option_anchor_outputs` does not apply to any commitment - * transactions - */ - /* i.e. We set it now for the channel permanently. */ - option_static_remotekey - = feature_negotiated(ld->our_features, - uc->peer->their_features, - OPT_STATIC_REMOTEKEY); - - option_anchor_outputs - = feature_negotiated(ld->our_features, - uc->peer->their_features, - OPT_ANCHOR_OUTPUTS); + /* BOLT-7b04b1461739c5036add61782d58ac490842d98b #9 + * | 222/223 | `option_dual_fund` + * | Use v2 of channel open, enables dual funding + * | IN9 + * | `option_anchor_outputs` */ + option_static_remotekey = true; + option_anchor_outputs = true; channel = new_channel(uc->peer, uc->dbid, NULL, /* No shachain yet */ diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index d20cfb3eb..920d8fe51 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -1004,7 +1005,14 @@ peer_connected_hook_cb(struct peer_connected_hook_payload *payload STEALS, error = NULL; send_error: - peer_start_openingd(peer, payload->pps, error); +#if EXPERIMENTAL_FEATURES + if (feature_negotiated(ld->our_features, + peer->their_features, + OPT_DUAL_FUND)) { + peer_start_dualopend(peer, payload->pps, error); + } else +#endif /* EXPERIMENTAL_FEATURES */ + peer_start_openingd(peer, payload->pps, error); tal_free(payload); } @@ -1258,6 +1266,7 @@ static struct command_result *json_listpeers(struct command *cmd, return command_success(cmd, response); } +/* Magic marker: remove at your own peril! */ static const struct json_command listpeers_command = { "listpeers", "network", @@ -1468,7 +1477,6 @@ static struct command_result *json_close(struct command *cmd, return command_still_pending(cmd); } -/* Magic marker: remove at your own peril! */ static const struct json_command close_command = { "close", "channels", diff --git a/lightningd/test/run-invoice-select-inchan.c b/lightningd/test/run-invoice-select-inchan.c index 2e5a32dd2..61efe48e7 100644 --- a/lightningd/test/run-invoice-select-inchan.c +++ b/lightningd/test/run-invoice-select-inchan.c @@ -138,6 +138,10 @@ void fatal(const char *fmt UNNEEDED, ...) /* Generated stub for feature_is_set */ bool feature_is_set(const u8 *features UNNEEDED, size_t bit UNNEEDED) { fprintf(stderr, "feature_is_set called!\n"); abort(); } +/* Generated stub for feature_negotiated */ +bool feature_negotiated(const struct feature_set *our_features UNNEEDED, + const u8 *their_features UNNEEDED, size_t f UNNEEDED) +{ fprintf(stderr, "feature_negotiated called!\n"); abort(); } /* Generated stub for fixup_htlcs_out */ void fixup_htlcs_out(struct lightningd *ld UNNEEDED) { fprintf(stderr, "fixup_htlcs_out called!\n"); abort(); } @@ -471,6 +475,11 @@ void peer_start_closingd(struct channel *channel UNNEEDED, bool reconnected UNNEEDED, const u8 *channel_reestablish UNNEEDED) { fprintf(stderr, "peer_start_closingd called!\n"); abort(); } +/* Generated stub for peer_start_dualopend */ +void peer_start_dualopend(struct peer *peer UNNEEDED, + struct per_peer_state *pps UNNEEDED, + const u8 *send_msg UNNEEDED) +{ fprintf(stderr, "peer_start_dualopend called!\n"); abort(); } /* Generated stub for peer_start_openingd */ void peer_start_openingd(struct peer *peer UNNEEDED, struct per_peer_state *pps UNNEEDED, diff --git a/wallet/db_postgres_sqlgen.c b/wallet/db_postgres_sqlgen.c index 781f378b2..ef3cb5ab5 100644 --- a/wallet/db_postgres_sqlgen.c +++ b/wallet/db_postgres_sqlgen.c @@ -1648,4 +1648,4 @@ struct db_query db_postgres_queries[] = { #endif /* LIGHTNINGD_WALLET_GEN_DB_POSTGRES */ -// SHA256STAMP:0838dffa4a6f4f42152ad48122d435039c2cff5fa8c067e2bd2b54ef8cb92ee9 +// SHA256STAMP:750952e0c2a627617fea597d3faa6b41b736c6a67101343b37ec86c47da7bad7 diff --git a/wallet/db_sqlite3_sqlgen.c b/wallet/db_sqlite3_sqlgen.c index c5b91f0f5..3ebb23094 100644 --- a/wallet/db_sqlite3_sqlgen.c +++ b/wallet/db_sqlite3_sqlgen.c @@ -1648,4 +1648,4 @@ struct db_query db_sqlite3_queries[] = { #endif /* LIGHTNINGD_WALLET_GEN_DB_SQLITE3 */ -// SHA256STAMP:0838dffa4a6f4f42152ad48122d435039c2cff5fa8c067e2bd2b54ef8cb92ee9 +// SHA256STAMP:750952e0c2a627617fea597d3faa6b41b736c6a67101343b37ec86c47da7bad7 diff --git a/wallet/statements_gettextgen.po b/wallet/statements_gettextgen.po index 99368f0c9..58e19111d 100644 --- a/wallet/statements_gettextgen.po +++ b/wallet/statements_gettextgen.po @@ -1082,7 +1082,7 @@ msgstr "" msgid "not a valid SQL statement" msgstr "" -#: wallet/test/run-wallet.c:1346 +#: wallet/test/run-wallet.c:1355 msgid "INSERT INTO channels (id) VALUES (1);" msgstr "" -# SHA256STAMP:b38439695ca8ff636fbd7b7b17d156d5d5d5408b8d5dd228d20744b7e25da2be +# SHA256STAMP:a2c4fd6e26d81d871d9ee5201a844e09d94b4ea50c3690060dea4dd640ef007b diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index da135daac..eb2bb2d17 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -111,6 +111,10 @@ char *encode_scriptpubkey_to_addr(const tal_t *ctx UNNEEDED, /* Generated stub for fatal */ void fatal(const char *fmt UNNEEDED, ...) { fprintf(stderr, "fatal called!\n"); abort(); } +/* Generated stub for feature_negotiated */ +bool feature_negotiated(const struct feature_set *our_features UNNEEDED, + const u8 *their_features UNNEEDED, size_t f UNNEEDED) +{ fprintf(stderr, "feature_negotiated called!\n"); abort(); } /* Generated stub for fromwire_channeld_dev_memleak_reply */ bool fromwire_channeld_dev_memleak_reply(const void *p UNNEEDED, bool *leak UNNEEDED) { fprintf(stderr, "fromwire_channeld_dev_memleak_reply called!\n"); abort(); } @@ -578,6 +582,11 @@ void peer_start_closingd(struct channel *channel UNNEEDED, bool reconnected UNNEEDED, const u8 *channel_reestablish UNNEEDED) { fprintf(stderr, "peer_start_closingd called!\n"); abort(); } +/* Generated stub for peer_start_dualopend */ +void peer_start_dualopend(struct peer *peer UNNEEDED, + struct per_peer_state *pps UNNEEDED, + const u8 *send_msg UNNEEDED) +{ fprintf(stderr, "peer_start_dualopend called!\n"); abort(); } /* Generated stub for peer_start_openingd */ void peer_start_openingd(struct peer *peer UNNEEDED, struct per_peer_state *pps UNNEEDED,