Skip to content

Commit ff549c5

Browse files
committed
Use specific signer ops masks for monitor async signing tests
1 parent af1f4c8 commit ff549c5

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

lightning/src/ln/async_signer_tests.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,6 @@ fn do_test_async_holder_signatures(anchors: bool, remote_commitment: bool) {
381381
route_payment(&nodes[0], &[&nodes[1]], 1_000_000);
382382
let error_message = "Channel force-closed";
383383

384-
nodes[0].set_channel_signer_available(&nodes[1].node.get_our_node_id(), &chan_id, false);
385384

386385
if remote_commitment {
387386
// Make the counterparty broadcast its latest commitment.
@@ -390,6 +389,8 @@ fn do_test_async_holder_signatures(anchors: bool, remote_commitment: bool) {
390389
check_closed_broadcast(&nodes[1], 1, true);
391390
check_closed_event(&nodes[1], 1, ClosureReason::HolderForceClosed, false, &[nodes[0].node.get_our_node_id()], 100_000);
392391
} else {
392+
nodes[0].set_channel_signer_ops_available(&nodes[1].node.get_our_node_id(), &chan_id, ops::SIGN_HOLDER_COMMITMENT_AND_HTLCS, false);
393+
nodes[0].set_channel_signer_ops_available(&nodes[1].node.get_our_node_id(), &chan_id, ops::SIGN_HOLDER_HTLC_TRANSACTION, false);
393394
// We'll connect blocks until the sender has to go onchain to time out the HTLC.
394395
connect_blocks(&nodes[0], TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS + 1);
395396

@@ -398,7 +399,8 @@ fn do_test_async_holder_signatures(anchors: bool, remote_commitment: bool) {
398399
assert!(nodes[0].chain_monitor.chain_monitor.get_and_clear_pending_events().is_empty());
399400

400401
// Mark it as available now, we should see the signed commitment transaction.
401-
nodes[0].set_channel_signer_available(&nodes[1].node.get_our_node_id(), &chan_id, true);
402+
nodes[0].set_channel_signer_ops_available(&nodes[1].node.get_our_node_id(), &chan_id, ops::SIGN_HOLDER_COMMITMENT_AND_HTLCS, true);
403+
nodes[0].set_channel_signer_ops_available(&nodes[1].node.get_our_node_id(), &chan_id, ops::SIGN_HOLDER_HTLC_TRANSACTION, true);
402404
get_monitor!(nodes[0], chan_id).signer_unblocked(nodes[0].tx_broadcaster, nodes[0].fee_estimator, &nodes[0].logger);
403405
}
404406

@@ -424,7 +426,13 @@ fn do_test_async_holder_signatures(anchors: bool, remote_commitment: bool) {
424426

425427
// Mark it as unavailable again to now test the HTLC transaction. We'll mine the commitment such
426428
// that the HTLC transaction is retried.
427-
nodes[0].set_channel_signer_available(&nodes[1].node.get_our_node_id(), &chan_id, false);
429+
let sign_htlc_mask = if remote_commitment {
430+
ops::SIGN_COUNTERPARTY_HTLC_TRANSACTION
431+
} else {
432+
ops::SIGN_HOLDER_HTLC_TRANSACTION
433+
};
434+
nodes[0].set_channel_signer_ops_available(&nodes[1].node.get_our_node_id(), &chan_id, sign_htlc_mask, false);
435+
nodes[0].set_channel_signer_ops_available(&nodes[1].node.get_our_node_id(), &chan_id, ops::SIGN_HOLDER_ANCHOR_INPUT, false);
428436
mine_transaction(&nodes[0], &commitment_tx);
429437

430438
check_added_monitors(&nodes[0], 1);
@@ -444,7 +452,8 @@ fn do_test_async_holder_signatures(anchors: bool, remote_commitment: bool) {
444452
assert!(nodes[0].tx_broadcaster.txn_broadcast().is_empty());
445453

446454
// Mark it as available now, we should see the signed HTLC transaction.
447-
nodes[0].set_channel_signer_available(&nodes[1].node.get_our_node_id(), &chan_id, true);
455+
nodes[0].set_channel_signer_ops_available(&nodes[1].node.get_our_node_id(), &chan_id, sign_htlc_mask, true);
456+
nodes[0].set_channel_signer_ops_available(&nodes[1].node.get_our_node_id(), &chan_id, ops::SIGN_HOLDER_ANCHOR_INPUT, true);
448457
get_monitor!(nodes[0], chan_id).signer_unblocked(nodes[0].tx_broadcaster, nodes[0].fee_estimator, &nodes[0].logger);
449458

450459
if anchors && !remote_commitment {
@@ -458,9 +467,21 @@ fn do_test_async_holder_signatures(anchors: bool, remote_commitment: bool) {
458467
}
459468

460469
#[test]
461-
fn test_async_holder_signatures() {
470+
fn test_async_holder_signatures_no_anchors() {
462471
do_test_async_holder_signatures(false, false);
472+
}
473+
474+
#[test]
475+
fn test_async_holder_signatures_remote_commitment_no_anchors() {
463476
do_test_async_holder_signatures(false, true);
477+
}
478+
479+
#[test]
480+
fn test_async_holder_signatures_anchors() {
464481
do_test_async_holder_signatures(true, false);
482+
}
483+
484+
#[test]
485+
fn test_async_holder_signatures_remote_commitment_anchors() {
465486
do_test_async_holder_signatures(true, true);
466487
}

lightning/src/util/test_channel_signer.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl ChannelSigner for TestChannelSigner {
210210
}
211211

212212
fn validate_counterparty_revocation(&self, idx: u64, _secret: &SecretKey) -> Result<(), ()> {
213-
if !*self.available.lock().unwrap() {
213+
if !self.is_signer_available(ops::VALIDATE_COUNTERPARTY_REVOCATION) {
214214
return Err(());
215215
}
216216
let mut state = self.state.lock().unwrap();
@@ -252,7 +252,7 @@ impl EcdsaChannelSigner for TestChannelSigner {
252252
}
253253

254254
fn sign_holder_commitment(&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
255-
if !*self.available.lock().unwrap() {
255+
if !self.is_signer_available(ops::SIGN_HOLDER_COMMITMENT_AND_HTLCS) {
256256
return Err(());
257257
}
258258
let trusted_tx = self.verify_holder_commitment_tx(commitment_tx, secp_ctx);
@@ -273,14 +273,14 @@ impl EcdsaChannelSigner for TestChannelSigner {
273273
}
274274

275275
fn sign_justice_revoked_output(&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
276-
if !*self.available.lock().unwrap() {
276+
if !self.is_signer_available(ops::SIGN_JUSTICE_REVOKED_OUTPUT) {
277277
return Err(());
278278
}
279279
Ok(EcdsaChannelSigner::sign_justice_revoked_output(&self.inner, justice_tx, input, amount, per_commitment_key, secp_ctx).unwrap())
280280
}
281281

282282
fn sign_justice_revoked_htlc(&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
283-
if !*self.available.lock().unwrap() {
283+
if !self.is_signer_available(ops::SIGN_JUSTICE_REVOKED_HTLC) {
284284
return Err(());
285285
}
286286
Ok(EcdsaChannelSigner::sign_justice_revoked_htlc(&self.inner, justice_tx, input, amount, per_commitment_key, htlc, secp_ctx).unwrap())
@@ -290,7 +290,7 @@ impl EcdsaChannelSigner for TestChannelSigner {
290290
&self, htlc_tx: &Transaction, input: usize, htlc_descriptor: &HTLCDescriptor,
291291
secp_ctx: &Secp256k1<secp256k1::All>
292292
) -> Result<Signature, ()> {
293-
if !*self.available.lock().unwrap() {
293+
if !self.is_signer_available(ops::SIGN_HOLDER_HTLC_TRANSACTION) {
294294
return Err(());
295295
}
296296
let state = self.state.lock().unwrap();
@@ -326,7 +326,7 @@ impl EcdsaChannelSigner for TestChannelSigner {
326326
}
327327

328328
fn sign_counterparty_htlc_transaction(&self, htlc_tx: &Transaction, input: usize, amount: u64, per_commitment_point: &PublicKey, htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
329-
if !*self.available.lock().unwrap() {
329+
if !self.is_signer_available(ops::SIGN_COUNTERPARTY_HTLC_TRANSACTION) {
330330
return Err(());
331331
}
332332
Ok(EcdsaChannelSigner::sign_counterparty_htlc_transaction(&self.inner, htlc_tx, input, amount, per_commitment_point, htlc, secp_ctx).unwrap())
@@ -345,7 +345,7 @@ impl EcdsaChannelSigner for TestChannelSigner {
345345
// As long as our minimum dust limit is enforced and is greater than our anchor output
346346
// value, an anchor output can only have an index within [0, 1].
347347
assert!(anchor_tx.input[input].previous_output.vout == 0 || anchor_tx.input[input].previous_output.vout == 1);
348-
if !*self.available.lock().unwrap() {
348+
if !self.is_signer_available(ops::SIGN_HOLDER_ANCHOR_INPUT) {
349349
return Err(());
350350
}
351351
EcdsaChannelSigner::sign_holder_anchor_input(&self.inner, anchor_tx, input, secp_ctx)

0 commit comments

Comments
 (0)