From bf675b64bcd230a7ccb35900c5433dab33689d64 Mon Sep 17 00:00:00 2001 From: Lucas Soriano del Pino Date: Tue, 28 Nov 2023 20:36:40 +1100 Subject: [PATCH] fixup! fixup! fixup! Enable spliting lightning channel I think we might need to update the `ChannelTransactionParameters` in the `OnchainTxHandler` when we split the channel. It seems necessary in general and it has become mandatory now that we have a `debug_assert_eq` checking the commitment TXIDs when handling a `ChannelMonitorUpdate` in the `ChannelMonitor`. --- lightning/src/chain/channelmonitor.rs | 10 +++++++++- lightning/src/ln/channel.rs | 3 +-- lightning/src/ln/channelmanager.rs | 8 ++++---- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index f66f060ae7f..5aba7ea1ef9 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -1292,12 +1292,20 @@ impl ChannelMonitor { if let Some(original) = inner.original_funding_info.as_ref() { if fund_outpoint == original.0 { inner.original_funding_info = None; + inner.onchain_tx_handler.channel_transaction_parameters.original_funding_outpoint = None; } } else { - inner.original_funding_info = Some((inner.funding_info.0.clone(), inner.funding_info.1.clone())); + let original_funding_txo = inner.funding_info.0; + let original_funding_script_pubkey = &inner.funding_info.1; + + inner.original_funding_info = Some((original_funding_txo, original_funding_script_pubkey.clone())); + inner.onchain_tx_handler.channel_transaction_parameters.original_funding_outpoint = Some(original_funding_txo); } inner.outputs_to_watch.insert(fund_outpoint.txid, vec![(fund_outpoint.index as u32, script.clone())]); + inner.funding_info = (fund_outpoint, script.clone()); + inner.onchain_tx_handler.channel_transaction_parameters.funding_outpoint = Some(fund_outpoint); + inner.channel_value_satoshis = channel_value_satoshis; inner.onchain_tx_handler.signer.set_channel_value_satoshis(channel_value_satoshis); script diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 260c00aad72..faf8a82e706 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -1076,8 +1076,7 @@ impl ChannelContext where SP::Target: SignerProvider { self.channel_transaction_parameters.original_funding_outpoint.or(self.get_funding_txo()) } - /// Set the funding output and value of the channel, returning a `ChannelMonitorUpdate` - /// containing a commitment for the new funding output if requested. + /// Set the funding output and value of the channel. fn set_funding_outpoint(&mut self, funding_outpoint: &OutPoint, channel_value_satoshis: u64, own_balance: u64) { self.channel_value_satoshis = channel_value_satoshis; diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 8f1a033af12..b814ca202ed 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -2720,6 +2720,10 @@ where let chan = channel_lock.get_channel(); let original_funding_txo = chan.context.get_original_funding_txo().unwrap(); + if ChannelMonitorUpdateStatus::Completed != self.chain_monitor.update_channel_funding_txo(chan.context.get_original_funding_txo().unwrap(), *funding_outpoint, channel_value_satoshis) { + return Err(APIError::APIMisuseError { err: "Could not update channel funding transaction.".to_string() }); + } + let monitor_update = chan.set_funding_outpoint(funding_outpoint, channel_value_satoshis, own_balance, true, &self.logger); if let Some(monitor_update) = &monitor_update { let update_res = self.chain_monitor.update_channel(original_funding_txo, monitor_update); @@ -2728,10 +2732,6 @@ where } } - if ChannelMonitorUpdateStatus::Completed != self.chain_monitor.update_channel_funding_txo(chan.context.get_original_funding_txo().unwrap(), *funding_outpoint, channel_value_satoshis) { - return Err(APIError::APIMisuseError { err: "Could not update channel funding transaction.".to_string() }); - } - let res = chan.monitor_updating_restored(&self.logger, &self.node_signer, self.genesis_hash, &self.default_configuration, self.best_block.read().unwrap().height()); let commit_tx_number = chan.get_cur_counterparty_commitment_transaction_number();