mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 07:04:22 +01:00
tests: make run-commit_tx output match the BOLT test vectors more closely
Still needs some massaging (we print HTLCs as we add them, rather then in the final order, which requires a manual move in one test vector), but this makes it more trivial to compare the output with the BOLT 3 text after https://github.com/lightningnetwork/lightning-rfc/pull/852 Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -52,8 +52,8 @@ static void add_offered_htlc_out(struct bitcoin_tx *tx, size_t n,
|
|||||||
option_anchor_outputs);
|
option_anchor_outputs);
|
||||||
p2wsh = scriptpubkey_p2wsh(tx, wscript);
|
p2wsh = scriptpubkey_p2wsh(tx, wscript);
|
||||||
bitcoin_tx_add_output(tx, p2wsh, wscript, amount);
|
bitcoin_tx_add_output(tx, p2wsh, wscript, amount);
|
||||||
SUPERVERBOSE("# HTLC %" PRIu64 " offered %s wscript %s\n", htlc->id,
|
SUPERVERBOSE("# HTLC #%" PRIu64 " offered amount %"PRIu64" wscript %s\n", htlc->id,
|
||||||
type_to_string(tmpctx, struct amount_sat, &amount),
|
amount.satoshis, /* Raw: BOLT 3 output match */
|
||||||
tal_hex(wscript, wscript));
|
tal_hex(wscript, wscript));
|
||||||
tal_free(wscript);
|
tal_free(wscript);
|
||||||
}
|
}
|
||||||
@@ -75,10 +75,9 @@ static void add_received_htlc_out(struct bitcoin_tx *tx, size_t n,
|
|||||||
|
|
||||||
bitcoin_tx_add_output(tx, p2wsh, wscript, amount);
|
bitcoin_tx_add_output(tx, p2wsh, wscript, amount);
|
||||||
|
|
||||||
SUPERVERBOSE("# HTLC %"PRIu64" received %s wscript %s\n",
|
SUPERVERBOSE("# HTLC #%"PRIu64" received amount %"PRIu64" wscript %s\n",
|
||||||
htlc->id,
|
htlc->id,
|
||||||
type_to_string(tmpctx, struct amount_sat,
|
amount.satoshis, /* Raw: BOLT 3 output match */
|
||||||
&amount),
|
|
||||||
tal_hex(wscript, wscript));
|
tal_hex(wscript, wscript));
|
||||||
tal_free(wscript);
|
tal_free(wscript);
|
||||||
}
|
}
|
||||||
@@ -138,8 +137,8 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
|
|||||||
base_fee = commit_tx_base_fee(feerate_per_kw, untrimmed,
|
base_fee = commit_tx_base_fee(feerate_per_kw, untrimmed,
|
||||||
option_anchor_outputs);
|
option_anchor_outputs);
|
||||||
|
|
||||||
SUPERVERBOSE("# base commitment transaction fee = %s\n",
|
SUPERVERBOSE("# base commitment transaction fee = %"PRIu64"\n",
|
||||||
type_to_string(tmpctx, struct amount_sat, &base_fee));
|
base_fee.satoshis /* Raw: spec uses raw numbers */);
|
||||||
|
|
||||||
/* BOLT #3:
|
/* BOLT #3:
|
||||||
* If `option_anchor_outputs` applies to the commitment
|
* If `option_anchor_outputs` applies to the commitment
|
||||||
@@ -244,8 +243,8 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
|
|||||||
(*htlcmap)[n] = direct_outputs ? dummy_to_local : NULL;
|
(*htlcmap)[n] = direct_outputs ? dummy_to_local : NULL;
|
||||||
/* We don't assign cltvs[n]: if we use it, order doesn't matter.
|
/* We don't assign cltvs[n]: if we use it, order doesn't matter.
|
||||||
* However, valgrind will warn us something wierd is happening */
|
* However, valgrind will warn us something wierd is happening */
|
||||||
SUPERVERBOSE("# to-local amount %s wscript %s\n",
|
SUPERVERBOSE("# to_local amount %"PRIu64" wscript %s\n",
|
||||||
type_to_string(tmpctx, struct amount_sat, &amount),
|
amount.satoshis, /* Raw: BOLT 3 output match */
|
||||||
tal_hex(tmpctx, wscript));
|
tal_hex(tmpctx, wscript));
|
||||||
n++;
|
n++;
|
||||||
to_local = true;
|
to_local = true;
|
||||||
@@ -287,9 +286,8 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
|
|||||||
(*htlcmap)[n] = direct_outputs ? dummy_to_remote : NULL;
|
(*htlcmap)[n] = direct_outputs ? dummy_to_remote : NULL;
|
||||||
/* We don't assign cltvs[n]: if we use it, order doesn't matter.
|
/* We don't assign cltvs[n]: if we use it, order doesn't matter.
|
||||||
* However, valgrind will warn us something wierd is happening */
|
* However, valgrind will warn us something wierd is happening */
|
||||||
SUPERVERBOSE("# to-remote amount %s key %s\n",
|
SUPERVERBOSE("# to_remote amount %"PRIu64" P2WPKH(%s)\n",
|
||||||
type_to_string(tmpctx, struct amount_sat,
|
amount.satoshis, /* Raw: BOLT 3 output match */
|
||||||
&amount),
|
|
||||||
type_to_string(tmpctx, struct pubkey,
|
type_to_string(tmpctx, struct pubkey,
|
||||||
&keyset->other_payment_key));
|
&keyset->other_payment_key));
|
||||||
n++;
|
n++;
|
||||||
|
|||||||
@@ -240,6 +240,7 @@ static void report_htlcs(const struct bitcoin_tx *tx,
|
|||||||
keyset.other_htlc_key = *remote_htlckey;
|
keyset.other_htlc_key = *remote_htlckey;
|
||||||
|
|
||||||
for (i = 0; i < tal_count(htlc_map); i++) {
|
for (i = 0; i < tal_count(htlc_map); i++) {
|
||||||
|
struct bitcoin_signature localhtlcsig;
|
||||||
const struct htlc *htlc = htlc_map[i];
|
const struct htlc *htlc = htlc_map[i];
|
||||||
|
|
||||||
if (!htlc)
|
if (!htlc)
|
||||||
@@ -281,19 +282,11 @@ static void report_htlcs(const struct bitcoin_tx *tx,
|
|||||||
x_remote_htlcsecretkey, remote_htlckey,
|
x_remote_htlcsecretkey, remote_htlckey,
|
||||||
SIGHASH_ALL,
|
SIGHASH_ALL,
|
||||||
&remotehtlcsig[i]);
|
&remotehtlcsig[i]);
|
||||||
printf("# signature for output %zi (htlc %"PRIu64")\n", i, htlc->id);
|
printf("# signature for output #%zi (%s for htlc #%"PRIu64")\n",
|
||||||
|
i, htlc_owner(htlc) == LOCAL ? "htlc-timeout" : "htlc-success", htlc->id);
|
||||||
printf("remote_htlc_signature = %s\n",
|
printf("remote_htlc_signature = %s\n",
|
||||||
type_to_string(tmpctx, struct bitcoin_signature,
|
type_to_string(tmpctx, secp256k1_ecdsa_signature,
|
||||||
&remotehtlcsig[i]));
|
&remotehtlcsig[i].s));
|
||||||
}
|
|
||||||
|
|
||||||
/* For any HTLC outputs, produce htlc_tx */
|
|
||||||
for (i = 0; i < tal_count(htlc_map); i++) {
|
|
||||||
struct bitcoin_signature localhtlcsig;
|
|
||||||
const struct htlc *htlc = htlc_map[i];
|
|
||||||
|
|
||||||
if (!htlc)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
sign_tx_input(htlc_tx[i], 0,
|
sign_tx_input(htlc_tx[i], 0,
|
||||||
NULL,
|
NULL,
|
||||||
@@ -301,9 +294,9 @@ static void report_htlcs(const struct bitcoin_tx *tx,
|
|||||||
local_htlcsecretkey, local_htlckey,
|
local_htlcsecretkey, local_htlckey,
|
||||||
SIGHASH_ALL,
|
SIGHASH_ALL,
|
||||||
&localhtlcsig);
|
&localhtlcsig);
|
||||||
printf("# local_signature = %s\n",
|
printf("# local_htlc_signature = %s\n",
|
||||||
type_to_string(tmpctx, struct bitcoin_signature,
|
type_to_string(tmpctx, secp256k1_ecdsa_signature,
|
||||||
&localhtlcsig));
|
&localhtlcsig.s));
|
||||||
if (htlc_owner(htlc) == LOCAL) {
|
if (htlc_owner(htlc) == LOCAL) {
|
||||||
htlc_timeout_tx_add_witness(htlc_tx[i],
|
htlc_timeout_tx_add_witness(htlc_tx[i],
|
||||||
local_htlckey,
|
local_htlckey,
|
||||||
@@ -324,7 +317,7 @@ static void report_htlcs(const struct bitcoin_tx *tx,
|
|||||||
remote_revocation_key,
|
remote_revocation_key,
|
||||||
option_anchor_outputs);
|
option_anchor_outputs);
|
||||||
}
|
}
|
||||||
printf("output htlc_%s_tx %"PRIu64": %s\n",
|
printf("htlc_%s_tx (htlc #%"PRIu64"): %s\n",
|
||||||
htlc_owner(htlc) == LOCAL ? "timeout" : "success",
|
htlc_owner(htlc) == LOCAL ? "timeout" : "success",
|
||||||
htlc->id,
|
htlc->id,
|
||||||
tal_hex(tmpctx, linearize_tx(tmpctx, htlc_tx[i])));
|
tal_hex(tmpctx, linearize_tx(tmpctx, htlc_tx[i])));
|
||||||
@@ -361,7 +354,7 @@ static void report(struct bitcoin_tx *tx,
|
|||||||
SIGHASH_ALL,
|
SIGHASH_ALL,
|
||||||
&remotesig);
|
&remotesig);
|
||||||
printf("remote_signature = %s\n",
|
printf("remote_signature = %s\n",
|
||||||
type_to_string(tmpctx, struct bitcoin_signature, &remotesig));
|
type_to_string(tmpctx, secp256k1_ecdsa_signature, &remotesig.s));
|
||||||
sign_tx_input(tx, 0,
|
sign_tx_input(tx, 0,
|
||||||
NULL,
|
NULL,
|
||||||
wscript,
|
wscript,
|
||||||
@@ -369,7 +362,7 @@ static void report(struct bitcoin_tx *tx,
|
|||||||
SIGHASH_ALL,
|
SIGHASH_ALL,
|
||||||
&localsig);
|
&localsig);
|
||||||
printf("# local_signature = %s\n",
|
printf("# local_signature = %s\n",
|
||||||
type_to_string(tmpctx, struct bitcoin_signature, &localsig));
|
type_to_string(tmpctx, secp256k1_ecdsa_signature, &localsig.s));
|
||||||
|
|
||||||
witness =
|
witness =
|
||||||
bitcoin_witness_2of2(tx, &localsig, &remotesig,
|
bitcoin_witness_2of2(tx, &localsig, &remotesig,
|
||||||
@@ -801,7 +794,7 @@ int main(int argc, const char *argv[])
|
|||||||
to_remote.millisatoshis = 3000000000;
|
to_remote.millisatoshis = 3000000000;
|
||||||
feerate_per_kw = 0;
|
feerate_per_kw = 0;
|
||||||
printf("\n"
|
printf("\n"
|
||||||
"name: commitment tx with all 5 htlcs untrimmed (minimum feerate)\n"
|
"name: commitment tx with all five HTLCs untrimmed (minimum feerate)\n"
|
||||||
"to_local_msat: %"PRIu64"\n"
|
"to_local_msat: %"PRIu64"\n"
|
||||||
"to_remote_msat: %"PRIu64"\n"
|
"to_remote_msat: %"PRIu64"\n"
|
||||||
"local_feerate_per_kw: %u\n",
|
"local_feerate_per_kw: %u\n",
|
||||||
@@ -901,12 +894,19 @@ int main(int argc, const char *argv[])
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
printf("\n"
|
printf("\n"
|
||||||
"name: commitment tx with %zu output%s untrimmed (maximum feerate)\n"
|
"name: commitment tx with %s untrimmed (maximum feerate)\n"
|
||||||
"to_local_msat: %"PRIu64"\n"
|
"to_local_msat: %"PRIu64"\n"
|
||||||
"to_remote_msat: %"PRIu64"\n"
|
"to_remote_msat: %"PRIu64"\n"
|
||||||
"local_feerate_per_kw: %u\n",
|
"local_feerate_per_kw: %u\n",
|
||||||
tx->wtx->num_outputs,
|
/* Spec was "neatened" to change these numbers to words! */
|
||||||
tx->wtx->num_outputs > 1 ? "s" : "",
|
tx->wtx->num_outputs == 7 ? "seven outputs"
|
||||||
|
: tx->wtx->num_outputs == 6 ? "six outputs"
|
||||||
|
: tx->wtx->num_outputs == 5 ? "five outputs"
|
||||||
|
: tx->wtx->num_outputs == 4 ? "four outputs"
|
||||||
|
: tx->wtx->num_outputs == 3 ? "three outputs"
|
||||||
|
: tx->wtx->num_outputs == 2 ? "two outputs"
|
||||||
|
: tx->wtx->num_outputs == 1 ? "one output"
|
||||||
|
: "no outputs???",
|
||||||
to_local.millisatoshis, to_remote.millisatoshis, feerate_per_kw-1);
|
to_local.millisatoshis, to_remote.millisatoshis, feerate_per_kw-1);
|
||||||
/* Recalc with verbosity on */
|
/* Recalc with verbosity on */
|
||||||
print_superverbose = true;
|
print_superverbose = true;
|
||||||
@@ -942,12 +942,19 @@ int main(int argc, const char *argv[])
|
|||||||
htlc_map);
|
htlc_map);
|
||||||
|
|
||||||
printf("\n"
|
printf("\n"
|
||||||
"name: commitment tx with %zu output%s untrimmed (minimum feerate)\n"
|
"name: commitment tx with %s untrimmed (minimum feerate)\n"
|
||||||
"to_local_msat: %"PRIu64"\n"
|
"to_local_msat: %"PRIu64"\n"
|
||||||
"to_remote_msat: %"PRIu64"\n"
|
"to_remote_msat: %"PRIu64"\n"
|
||||||
"local_feerate_per_kw: %u\n",
|
"local_feerate_per_kw: %u\n",
|
||||||
newtx->wtx->num_outputs,
|
/* Spec was "neatened" to change these numbers to words! */
|
||||||
newtx->wtx->num_outputs > 1 ? "s" : "",
|
newtx->wtx->num_outputs == 7 ? "seven outputs"
|
||||||
|
: newtx->wtx->num_outputs == 6 ? "six outputs"
|
||||||
|
: newtx->wtx->num_outputs == 5 ? "five outputs"
|
||||||
|
: newtx->wtx->num_outputs == 4 ? "four outputs"
|
||||||
|
: newtx->wtx->num_outputs == 3 ? "three outputs"
|
||||||
|
: newtx->wtx->num_outputs == 2 ? "two outputs"
|
||||||
|
: newtx->wtx->num_outputs == 1 ? "one output"
|
||||||
|
: "no outputs???",
|
||||||
to_local.millisatoshis, to_remote.millisatoshis, feerate_per_kw);
|
to_local.millisatoshis, to_remote.millisatoshis, feerate_per_kw);
|
||||||
/* Recalc with verbosity on */
|
/* Recalc with verbosity on */
|
||||||
print_superverbose = true;
|
print_superverbose = true;
|
||||||
@@ -1020,7 +1027,7 @@ int main(int argc, const char *argv[])
|
|||||||
assert(feerate_per_kw == 9651936);
|
assert(feerate_per_kw == 9651936);
|
||||||
|
|
||||||
printf("\n"
|
printf("\n"
|
||||||
"name: commitment tx with fee greater than opener amount\n"
|
"name: commitment tx with fee greater than funder amount\n"
|
||||||
"to_local_msat: %"PRIu64"\n"
|
"to_local_msat: %"PRIu64"\n"
|
||||||
"to_remote_msat: %"PRIu64"\n"
|
"to_remote_msat: %"PRIu64"\n"
|
||||||
"local_feerate_per_kw: %u\n",
|
"local_feerate_per_kw: %u\n",
|
||||||
|
|||||||
Reference in New Issue
Block a user