Pass the initial counterparty commit tx to `ChannelMonitor::new`
What changed, and why it matters
This commit fixes an internal consistency problem in how a new Lightning channel's first monitoring data is built. Previously, the code created a ChannelMonitor first and then separately supplied the counterparty's initial commitment transaction. A recent change made the monitor panic if it was saved to disk before that transaction was supplied. The fix requires the transaction to be passed directly into ChannelMonitor::new, eliminating a window where the monitor could be incomplete. It is a robustness/API-cleanup fix rather than an externally exploitable vulnerability.
No urgent security action required. Treat as a normal code-quality/robustness improvement. Review related tests and any downstream code that constructs ChannelMonitor directly to ensure the new required parameter is supplied.
Security signals we found
Eliminates a window where ChannelMonitor could be serialized without the required initial counterparty commitment transaction
Recent code change introduced a panic on serialization when the transaction was missing
Moves a required initialization step from a separate call into the constructor, enforcing it by API
Evidence from the diff
The patch changes ChannelMonitor::new to accept initial_counterparty_commitment_tx: CommitmentTransaction as a required parameter and immediately calls provide_initial_counterparty_commitment_tx on the newly constructed ChannelMonitorImpl before returning. The previous pub(crate) method provide_initial_counterparty_commitment_tx on ChannelMonitor is removed, and the only caller in channel.rs is updated to pass the transaction at construction time. A dummy monitor helper is also updated. This closes a temporal gap where serialization could occur before the initial counterparty commitment transaction was provided, which had started causing a panic after a recent change.
Changed components
lightning/src/chain/channelmonitor.rslightning/src/ln/channel.rsChannelMonitor::newChannelMonitorImpl initializationdummy_monitor test helperInspect captured patch +18 / −19
### lightning/src/chain/channelmonitor.rs
@@ -1992,7 +1992,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
on_counterparty_tx_csv: u16, destination_script: &Script,
channel_parameters: &ChannelTransactionParameters, holder_pays_commitment_tx_fee: bool,
commitment_transaction_number_obscure_factor: u64,
- initial_holder_commitment_tx: HolderCommitmentTransaction, best_block: BlockLocator,
+ initial_holder_commitment_tx: HolderCommitmentTransaction,
+ initial_counterparty_commitment_tx: CommitmentTransaction, best_block: BlockLocator,
counterparty_node_id: PublicKey, channel_id: ChannelId,
is_manual_broadcast: bool,
) -> ChannelMonitor<Signer> {
@@ -2029,7 +2030,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
funding_outpoint.txid, vec![(funding_outpoint.index as u32, funding_script.clone())],
);
- Self::from_impl(ChannelMonitorImpl {
+ let mut monitor = ChannelMonitorImpl {
funding: FundingScope {
channel_parameters: channel_parameters.clone(),
@@ -2110,7 +2111,9 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
alternative_funding_confirmed: None,
written_by_0_1_or_later: true,
- })
+ };
+ monitor.provide_initial_counterparty_commitment_tx(initial_counterparty_commitment_tx);
+ Self::from_impl(monitor)
}
/// Returns a unique id for persisting the [`ChannelMonitor`], which is used as a key in a
@@ -2138,20 +2141,6 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
self.inner.lock().unwrap().provide_secret(idx, secret)
}
- /// A variant of `Self::provide_latest_counterparty_commitment_tx` used to provide
- /// the counterparty commitment transaction to the monitor so that the transaction
- /// can be retrieved during the initial persistence of the monitor (mainly for use in
- /// third-party watchtowers).
- ///
- /// This is used to provide the counterparty commitment transaction directly to the monitor
- /// before the initial persistence of a new channel.
- pub(crate) fn provide_initial_counterparty_commitment_tx(
- &self, commitment_tx: CommitmentTransaction,
- ) {
- let mut inner = self.inner.lock().unwrap();
- inner.provide_initial_counterparty_commitment_tx(commitment_tx);
- }
-
/// Informs this monitor of the latest counterparty (ie non-broadcastable) commitment transaction.
/// The monitor watches for it to be broadcasted and then uses the HTLC information (and
/// possibly future revocation/preimage information) to claim outputs where possible.
@@ -7518,6 +7507,16 @@ pub(super) fn dummy_monitor<S: EcdsaChannelSigner + 'static>(
channel_type_features: ChannelTypeFeatures::only_static_remote_key(),
channel_value_satoshis: 0,
};
+ let counterparty_commitment_tx = CommitmentTransaction::new(
+ INITIAL_COMMITMENT_NUMBER,
+ &dummy_key,
+ 0,
+ 0,
+ 0,
+ Vec::new(),
+ &channel_parameters.as_counterparty_broadcastable(),
+ &secp_ctx,
+ );
let shutdown_script = crate::ln::script::ShutdownScript::new_p2wpkh_from_pubkey(dummy_key);
let best_block = BlockLocator::from_network(Network::Testnet);
let signer = wrap_signer(keys);
@@ -7531,6 +7530,7 @@ pub(super) fn dummy_monitor<S: EcdsaChannelSigner + 'static>(
true,
0,
HolderCommitmentTransaction::dummy(0, funding_outpoint, Vec::new()),
+ counterparty_commitment_tx,
best_block,
dummy_key,
channel_id,
### lightning/src/ln/channel.rs
@@ -4068,13 +4068,12 @@ trait InitialRemoteCommitmentReceiver<SP: SignerProvider> {
funding.is_outbound(),
obscure_factor,
holder_commitment_tx,
+ counterparty_initial_commitment_tx.clone(),
best_block,
context.counterparty_node_id,
context.channel_id(),
context.is_manual_broadcast,
);
- channel_monitor
- .provide_initial_counterparty_commitment_tx(counterparty_initial_commitment_tx.clone());
self.context_mut().counterparty_next_commitment_transaction_number -= 1;
Why this scored 31/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.