Skip to content

Commit 78acf18

Browse files
committed
Split commitment_signed handling by check-accept
When handling commitment_signed messages, a number of checks are performed before a ChannelMonitorUpdate is created and returned. Once splicing is added, these checks need to be performed on the primary FundingScope and any pending scopes that resulted from splicing or RBF. This commit splits the handling into a check and accepts methods, taking &self and &mut self, respectively. This ensures that the ChannelContext is not modified between checks. Once all funding scopes have been checked successfully, the accept portion of the code can then execute.
1 parent 36ba27a commit 78acf18

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

lightning/src/chain/channelmonitor.rs

+8
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,14 @@ impl_writeable_tlv_based_enum_upgradable!(OnchainEvent,
529529

530530
);
531531

532+
/// Partial data from ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo used to simplify the
533+
/// return type of [`FundedChannel::commitment_signed_check`].
534+
pub(crate) struct LatestHolderCommitmentTXInfo {
535+
pub commitment_tx: HolderCommitmentTransaction,
536+
pub htlc_outputs: Vec<(HTLCOutputInCommitment, Option<Signature>, Option<HTLCSource>)>,
537+
pub nondust_htlc_sources: Vec<HTLCSource>,
538+
}
539+
532540
#[derive(Clone, Debug, PartialEq, Eq)]
533541
pub(crate) enum ChannelMonitorUpdateStep {
534542
LatestHolderCommitmentTXInfo {

lightning/src/ln/channel.rs

+19-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use crate::ln::chan_utils;
5252
use crate::ln::onion_utils::HTLCFailReason;
5353
use crate::chain::BestBlock;
5454
use crate::chain::chaininterface::{FeeEstimator, ConfirmationTarget, LowerBoundedFeeEstimator, fee_for_weight};
55-
use crate::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateStep, LATENCY_GRACE_PERIOD_BLOCKS};
55+
use crate::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateStep, LatestHolderCommitmentTXInfo, LATENCY_GRACE_PERIOD_BLOCKS};
5656
use crate::chain::transaction::{OutPoint, TransactionData};
5757
use crate::sign::ecdsa::EcdsaChannelSigner;
5858
use crate::sign::{EntropySource, ChannelSigner, SignerProvider, NodeSigner, Recipient};
@@ -5494,7 +5494,7 @@ impl<SP: Deref> FundedChannel<SP> where
54945494
Ok(channel_monitor)
54955495
}
54965496

5497-
pub fn commitment_signed<L: Deref>(&mut self, msg: &msgs::CommitmentSigned, logger: &L) -> Result<Option<ChannelMonitorUpdate>, ChannelError>
5497+
fn commitment_signed_check<L: Deref>(&self, msg: &msgs::CommitmentSigned, logger: &L) -> Result<LatestHolderCommitmentTXInfo, ChannelError>
54985498
where L::Target: Logger
54995499
{
55005500
if self.context.channel_state.is_quiescent() {
@@ -5622,6 +5622,18 @@ impl<SP: Deref> FundedChannel<SP> where
56225622
self.context.holder_signer.as_ref().validate_holder_commitment(&holder_commitment_tx, commitment_stats.outbound_htlc_preimages)
56235623
.map_err(|_| ChannelError::close("Failed to validate our commitment".to_owned()))?;
56245624

5625+
Ok(LatestHolderCommitmentTXInfo {
5626+
commitment_tx: holder_commitment_tx,
5627+
htlc_outputs: htlcs_and_sigs,
5628+
nondust_htlc_sources,
5629+
})
5630+
}
5631+
5632+
pub fn commitment_signed<L: Deref>(&mut self, msg: &msgs::CommitmentSigned, logger: &L) -> Result<Option<ChannelMonitorUpdate>, ChannelError>
5633+
where L::Target: Logger
5634+
{
5635+
let commitment_tx_info = self.commitment_signed_check(msg, logger)?;
5636+
56255637
// Update state now that we've passed all the can-fail calls...
56265638
let mut need_commitment = false;
56275639
if let &mut Some((_, ref mut update_state)) = &mut self.context.pending_update_fee {
@@ -5661,13 +5673,16 @@ impl<SP: Deref> FundedChannel<SP> where
56615673
}
56625674
}
56635675

5676+
let LatestHolderCommitmentTXInfo {
5677+
commitment_tx, htlc_outputs, nondust_htlc_sources,
5678+
} = commitment_tx_info;
56645679
self.context.latest_monitor_update_id += 1;
56655680
let mut monitor_update = ChannelMonitorUpdate {
56665681
update_id: self.context.latest_monitor_update_id,
56675682
counterparty_node_id: Some(self.context.counterparty_node_id),
56685683
updates: vec![ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo {
5669-
commitment_tx: holder_commitment_tx,
5670-
htlc_outputs: htlcs_and_sigs,
5684+
commitment_tx,
5685+
htlc_outputs,
56715686
claimed_htlcs,
56725687
nondust_htlc_sources,
56735688
}],

0 commit comments

Comments
 (0)