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 <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2023-04-10 09:45:56 +09:30
parent 57b2cbcb32
commit 2fb942d21c
10 changed files with 27 additions and 27 deletions

View File

@ -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)

View File

@ -329,9 +329,9 @@ u8 *scriptpubkey_witness_raw(const tal_t *ctx, u8 version,
* <remote_pubkey> 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

View File

@ -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);

View File

@ -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(); }

View File

@ -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(); }

View File

@ -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(); }

View File

@ -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);

View File

@ -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);

View File

@ -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),

View File

@ -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 {