Skip to content

Commit 2eb7d31

Browse files
committed
Run async_signer_tests::test_async_holder_signatures with P2A anchors
1 parent 1ebc270 commit 2eb7d31

File tree

1 file changed

+31
-36
lines changed

1 file changed

+31
-36
lines changed

lightning/src/ln/async_signer_tests.rs

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,10 @@
1111
//! properly with a signer implementation that asynchronously derives signatures.
1212
1313
use crate::prelude::*;
14-
use bitcoin::locktime::absolute::LockTime;
1514
use bitcoin::secp256k1::Secp256k1;
16-
use bitcoin::transaction::Version;
17-
use bitcoin::{Amount, Transaction, TxIn, TxOut};
1815

1916
use crate::chain::channelmonitor::LATENCY_GRACE_PERIOD_BLOCKS;
2017
use crate::chain::ChannelMonitorUpdateStatus;
21-
use crate::events::bump_transaction::sync::WalletSourceSync;
2218
use crate::events::{ClosureReason, Event};
2319
use crate::ln::chan_utils::ClosingTransaction;
2420
use crate::ln::channel::DISCONNECT_PEER_AWAITING_RESPONSE_TICKS;
@@ -972,15 +968,14 @@ fn do_test_async_commitment_signature_ordering(monitor_update_failure: bool) {
972968
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_2);
973969
}
974970

975-
fn do_test_async_holder_signatures(anchors: bool, remote_commitment: bool) {
971+
fn do_test_async_holder_signatures(keyed_anchors: bool, p2a_anchor: bool, remote_commitment: bool) {
976972
// Ensures that we can obtain holder signatures for commitment and HTLC transactions
977973
// asynchronously by allowing their retrieval to fail and retrying via
978974
// `ChannelMonitor::signer_unblocked`.
979975
let mut config = test_default_channel_config();
980-
if anchors {
981-
config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true;
982-
config.manually_accept_inbound_channels = true;
983-
}
976+
config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = keyed_anchors;
977+
config.channel_handshake_config.negotiate_anchor_zero_fee_commitments = p2a_anchor;
978+
config.manually_accept_inbound_channels = keyed_anchors || p2a_anchor;
984979

985980
let chanmon_cfgs = create_chanmon_cfgs(2);
986981
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
@@ -990,23 +985,8 @@ fn do_test_async_holder_signatures(anchors: bool, remote_commitment: bool) {
990985
let node_b_id = nodes[1].node.get_our_node_id();
991986

992987
let closing_node = if remote_commitment { &nodes[1] } else { &nodes[0] };
993-
let coinbase_tx = Transaction {
994-
version: Version::TWO,
995-
lock_time: LockTime::ZERO,
996-
input: vec![TxIn { ..Default::default() }],
997-
output: vec![TxOut {
998-
value: Amount::ONE_BTC,
999-
script_pubkey: closing_node.wallet_source.get_change_script().unwrap(),
1000-
}],
1001-
};
1002-
if anchors {
1003-
*nodes[0].fee_estimator.sat_per_kw.lock().unwrap() *= 2;
1004-
*nodes[1].fee_estimator.sat_per_kw.lock().unwrap() *= 2;
1005-
closing_node.wallet_source.add_utxo(
1006-
bitcoin::OutPoint { txid: coinbase_tx.compute_txid(), vout: 0 },
1007-
coinbase_tx.output[0].value,
1008-
);
1009-
}
988+
989+
let coinbase_tx = provide_anchor_reserves(&nodes);
1010990

1011991
// Route an HTLC and set the signer as unavailable.
1012992
let (_, _, chan_id, funding_tx) = create_announced_chan_between_nodes(&nodes, 0, 1);
@@ -1051,13 +1031,18 @@ fn do_test_async_holder_signatures(anchors: bool, remote_commitment: bool) {
10511031
&nodes[0].logger,
10521032
);
10531033
}
1054-
if anchors {
1034+
if keyed_anchors || p2a_anchor {
10551035
handle_bump_close_event(closing_node);
10561036
}
10571037

10581038
let commitment_tx = {
10591039
let mut txn = closing_node.tx_broadcaster.txn_broadcast();
1060-
if anchors || remote_commitment {
1040+
if p2a_anchor {
1041+
assert_eq!(txn.len(), 2);
1042+
check_spends!(txn[0], funding_tx);
1043+
check_spends!(txn[1], txn[0], coinbase_tx);
1044+
txn.remove(0)
1045+
} else if keyed_anchors || remote_commitment {
10611046
assert_eq!(txn.len(), 1);
10621047
check_spends!(txn[0], funding_tx);
10631048
txn.remove(0)
@@ -1102,7 +1087,7 @@ fn do_test_async_holder_signatures(anchors: bool, remote_commitment: bool) {
11021087
}
11031088

11041089
// No HTLC transaction should be broadcast as the signer is not available yet.
1105-
if anchors && !remote_commitment {
1090+
if (keyed_anchors || p2a_anchor) && !remote_commitment {
11061091
handle_bump_htlc_event(&nodes[0], 1);
11071092
}
11081093
let txn = nodes[0].tx_broadcaster.txn_broadcast();
@@ -1117,7 +1102,7 @@ fn do_test_async_holder_signatures(anchors: bool, remote_commitment: bool) {
11171102
&nodes[0].logger,
11181103
);
11191104

1120-
if anchors && !remote_commitment {
1105+
if (keyed_anchors || p2a_anchor) && !remote_commitment {
11211106
handle_bump_htlc_event(&nodes[0], 1);
11221107
}
11231108
{
@@ -1129,22 +1114,32 @@ fn do_test_async_holder_signatures(anchors: bool, remote_commitment: bool) {
11291114

11301115
#[test]
11311116
fn test_async_holder_signatures_no_anchors() {
1132-
do_test_async_holder_signatures(false, false);
1117+
do_test_async_holder_signatures(false, false, false);
11331118
}
11341119

11351120
#[test]
11361121
fn test_async_holder_signatures_remote_commitment_no_anchors() {
1137-
do_test_async_holder_signatures(false, true);
1122+
do_test_async_holder_signatures(false, false, true);
1123+
}
1124+
1125+
#[test]
1126+
fn test_async_holder_signatures_keyed_anchors() {
1127+
do_test_async_holder_signatures(true, false, false);
1128+
}
1129+
1130+
#[test]
1131+
fn test_async_holder_signatures_remote_commitment_keyed_anchors() {
1132+
do_test_async_holder_signatures(true, false, true);
11381133
}
11391134

11401135
#[test]
1141-
fn test_async_holder_signatures_anchors() {
1142-
do_test_async_holder_signatures(true, false);
1136+
fn test_async_holder_signatures_p2a_anchor() {
1137+
do_test_async_holder_signatures(false, true, false);
11431138
}
11441139

11451140
#[test]
1146-
fn test_async_holder_signatures_remote_commitment_anchors() {
1147-
do_test_async_holder_signatures(true, true);
1141+
fn test_async_holder_signatures_remote_commitment_p2a_anchor() {
1142+
do_test_async_holder_signatures(false, true, true);
11481143
}
11491144

11501145
#[test]

0 commit comments

Comments
 (0)