From b6d7ee1f115531733f40067e5ded7f8470899bde Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 19 Jun 2024 09:30:01 +0930 Subject: [PATCH] common: No longer support new channels without option_static_remotekey. We still support *existing* channels. Just not new ones (before they could, in theory, explicitly ask for one). Signed-off-by: Rusty Russell --- Makefile | 2 +- channeld/channeld.c | 49 ++++++++++--------------------- channeld/channeld_wire.csv | 2 -- channeld/test/run-full_channel.c | 34 +++++++++++---------- common/channel_type.c | 46 ++++++++++++++--------------- common/channel_type.h | 4 ++- common/features.h | 4 +-- common/key_derive.c | 6 ++++ common/keyset.c | 5 ++++ common/test/run-channel_type.c | 1 - devtools/mkcommit.c | 2 +- hsmd/libhsmd.c | 7 +++++ lightningd/channel.c | 7 ++--- lightningd/channel.h | 4 +-- lightningd/channel_control.c | 19 ++++-------- lightningd/channel_control.h | 2 +- lightningd/dual_open_control.c | 4 +-- lightningd/onchain_control.c | 3 +- lightningd/opening_control.c | 8 ++--- lightningd/peer_control.c | 4 +-- openingd/dualopend.c | 10 +++---- tests/fuzz/fuzz-initial_channel.c | 7 ++--- wallet/db.c | 2 +- wallet/test/run-db.c | 2 +- wallet/wallet.c | 14 ++++----- 25 files changed, 117 insertions(+), 131 deletions(-) diff --git a/Makefile b/Makefile index 140844b60..065e4b0b2 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ CCANDIR := ccan # Where we keep the BOLT RFCs BOLTDIR := ../bolts/ -DEFAULT_BOLTVERSION := ed012edc15998ed378ede999fad9b181297a0f28 +DEFAULT_BOLTVERSION := 91f4bd2383cc2fc7a0a43b697e209f9eb9f5183c # Can be overridden on cmdline. BOLTVERSION := $(DEFAULT_BOLTVERSION) diff --git a/channeld/channeld.c b/channeld/channeld.c index 3072a9436..c308e5f77 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -4494,21 +4494,17 @@ static void resend_commitment(struct peer *peer, struct changed_htlc *last) /* BOLT #2: * * A receiving node: - * - if `option_static_remotekey` applies to the commitment transaction: + * - MUST ignore `my_current_per_commitment_point`, but MAY require it to be + * a valid point. * - if `next_revocation_number` is greater than expected above, AND * `your_last_per_commitment_secret` is correct for that * `next_revocation_number` minus 1: - *... - * - otherwise, if it supports `option_data_loss_protect`: - * - if `next_revocation_number` is greater than expected above, - * AND `your_last_per_commitment_secret` is correct for that - * `next_revocation_number` minus 1: + * - MUST NOT broadcast its commitment transaction. + * - SHOULD send an `error` to request the peer to fail the channel. */ static void check_future_dataloss_fields(struct peer *peer, u64 next_revocation_number, - const struct secret *last_local_per_commit_secret, - /* This is NULL if option_static_remotekey */ - const struct pubkey *remote_current_per_commitment_point) + const struct secret *last_local_per_commit_secret) { const u8 *msg; bool correct; @@ -4541,13 +4537,9 @@ static void check_future_dataloss_fields(struct peer *peer, /* BOLT #2: * - MUST NOT broadcast its commitment transaction. * - SHOULD send an `error` to request the peer to fail the channel. - * - SHOULD store `my_current_per_commitment_point` to - * retrieve funds should the sending node broadcast its - * commitment transaction on-chain. */ wire_sync_write(MASTER_FD, - take(towire_channeld_fail_fallen_behind(NULL, - remote_current_per_commitment_point))); + take(towire_channeld_fail_fallen_behind(NULL))); sleep(1); /* We have to send them an error to trigger dropping to chain. */ @@ -4558,15 +4550,9 @@ static void check_future_dataloss_fields(struct peer *peer, /* BOLT #2: * * A receiving node: - * - if `option_static_remotekey` applies to the commitment transaction: * ... * - if `your_last_per_commitment_secret` does not match the expected values: * - SHOULD send an `error` and fail the channel. - * - otherwise, if it supports `option_data_loss_protect`: - *... - * - otherwise (`your_last_per_commitment_secret` or - * `my_current_per_commitment_point` do not match the expected values): - * - SHOULD send an `error` and fail the channel. */ static void check_current_dataloss_fields(struct peer *peer, u64 next_revocation_number, @@ -4815,14 +4801,7 @@ static void peer_reconnect(struct peer *peer, * of the next `commitment_signed` it expects to receive. * - MUST set `next_revocation_number` to the commitment number * of the next `revoke_and_ack` message it expects to receive. - * - if `option_static_remotekey` applies to the commitment transaction: - * - MUST set `my_current_per_commitment_point` to a valid point. - * - otherwise: - * - MUST set `my_current_per_commitment_point` to its commitment - * point for the last signed commitment it received from its - * channel peer (i.e. the commitment_point corresponding to the - * commitment transaction the sender would use to unilaterally - * close). + * - MUST set `my_current_per_commitment_point` to a valid point. * - if `next_revocation_number` equals 0: * - MUST set `your_last_per_commitment_secret` to all zeroes * - otherwise: @@ -4838,6 +4817,14 @@ static void peer_reconnect(struct peer *peer, /* Can send any (valid) point here */ &peer->remote_per_commit, send_tlvs); } else { + /* Older BOLT spec said for non-static-remotekey: + * + * - MUST set `my_current_per_commitment_point` to its + * commitment point for the last signed commitment it + * received from its channel peer (i.e. the commitment_point + * corresponding to the commitment transaction the sender + * would use to unilaterally close). + */ msg = towire_channel_reestablish (NULL, &peer->channel_id, peer->next_index[LOCAL], @@ -5057,11 +5044,7 @@ static void peer_reconnect(struct peer *peer, * Does not return. */ check_future_dataloss_fields(peer, next_revocation_number, - &last_local_per_commitment_secret, - channel_has(peer->channel, - OPT_STATIC_REMOTEKEY) - ? NULL : - &remote_current_per_commitment_point); + &last_local_per_commitment_secret); } else retransmit_revoke_and_ack = false; diff --git a/channeld/channeld_wire.csv b/channeld/channeld_wire.csv index d68b87a25..ec552abb3 100644 --- a/channeld/channeld_wire.csv +++ b/channeld/channeld_wire.csv @@ -322,8 +322,6 @@ msgdata,channeld_dev_memleak_reply,leak,bool, # Peer presented proof it was from the future. msgtype,channeld_fail_fallen_behind,1028 -# This is NULL if option_static_remotekey. -msgdata,channeld_fail_fallen_behind,remote_per_commitment_point,?pubkey, # When we receive announcement_signatures for channel announce msgtype,channeld_got_announcement,1017 diff --git a/channeld/test/run-full_channel.c b/channeld/test/run-full_channel.c index 6326ec33e..5a2fe83c1 100644 --- a/channeld/test/run-full_channel.c +++ b/channeld/test/run-full_channel.c @@ -493,7 +493,7 @@ int main(int argc, const char *argv[]) &localbase, &remotebase, &local_funding_pubkey, &remote_funding_pubkey, - take(channel_type_none(NULL)), false, LOCAL); + take(channel_type_static_remotekey(NULL)), false, LOCAL); rchannel = new_full_channel(tmpctx, &cid, &funding, 0, take(new_height_states(NULL, REMOTE, &blockheight)), @@ -506,7 +506,7 @@ int main(int argc, const char *argv[]) &remotebase, &localbase, &remote_funding_pubkey, &local_funding_pubkey, - take(channel_type_none(NULL)), false, REMOTE); + take(channel_type_static_remotekey(NULL)), false, REMOTE); /* BOLT #3: * @@ -519,14 +519,16 @@ int main(int argc, const char *argv[]) * local_delayedpubkey: 03fd5960528dc152014952efdb702a88f71e3c1653b2314431701ec77e57fde83c * local_revocation_pubkey: 0212a140cd0c6539d07cd08dfe09984dec3251ea808b892efeac3ede9402bf2b19 */ - keyset.self_payment_key = pubkey_from_hex("030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e7"); - keyset.other_payment_key = pubkey_from_hex("0394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b"); + + /* FIXME: Above is wrong for static remotekey! local/remote pubkey are just the basepoints */ + keyset.self_payment_key = localbase.payment; + keyset.other_payment_key = remotebase.payment; keyset.self_delayed_payment_key = pubkey_from_hex("03fd5960528dc152014952efdb702a88f71e3c1653b2314431701ec77e57fde83c"); keyset.self_revocation_key = pubkey_from_hex("0212a140cd0c6539d07cd08dfe09984dec3251ea808b892efeac3ede9402bf2b19"); /* FIXME: Update bolt */ - keyset.self_htlc_key = keyset.self_payment_key; - keyset.other_htlc_key = keyset.other_payment_key; + keyset.self_htlc_key = pubkey_from_hex("030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e7"); + keyset.other_htlc_key = pubkey_from_hex("0394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b"); raw_tx = commit_tx(tmpctx, &funding, @@ -618,45 +620,45 @@ int main(int argc, const char *argv[]) /* FIXME: Compare signatures! */ /* BOLT #3: * - * htlc_success_tx (htlc #0): 020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219700000000000000000001e8030000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e050047304402206a6e59f18764a5bf8d4fa45eebc591566689441229c918b480fb2af8cc6a4aeb02205248f273be447684b33e3c8d1d85a8e0ca9fa0bae9ae33f0527ada9c162919a60147304402207cb324fa0de88f452ffa9389678127ebcf4cabe1dd848b8e076c1a1962bf34720220116ed922b12311bd602d67e60d2529917f21c5b82f25ff6506c0f87886b4dfd5012000000000000000000000000000000000000000000000000000000000000000008a76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a914b8bcb07f6344b42ab04250c86a6e8b75d3fdbbc688527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f401b175ac686800000000 + * htlc_success_tx (htlc #0): 02000000000101ab84ff284f162cfbfef241f853b47d4368d171f9e2a1445160cd591c4c7d882b00000000000000000001e8030000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e0500483045022100d9e29616b8f3959f1d3d7f7ce893ffedcdc407717d0de8e37d808c91d3a7c50d022078c3033f6d00095c8720a4bc943c1b45727818c082e4e3ddbc6d3116435b624b014730440220636de5682ef0c5b61f124ec74e8aa2461a69777521d6998295dcea36bc3338110220165285594b23c50b28b82df200234566628a27bcd17f7f14404bd865354eb3ce012000000000000000000000000000000000000000000000000000000000000000008a76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a914b8bcb07f6344b42ab04250c86a6e8b75d3fdbbc688527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f401b175ac686800000000 */ - raw_tx = tx_from_hex(tmpctx, "020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219700000000000000000001e8030000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e050047304402206a6e59f18764a5bf8d4fa45eebc591566689441229c918b480fb2af8cc6a4aeb02205248f273be447684b33e3c8d1d85a8e0ca9fa0bae9ae33f0527ada9c162919a60147304402207cb324fa0de88f452ffa9389678127ebcf4cabe1dd848b8e076c1a1962bf34720220116ed922b12311bd602d67e60d2529917f21c5b82f25ff6506c0f87886b4dfd5012000000000000000000000000000000000000000000000000000000000000000008a76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a914b8bcb07f6344b42ab04250c86a6e8b75d3fdbbc688527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f401b175ac686800000000"); + raw_tx = tx_from_hex(tmpctx, "02000000000101ab84ff284f162cfbfef241f853b47d4368d171f9e2a1445160cd591c4c7d882b00000000000000000001e8030000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e0500483045022100d9e29616b8f3959f1d3d7f7ce893ffedcdc407717d0de8e37d808c91d3a7c50d022078c3033f6d00095c8720a4bc943c1b45727818c082e4e3ddbc6d3116435b624b014730440220636de5682ef0c5b61f124ec74e8aa2461a69777521d6998295dcea36bc3338110220165285594b23c50b28b82df200234566628a27bcd17f7f14404bd865354eb3ce012000000000000000000000000000000000000000000000000000000000000000008a76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a914b8bcb07f6344b42ab04250c86a6e8b75d3fdbbc688527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f401b175ac686800000000"); raw_tx->chainparams = chainparams; bitcoin_tx_input_set_witness(raw_tx, 0, NULL); tx_must_be_eq(raw_tx, txs[1]); /* BOLT #3: * - * htlc_timeout_tx (htlc #2): 020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219701000000000000000001d0070000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e0500483045022100d5275b3619953cb0c3b5aa577f04bc512380e60fa551762ce3d7a1bb7401cff9022037237ab0dac3fe100cde094e82e2bed9ba0ed1bb40154b48e56aa70f259e608b01483045022100c89172099507ff50f4c925e6c5150e871fb6e83dd73ff9fbb72f6ce829a9633f02203a63821d9162e99f9be712a68f9e589483994feae2661e4546cd5b6cec007be501008576a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c820120876475527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae67a914b43e1b38138a41b37f7cd9a1d274bc63e3a9b5d188ac6868f6010000 + * htlc_timeout_tx (htlc #2): 02000000000101ab84ff284f162cfbfef241f853b47d4368d171f9e2a1445160cd591c4c7d882b01000000000000000001d0070000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e05004730440220649fe8b20e67e46cbb0d09b4acea87dbec001b39b08dee7bdd0b1f03922a8640022037c462dff79df501cecfdb12ea7f4de91f99230bb544726f6e04527b1f89600401483045022100803159dee7935dba4a1d36a61055ce8fd62caa528573cc221ae288515405a252022029c59e7cffce374fe860100a4a63787e105c3cf5156d40b12dd53ff55ac8cf3f01008576a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c820120876475527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae67a914b43e1b38138a41b37f7cd9a1d274bc63e3a9b5d188ac6868f6010000 */ - raw_tx = tx_from_hex(tmpctx, "020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219701000000000000000001d0070000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e0500483045022100d5275b3619953cb0c3b5aa577f04bc512380e60fa551762ce3d7a1bb7401cff9022037237ab0dac3fe100cde094e82e2bed9ba0ed1bb40154b48e56aa70f259e608b01483045022100c89172099507ff50f4c925e6c5150e871fb6e83dd73ff9fbb72f6ce829a9633f02203a63821d9162e99f9be712a68f9e589483994feae2661e4546cd5b6cec007be501008576a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c820120876475527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae67a914b43e1b38138a41b37f7cd9a1d274bc63e3a9b5d188ac6868f6010000"); + raw_tx = tx_from_hex(tmpctx, "02000000000101ab84ff284f162cfbfef241f853b47d4368d171f9e2a1445160cd591c4c7d882b01000000000000000001d0070000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e05004730440220649fe8b20e67e46cbb0d09b4acea87dbec001b39b08dee7bdd0b1f03922a8640022037c462dff79df501cecfdb12ea7f4de91f99230bb544726f6e04527b1f89600401483045022100803159dee7935dba4a1d36a61055ce8fd62caa528573cc221ae288515405a252022029c59e7cffce374fe860100a4a63787e105c3cf5156d40b12dd53ff55ac8cf3f01008576a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c820120876475527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae67a914b43e1b38138a41b37f7cd9a1d274bc63e3a9b5d188ac6868f6010000"); raw_tx->chainparams = chainparams; bitcoin_tx_input_set_witness(raw_tx, 0, NULL); tx_must_be_eq(raw_tx, txs[2]); /* BOLT #3: * - * htlc_success_tx (htlc #1): 020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219702000000000000000001d0070000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e050047304402201b63ec807771baf4fdff523c644080de17f1da478989308ad13a58b51db91d360220568939d38c9ce295adba15665fa68f51d967e8ed14a007b751540a80b325f20201483045022100def389deab09cee69eaa1ec14d9428770e45bcbe9feb46468ecf481371165c2f022015d2e3c46600b2ebba8dcc899768874cc6851fd1ecb3fffd15db1cc3de7e10da012001010101010101010101010101010101010101010101010101010101010101018a76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a9144b6b2e5444c2639cc0fb7bcea5afba3f3cdce23988527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f501b175ac686800000000 + * htlc_success_tx (htlc #1): 02000000000101ab84ff284f162cfbfef241f853b47d4368d171f9e2a1445160cd591c4c7d882b02000000000000000001d0070000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e05004730440220770fc321e97a19f38985f2e7732dd9fe08d16a2efa4bcbc0429400a447faf49102204d40b417f3113e1b0944ae0986f517564ab4acd3d190503faf97a6e420d4335201483045022100a437cc2ce77400ecde441b3398fea3c3ad8bdad8132be818227fe3c5b8345989022069d45e7fa0ae551ec37240845e2c561ceb2567eacf3076a6a43a502d05865faa012001010101010101010101010101010101010101010101010101010101010101018a76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a9144b6b2e5444c2639cc0fb7bcea5afba3f3cdce23988527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f501b175ac686800000000 */ - raw_tx = tx_from_hex(tmpctx, "020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219702000000000000000001d0070000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e050047304402201b63ec807771baf4fdff523c644080de17f1da478989308ad13a58b51db91d360220568939d38c9ce295adba15665fa68f51d967e8ed14a007b751540a80b325f20201483045022100def389deab09cee69eaa1ec14d9428770e45bcbe9feb46468ecf481371165c2f022015d2e3c46600b2ebba8dcc899768874cc6851fd1ecb3fffd15db1cc3de7e10da012001010101010101010101010101010101010101010101010101010101010101018a76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a9144b6b2e5444c2639cc0fb7bcea5afba3f3cdce23988527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f501b175ac686800000000"); + raw_tx = tx_from_hex(tmpctx, "02000000000101ab84ff284f162cfbfef241f853b47d4368d171f9e2a1445160cd591c4c7d882b02000000000000000001d0070000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e05004730440220770fc321e97a19f38985f2e7732dd9fe08d16a2efa4bcbc0429400a447faf49102204d40b417f3113e1b0944ae0986f517564ab4acd3d190503faf97a6e420d4335201483045022100a437cc2ce77400ecde441b3398fea3c3ad8bdad8132be818227fe3c5b8345989022069d45e7fa0ae551ec37240845e2c561ceb2567eacf3076a6a43a502d05865faa012001010101010101010101010101010101010101010101010101010101010101018a76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a9144b6b2e5444c2639cc0fb7bcea5afba3f3cdce23988527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f501b175ac686800000000"); raw_tx->chainparams = chainparams; bitcoin_tx_input_set_witness(raw_tx, 0, NULL); tx_must_be_eq(raw_tx, txs[3]); /* BOLT #3: * - * htlc_timeout_tx (htlc #3): 020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219703000000000000000001b80b0000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e0500483045022100daee1808f9861b6c3ecd14f7b707eca02dd6bdfc714ba2f33bc8cdba507bb182022026654bf8863af77d74f51f4e0b62d461a019561bb12acb120d3f7195d148a554014730440220643aacb19bbb72bd2b635bc3f7375481f5981bace78cdd8319b2988ffcc6704202203d27784ec8ad51ed3bd517a05525a5139bb0b755dd719e0054332d186ac0872701008576a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c820120876475527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae67a9148a486ff2e31d6158bf39e2608864d63fefd09d5b88ac6868f7010000 + * htlc_timeout_tx (htlc #3): 02000000000101ab84ff284f162cfbfef241f853b47d4368d171f9e2a1445160cd591c4c7d882b03000000000000000001b80b0000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e050047304402207bcbf4f60a9829b05d2dbab84ed593e0291836be715dc7db6b72a64caf646af802201e489a5a84f7c5cc130398b841d138d031a5137ac8f4c49c770a4959dc3c13630147304402203121d9b9c055f354304b016a36662ee99e1110d9501cb271b087ddb6f382c2c80220549882f3f3b78d9c492de47543cb9a697cecc493174726146536c5954dac748701008576a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c820120876475527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae67a9148a486ff2e31d6158bf39e2608864d63fefd09d5b88ac6868f7010000 */ - raw_tx = tx_from_hex(tmpctx, "020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219703000000000000000001b80b0000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e0500483045022100daee1808f9861b6c3ecd14f7b707eca02dd6bdfc714ba2f33bc8cdba507bb182022026654bf8863af77d74f51f4e0b62d461a019561bb12acb120d3f7195d148a554014730440220643aacb19bbb72bd2b635bc3f7375481f5981bace78cdd8319b2988ffcc6704202203d27784ec8ad51ed3bd517a05525a5139bb0b755dd719e0054332d186ac0872701008576a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c820120876475527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae67a9148a486ff2e31d6158bf39e2608864d63fefd09d5b88ac6868f7010000"); + raw_tx = tx_from_hex(tmpctx, "02000000000101ab84ff284f162cfbfef241f853b47d4368d171f9e2a1445160cd591c4c7d882b03000000000000000001b80b0000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e050047304402207bcbf4f60a9829b05d2dbab84ed593e0291836be715dc7db6b72a64caf646af802201e489a5a84f7c5cc130398b841d138d031a5137ac8f4c49c770a4959dc3c13630147304402203121d9b9c055f354304b016a36662ee99e1110d9501cb271b087ddb6f382c2c80220549882f3f3b78d9c492de47543cb9a697cecc493174726146536c5954dac748701008576a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c820120876475527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae67a9148a486ff2e31d6158bf39e2608864d63fefd09d5b88ac6868f7010000"); raw_tx->chainparams = chainparams; bitcoin_tx_input_set_witness(raw_tx, 0, NULL); tx_must_be_eq(raw_tx, txs[4]); /* BOLT #3: * - * htlc_success_tx (htlc #4): 020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219704000000000000000001a00f0000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e050047304402207e0410e45454b0978a623f36a10626ef17b27d9ad44e2760f98cfa3efb37924f0220220bd8acd43ecaa916a80bd4f919c495a2c58982ce7c8625153f8596692a801d014730440220549e80b4496803cbc4a1d09d46df50109f546d43fbbf86cd90b174b1484acd5402205f12a4f995cb9bded597eabfee195a285986aa6d93ae5bb72507ebc6a4e2349e012004040404040404040404040404040404040404040404040404040404040404048a76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a91418bc1a114ccf9c052d3d23e28d3b0a9d1227434288527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f801b175ac686800000000 + * htlc_success_tx (htlc #4): 02000000000101ab84ff284f162cfbfef241f853b47d4368d171f9e2a1445160cd591c4c7d882b04000000000000000001a00f0000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e0500473044022076dca5cb81ba7e466e349b7128cdba216d4d01659e29b96025b9524aaf0d1899022060de85697b88b21c749702b7d2cfa7dfeaa1f472c8f1d7d9c23f2bf968464b8701483045022100d9080f103cc92bac15ec42464a95f070c7fb6925014e673ee2ea1374d36a7f7502200c65294d22eb20d48564954d5afe04a385551919d8b2ddb4ae2459daaeee1d95012004040404040404040404040404040404040404040404040404040404040404048a76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a91418bc1a114ccf9c052d3d23e28d3b0a9d1227434288527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f801b175ac686800000000 */ - raw_tx = tx_from_hex(tmpctx, "020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219704000000000000000001a00f0000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e050047304402207e0410e45454b0978a623f36a10626ef17b27d9ad44e2760f98cfa3efb37924f0220220bd8acd43ecaa916a80bd4f919c495a2c58982ce7c8625153f8596692a801d014730440220549e80b4496803cbc4a1d09d46df50109f546d43fbbf86cd90b174b1484acd5402205f12a4f995cb9bded597eabfee195a285986aa6d93ae5bb72507ebc6a4e2349e012004040404040404040404040404040404040404040404040404040404040404048a76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a91418bc1a114ccf9c052d3d23e28d3b0a9d1227434288527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f801b175ac686800000000"); + raw_tx = tx_from_hex(tmpctx, "02000000000101ab84ff284f162cfbfef241f853b47d4368d171f9e2a1445160cd591c4c7d882b04000000000000000001a00f0000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e0500473044022076dca5cb81ba7e466e349b7128cdba216d4d01659e29b96025b9524aaf0d1899022060de85697b88b21c749702b7d2cfa7dfeaa1f472c8f1d7d9c23f2bf968464b8701483045022100d9080f103cc92bac15ec42464a95f070c7fb6925014e673ee2ea1374d36a7f7502200c65294d22eb20d48564954d5afe04a385551919d8b2ddb4ae2459daaeee1d95012004040404040404040404040404040404040404040404040404040404040404048a76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a91418bc1a114ccf9c052d3d23e28d3b0a9d1227434288527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f801b175ac686800000000"); raw_tx->chainparams = chainparams; bitcoin_tx_input_set_witness(raw_tx, 0, NULL); tx_must_be_eq(raw_tx, txs[5]); diff --git a/common/channel_type.c b/common/channel_type.c index 0c844e80f..43bedc834 100644 --- a/common/channel_type.c +++ b/common/channel_type.c @@ -2,6 +2,21 @@ #include #include +static struct channel_type *new_channel_type(const tal_t *ctx) +{ + struct channel_type *type = tal(ctx, struct channel_type); + + type->features = tal_arr(type, u8, 0); + return type; +} + +/* These can still exist in the database */ +struct channel_type *channel_type_none_obsolete(const tal_t *ctx) +{ + return new_channel_type(ctx); +} + + /* BOLT #2: * Channel types are an explicit enumeration: for convenience of future * definitions they reuse even feature bits, but they are not an @@ -9,23 +24,16 @@ * affect the channel operation). * * The currently defined basic types are: - * - no features (no bits set) * - `option_static_remotekey` (bit 12) * - `option_anchor_outputs` and `option_static_remotekey` (bits 20 and 12) * - `option_anchors_zero_fee_htlc_tx` and `option_static_remotekey` (bits 22 * and 12) + * + * Each basic type has the following variations allowed: */ -struct channel_type *channel_type_none(const tal_t *ctx) -{ - struct channel_type *type = tal(ctx, struct channel_type); - - type->features = tal_arr(type, u8, 0); - return type; -} - struct channel_type *channel_type_static_remotekey(const tal_t *ctx) { - struct channel_type *type = channel_type_none(ctx); + struct channel_type *type = new_channel_type(ctx); set_feature_bit(&type->features, COMPULSORY_FEATURE(OPT_STATIC_REMOTEKEY)); @@ -34,7 +42,7 @@ struct channel_type *channel_type_static_remotekey(const tal_t *ctx) struct channel_type *channel_type_anchor_outputs(const tal_t *ctx) { - struct channel_type *type = channel_type_none(ctx); + struct channel_type *type = new_channel_type(ctx); set_feature_bit(&type->features, COMPULSORY_FEATURE(OPT_ANCHOR_OUTPUTS)); @@ -57,7 +65,7 @@ void channel_type_set_scid_alias(struct channel_type *type) struct channel_type *channel_type_anchors_zero_fee_htlc(const tal_t *ctx) { - struct channel_type *type = channel_type_none(ctx); + struct channel_type *type = new_channel_type(ctx); set_feature_bit(&type->features, COMPULSORY_FEATURE(OPT_ANCHORS_ZERO_FEE_HTLC_TX)); @@ -92,18 +100,11 @@ struct channel_type *default_channel_type(const tal_t *ctx, /* OPT_DUAL_FUND implies static remotekey */ return channel_type_static_remotekey(ctx); /* BOLT #2: - * - otherwise, if `option_static_remotekey` was negotiated: + * - otherwise: * - the `channel_type` is `option_static_remotekey` (bit 12) */ - else if (feature_negotiated(our_features, their_features, - OPT_STATIC_REMOTEKEY)) - return channel_type_static_remotekey(ctx); - /* BOLT #2: - * - otherwise: - * - the `channel_type` is empty - */ else - return channel_type_none(ctx); + return channel_type_static_remotekey(ctx); } bool channel_type_has(const struct channel_type *type, int feature) @@ -186,8 +187,7 @@ struct channel_type *channel_type_accept(const tal_t *ctx, featurebits_unset(&proposed.features, variants[i]); /* Otherwise, just needs to be a known channel type. */ - if (channel_type_eq(&proposed, channel_type_none(tmpctx)) || - channel_type_eq(&proposed, + if (channel_type_eq(&proposed, channel_type_static_remotekey(tmpctx)) || channel_type_eq(&proposed, channel_type_anchors_zero_fee_htlc(tmpctx)) || diff --git a/common/channel_type.h b/common/channel_type.h index 95edab6f8..9606df527 100644 --- a/common/channel_type.h +++ b/common/channel_type.h @@ -6,7 +6,6 @@ #include /* Explicit channel types */ -struct channel_type *channel_type_none(const tal_t *ctx); struct channel_type *channel_type_static_remotekey(const tal_t *ctx); struct channel_type *channel_type_anchor_outputs(const tal_t *ctx); struct channel_type *channel_type_anchors_zero_fee_htlc(const tal_t *ctx); @@ -45,4 +44,7 @@ struct channel_type *channel_type_accept(const tal_t *ctx, /* Return an array of feature strings indicating channel type. */ const char **channel_type_name(const tal_t *ctx, const struct channel_type *t); + +/* Obsolete channels can exist in db still */ +struct channel_type *channel_type_none_obsolete(const tal_t *ctx); #endif /* LIGHTNING_COMMON_CHANNEL_TYPE_H */ diff --git a/common/features.h b/common/features.h index 2798f5527..b534b5032 100644 --- a/common/features.h +++ b/common/features.h @@ -102,13 +102,13 @@ struct feature_set *feature_set_dup(const tal_t *ctx, /* BOLT #9: * * | Bits | Name |... - * | 0/1 | `option_data_loss_protect` |... IN ... + * | 0/1 | `option_data_loss_protect` |... ASSUMED ... * | 3 | `initial_routing_sync` |... I ... * | 4/5 | `option_upfront_shutdown_script` |... IN ... * | 6/7 | `gossip_queries` |... IN ... * | 8/9 | `var_onion_optin` |... IN9 ... * | 10/11 | `gossip_queries_ex` |... IN ... - * | 12/13 | `option_static_remotekey` |... IN ... + * | 12/13 | `option_static_remotekey` |... ASSUMED ... * | 14/15 | `payment_secret` |... IN9 ... * | 16/17 | `basic_mpp` |... IN9 ... * | 18/19 | `option_support_large_channel` |... IN ... diff --git a/common/key_derive.c b/common/key_derive.c index d2672192e..c6daa68c5 100644 --- a/common/key_derive.c +++ b/common/key_derive.c @@ -20,6 +20,12 @@ * the `local_delayedpubkey` uses the local node's `delayed_payment_basepoint`; * and the `remote_delayedpubkey` uses the remote node's `delayed_payment_basepoint`. *... + * The `remotepubkey` is simply the remote node's `payment_basepoint`. + */ + +/* The old BOLT defined what happened prior to option_static_remotekey, + * which we still support for existing channels: + * * If `option_static_remotekey` or `option_anchors` is negotiated, the * `remotepubkey` is simply the remote node's `payment_basepoint`, otherwise * it is calculated as above using the remote node's `payment_basepoint`. diff --git a/common/keyset.c b/common/keyset.c index 9630c76f7..8e688a6ca 100644 --- a/common/keyset.c +++ b/common/keyset.c @@ -33,6 +33,11 @@ bool derive_keyset(const struct pubkey *per_commitment_point, * * ### `remotepubkey` Derivation * + * The `remotepubkey` is simply the remote node's `payment_basepoint`. + */ + /* The old BOLT defined what happened prior to option_static_remotekey, + * which we still support for existing channels: + * * If `option_static_remotekey` or `option_anchors` is * negotiated, the `remotepubkey` is simply the remote node's * `payment_basepoint`, otherwise it is calculated as above using the diff --git a/common/test/run-channel_type.c b/common/test/run-channel_type.c index 05fe66975..dd531a38f 100644 --- a/common/test/run-channel_type.c +++ b/common/test/run-channel_type.c @@ -120,7 +120,6 @@ int main(int argc, char *argv[]) common_setup(argv[0]); - assert_names_eq(channel_type_name(tmpctx, channel_type_none(tmpctx)), ""); assert_names_eq(channel_type_name(tmpctx, channel_type_static_remotekey(tmpctx)), "static_remotekey/even"); assert_names_eq(channel_type_name(tmpctx, channel_type_anchor_outputs(tmpctx)), diff --git a/devtools/mkcommit.c b/devtools/mkcommit.c index 512e7f3c2..1252357a1 100644 --- a/devtools/mkcommit.c +++ b/devtools/mkcommit.c @@ -395,7 +395,7 @@ int main(int argc, char *argv[]) else if (option_static_remotekey) channel_type = channel_type_static_remotekey(NULL); else - channel_type = channel_type_none(NULL); + channel_type = channel_type_none_obsolete(NULL); channel = new_full_channel(NULL, &cid, diff --git a/hsmd/libhsmd.c b/hsmd/libhsmd.c index 69f34f9f2..43c231e76 100644 --- a/hsmd/libhsmd.c +++ b/hsmd/libhsmd.c @@ -465,6 +465,13 @@ static void hsm_unilateral_close_privkey(struct privkey *dst, derive_basepoints(&channel_seed, NULL, &basepoints, &secrets, NULL); /* BOLT #3: + * + * ### `remotepubkey` Derivation + * + * The `remotepubkey` is simply the remote node's `payment_basepoint`. + */ + /* The old BOLT defined what happened prior to option_static_remotekey, + * which we still support for existing channels: * * If `option_static_remotekey` or `option_anchors` is * negotiated, the `remotepubkey` is simply the remote node's diff --git a/lightningd/channel.c b/lightningd/channel.c index 4f27ed5a2..a835db655 100644 --- a/lightningd/channel.c +++ b/lightningd/channel.c @@ -304,7 +304,7 @@ struct channel *new_unsaved_channel(struct peer *peer, channel->static_remotekey_start[LOCAL] = channel->static_remotekey_start[REMOTE] = 0; - channel->future_per_commitment_point = NULL; + channel->has_future_per_commitment_point = false; channel->lease_commit_sig = NULL; channel->ignore_fee_limits = ld->config.ignore_fee_limits; @@ -424,7 +424,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid, u32 max_possible_feerate, const struct basepoints *local_basepoints, const struct pubkey *local_funding_pubkey, - const struct pubkey *future_per_commitment_point, + bool has_future_per_commitment_point, u32 feerate_base, u32 feerate_ppm, const u8 *remote_upfront_shutdown_script, @@ -555,8 +555,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid, channel->max_possible_feerate = max_possible_feerate; channel->local_basepoints = *local_basepoints; channel->local_funding_pubkey = *local_funding_pubkey; - channel->future_per_commitment_point - = tal_steal(channel, future_per_commitment_point); + channel->has_future_per_commitment_point = has_future_per_commitment_point; channel->feerate_base = feerate_base; channel->feerate_ppm = feerate_ppm; channel->old_feerate_timeout.ts.tv_sec = 0; diff --git a/lightningd/channel.h b/lightningd/channel.h index 69f8181f6..b04e68d84 100644 --- a/lightningd/channel.h +++ b/lightningd/channel.h @@ -249,7 +249,7 @@ struct channel { /* Do we have an "impossible" future per_commitment_point from * peer via option_data_loss_protect? */ - const struct pubkey *future_per_commitment_point; + bool has_future_per_commitment_point; /* Min/max htlc amount allowed in channel. */ struct amount_msat htlc_minimum_msat, htlc_maximum_msat; @@ -373,7 +373,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid, u32 max_possible_feerate, const struct basepoints *local_basepoints, const struct pubkey *local_funding_pubkey, - const struct pubkey *future_per_commitment_point, + bool has_future_per_commitment_point, u32 feerate_base, u32 feerate_ppm, /* NULL or stolen */ diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index 2a15fdb92..f4ad0aac5 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -1219,32 +1219,23 @@ static void peer_got_shutdown(struct channel *channel, const u8 *msg) wallet_channel_save(ld->wallet, channel); } -void channel_fallen_behind(struct channel *channel, const u8 *msg) +void channel_fallen_behind(struct channel *channel) { - - /* per_commitment_point is NULL if option_static_remotekey, but we - * use its presence as a flag so set it any valid key in that case. */ - if (!channel->future_per_commitment_point) { - struct pubkey *any = tal(channel, struct pubkey); - if (!pubkey_from_node_id(any, &channel->peer->ld->id)) - fatal("Our own id invalid?"); - channel->future_per_commitment_point = any; - } + channel->has_future_per_commitment_point = true; + wallet_channel_save(channel->peer->ld->wallet, channel); } static void channel_fail_fallen_behind(struct channel *channel, const u8 *msg) { - if (!fromwire_channeld_fail_fallen_behind(channel, msg, - cast_const2(struct pubkey **, - &channel->future_per_commitment_point))) { + if (!fromwire_channeld_fail_fallen_behind(msg)) { channel_internal_error(channel, "bad channel_fail_fallen_behind %s", tal_hex(tmpctx, msg)); return; } - channel_fallen_behind(channel, msg); + channel_fallen_behind(channel); } static void peer_start_closingd_after_shutdown(struct channel *channel, diff --git a/lightningd/channel_control.h b/lightningd/channel_control.h index 638fac464..199657abe 100644 --- a/lightningd/channel_control.h +++ b/lightningd/channel_control.h @@ -40,7 +40,7 @@ bool channel_on_channel_ready(struct channel *channel, void channel_record_open(struct channel *channel, u32 blockheight, bool record_push); /* A channel has unrecoverably fallen behind */ -void channel_fallen_behind(struct channel *channel, const u8 *msg); +void channel_fallen_behind(struct channel *channel); /* Tell channel about new feerates (owner must be channeld!) */ void channel_update_feerates(struct lightningd *ld, const struct channel *channel); diff --git a/lightningd/dual_open_control.c b/lightningd/dual_open_control.c index f5938def1..215603558 100644 --- a/lightningd/dual_open_control.c +++ b/lightningd/dual_open_control.c @@ -130,7 +130,7 @@ void json_add_unsaved_channel(struct json_stream *response, json_add_string(response, "owner", channel->owner->name); json_add_string(response, "opener", channel->opener == LOCAL ? "local" : "remote"); - json_add_bool(response, "lost_state", channel->future_per_commitment_point ? true : false); + json_add_bool(response, "lost_state", channel->has_future_per_commitment_point); json_array_start(response, "status"); for (size_t i = 0; i < ARRAY_SIZE(channel->billboard.permanent); i++) { if (!channel->billboard.permanent[i]) @@ -3371,7 +3371,7 @@ channel_fail_fallen_behind(struct subd* dualopend, const u8 *msg) return; } - channel_fallen_behind(channel, msg); + channel_fallen_behind(channel); } static void handle_psbt_changed(struct subd *dualopend, diff --git a/lightningd/onchain_control.c b/lightningd/onchain_control.c index 92c0a0cb8..f5128d168 100644 --- a/lightningd/onchain_control.c +++ b/lightningd/onchain_control.c @@ -1624,7 +1624,8 @@ enum watch_result onchaind_funding_spent(struct channel *channel, channel->last_htlc_sigs, channel->min_possible_feerate, channel->max_possible_feerate, - channel->future_per_commitment_point, + /* FIXME: remove support from onchaind */ + NULL, &channel->local_funding_pubkey, &channel->channel_info.remote_fundingkey, channel->static_remotekey_start[LOCAL], diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index 1d3a4b385..8f3abc174 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -157,10 +157,8 @@ wallet_commit_channel(struct lightningd *ld, * - otherwise, if `option_anchor_outputs` was negotiated: * - the `channel_type` is `option_anchor_outputs` and * `option_static_remotekey` (bits 20 and 12) - * - otherwise, if `option_static_remotekey` was negotiated: - * - the `channel_type` is `option_static_remotekey` (bit 12) * - otherwise: - * - the `channel_type` is empty + * - the `channel_type` is `option_static_remotekey` (bit 12) * - MUST use that `channel_type` for all commitment transactions. */ /* i.e. We set it now for the channel permanently. */ @@ -215,7 +213,7 @@ wallet_commit_channel(struct lightningd *ld, feerate, feerate, &uc->local_basepoints, &uc->local_funding_pubkey, - NULL, + false, /* !has_future_per_commitment_point */ ld->config.fee_base, ld->config.fee_per_satoshi, remote_upfront_shutdown_script, @@ -1586,7 +1584,7 @@ static struct channel *stub_chan(struct command *cmd, funding_sats.satoshis / MINIMUM_TX_WEIGHT * 1000 /* Raw: convert to feerate */, &basepoints, &localFundingPubkey, - NULL, + false, ld->config.fee_base, ld->config.fee_per_satoshi, NULL, diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 5c93158f2..d191655d3 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -373,7 +373,7 @@ void drop_to_chain(struct lightningd *ld, struct channel *channel, * `next_revocation_number` minus 1: * - MUST NOT broadcast its commitment transaction. */ - if (channel->future_per_commitment_point && !cooperative) { + if (channel->has_future_per_commitment_point && !cooperative) { log_broken(channel->log, "Cannot broadcast our commitment tx:" " they have a future one"); @@ -879,7 +879,7 @@ static void NON_NULL_ARGS(1, 2, 4, 5) json_add_channel(struct lightningd *ld, bitcoin_tx_compute_fee(channel->last_tx)); } - json_add_bool(response, "lost_state", channel->future_per_commitment_point ? true : false); + json_add_bool(response, "lost_state", channel->has_future_per_commitment_point); json_object_start(response, "feerate"); feerate = get_feerate(channel->fee_states, channel->opener, LOCAL); json_add_u32(response, feerate_style_name(FEERATE_PER_KSIPA), feerate); diff --git a/openingd/dualopend.c b/openingd/dualopend.c index 8792360ec..ab3855fd6 100644 --- a/openingd/dualopend.c +++ b/openingd/dualopend.c @@ -3922,15 +3922,13 @@ static u8 *handle_funding_depth(struct state *state, u8 *msg) /* BOLT #2: * * A receiving node: - * - if `option_static_remotekey` applies to the commitment transaction: + * - MUST ignore `my_current_per_commitment_point`, but MAY require it to be + * a valid point. * - if `next_revocation_number` is greater than expected above, AND * `your_last_per_commitment_secret` is correct for that * `next_revocation_number` minus 1: - *... - * - otherwise, if it supports `option_data_loss_protect`: - * - if `next_revocation_number` is greater than expected above, - * AND `your_last_per_commitment_secret` is correct for that - * `next_revocation_number` minus 1: + * - MUST NOT broadcast its commitment transaction. + * - SHOULD send an `error` to request the peer to fail the channel. */ static void check_future_dataloss_fields(struct state *state, diff --git a/tests/fuzz/fuzz-initial_channel.c b/tests/fuzz/fuzz-initial_channel.c index 377ca8509..bda1ffb3d 100644 --- a/tests/fuzz/fuzz-initial_channel.c +++ b/tests/fuzz/fuzz-initial_channel.c @@ -40,7 +40,7 @@ void run(const uint8_t *data, size_t size) struct channel_config local, remote; struct basepoints local_basepoints, remote_basepoints; struct pubkey local_funding_pubkey, remote_funding_pubkey; - bool option_static_remotekey, option_anchor_outputs, wumbo; + bool option_anchor_outputs, wumbo; struct channel_type *channel_type; struct channel *channel; @@ -63,14 +63,11 @@ void run(const uint8_t *data, size_t size) fromwire_pubkey(&data, &size, &remote_funding_pubkey); wumbo = fromwire_bool(&data, &size); option_anchor_outputs = fromwire_bool(&data, &size); - option_static_remotekey = option_anchor_outputs || fromwire_bool(&data, &size); if (option_anchor_outputs) channel_type = channel_type_anchor_outputs(tmpctx); - else if (option_static_remotekey) - channel_type = channel_type_static_remotekey(tmpctx); else - channel_type = channel_type_none(tmpctx); + channel_type = channel_type_static_remotekey(tmpctx); /* TODO: determine if it makes sense to check at each step for libfuzzer * to deduce pertinent inputs */ diff --git a/wallet/db.c b/wallet/db.c index c283556eb..9d8a6a350 100644 --- a/wallet/db.c +++ b/wallet/db.c @@ -1686,7 +1686,7 @@ static void migrate_fill_in_channel_type(struct lightningd *ld, } else if (db_col_u64(stmt, "local_static_remotekey_start") != 0x7FFFFFFFFFFFFFFFULL) type = channel_type_static_remotekey(tmpctx); else - type = channel_type_none(tmpctx); + type = channel_type_none_obsolete(tmpctx); /* We didn't keep type in db, so assume all private * channels which support aliases don't want us to fwd diff --git a/wallet/test/run-db.c b/wallet/test/run-db.c index eb886529b..07620011e 100644 --- a/wallet/test/run-db.c +++ b/wallet/test/run-db.c @@ -166,7 +166,7 @@ struct channel *new_channel(struct peer *peer UNNEEDED, u64 dbid UNNEEDED, u32 max_possible_feerate UNNEEDED, const struct basepoints *local_basepoints UNNEEDED, const struct pubkey *local_funding_pubkey UNNEEDED, - const struct pubkey *future_per_commitment_point UNNEEDED, + bool has_future_per_commitment_point UNNEEDED, u32 feerate_base UNNEEDED, u32 feerate_ppm UNNEEDED, /* NULL or stolen */ diff --git a/wallet/wallet.c b/wallet/wallet.c index 2b1e0fb7e..48c957bc5 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -1527,7 +1527,7 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm s64 final_key_idx, channel_config_id; struct basepoints local_basepoints; struct pubkey local_funding_pubkey; - struct pubkey *future_per_commitment_point; + bool has_future_per_commitment_point; struct amount_sat funding_sat, our_funding_sat; struct amount_msat push_msat, our_msat, msat_to_us_min, msat_to_us_max, htlc_minimum_msat, htlc_maximum_msat; struct channel_type *type; @@ -1582,9 +1582,8 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm db_col_ignore(stmt, "last_sent_commit_state"); db_col_ignore(stmt, "last_sent_commit_id"); - future_per_commitment_point = db_col_optional(tmpctx, stmt, - "future_per_commitment_point", - pubkey); + has_future_per_commitment_point = !db_col_is_null(stmt, + "future_per_commitment_point"); db_col_channel_id(stmt, "full_channel_id", &cid); channel_config_id = db_col_u64(stmt, "channel_config_local"); @@ -1760,7 +1759,7 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm db_col_int(stmt, "min_possible_feerate"), db_col_int(stmt, "max_possible_feerate"), &local_basepoints, &local_funding_pubkey, - future_per_commitment_point, + has_future_per_commitment_point, db_col_int(stmt, "feerate_base"), db_col_int(stmt, "feerate_ppm"), db_col_arr(tmpctx, stmt, "remote_upfront_shutdown_script", u8), @@ -2417,8 +2416,9 @@ void wallet_channel_save(struct wallet *w, struct channel *chan) db_bind_pubkey(stmt, &chan->channel_info.remote_per_commit); db_bind_pubkey(stmt, &chan->channel_info.old_remote_per_commit); db_bind_u64(stmt, chan->channel_info.their_config.id); - if (chan->future_per_commitment_point) - db_bind_pubkey(stmt, chan->future_per_commitment_point); + /* Any pubkey works here: use our own node id */ + if (chan->has_future_per_commitment_point) + db_bind_node_id(stmt, &chan->peer->ld->id); else db_bind_null(stmt); db_bind_u64(stmt, chan->dbid);