Skip to content

Commit ba289f6

Browse files
committed
f call begin_interactive_funding_tx_construction in InboundChannelV2::new
1 parent 83a121e commit ba289f6

File tree

2 files changed

+36
-33
lines changed

2 files changed

+36
-33
lines changed

lightning/src/ln/channel.rs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use crate::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, Channel
4747
use crate::chain::transaction::{OutPoint, TransactionData};
4848
use crate::sign::ecdsa::EcdsaChannelSigner;
4949
use crate::sign::{EntropySource, ChannelSigner, SignerProvider, NodeSigner, Recipient};
50-
use crate::events::ClosureReason;
50+
use crate::events::{ClosureReason, MessageSendEvent};
5151
use crate::routing::gossip::NodeId;
5252
use crate::util::ser::{Readable, ReadableArgs, TransactionU16LenLimited, Writeable, Writer};
5353
use crate::util::logger::{Logger, Record, WithContext};
@@ -8440,7 +8440,7 @@ impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
84408440
their_features: &InitFeatures, msg: &msgs::OpenChannelV2,
84418441
funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>, user_id: u128, config: &UserConfig,
84428442
current_chain_height: u32, logger: &L,
8443-
) -> Result<InboundV2Channel<SP>, ChannelError>
8443+
) -> Result<(InboundV2Channel<SP>, Option<MessageSendEvent>), ChannelError>
84448444
where ES::Target: EntropySource,
84458445
F::Target: FeeEstimator,
84468446
L::Target: Logger,
@@ -8501,7 +8501,7 @@ impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
85018501
&context.get_counterparty_pubkeys().revocation_basepoint);
85028502
context.channel_id = channel_id;
85038503

8504-
let chan = Self {
8504+
let mut channel = Self {
85058505
context,
85068506
unfunded_context: UnfundedChannelContext { unfunded_channel_age_ticks: 0 },
85078507
dual_funding_context: DualFundingChannelContext {
@@ -8514,7 +8514,34 @@ impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
85148514
interactive_tx_constructor: None,
85158515
};
85168516

8517-
Ok(chan)
8517+
let tx_msg_opt_res = channel.begin_interactive_funding_tx_construction(
8518+
entropy_source,
8519+
);
8520+
let pending_msg_send_event = match tx_msg_opt_res {
8521+
Ok(tx_msg_opt) => {
8522+
if let Some(tx_msg) = tx_msg_opt {
8523+
let msg_send_event = match tx_msg {
8524+
InteractiveTxMessageSend::TxAddInput(msg) => MessageSendEvent::SendTxAddInput {
8525+
node_id: channel.context.counterparty_node_id, msg },
8526+
InteractiveTxMessageSend::TxAddOutput(msg) => MessageSendEvent::SendTxAddOutput {
8527+
node_id: channel.context.counterparty_node_id, msg },
8528+
InteractiveTxMessageSend::TxComplete(msg) => MessageSendEvent::SendTxComplete {
8529+
node_id: channel.context.counterparty_node_id, msg },
8530+
};
8531+
Some(msg_send_event)
8532+
} else {
8533+
None
8534+
}
8535+
},
8536+
Err(_) => {
8537+
return Err(ChannelError::Close((
8538+
"V2 channel rejected due to sender error".into(),
8539+
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
8540+
)));
8541+
}
8542+
};
8543+
8544+
Ok((channel, pending_msg_send_event))
85188545
}
85198546

85208547
/// Marks an inbound channel as accepted and generates a [`msgs::AcceptChannelV2`] message which

lightning/src/ln/channelmanager.rs

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7016,31 +7016,11 @@ where
70167016
&open_channel_msg, funding_inputs, user_channel_id, &self.default_configuration, best_block_height,
70177017
&self.logger);
70187018
match channel_res {
7019-
Ok(mut channel) => {
7020-
let tx_msg_opt_res = channel.begin_interactive_funding_tx_construction(&self.entropy_source);
7021-
match tx_msg_opt_res {
7022-
Ok(tx_msg_opt) => {
7023-
if let Some(tx_msg) = tx_msg_opt {
7024-
let msg_send_event = match tx_msg {
7025-
InteractiveTxMessageSend::TxAddInput(msg) => events::MessageSendEvent::SendTxAddInput {
7026-
node_id: *counterparty_node_id, msg },
7027-
InteractiveTxMessageSend::TxAddOutput(msg) => events::MessageSendEvent::SendTxAddOutput {
7028-
node_id: *counterparty_node_id, msg },
7029-
InteractiveTxMessageSend::TxComplete(msg) => events::MessageSendEvent::SendTxComplete {
7030-
node_id: *counterparty_node_id, msg },
7031-
};
7032-
peer_state.pending_msg_events.push(msg_send_event);
7033-
}
7034-
Ok(ChannelPhase::UnfundedInboundV2(channel))
7035-
},
7036-
Err(_) => {
7037-
Err(MsgHandleErrInternal::from_chan_no_close(ChannelError::Close(
7038-
(
7039-
"V2 channel rejected due to sender error".into(),
7040-
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
7041-
)), *temporary_channel_id))
7042-
}
7019+
Ok((channel, msg_send_event_opt)) => {
7020+
if let Some(msg_send_event) = msg_send_event_opt {
7021+
peer_state.pending_msg_events.push(msg_send_event);
70437022
}
7023+
Ok(ChannelPhase::UnfundedInboundV2(channel))
70447024
},
70457025
Err(_) => Err(MsgHandleErrInternal::from_chan_no_close(ChannelError::Close(
70467026
(
@@ -7337,7 +7317,7 @@ where
73377317
let mut random_bytes = [0u8; 16];
73387318
random_bytes.copy_from_slice(&self.entropy_source.get_secure_random_bytes()[..16]);
73397319
let user_channel_id = u128::from_be_bytes(random_bytes);
7340-
let mut channel = match InboundV2Channel::new(&self.fee_estimator, &self.entropy_source,
7320+
let (mut channel, _) = match InboundV2Channel::new(&self.fee_estimator, &self.entropy_source,
73417321
&self.signer_provider, counterparty_node_id.clone(), &self.channel_type_features(),
73427322
&peer_state.latest_features, &msg, vec![], user_channel_id, &self.default_configuration,
73437323
best_block_height, &self.logger)
@@ -7359,10 +7339,6 @@ where
73597339
let outbound_scid_alias = self.create_and_insert_outbound_scid_alias();
73607340
channel.context.set_outbound_scid_alias(outbound_scid_alias);
73617341

7362-
channel.begin_interactive_funding_tx_construction(&self.entropy_source)
7363-
.map_err(|_| MsgHandleErrInternal::send_err_msg_no_close(
7364-
"Failed to start interactive transaction construction".to_owned(), msg.common_fields.temporary_channel_id))?;
7365-
73667342
peer_state.pending_msg_events.push(events::MessageSendEvent::SendAcceptChannelV2 {
73677343
node_id: counterparty_node_id.clone(),
73687344
msg: channel.accept_inbound_dual_funded_channel(),

0 commit comments

Comments
 (0)