Skip to content

Commit 8469089

Browse files
committed
Return non-Optional Transaction from received_tx_signatures
We did not need to return `Option<Transaction>` as we actually don't need to check if the counterparty had already sent their `tx_signatures` before (in which case we'd return a `None` for `Option<Transaction>`). Therefore, we just return a plain `Transaction` in the tuple here. Further, we can get rid of the clone of `funding_tx` in `Channel::tx_signatures` when setting the `Context::funding_transaction` as we don't actually need to propagate it through to `ChannelManager::internal_tx_complete` as we can use `ChannelContext::unbroadcasted_funding()` which clones the `ChannelContext::funding_transaction` anyway.
1 parent b636731 commit 8469089

File tree

3 files changed

+10
-21
lines changed

3 files changed

+10
-21
lines changed

lightning/src/ln/channel.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5701,7 +5701,7 @@ impl<SP: Deref> Channel<SP> where
57015701
}
57025702
}
57035703

5704-
pub fn tx_signatures<L: Deref>(&mut self, msg: &msgs::TxSignatures, logger: &L) -> Result<(Option<msgs::TxSignatures>, Option<Transaction>), ChannelError>
5704+
pub fn tx_signatures<L: Deref>(&mut self, msg: &msgs::TxSignatures, logger: &L) -> Result<Option<msgs::TxSignatures>, ChannelError>
57055705
where L::Target: Logger
57065706
{
57075707
if !matches!(self.context.channel_state, ChannelState::FundingNegotiated) {
@@ -5738,12 +5738,10 @@ impl<SP: Deref> Channel<SP> where
57385738
// for spending. Doesn't seem to be anything in rust-bitcoin.
57395739
}
57405740

5741-
let (tx_signatures_opt, funding_tx_opt) = signing_session.received_tx_signatures(msg.clone())
5741+
let (tx_signatures_opt, funding_tx) = signing_session.received_tx_signatures(msg.clone())
57425742
.map_err(|_| ChannelError::Warn("Witness count did not match contributed input count".to_string()))?;
5743-
if funding_tx_opt.is_some() {
5744-
self.context.channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
5745-
}
5746-
self.context.funding_transaction = funding_tx_opt.clone();
5743+
self.context.channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
5744+
self.context.funding_transaction = Some(funding_tx);
57475745

57485746
self.context.next_funding_txid = None;
57495747

@@ -5753,10 +5751,10 @@ impl<SP: Deref> Channel<SP> where
57535751
if tx_signatures_opt.is_some() && self.context.channel_state.is_monitor_update_in_progress() {
57545752
log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
57555753
self.context.monitor_pending_tx_signatures = tx_signatures_opt;
5756-
return Ok((None, None));
5754+
return Ok(None);
57575755
}
57585756

5759-
Ok((tx_signatures_opt, funding_tx_opt))
5757+
Ok(tx_signatures_opt)
57605758
} else {
57615759
Err(ChannelError::Close((
57625760
"Unexpected tx_signatures. No funding transaction awaiting signatures".to_string(),

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8316,14 +8316,14 @@ where
83168316
match channel_phase {
83178317
ChannelPhase::Funded(chan) => {
83188318
let logger = WithChannelContext::from(&self.logger, &chan.context, None);
8319-
let (tx_signatures_opt, funding_tx_opt) = try_chan_phase_entry!(self, peer_state, chan.tx_signatures(msg, &&logger), chan_phase_entry);
8319+
let tx_signatures_opt = try_chan_phase_entry!(self, peer_state, chan.tx_signatures(msg, &&logger), chan_phase_entry);
83208320
if let Some(tx_signatures) = tx_signatures_opt {
83218321
peer_state.pending_msg_events.push(events::MessageSendEvent::SendTxSignatures {
83228322
node_id: *counterparty_node_id,
83238323
msg: tx_signatures,
83248324
});
83258325
}
8326-
if let Some(ref funding_tx) = funding_tx_opt {
8326+
if let Some(ref funding_tx) = chan.context.unbroadcasted_funding() {
83278327
self.tx_broadcaster.broadcast_transactions(&[funding_tx]);
83288328
{
83298329
let mut pending_events = self.pending_events.lock().unwrap();

lightning/src/ln/interactivetxs.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,7 @@ impl InteractiveTxSigningSession {
320320
/// unsigned transaction.
321321
pub fn received_tx_signatures(
322322
&mut self, tx_signatures: TxSignatures,
323-
) -> Result<(Option<TxSignatures>, Option<Transaction>), ()> {
324-
if self.counterparty_sent_tx_signatures {
325-
return Ok((None, None));
326-
};
323+
) -> Result<(Option<TxSignatures>, Transaction), ()> {
327324
if self.remote_inputs_count() != tx_signatures.witnesses.len() {
328325
return Err(());
329326
}
@@ -336,13 +333,7 @@ impl InteractiveTxSigningSession {
336333
None
337334
};
338335

339-
let funding_tx = if self.holder_tx_signatures.is_some() {
340-
Some(self.finalize_funding_tx())
341-
} else {
342-
None
343-
};
344-
345-
Ok((holder_tx_signatures, funding_tx))
336+
Ok((holder_tx_signatures, self.finalize_funding_tx()))
346337
}
347338

348339
/// Provides the holder witnesses for the unsigned transaction.

0 commit comments

Comments
 (0)