From 2fb942d21cf86b20395518c2eebda3bcdf9f6e14 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 10 Apr 2023 09:45:56 +0930 Subject: [PATCH] bitcoin: rename confusing functions. 1. anchor_to_remote_redeem => bitcoin_wscript_to_remote_anchored, which matches other witness script producing functions and makes it clear that it's a to_remote variant. 2. is_anchor_witness_script => is_to_remote_anchored_witness_script makes it clear that it's about a to_remote output (as altered when anchors are enabled) not an anchor output! Signed-off-by: Rusty Russell --- bitcoin/psbt.c | 4 ++-- bitcoin/script.c | 10 +++++----- bitcoin/script.h | 10 +++++----- bitcoin/test/run-bitcoin_block_from_hex.c | 6 +++--- bitcoin/test/run-psbt-from-tx.c | 6 +++--- bitcoin/test/run-tx-encode.c | 6 +++--- channeld/commit_tx.c | 2 +- common/initial_commit_tx.c | 2 +- hsmd/libhsmd.c | 6 +++--- onchaind/onchaind.c | 2 +- 10 files changed, 27 insertions(+), 27 deletions(-) diff --git a/bitcoin/psbt.c b/bitcoin/psbt.c index f73c0aef4..7281fc274 100644 --- a/bitcoin/psbt.c +++ b/bitcoin/psbt.c @@ -611,8 +611,8 @@ bool psbt_finalize(struct wally_psbt *psbt) const struct wally_map_item *iws; iws = wally_map_get_integer(&input->psbt_fields, /* PSBT_IN_WITNESS_SCRIPT */ 0x05); - if (!iws || !is_anchor_witness_script(iws->value, - iws->value_len)) + if (!iws || !is_to_remote_anchored_witness_script(iws->value, + iws->value_len)) continue; if (input->signatures.num_items != 1) diff --git a/bitcoin/script.c b/bitcoin/script.c index a66c26f97..a127ce96c 100644 --- a/bitcoin/script.c +++ b/bitcoin/script.c @@ -329,9 +329,9 @@ u8 *scriptpubkey_witness_raw(const tal_t *ctx, u8 version, * OP_CHECKSIGVERIFY MAX(1, lease_end - blockheight) OP_CHECKSEQUENCEVERIFY */ -u8 *anchor_to_remote_redeem(const tal_t *ctx, - const struct pubkey *remote_key, - u32 csv_lock) +u8 *bitcoin_wscript_to_remote_anchored(const tal_t *ctx, + const struct pubkey *remote_key, + u32 csv_lock) { u8 *script = tal_arr(ctx, u8, 0); add_push_key(&script, remote_key); @@ -339,11 +339,11 @@ u8 *anchor_to_remote_redeem(const tal_t *ctx, add_number(&script, csv_lock); add_op(&script, OP_CHECKSEQUENCEVERIFY); - assert(is_anchor_witness_script(script, tal_bytelen(script))); + assert(is_to_remote_anchored_witness_script(script, tal_bytelen(script))); return script; } -bool is_anchor_witness_script(const u8 *script, size_t script_len) +bool is_to_remote_anchored_witness_script(const u8 *script, size_t script_len) { size_t len = 34 + 1 + 1 + 1; /* With option_will_fund, the pushbytes can be up to 2 bytes more diff --git a/bitcoin/script.h b/bitcoin/script.h index 89f225ae8..a00f12cc2 100644 --- a/bitcoin/script.h +++ b/bitcoin/script.h @@ -64,9 +64,9 @@ u8 *scriptpubkey_witness_raw(const tal_t *ctx, u8 version, const u8 *wprog, size_t wprog_size); /* To-remotekey with csv max(lease_expiry - blockheight, 1) delay. */ -u8 *anchor_to_remote_redeem(const tal_t *ctx, - const struct pubkey *remote_key, - u32 csv_lock); +u8 *bitcoin_wscript_to_remote_anchored(const tal_t *ctx, + const struct pubkey *remote_key, + u32 csv_lock); /* Create a witness which spends the 2of2. */ u8 **bitcoin_witness_2of2(const tal_t *ctx, @@ -156,8 +156,8 @@ bool is_p2wpkh(const u8 *script, struct bitcoin_address *addr); /* Is this one of the four above script types? */ bool is_known_scripttype(const u8 *script); -/* Is this an anchor witness script? */ -bool is_anchor_witness_script(const u8 *script, size_t script_len); +/* Is this a to-remote witness script (used for option_anchor_outputs)? */ +bool is_to_remote_anchored_witness_script(const u8 *script, size_t script_len); /* Are these two scripts equal? */ bool scripteq(const u8 *s1, const u8 *s2); diff --git a/bitcoin/test/run-bitcoin_block_from_hex.c b/bitcoin/test/run-bitcoin_block_from_hex.c index 579916a69..0495e5af1 100644 --- a/bitcoin/test/run-bitcoin_block_from_hex.c +++ b/bitcoin/test/run-bitcoin_block_from_hex.c @@ -69,9 +69,9 @@ u8 fromwire_u8(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) /* Generated stub for fromwire_u8_array */ void fromwire_u8_array(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, u8 *arr UNNEEDED, size_t num UNNEEDED) { fprintf(stderr, "fromwire_u8_array called!\n"); abort(); } -/* Generated stub for is_anchor_witness_script */ -bool is_anchor_witness_script(const u8 *script UNNEEDED, size_t script_len UNNEEDED) -{ fprintf(stderr, "is_anchor_witness_script called!\n"); abort(); } +/* Generated stub for is_to_remote_anchored_witness_script */ +bool is_to_remote_anchored_witness_script(const u8 *script UNNEEDED, size_t script_len UNNEEDED) +{ fprintf(stderr, "is_to_remote_anchored_witness_script called!\n"); abort(); } /* Generated stub for pubkey_to_der */ void pubkey_to_der(u8 der[PUBKEY_CMPR_LEN] UNNEEDED, const struct pubkey *key UNNEEDED) { fprintf(stderr, "pubkey_to_der called!\n"); abort(); } diff --git a/bitcoin/test/run-psbt-from-tx.c b/bitcoin/test/run-psbt-from-tx.c index f3908f377..9fe77ea4f 100644 --- a/bitcoin/test/run-psbt-from-tx.c +++ b/bitcoin/test/run-psbt-from-tx.c @@ -50,9 +50,9 @@ struct amount_sat amount_tx_fee(u32 fee_per_kw UNNEEDED, size_t weight UNNEEDED) void fromwire_sha256_double(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct sha256_double *sha256d UNNEEDED) { fprintf(stderr, "fromwire_sha256_double called!\n"); abort(); } -/* Generated stub for is_anchor_witness_script */ -bool is_anchor_witness_script(const u8 *script UNNEEDED, size_t script_len UNNEEDED) -{ fprintf(stderr, "is_anchor_witness_script called!\n"); abort(); } +/* Generated stub for is_to_remote_anchored_witness_script */ +bool is_to_remote_anchored_witness_script(const u8 *script UNNEEDED, size_t script_len UNNEEDED) +{ fprintf(stderr, "is_to_remote_anchored_witness_script called!\n"); abort(); } /* Generated stub for pubkey_to_der */ void pubkey_to_der(u8 der[PUBKEY_CMPR_LEN] UNNEEDED, const struct pubkey *key UNNEEDED) { fprintf(stderr, "pubkey_to_der called!\n"); abort(); } diff --git a/bitcoin/test/run-tx-encode.c b/bitcoin/test/run-tx-encode.c index d45f51ee0..d99c838a4 100644 --- a/bitcoin/test/run-tx-encode.c +++ b/bitcoin/test/run-tx-encode.c @@ -70,9 +70,9 @@ u8 fromwire_u8(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) /* Generated stub for fromwire_u8_array */ void fromwire_u8_array(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, u8 *arr UNNEEDED, size_t num UNNEEDED) { fprintf(stderr, "fromwire_u8_array called!\n"); abort(); } -/* Generated stub for is_anchor_witness_script */ -bool is_anchor_witness_script(const u8 *script UNNEEDED, size_t script_len UNNEEDED) -{ fprintf(stderr, "is_anchor_witness_script called!\n"); abort(); } +/* Generated stub for is_to_remote_anchored_witness_script */ +bool is_to_remote_anchored_witness_script(const u8 *script UNNEEDED, size_t script_len UNNEEDED) +{ fprintf(stderr, "is_to_remote_anchored_witness_script called!\n"); abort(); } /* Generated stub for pubkey_to_der */ void pubkey_to_der(u8 der[PUBKEY_CMPR_LEN] UNNEEDED, const struct pubkey *key UNNEEDED) { fprintf(stderr, "pubkey_to_der called!\n"); abort(); } diff --git a/channeld/commit_tx.c b/channeld/commit_tx.c index 43851498f..30f946de7 100644 --- a/channeld/commit_tx.c +++ b/channeld/commit_tx.c @@ -304,7 +304,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, * Otherwise, this output is a simple P2WPKH to `remotepubkey`. */ if (option_anchor_outputs) { - redeem = anchor_to_remote_redeem(tmpctx, + redeem = bitcoin_wscript_to_remote_anchored(tmpctx, &keyset->other_payment_key, (!side) == lessor ? csv_lock : 1); diff --git a/common/initial_commit_tx.c b/common/initial_commit_tx.c index 97afedb15..5d6ade5b3 100644 --- a/common/initial_commit_tx.c +++ b/common/initial_commit_tx.c @@ -247,7 +247,7 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx, amount = amount_msat_to_sat_round_down(other_pay); if (option_anchor_outputs) { - redeem = anchor_to_remote_redeem(tmpctx, + redeem = bitcoin_wscript_to_remote_anchored(tmpctx, &keyset->other_payment_key, (!side) == lessor ? csv_lock : 1); scriptpubkey = scriptpubkey_p2wsh(tmpctx, redeem); diff --git a/hsmd/libhsmd.c b/hsmd/libhsmd.c index 7fd4c0d4f..f516e8a31 100644 --- a/hsmd/libhsmd.c +++ b/hsmd/libhsmd.c @@ -490,9 +490,9 @@ static void sign_our_inputs(struct utxo **utxos, struct wally_psbt *psbt) /* It's actually a P2WSH in this case. */ if (utxo->close_info && utxo->close_info->option_anchor_outputs) { const u8 *wscript - = anchor_to_remote_redeem(tmpctx, - &pubkey, - utxo->close_info->csv); + = bitcoin_wscript_to_remote_anchored(tmpctx, + &pubkey, + utxo->close_info->csv); psbt_input_set_witscript(psbt, j, wscript); psbt_input_set_wit_utxo(psbt, j, scriptpubkey_p2wsh(psbt, wscript), diff --git a/onchaind/onchaind.c b/onchaind/onchaind.c index d9476fbc1..9669d6d6c 100644 --- a/onchaind/onchaind.c +++ b/onchaind/onchaind.c @@ -2116,7 +2116,7 @@ static u8 *scriptpubkey_to_remote(const tal_t *ctx, */ if (option_anchor_outputs) { return scriptpubkey_p2wsh(ctx, - anchor_to_remote_redeem(tmpctx, + bitcoin_wscript_to_remote_anchored(tmpctx, remotekey, csv_lock)); } else {