Skip to content

Commit 0b359ee

Browse files
committed
Consider pending funding when handling commitment_signed
A FundedChannel may have more than one pending FundingScope during splicing, one for the splice attempt and one or more for any RBF attempts. When handling a commitment_signed, each FundingScope needs to be considered during validation. If validation fails for any scope, then the commitment_signed must be failed.
1 parent 8ec81ef commit 0b359ee

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

lightning/src/ln/channel.rs

+23-10
Original file line numberDiff line numberDiff line change
@@ -5651,7 +5651,17 @@ impl<SP: Deref> FundedChannel<SP> where
56515651
return Err(ChannelError::close("Peer sent commitment_signed after we'd started exchanging closing_signeds".to_owned()));
56525652
}
56535653

5654-
let commitment_tx_info = self.context.validate_commitment_signed(&self.funding, &self.holder_commitment_point, msg, logger)?;
5654+
let mut updates: Vec<ChannelMonitorUpdateStep> = core::iter::once(&self.funding)
5655+
.chain(self.pending_funding.iter())
5656+
.map(|funding| self.context
5657+
.validate_commitment_signed(funding, &self.holder_commitment_point, msg, logger)
5658+
.map(|LatestHolderCommitmentTXInfo { commitment_tx, htlc_outputs, nondust_htlc_sources }|
5659+
ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo {
5660+
commitment_tx, htlc_outputs, claimed_htlcs: vec![], nondust_htlc_sources,
5661+
}
5662+
)
5663+
)
5664+
.collect::<Result<Vec<_>, ChannelError>>()?;
56555665

56565666
if self.holder_commitment_point.advance(&self.context.holder_signer, &self.context.secp_ctx, logger).is_err() {
56575667
// We only fail to advance our commitment point/number if we're currently
@@ -5706,19 +5716,22 @@ impl<SP: Deref> FundedChannel<SP> where
57065716
}
57075717
}
57085718

5709-
let LatestHolderCommitmentTXInfo {
5710-
commitment_tx, htlc_outputs, nondust_htlc_sources,
5711-
} = commitment_tx_info;
5719+
for mut update in updates.iter_mut() {
5720+
if let ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo {
5721+
claimed_htlcs: ref mut update_claimed_htlcs, ..
5722+
} = &mut update {
5723+
debug_assert!(update_claimed_htlcs.is_empty());
5724+
*update_claimed_htlcs = claimed_htlcs.clone();
5725+
} else {
5726+
debug_assert!(false);
5727+
}
5728+
}
5729+
57125730
self.context.latest_monitor_update_id += 1;
57135731
let mut monitor_update = ChannelMonitorUpdate {
57145732
update_id: self.context.latest_monitor_update_id,
57155733
counterparty_node_id: Some(self.context.counterparty_node_id),
5716-
updates: vec![ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo {
5717-
commitment_tx,
5718-
htlc_outputs,
5719-
claimed_htlcs,
5720-
nondust_htlc_sources,
5721-
}],
5734+
updates,
57225735
channel_id: Some(self.context.channel_id()),
57235736
};
57245737

0 commit comments

Comments
 (0)