Skip to content

Commit 4773cb8

Browse files
authored
Merge pull request #4629 from wpaulino/require-user-approval-reestablish-interactive-funding
Gate interactive commitment_signed on user approval during reestablish
2 parents 6eb5bf2 + fad7505 commit 4773cb8

2 files changed

Lines changed: 95 additions & 22 deletions

File tree

lightning/src/ln/channel.rs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10584,30 +10584,32 @@ where
1058410584
self.context.expecting_peer_commitment_signed = true;
1058510585
}
1058610586

10587-
// - if it has not received `tx_signatures` for that funding transaction:
10588-
// - if the `commitment_signed` bit is set in `retransmit_flags`:
10589-
if !session.has_received_tx_signatures()
10590-
&& next_funding.should_retransmit(msgs::NextFundingFlag::CommitmentSigned)
10591-
{
10592-
// - MUST retransmit its `commitment_signed` for that funding transaction.
10593-
retransmit_funding_commit_sig = Some(next_funding.txid);
10594-
}
10587+
if !session.has_holder_witnesses() {
10588+
log_debug!(logger, "Waiting for funding transaction signatures to be provided");
10589+
} else {
10590+
// - if it has not received `tx_signatures` for that funding transaction:
10591+
// - if the `commitment_signed` bit is set in `retransmit_flags`:
10592+
if !session.has_received_tx_signatures()
10593+
&& next_funding.should_retransmit(msgs::NextFundingFlag::CommitmentSigned)
10594+
{
10595+
// - MUST retransmit its `commitment_signed` for that funding transaction.
10596+
retransmit_funding_commit_sig = Some(next_funding.txid);
10597+
}
1059510598

10596-
// - if it has already received `commitment_signed` and it should sign first
10597-
// - MUST send its `tx_signatures` for that funding transaction.
10598-
//
10599-
// - if it has already received `tx_signatures` for that funding transaction:
10600-
// - MUST send its `tx_signatures` for that funding transaction.
10601-
if let Some(holder_tx_signatures) = session.holder_tx_signatures() {
10602-
if self.is_awaiting_monitor_update() {
10603-
log_debug!(logger, "Waiting for monitor update before providing funding transaction signatures");
10604-
} else if self.context.signer_pending_funding {
10605-
log_debug!(logger, "Waiting for signer to provide counterparty commitment_signed before releasing funding transaction signatures");
10606-
} else {
10607-
tx_signatures = Some(holder_tx_signatures);
10599+
// - if it has already received `commitment_signed` and it should sign first
10600+
// - MUST send its `tx_signatures` for that funding transaction.
10601+
//
10602+
// - if it has already received `tx_signatures` for that funding transaction:
10603+
// - MUST send its `tx_signatures` for that funding transaction.
10604+
if let Some(holder_tx_signatures) = session.holder_tx_signatures() {
10605+
if self.is_awaiting_monitor_update() {
10606+
log_debug!(logger, "Waiting for monitor update before providing funding transaction signatures");
10607+
} else if self.context.signer_pending_funding {
10608+
log_debug!(logger, "Waiting for signer to provide counterparty commitment_signed before releasing funding transaction signatures");
10609+
} else {
10610+
tx_signatures = Some(holder_tx_signatures);
10611+
}
1060810612
}
10609-
} else if !session.has_holder_witnesses() {
10610-
log_debug!(logger, "Waiting for funding transaction signatures to be provided");
1061110613
}
1061210614
} else {
1061310615
// We'll just send a `tx_abort` here if we don't have a signing session for this channel

lightning/src/ln/splicing_tests.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2676,6 +2676,77 @@ fn test_splice_locked_waits_for_channel_reestablish() {
26762676
send_payment(&nodes[0], &[&nodes[1]], 1_000_000);
26772677
}
26782678

2679+
#[test]
2680+
fn test_splice_reestablish_waits_for_holder_tx_signatures_before_commitment_signed() {
2681+
let chanmon_cfgs = create_chanmon_cfgs(2);
2682+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
2683+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
2684+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
2685+
2686+
let node_id_0 = nodes[0].node.get_our_node_id();
2687+
let node_id_1 = nodes[1].node.get_our_node_id();
2688+
2689+
let initial_channel_value_sat = 100_000;
2690+
let (_, _, channel_id, _) =
2691+
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, initial_channel_value_sat, 0);
2692+
2693+
let outputs = vec![TxOut {
2694+
value: Amount::from_sat(initial_channel_value_sat / 4),
2695+
script_pubkey: nodes[0].wallet_source.get_change_script().unwrap(),
2696+
}];
2697+
let initiator_contribution =
2698+
initiate_splice_out(&nodes[0], &nodes[1], channel_id, outputs).unwrap();
2699+
negotiate_splice_tx(&nodes[0], &nodes[1], channel_id, initiator_contribution);
2700+
2701+
let signing_event = get_event!(nodes[0], Event::FundingTransactionReadyForSigning);
2702+
assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty());
2703+
2704+
// Drop the acceptor's initial `commitment_signed`. On reconnection, node 0's
2705+
// `channel_reestablish` should request it again, while node 1's `channel_reestablish` should
2706+
// not make node 0 retransmit a `commitment_signed` before holder transaction signatures are
2707+
// available.
2708+
let _ = get_htlc_update_msgs(&nodes[1], &node_id_0);
2709+
nodes[0].node.peer_disconnected(node_id_1);
2710+
nodes[1].node.peer_disconnected(node_id_0);
2711+
2712+
let mut reconnect_args = ReconnectArgs::new(&nodes[0], &nodes[1]);
2713+
reconnect_args.send_announcement_sigs = (true, true);
2714+
reconnect_args.send_interactive_tx_commit_sig = (true, false);
2715+
reconnect_nodes(reconnect_args);
2716+
2717+
assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty());
2718+
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
2719+
2720+
let unsigned_transaction = if let Event::FundingTransactionReadyForSigning {
2721+
unsigned_transaction,
2722+
..
2723+
} = signing_event
2724+
{
2725+
unsigned_transaction
2726+
} else {
2727+
panic!("Expected FundingTransactionReadyForSigning event");
2728+
};
2729+
let tx = nodes[0].wallet_source.sign_tx(unsigned_transaction).unwrap();
2730+
nodes[0].node.funding_transaction_signed(&channel_id, &node_id_1, tx).unwrap();
2731+
check_added_monitors(&nodes[0], 1);
2732+
2733+
let initiator_commit_sig = get_htlc_update_msgs(&nodes[0], &node_id_1);
2734+
nodes[1]
2735+
.node
2736+
.handle_commitment_signed_batch_test(node_id_0, &initiator_commit_sig.commitment_signed);
2737+
check_added_monitors(&nodes[1], 1);
2738+
2739+
let acceptor_tx_signatures =
2740+
get_event_msg!(nodes[1], MessageSendEvent::SendTxSignatures, node_id_0);
2741+
nodes[0].node.handle_tx_signatures(node_id_1, &acceptor_tx_signatures);
2742+
let initiator_tx_signatures =
2743+
get_event_msg!(nodes[0], MessageSendEvent::SendTxSignatures, node_id_1);
2744+
nodes[1].node.handle_tx_signatures(node_id_0, &initiator_tx_signatures);
2745+
2746+
expect_splice_pending_event(&nodes[0], &node_id_1);
2747+
expect_splice_pending_event(&nodes[1], &node_id_0);
2748+
}
2749+
26792750
#[test]
26802751
fn test_splice_confirms_on_both_sides_while_disconnected() {
26812752
// Regression test: when a splice transaction confirms on both sides while peers are

0 commit comments

Comments
 (0)