Skip to content

Commit

Permalink
fixup! fixup! fixup! Enable spliting lightning channel
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
luckysori committed Nov 29, 2023
1 parent d4e130d commit 342fecb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
10 changes: 9 additions & 1 deletion lightning/src/chain/channelmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1292,12 +1292,20 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
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
Expand Down
3 changes: 1 addition & 2 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1076,8 +1076,7 @@ impl<SP: Deref> ChannelContext<SP> 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;
Expand Down
8 changes: 4 additions & 4 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down

0 comments on commit 342fecb

Please sign in to comment.