Skip to content

Commit 2d1384a

Browse files
committed
f call begin_interactive_funding_tx_construction in InboundChannelV2::new
1 parent 0f8cc71 commit 2d1384a

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};
@@ -8390,7 +8390,7 @@ impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
83908390
their_features: &InitFeatures, msg: &msgs::OpenChannelV2,
83918391
funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>, user_id: u128, config: &UserConfig,
83928392
current_chain_height: u32, logger: &L,
8393-
) -> Result<InboundV2Channel<SP>, ChannelError>
8393+
) -> Result<(InboundV2Channel<SP>, Option<MessageSendEvent>), ChannelError>
83948394
where ES::Target: EntropySource,
83958395
F::Target: FeeEstimator,
83968396
L::Target: Logger,
@@ -8451,7 +8451,7 @@ impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
84518451
&context.get_counterparty_pubkeys().revocation_basepoint);
84528452
context.channel_id = channel_id;
84538453

8454-
let chan = Self {
8454+
let mut channel = Self {
84558455
context,
84568456
unfunded_context: UnfundedChannelContext { unfunded_channel_age_ticks: 0 },
84578457
dual_funding_context: DualFundingChannelContext {
@@ -8464,7 +8464,34 @@ impl<SP: Deref> InboundV2Channel<SP> where SP::Target: SignerProvider {
84648464
interactive_tx_constructor: None,
84658465
};
84668466

8467-
Ok(chan)
8467+
let tx_msg_opt_res = channel.begin_interactive_funding_tx_construction(
8468+
entropy_source,
8469+
);
8470+
let pending_msg_send_event = match tx_msg_opt_res {
8471+
Ok(tx_msg_opt) => {
8472+
if let Some(tx_msg) = tx_msg_opt {
8473+
let msg_send_event = match tx_msg {
8474+
InteractiveTxMessageSend::TxAddInput(msg) => MessageSendEvent::SendTxAddInput {
8475+
node_id: channel.context.counterparty_node_id, msg },
8476+
InteractiveTxMessageSend::TxAddOutput(msg) => MessageSendEvent::SendTxAddOutput {
8477+
node_id: channel.context.counterparty_node_id, msg },
8478+
InteractiveTxMessageSend::TxComplete(msg) => MessageSendEvent::SendTxComplete {
8479+
node_id: channel.context.counterparty_node_id, msg },
8480+
};
8481+
Some(msg_send_event)
8482+
} else {
8483+
None
8484+
}
8485+
},
8486+
Err(_) => {
8487+
return Err(ChannelError::Close((
8488+
"V2 channel rejected due to sender error".into(),
8489+
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
8490+
)));
8491+
}
8492+
};
8493+
8494+
Ok((channel, pending_msg_send_event))
84688495
}
84698496

84708497
/// 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
@@ -6793,31 +6793,11 @@ where
67936793
&open_channel_msg, funding_inputs, user_channel_id, &self.default_configuration, best_block_height,
67946794
&self.logger);
67956795
match channel_res {
6796-
Ok(mut channel) => {
6797-
let tx_msg_opt_res = channel.begin_interactive_funding_tx_construction(&self.entropy_source);
6798-
match tx_msg_opt_res {
6799-
Ok(tx_msg_opt) => {
6800-
if let Some(tx_msg) = tx_msg_opt {
6801-
let msg_send_event = match tx_msg {
6802-
InteractiveTxMessageSend::TxAddInput(msg) => events::MessageSendEvent::SendTxAddInput {
6803-
node_id: *counterparty_node_id, msg },
6804-
InteractiveTxMessageSend::TxAddOutput(msg) => events::MessageSendEvent::SendTxAddOutput {
6805-
node_id: *counterparty_node_id, msg },
6806-
InteractiveTxMessageSend::TxComplete(msg) => events::MessageSendEvent::SendTxComplete {
6807-
node_id: *counterparty_node_id, msg },
6808-
};
6809-
peer_state.pending_msg_events.push(msg_send_event);
6810-
}
6811-
Ok(ChannelPhase::UnfundedInboundV2(channel))
6812-
},
6813-
Err(_) => {
6814-
Err(MsgHandleErrInternal::from_chan_no_close(ChannelError::Close(
6815-
(
6816-
"V2 channel rejected due to sender error".into(),
6817-
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
6818-
)), *temporary_channel_id))
6819-
}
6796+
Ok((channel, msg_send_event_opt)) => {
6797+
if let Some(msg_send_event) = msg_send_event_opt {
6798+
peer_state.pending_msg_events.push(msg_send_event);
68206799
}
6800+
Ok(ChannelPhase::UnfundedInboundV2(channel))
68216801
},
68226802
Err(_) => Err(MsgHandleErrInternal::from_chan_no_close(ChannelError::Close(
68236803
(
@@ -7114,7 +7094,7 @@ where
71147094
let mut random_bytes = [0u8; 16];
71157095
random_bytes.copy_from_slice(&self.entropy_source.get_secure_random_bytes()[..16]);
71167096
let user_channel_id = u128::from_be_bytes(random_bytes);
7117-
let mut channel = match InboundV2Channel::new(&self.fee_estimator, &self.entropy_source,
7097+
let (mut channel, _) = match InboundV2Channel::new(&self.fee_estimator, &self.entropy_source,
71187098
&self.signer_provider, counterparty_node_id.clone(), &self.channel_type_features(),
71197099
&peer_state.latest_features, &msg, vec![], user_channel_id, &self.default_configuration,
71207100
best_block_height, &self.logger)
@@ -7136,10 +7116,6 @@ where
71367116
let outbound_scid_alias = self.create_and_insert_outbound_scid_alias();
71377117
channel.context.set_outbound_scid_alias(outbound_scid_alias);
71387118

7139-
channel.begin_interactive_funding_tx_construction(&self.entropy_source)
7140-
.map_err(|_| MsgHandleErrInternal::send_err_msg_no_close(
7141-
"Failed to start interactive transaction construction".to_owned(), msg.common_fields.temporary_channel_id))?;
7142-
71437119
peer_state.pending_msg_events.push(events::MessageSendEvent::SendAcceptChannelV2 {
71447120
node_id: counterparty_node_id.clone(),
71457121
msg: channel.accept_inbound_dual_funded_channel(),

0 commit comments

Comments
 (0)