Skip to content

Commit d062afb

Browse files
committed
Use specific async signer ops for commitment signature tests
1 parent 24d68eb commit d062afb

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

lightning/src/ln/async_signer_tests.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use crate::events::{Event, MessageSendEvent, MessageSendEventsProvider, ClosureR
2020
use crate::ln::functional_test_utils::*;
2121
use crate::ln::msgs::ChannelMessageHandler;
2222
use crate::ln::channelmanager::{PaymentId, RecipientOnionFields};
23+
use crate::util::test_channel_signer::SignerOp;
2324

2425
#[test]
2526
fn test_async_commitment_signature_for_funding_created() {
@@ -43,7 +44,7 @@ fn test_async_commitment_signature_for_funding_created() {
4344
// But! Let's make node[0]'s signer be unavailable: we should *not* broadcast a funding_created
4445
// message...
4546
let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42);
46-
nodes[0].set_channel_signer_available(&nodes[1].node.get_our_node_id(), &temporary_channel_id, false);
47+
nodes[0].disable_channel_signer_op(&nodes[1].node.get_our_node_id(), &temporary_channel_id, SignerOp::SignCounterpartyCommitment);
4748
nodes[0].node.funding_transaction_generated(&temporary_channel_id, &nodes[1].node.get_our_node_id(), tx.clone()).unwrap();
4849
check_added_monitors(&nodes[0], 0);
4950

@@ -57,7 +58,7 @@ fn test_async_commitment_signature_for_funding_created() {
5758
channels[0].channel_id
5859
};
5960

60-
nodes[0].set_channel_signer_available(&nodes[1].node.get_our_node_id(), &chan_id, true);
61+
nodes[0].enable_channel_signer_op(&nodes[1].node.get_our_node_id(), &chan_id, SignerOp::SignCounterpartyCommitment);
6162
nodes[0].node.signer_unblocked(Some((nodes[1].node.get_our_node_id(), chan_id)));
6263

6364
let mut funding_created_msg = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id());
@@ -98,7 +99,7 @@ fn test_async_commitment_signature_for_funding_signed() {
9899

99100
// Now let's make node[1]'s signer be unavailable while handling the `funding_created`. It should
100101
// *not* broadcast a `funding_signed`...
101-
nodes[1].set_channel_signer_available(&nodes[0].node.get_our_node_id(), &temporary_channel_id, false);
102+
nodes[1].disable_channel_signer_op(&nodes[0].node.get_our_node_id(), &temporary_channel_id, SignerOp::SignCounterpartyCommitment);
102103
nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &funding_created_msg);
103104
check_added_monitors(&nodes[1], 1);
104105

@@ -111,7 +112,7 @@ fn test_async_commitment_signature_for_funding_signed() {
111112
assert_eq!(channels.len(), 1, "expected one channel, not {}", channels.len());
112113
channels[0].channel_id
113114
};
114-
nodes[1].set_channel_signer_available(&nodes[0].node.get_our_node_id(), &chan_id, true);
115+
nodes[1].enable_channel_signer_op(&nodes[0].node.get_our_node_id(), &chan_id, SignerOp::SignCounterpartyCommitment);
115116
nodes[1].node.signer_unblocked(Some((nodes[0].node.get_our_node_id(), chan_id)));
116117

117118
expect_channel_pending_event(&nodes[1], &nodes[0].node.get_our_node_id());
@@ -152,14 +153,14 @@ fn test_async_commitment_signature_for_commitment_signed() {
152153

153154
// Mark dst's signer as unavailable and handle src's commitment_signed: while dst won't yet have a
154155
// `commitment_signed` of its own to offer, it should publish a `revoke_and_ack`.
155-
dst.set_channel_signer_available(&src.node.get_our_node_id(), &chan_id, false);
156+
dst.disable_channel_signer_op(&src.node.get_our_node_id(), &chan_id, SignerOp::SignCounterpartyCommitment);
156157
dst.node.handle_commitment_signed(&src.node.get_our_node_id(), &payment_event.commitment_msg);
157158
check_added_monitors(dst, 1);
158159

159160
get_event_msg!(dst, MessageSendEvent::SendRevokeAndACK, src.node.get_our_node_id());
160161

161162
// Mark dst's signer as available and retry: we now expect to see dst's `commitment_signed`.
162-
dst.set_channel_signer_available(&src.node.get_our_node_id(), &chan_id, true);
163+
dst.enable_channel_signer_op(&src.node.get_our_node_id(), &chan_id, SignerOp::SignCounterpartyCommitment);
163164
dst.node.signer_unblocked(Some((src.node.get_our_node_id(), chan_id)));
164165

165166
let events = dst.node.get_and_clear_pending_msg_events();
@@ -215,7 +216,7 @@ fn test_async_commitment_signature_for_funding_signed_0conf() {
215216

216217
// Now let's make node[1]'s signer be unavailable while handling the `funding_created`. It should
217218
// *not* broadcast a `funding_signed`...
218-
nodes[1].set_channel_signer_available(&nodes[0].node.get_our_node_id(), &temporary_channel_id, false);
219+
nodes[1].disable_channel_signer_op(&nodes[0].node.get_our_node_id(), &temporary_channel_id, SignerOp::SignCounterpartyCommitment);
219220
nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &funding_created_msg);
220221
check_added_monitors(&nodes[1], 1);
221222

@@ -230,7 +231,7 @@ fn test_async_commitment_signature_for_funding_signed_0conf() {
230231
};
231232

232233
// At this point, we basically expect the channel to open like a normal zero-conf channel.
233-
nodes[1].set_channel_signer_available(&nodes[0].node.get_our_node_id(), &chan_id, true);
234+
nodes[1].enable_channel_signer_op(&nodes[0].node.get_our_node_id(), &chan_id, SignerOp::SignCounterpartyCommitment);
234235
nodes[1].node.signer_unblocked(Some((nodes[0].node.get_our_node_id(), chan_id)));
235236

236237
let (funding_signed, channel_ready_1) = {
@@ -299,7 +300,7 @@ fn test_async_commitment_signature_for_peer_disconnect() {
299300

300301
// Mark dst's signer as unavailable and handle src's commitment_signed: while dst won't yet have a
301302
// `commitment_signed` of its own to offer, it should publish a `revoke_and_ack`.
302-
dst.set_channel_signer_available(&src.node.get_our_node_id(), &chan_id, false);
303+
dst.disable_channel_signer_op(&src.node.get_our_node_id(), &chan_id, SignerOp::SignCounterpartyCommitment);
303304
dst.node.handle_commitment_signed(&src.node.get_our_node_id(), &payment_event.commitment_msg);
304305
check_added_monitors(dst, 1);
305306

@@ -314,7 +315,7 @@ fn test_async_commitment_signature_for_peer_disconnect() {
314315
reconnect_nodes(reconnect_args);
315316

316317
// Mark dst's signer as available and retry: we now expect to see dst's `commitment_signed`.
317-
dst.set_channel_signer_available(&src.node.get_our_node_id(), &chan_id, true);
318+
dst.enable_channel_signer_op(&src.node.get_our_node_id(), &chan_id, SignerOp::SignCounterpartyCommitment);
318319
dst.node.signer_unblocked(Some((src.node.get_our_node_id(), chan_id)));
319320

320321
{

lightning/src/util/test_channel_signer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl ChannelSigner for TestChannelSigner {
203203
}
204204

205205
fn validate_counterparty_revocation(&self, idx: u64, _secret: &SecretKey) -> Result<(), ()> {
206-
if !*self.available.lock().unwrap() {
206+
if !self.is_signer_available(SignerOp::ValidateCounterpartyRevocation) {
207207
return Err(());
208208
}
209209
let mut state = self.state.lock().unwrap();
@@ -226,7 +226,7 @@ impl EcdsaChannelSigner for TestChannelSigner {
226226
self.verify_counterparty_commitment_tx(commitment_tx, secp_ctx);
227227

228228
{
229-
if !*self.available.lock().unwrap() {
229+
if !self.is_signer_available(SignerOp::SignCounterpartyCommitment) {
230230
return Err(());
231231
}
232232
let mut state = self.state.lock().unwrap();

0 commit comments

Comments
 (0)