Skip to content

Commit 8130b69

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 2e44245 commit 8130b69

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
@@ -5693,7 +5693,7 @@ impl<SP: Deref> Channel<SP> where
56935693
}
56945694
}
56955695

5696-
pub fn tx_signatures<L: Deref>(&mut self, msg: &msgs::TxSignatures, logger: &L) -> Result<(Option<msgs::TxSignatures>, Option<Transaction>), ChannelError>
5696+
pub fn tx_signatures<L: Deref>(&mut self, msg: &msgs::TxSignatures, logger: &L) -> Result<Option<msgs::TxSignatures>, ChannelError>
56975697
where L::Target: Logger
56985698
{
56995699
if !matches!(self.context.channel_state, ChannelState::FundingNegotiated) {
@@ -5730,12 +5730,10 @@ impl<SP: Deref> Channel<SP> where
57305730
// for spending. Doesn't seem to be anything in rust-bitcoin.
57315731
}
57325732

5733-
let (tx_signatures_opt, funding_tx_opt) = signing_session.received_tx_signatures(msg.clone())
5733+
let (tx_signatures_opt, funding_tx) = signing_session.received_tx_signatures(msg.clone())
57345734
.map_err(|_| ChannelError::Warn("Witness count did not match contributed input count".to_string()))?;
5735-
if funding_tx_opt.is_some() {
5736-
self.context.channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
5737-
}
5738-
self.context.funding_transaction = funding_tx_opt.clone();
5735+
self.context.channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
5736+
self.context.funding_transaction = Some(funding_tx);
57395737

57405738
self.context.next_funding_txid = None;
57415739

@@ -5745,10 +5743,10 @@ impl<SP: Deref> Channel<SP> where
57455743
if tx_signatures_opt.is_some() && self.context.channel_state.is_monitor_update_in_progress() {
57465744
log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
57475745
self.context.monitor_pending_tx_signatures = tx_signatures_opt;
5748-
return Ok((None, None));
5746+
return Ok(None);
57495747
}
57505748

5751-
Ok((tx_signatures_opt, funding_tx_opt))
5749+
Ok(tx_signatures_opt)
57525750
} else {
57535751
Err(ChannelError::Close((
57545752
"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
@@ -8370,14 +8370,14 @@ where
83708370
match channel_phase {
83718371
ChannelPhase::Funded(chan) => {
83728372
let logger = WithChannelContext::from(&self.logger, &chan.context, None);
8373-
let (tx_signatures_opt, funding_tx_opt) = try_chan_phase_entry!(self, peer_state, chan.tx_signatures(msg, &&logger), chan_phase_entry);
8373+
let tx_signatures_opt = try_chan_phase_entry!(self, peer_state, chan.tx_signatures(msg, &&logger), chan_phase_entry);
83748374
if let Some(tx_signatures) = tx_signatures_opt {
83758375
peer_state.pending_msg_events.push(events::MessageSendEvent::SendTxSignatures {
83768376
node_id: *counterparty_node_id,
83778377
msg: tx_signatures,
83788378
});
83798379
}
8380-
if let Some(ref funding_tx) = funding_tx_opt {
8380+
if let Some(ref funding_tx) = chan.context.unbroadcasted_funding() {
83818381
self.tx_broadcaster.broadcast_transactions(&[funding_tx]);
83828382
{
83838383
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)