Skip to content

Commit eb30c39

Browse files
committed
Test async get per commitment point for revoke_and_ack
Note: this does not test the CS -> RAA resend ordering, because this requires handling async get_per_commitment_point for channel reestablishment, which will be addressed in a follow up PR.
1 parent 4cc4eff commit eb30c39

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

lightning/src/ln/async_signer_tests.rs

+27-12
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ fn test_async_commitment_signature_for_funding_signed() {
127127

128128
#[test]
129129
fn test_async_commitment_signature_for_commitment_signed() {
130+
do_test_async_commitment_signature_for_commitment_signed_revoke_and_ack(0);
131+
do_test_async_commitment_signature_for_commitment_signed_revoke_and_ack(1);
132+
}
133+
134+
fn do_test_async_commitment_signature_for_commitment_signed_revoke_and_ack(test_case: u8) {
130135
let chanmon_cfgs = create_chanmon_cfgs(2);
131136
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
132137
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
@@ -154,23 +159,33 @@ fn test_async_commitment_signature_for_commitment_signed() {
154159

155160
// Mark dst's signer as unavailable and handle src's commitment_signed: while dst won't yet have a
156161
// `commitment_signed` of its own to offer, it should publish a `revoke_and_ack`.
162+
dst.disable_channel_signer_op(&src.node.get_our_node_id(), &chan_id, SignerOp::GetPerCommitmentPoint);
157163
dst.disable_channel_signer_op(&src.node.get_our_node_id(), &chan_id, SignerOp::SignCounterpartyCommitment);
158164
dst.node.handle_commitment_signed(&src.node.get_our_node_id(), &payment_event.commitment_msg);
159165
check_added_monitors(dst, 1);
160166

161-
get_event_msg!(dst, MessageSendEvent::SendRevokeAndACK, src.node.get_our_node_id());
162-
163-
// Mark dst's signer as available and retry: we now expect to see dst's `commitment_signed`.
164-
dst.enable_channel_signer_op(&src.node.get_our_node_id(), &chan_id, SignerOp::SignCounterpartyCommitment);
165-
dst.node.signer_unblocked(Some((src.node.get_our_node_id(), chan_id)));
167+
if test_case == 0 {
168+
// Unblock CS -> no messages should be sent, since we must send RAA first.
169+
dst.enable_channel_signer_op(&src.node.get_our_node_id(), &chan_id, SignerOp::SignCounterpartyCommitment);
170+
dst.node.signer_unblocked(Some((src.node.get_our_node_id(), chan_id)));
171+
let events = dst.node.get_and_clear_pending_msg_events();
172+
assert!(events.is_empty(), "expected no message, got {}", events.len());
173+
174+
// Unblock revoke_and_ack -> we should send both RAA + CS.
175+
dst.enable_channel_signer_op(&src.node.get_our_node_id(), &chan_id, SignerOp::GetPerCommitmentPoint);
176+
dst.node.signer_unblocked(Some((src.node.get_our_node_id(), chan_id)));
177+
get_revoke_commit_msgs(&dst, &src.node.get_our_node_id());
178+
} else if test_case == 1 {
179+
// Unblock revoke_and_ack -> we should send just RAA.
180+
dst.enable_channel_signer_op(&src.node.get_our_node_id(), &chan_id, SignerOp::GetPerCommitmentPoint);
181+
dst.node.signer_unblocked(Some((src.node.get_our_node_id(), chan_id)));
182+
get_event_msg!(dst, MessageSendEvent::SendRevokeAndACK, src.node.get_our_node_id());
166183

167-
let events = dst.node.get_and_clear_pending_msg_events();
168-
assert_eq!(events.len(), 1, "expected one message, got {}", events.len());
169-
if let MessageSendEvent::UpdateHTLCs { ref node_id, .. } = events[0] {
170-
assert_eq!(node_id, &src.node.get_our_node_id());
171-
} else {
172-
panic!("expected UpdateHTLCs message, not {:?}", events[0]);
173-
};
184+
// Unblock commitment signed -> we should send CS.
185+
dst.enable_channel_signer_op(&src.node.get_our_node_id(), &chan_id, SignerOp::SignCounterpartyCommitment);
186+
dst.node.signer_unblocked(Some((src.node.get_our_node_id(), chan_id)));
187+
get_htlc_update_msgs(dst, &src.node.get_our_node_id());
188+
}
174189
}
175190

176191
#[test]

lightning/src/util/test_channel_signer.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,10 @@ impl TestChannelSigner {
165165

166166
impl ChannelSigner for TestChannelSigner {
167167
fn get_per_commitment_point(&self, idx: u64, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<PublicKey, ()> {
168-
// TODO: implement a mask in EnforcementState to let you test signatures being
169-
// unavailable
168+
#[cfg(test)]
169+
if !self.is_signer_available(SignerOp::GetPerCommitmentPoint) {
170+
return Err(());
171+
}
170172
self.inner.get_per_commitment_point(idx, secp_ctx)
171173
}
172174

0 commit comments

Comments
 (0)