Skip to content

Commit 9ad6f28

Browse files
committed
f set and clear next_funding_txid in channel.rs directly
1 parent ecdd54a commit 9ad6f28

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

lightning/src/ln/channel.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ use crate::types::payment::{PaymentPreimage, PaymentHash};
3131
use crate::types::features::{ChannelTypeFeatures, InitFeatures};
3232
use crate::ln::interactivetxs::{
3333
ConstructedTransaction, estimate_input_weight, get_output_weight,
34-
HandleTxCompleteResult, InteractiveTxConstructor, InteractiveTxConstructorArgs,
35-
InteractiveTxSigningSession, InteractiveTxMessageSendResult, TX_COMMON_FIELDS_WEIGHT,
34+
HandleTxCompleteValue, HandleTxCompleteResult, InteractiveTxConstructor,
35+
InteractiveTxConstructorArgs, InteractiveTxSigningSession, InteractiveTxMessageSendResult,
36+
TX_COMMON_FIELDS_WEIGHT,
3637
};
3738
use crate::ln::msgs;
3839
use crate::ln::msgs::{ClosingSigned, ClosingSignedFeeRange, DecodeError};
@@ -1726,8 +1727,16 @@ pub(super) trait InteractivelyFunded<SP: Deref> where SP::Target: SignerProvider
17261727

17271728
fn tx_complete(&mut self, msg: &msgs::TxComplete) -> HandleTxCompleteResult {
17281729
HandleTxCompleteResult(match self.interactive_tx_constructor_mut() {
1729-
Some(ref mut tx_constructor) => tx_constructor.handle_tx_complete(msg).map_err(
1730-
|reason| reason.into_tx_abort_msg(self.context().channel_id())),
1730+
Some(ref mut tx_constructor) => tx_constructor.handle_tx_complete(msg)
1731+
// TODO: Change this to Result::inspect when MSRV >= 1.76
1732+
// See: https://doc.rust-lang.org/stable/std/result/enum.Result.html#method.inspect
1733+
.map(|tx_complete_value| {
1734+
if let HandleTxCompleteValue::SendTxComplete(_, ref signing_session) = tx_complete_value {
1735+
self.context_mut().next_funding_txid = Some(signing_session.unsigned_tx.txid());
1736+
}
1737+
tx_complete_value
1738+
})
1739+
.map_err(|reason| reason.into_tx_abort_msg(self.context().channel_id())),
17311740
None => Err(msgs::TxAbort {
17321741
channel_id: self.context().channel_id(),
17331742
data: b"No interactive transaction negotiation in progress".to_vec()
@@ -4672,14 +4681,6 @@ impl<SP: Deref> Channel<SP> where
46724681
self.context.channel_state.clear_waiting_for_batch();
46734682
}
46744683

4675-
pub fn set_next_funding_txid(&mut self, txid: &Txid) {
4676-
self.context.next_funding_txid = Some(*txid);
4677-
}
4678-
4679-
pub fn clear_next_funding_txid(&mut self) {
4680-
self.context.next_funding_txid = None;
4681-
}
4682-
46834684
/// Unsets the existing funding information.
46844685
///
46854686
/// This must only be used if the channel has not yet completed funding and has not been used.
@@ -5701,6 +5702,8 @@ impl<SP: Deref> Channel<SP> where
57015702
}
57025703
self.context.funding_transaction = funding_tx_opt.clone();
57035704

5705+
self.context.next_funding_txid = None;
5706+
57045707
// Clear out the signing session
57055708
self.interactive_tx_signing_session = None;
57065709

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8279,7 +8279,6 @@ where
82798279
peer_state.pending_msg_events.push(msg_send_event);
82808280
};
82818281
if let Some(mut signing_session) = signing_session_opt {
8282-
let funding_txid = signing_session.unsigned_tx.txid();
82838282
let (commitment_signed, funding_ready_for_sig_event_opt) = match chan_phase_entry.get_mut() {
82848283
ChannelPhase::UnfundedOutboundV2(chan) => {
82858284
chan.funding_tx_constructed(&mut signing_session, &self.logger)
@@ -8292,7 +8291,7 @@ where
82928291
.into())),
82938292
}.map_err(|err| MsgHandleErrInternal::send_err_msg_no_close(format!("{}", err), msg.channel_id))?;
82948293
let (channel_id, channel_phase) = chan_phase_entry.remove_entry();
8295-
let mut channel = match channel_phase {
8294+
let channel = match channel_phase {
82968295
ChannelPhase::UnfundedOutboundV2(chan) => chan.into_channel(signing_session),
82978296
ChannelPhase::UnfundedInboundV2(chan) => chan.into_channel(signing_session),
82988297
_ => {
@@ -8302,7 +8301,6 @@ where
83028301
.into()))
83038302
},
83048303
}.map_err(|err| MsgHandleErrInternal::send_err_msg_no_close(format!("{}", err), msg.channel_id))?;
8305-
channel.set_next_funding_txid(&funding_txid);
83068304
peer_state.channel_by_id.insert(channel_id, ChannelPhase::Funded(channel));
83078305
if let Some(funding_ready_for_sig_event) = funding_ready_for_sig_event_opt {
83088306
let mut pending_events = self.pending_events.lock().unwrap();
@@ -8346,7 +8344,6 @@ where
83468344
match channel_phase {
83478345
ChannelPhase::Funded(chan) => {
83488346
let (tx_signatures_opt, funding_tx_opt) = try_chan_phase_entry!(self, chan.tx_signatures(msg), chan_phase_entry);
8349-
chan.clear_next_funding_txid();
83508347
if let Some(tx_signatures) = tx_signatures_opt {
83518348
peer_state.pending_msg_events.push(events::MessageSendEvent::SendTxSignatures {
83528349
node_id: *counterparty_node_id,

0 commit comments

Comments
 (0)