Skip to content

Commit 934ec75

Browse files
committed
f - test coverage for handling closing_signed while waiting on signer
1 parent e3f2831 commit 934ec75

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

lightning/src/ln/async_signer_tests.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//! Tests for asynchronous signing. These tests verify that the channel state machine behaves
1111
//! properly with a signer implementation that asynchronously derives signatures.
1212
13+
use bitcoin::key::Secp256k1;
1314
use bitcoin::{Transaction, TxOut, TxIn, Amount};
1415
use bitcoin::blockdata::locktime::absolute::LockTime;
1516
use bitcoin::transaction::Version;
@@ -18,10 +19,13 @@ use crate::chain::channelmonitor::LATENCY_GRACE_PERIOD_BLOCKS;
1819
use crate::chain::ChannelMonitorUpdateStatus;
1920
use crate::events::bump_transaction::WalletSource;
2021
use crate::events::{ClosureReason, Event, MessageSendEvent, MessageSendEventsProvider};
22+
use crate::ln::chan_utils::ClosingTransaction;
2123
use crate::ln::{functional_test_utils::*, msgs};
2224
use crate::ln::channel_state::{ChannelDetails, ChannelShutdownState};
2325
use crate::ln::msgs::ChannelMessageHandler;
2426
use crate::ln::channelmanager::{PaymentId, RAACommitmentOrder, RecipientOnionFields};
27+
use crate::sign::ecdsa::EcdsaChannelSigner;
28+
use crate::sign::SignerProvider;
2529
use crate::util::test_channel_signer::SignerOp;
2630

2731
#[test]
@@ -699,6 +703,11 @@ fn test_async_holder_signatures_remote_commitment_anchors() {
699703

700704
#[test]
701705
fn test_closing_signed() {
706+
do_test_closing_signed(false);
707+
do_test_closing_signed(true);
708+
}
709+
710+
fn do_test_closing_signed(extra_closing_signed: bool) {
702711
// Based off of `expect_channel_shutdown_state`.
703712
// Test that we can asynchronously sign closing transactions.
704713
let chanmon_cfgs = create_chanmon_cfgs(2);
@@ -746,6 +755,40 @@ fn test_closing_signed() {
746755
nodes[0].disable_channel_signer_op(&nodes[1].node.get_our_node_id(), &chan_1.2, SignerOp::SignClosingTransaction);
747756
nodes[0].node.handle_closing_signed(&nodes[1].node.get_our_node_id(), &node_1_closing_signed);
748757
nodes[0].enable_channel_signer_op(&nodes[1].node.get_our_node_id(), &chan_1.2, SignerOp::SignClosingTransaction);
758+
759+
if extra_closing_signed {
760+
let node_1_closing_signed_2_bad = {
761+
let mut node_1_closing_signed_2 = node_1_closing_signed.clone();
762+
//node_1_closing_signed_2.signature.
763+
let holder_script = nodes[0].keys_manager.get_shutdown_scriptpubkey().unwrap();
764+
let counterparty_script = nodes[1].keys_manager.get_shutdown_scriptpubkey().unwrap();
765+
let funding_outpoint = bitcoin::OutPoint { txid: chan_1.3.txid(), vout: 0 };
766+
let closing_tx_2 = ClosingTransaction::new(50000, 0, holder_script.into(),
767+
counterparty_script.into(), funding_outpoint);
768+
769+
let per_peer_state = nodes[1].node.per_peer_state.read().unwrap();
770+
let mut chan_lock = per_peer_state.get(&nodes[0].node.get_our_node_id()).unwrap().lock().unwrap();
771+
let chan = chan_lock.channel_by_id.get_mut(&chan_1.2).map(|phase| phase.context_mut()).unwrap();
772+
773+
let signer = chan.get_mut_signer().as_mut_ecdsa().unwrap();
774+
let signature = signer.sign_closing_transaction(&closing_tx_2, &Secp256k1::new()).unwrap();
775+
node_1_closing_signed_2.signature = signature;
776+
node_1_closing_signed_2
777+
};
778+
nodes[0].node.handle_closing_signed(&nodes[1].node.get_our_node_id(), &node_1_closing_signed_2_bad);
779+
780+
let events = nodes[0].node.get_and_clear_pending_msg_events();
781+
assert_eq!(events.len(), 1);
782+
match events[0] {
783+
MessageSendEvent::HandleError {
784+
action: msgs::ErrorAction::SendWarningMessage { .. }, ref node_id
785+
} => {
786+
assert_eq!(node_id, &nodes[1].node.get_our_node_id());
787+
},
788+
_ => panic!("Unexpected event: {:?}", events[0]),
789+
};
790+
}
791+
749792
nodes[0].node.signer_unblocked(None);
750793
let (_, node_0_2nd_closing_signed) = get_closing_signed_broadcast!(nodes[0].node, nodes[1].node.get_our_node_id());
751794

0 commit comments

Comments
 (0)