Skip to content

Commit d38cf5b

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

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

lightning/src/ln/async_signer_tests.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,6 @@ fn do_test_async_holder_signatures(anchors: bool, remote_commitment: bool) {
367367
route_payment(&nodes[0], &[&nodes[1]], 1_000_000);
368368
let error_message = "Channel force-closed";
369369

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

372371
if remote_commitment {
373372
// Make the counterparty broadcast its latest commitment.
@@ -376,6 +375,8 @@ fn do_test_async_holder_signatures(anchors: bool, remote_commitment: bool) {
376375
check_closed_broadcast(&nodes[1], 1, true);
377376
check_closed_event(&nodes[1], 1, ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(true) }, false, &[nodes[0].node.get_our_node_id()], 100_000);
378377
} else {
378+
nodes[0].disable_channel_signer_op(&nodes[1].node.get_our_node_id(), &chan_id, SignerOp::SignHolderCommitment);
379+
nodes[0].disable_channel_signer_op(&nodes[1].node.get_our_node_id(), &chan_id, SignerOp::SignHolderHtlcTransaction);
379380
// We'll connect blocks until the sender has to go onchain to time out the HTLC.
380381
connect_blocks(&nodes[0], TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS + 1);
381382

@@ -384,7 +385,8 @@ fn do_test_async_holder_signatures(anchors: bool, remote_commitment: bool) {
384385
assert!(nodes[0].chain_monitor.chain_monitor.get_and_clear_pending_events().is_empty());
385386

386387
// Mark it as available now, we should see the signed commitment transaction.
387-
nodes[0].set_channel_signer_available(&nodes[1].node.get_our_node_id(), &chan_id, true);
388+
nodes[0].enable_channel_signer_op(&nodes[1].node.get_our_node_id(), &chan_id, SignerOp::SignHolderCommitment);
389+
nodes[0].enable_channel_signer_op(&nodes[1].node.get_our_node_id(), &chan_id, SignerOp::SignHolderHtlcTransaction);
388390
get_monitor!(nodes[0], chan_id).signer_unblocked(nodes[0].tx_broadcaster, nodes[0].fee_estimator, &nodes[0].logger);
389391
}
390392

@@ -410,7 +412,13 @@ fn do_test_async_holder_signatures(anchors: bool, remote_commitment: bool) {
410412

411413
// Mark it as unavailable again to now test the HTLC transaction. We'll mine the commitment such
412414
// that the HTLC transaction is retried.
413-
nodes[0].set_channel_signer_available(&nodes[1].node.get_our_node_id(), &chan_id, false);
415+
let sign_htlc_op = if remote_commitment {
416+
SignerOp::SignCounterpartyHtlcTransaction
417+
} else {
418+
SignerOp::SignHolderHtlcTransaction
419+
};
420+
nodes[0].disable_channel_signer_op(&nodes[1].node.get_our_node_id(), &chan_id, SignerOp::SignHolderCommitment);
421+
nodes[0].disable_channel_signer_op(&nodes[1].node.get_our_node_id(), &chan_id, sign_htlc_op);
414422
mine_transaction(&nodes[0], &commitment_tx);
415423

416424
check_added_monitors(&nodes[0], 1);
@@ -427,10 +435,12 @@ fn do_test_async_holder_signatures(anchors: bool, remote_commitment: bool) {
427435
if anchors && !remote_commitment {
428436
handle_bump_htlc_event(&nodes[0], 1);
429437
}
430-
assert!(nodes[0].tx_broadcaster.txn_broadcast().is_empty());
438+
let txn = nodes[0].tx_broadcaster.txn_broadcast();
439+
assert!(txn.is_empty(), "expected no transaction to be broadcast, got {:?}", txn);
431440

432441
// Mark it as available now, we should see the signed HTLC transaction.
433-
nodes[0].set_channel_signer_available(&nodes[1].node.get_our_node_id(), &chan_id, true);
442+
nodes[0].enable_channel_signer_op(&nodes[1].node.get_our_node_id(), &chan_id, SignerOp::SignHolderCommitment);
443+
nodes[0].enable_channel_signer_op(&nodes[1].node.get_our_node_id(), &chan_id, sign_htlc_op);
434444
get_monitor!(nodes[0], chan_id).signer_unblocked(nodes[0].tx_broadcaster, nodes[0].fee_estimator, &nodes[0].logger);
435445

436446
if anchors && !remote_commitment {
@@ -444,9 +454,21 @@ fn do_test_async_holder_signatures(anchors: bool, remote_commitment: bool) {
444454
}
445455

446456
#[test]
447-
fn test_async_holder_signatures() {
457+
fn test_async_holder_signatures_no_anchors() {
448458
do_test_async_holder_signatures(false, false);
459+
}
460+
461+
#[test]
462+
fn test_async_holder_signatures_remote_commitment_no_anchors() {
449463
do_test_async_holder_signatures(false, true);
464+
}
465+
466+
#[test]
467+
fn test_async_holder_signatures_anchors() {
450468
do_test_async_holder_signatures(true, false);
469+
}
470+
471+
#[test]
472+
fn test_async_holder_signatures_remote_commitment_anchors() {
451473
do_test_async_holder_signatures(true, true);
452474
}

lightning/src/util/test_channel_signer.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ impl EcdsaChannelSigner for TestChannelSigner {
245245
}
246246

247247
fn sign_holder_commitment(&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
248-
if !*self.available.lock().unwrap() {
248+
if !self.is_signer_available(SignerOp::SignHolderCommitment) {
249249
return Err(());
250250
}
251251
let trusted_tx = self.verify_holder_commitment_tx(commitment_tx, secp_ctx);
@@ -266,14 +266,14 @@ impl EcdsaChannelSigner for TestChannelSigner {
266266
}
267267

268268
fn sign_justice_revoked_output(&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
269-
if !*self.available.lock().unwrap() {
269+
if !self.is_signer_available(SignerOp::SignJusticeRevokedOutput) {
270270
return Err(());
271271
}
272272
Ok(EcdsaChannelSigner::sign_justice_revoked_output(&self.inner, justice_tx, input, amount, per_commitment_key, secp_ctx).unwrap())
273273
}
274274

275275
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, ()> {
276-
if !*self.available.lock().unwrap() {
276+
if !self.is_signer_available(SignerOp::SignJusticeRevokedHtlc) {
277277
return Err(());
278278
}
279279
Ok(EcdsaChannelSigner::sign_justice_revoked_htlc(&self.inner, justice_tx, input, amount, per_commitment_key, htlc, secp_ctx).unwrap())
@@ -283,7 +283,7 @@ impl EcdsaChannelSigner for TestChannelSigner {
283283
&self, htlc_tx: &Transaction, input: usize, htlc_descriptor: &HTLCDescriptor,
284284
secp_ctx: &Secp256k1<secp256k1::All>
285285
) -> Result<Signature, ()> {
286-
if !*self.available.lock().unwrap() {
286+
if !self.is_signer_available(SignerOp::SignHolderHtlcTransaction) {
287287
return Err(());
288288
}
289289
let state = self.state.lock().unwrap();
@@ -319,7 +319,7 @@ impl EcdsaChannelSigner for TestChannelSigner {
319319
}
320320

321321
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, ()> {
322-
if !*self.available.lock().unwrap() {
322+
if !self.is_signer_available(SignerOp::SignCounterpartyHtlcTransaction) {
323323
return Err(());
324324
}
325325
Ok(EcdsaChannelSigner::sign_counterparty_htlc_transaction(&self.inner, htlc_tx, input, amount, per_commitment_point, htlc, secp_ctx).unwrap())
@@ -338,7 +338,7 @@ impl EcdsaChannelSigner for TestChannelSigner {
338338
// As long as our minimum dust limit is enforced and is greater than our anchor output
339339
// value, an anchor output can only have an index within [0, 1].
340340
assert!(anchor_tx.input[input].previous_output.vout == 0 || anchor_tx.input[input].previous_output.vout == 1);
341-
if !*self.available.lock().unwrap() {
341+
if !self.is_signer_available(SignerOp::SignHolderAnchorInput) {
342342
return Err(());
343343
}
344344
EcdsaChannelSigner::sign_holder_anchor_input(&self.inner, anchor_tx, input, secp_ctx)

0 commit comments

Comments
 (0)