@@ -1412,27 +1412,51 @@ impl<SP: Deref> Channel<SP> where
1412
1412
where
1413
1413
L::Target: Logger
1414
1414
{
1415
- let phase = core::mem::replace(&mut self.phase, ChannelPhase::Undefined);
1416
- let result = if let ChannelPhase::UnfundedV2(chan) = phase {
1415
+ let result = if let ChannelPhase::UnfundedV2(chan) = &mut self.phase {
1417
1416
let logger = WithChannelContext::from(logger, &chan.context, None);
1418
- match chan.funding_tx_constructed(signing_session, &&logger) {
1419
- Ok((chan, commitment_signed, event)) => {
1420
- self.phase = ChannelPhase::Funded(chan);
1421
- Ok((commitment_signed, event))
1422
- },
1423
- Err((chan, e)) => {
1424
- self.phase = ChannelPhase::UnfundedV2(chan);
1425
- Err(e)
1426
- },
1427
- }
1417
+ chan.funding_tx_constructed(signing_session, &&logger)
1428
1418
} else {
1429
- self.phase = phase;
1430
1419
Err(ChannelError::Warn("Got a tx_complete message with no interactive transaction construction expected or in-progress".to_owned()))
1431
1420
};
1432
1421
1433
- debug_assert!(!matches!(self.phase, ChannelPhase::Undefined));
1434
1422
result
1435
1423
}
1424
+
1425
+ pub fn commitment_signed<L: Deref>(
1426
+ &mut self, msg: &msgs::CommitmentSigned, best_block: BestBlock, signer_provider: &SP, logger: &L
1427
+ ) -> Result<(Option<ChannelMonitor<<SP::Target as SignerProvider>::EcdsaSigner>>, Option<ChannelMonitorUpdate>), ChannelError>
1428
+ where
1429
+ L::Target: Logger
1430
+ {
1431
+ let phase = core::mem::replace(&mut self.phase, ChannelPhase::Undefined);
1432
+ match phase {
1433
+ ChannelPhase::UnfundedV2(chan) => {
1434
+ let mut funded_channel = match chan.into_funded_channel() {
1435
+ Ok(funded_channel) => funded_channel,
1436
+ Err((pending_channel, err)) => {
1437
+ self.phase = ChannelPhase::UnfundedV2(pending_channel);
1438
+ return Err(err);
1439
+ }
1440
+ };
1441
+ let res = match funded_channel.commitment_signed_initial_v2(msg, best_block, signer_provider, logger) {
1442
+ Ok(monitor) => {
1443
+ Ok((Some(monitor), None))
1444
+ },
1445
+ Err(err) => {
1446
+ Err(err)
1447
+ }
1448
+ };
1449
+ self.phase = ChannelPhase::Funded(funded_channel);
1450
+ res
1451
+ },
1452
+ ChannelPhase::Funded(mut funded_channel) => {
1453
+ let res = funded_channel.commitment_signed(msg, logger).map(|monitor_update_opt| (None, monitor_update_opt));
1454
+ self.phase = ChannelPhase::Funded(funded_channel);
1455
+ res
1456
+ },
1457
+ _ => Err(ChannelError::close("Got a commitment_signed message for an unfunded V1 channel!".into())),
1458
+ }
1459
+ }
1436
1460
}
1437
1461
1438
1462
impl<SP: Deref> From<OutboundV1Channel<SP>> for Channel<SP>
@@ -2074,8 +2098,8 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2074
2098
}
2075
2099
2076
2100
pub fn funding_tx_constructed<L: Deref>(
2077
- mut self, mut signing_session: InteractiveTxSigningSession, logger: &L
2078
- ) -> Result<(FundedChannel<SP>, msgs::CommitmentSigned, Option<Event>), (PendingV2Channel<SP>, ChannelError) >
2101
+ & mut self, mut signing_session: InteractiveTxSigningSession, logger: &L
2102
+ ) -> Result<(msgs::CommitmentSigned, Option<Event>), ChannelError>
2079
2103
where
2080
2104
L::Target: Logger
2081
2105
{
@@ -2091,7 +2115,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2091
2115
(
2092
2116
"Multiple outputs matched the expected script and value".to_owned(),
2093
2117
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
2094
- ))).map_err(|e| (self, e)) ;
2118
+ )));
2095
2119
}
2096
2120
output_index = Some(idx as u16);
2097
2121
}
@@ -2103,7 +2127,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2103
2127
(
2104
2128
"No output matched the funding script_pubkey".to_owned(),
2105
2129
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
2106
- ))).map_err(|e| (self, e)) ;
2130
+ )));
2107
2131
};
2108
2132
self.context.channel_transaction_parameters.funding_outpoint = Some(outpoint);
2109
2133
self.context.holder_signer.as_mut().provide_channel_parameters(&self.context.channel_transaction_parameters);
@@ -2117,8 +2141,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2117
2141
},
2118
2142
Err(err) => {
2119
2143
self.context.channel_transaction_parameters.funding_outpoint = None;
2120
- return Err(ChannelError::Close((err.to_string(), ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) })))
2121
- .map_err(|e| (self, e));
2144
+ return Err(ChannelError::Close((err.to_string(), ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) })));
2122
2145
},
2123
2146
};
2124
2147
@@ -2129,10 +2152,10 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2129
2152
false,
2130
2153
"Zero inputs were provided & zero witnesses were provided, but a count mismatch was somehow found",
2131
2154
);
2132
- return Err((self, ChannelError::Close((
2155
+ return Err(ChannelError::Close((
2133
2156
"V2 channel rejected due to sender error".into(),
2134
2157
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) }
2135
- )))) ;
2158
+ )));
2136
2159
}
2137
2160
None
2138
2161
} else {
@@ -2154,36 +2177,19 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2154
2177
false,
2155
2178
"We don't support users providing inputs but somehow we had more than zero inputs",
2156
2179
);
2157
- return Err((self, ChannelError::Close((
2180
+ return Err(ChannelError::Close((
2158
2181
"V2 channel rejected due to sender error".into(),
2159
2182
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) }
2160
- )))) ;
2183
+ )));
2161
2184
};
2162
2185
2163
2186
self.context.channel_state = ChannelState::FundingNegotiated;
2164
2187
2165
2188
// Clear the interactive transaction constructor
2166
2189
self.interactive_tx_constructor.take();
2190
+ self.interactive_tx_signing_session = Some(signing_session);
2167
2191
2168
- match self.unfunded_context.holder_commitment_point {
2169
- Some(holder_commitment_point) => {
2170
- let funded_chan = FundedChannel {
2171
- context: self.context,
2172
- interactive_tx_signing_session: Some(signing_session),
2173
- holder_commitment_point,
2174
- is_v2_established: true,
2175
- };
2176
- Ok((funded_chan, commitment_signed, funding_ready_for_sig_event))
2177
- },
2178
- None => {
2179
- Err(ChannelError::close(
2180
- format!(
2181
- "Expected to have holder commitment points available upon finishing interactive tx construction for channel {}",
2182
- self.context.channel_id(),
2183
- )))
2184
- .map_err(|e| (self, e))
2185
- },
2186
- }
2192
+ Ok((commitment_signed, funding_ready_for_sig_event))
2187
2193
}
2188
2194
}
2189
2195
@@ -9093,6 +9099,8 @@ pub(super) struct PendingV2Channel<SP: Deref> where SP::Target: SignerProvider {
9093
9099
pub dual_funding_context: DualFundingChannelContext,
9094
9100
/// The current interactive transaction construction session under negotiation.
9095
9101
pub interactive_tx_constructor: Option<InteractiveTxConstructor>,
9102
+ /// The signing session created after `tx_complete` handling
9103
+ pub interactive_tx_signing_session: Option<InteractiveTxSigningSession>,
9096
9104
}
9097
9105
9098
9106
impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
@@ -9157,6 +9165,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
9157
9165
our_funding_inputs: funding_inputs,
9158
9166
},
9159
9167
interactive_tx_constructor: None,
9168
+ interactive_tx_signing_session: None,
9160
9169
};
9161
9170
Ok(chan)
9162
9171
}
@@ -9327,6 +9336,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
9327
9336
context,
9328
9337
dual_funding_context,
9329
9338
interactive_tx_constructor,
9339
+ interactive_tx_signing_session: None,
9330
9340
unfunded_context,
9331
9341
})
9332
9342
}
@@ -9404,6 +9414,24 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
9404
9414
pub fn get_accept_channel_v2_message(&self) -> msgs::AcceptChannelV2 {
9405
9415
self.generate_accept_channel_v2_message()
9406
9416
}
9417
+
9418
+ pub fn into_funded_channel(self) -> Result<FundedChannel<SP>, (PendingV2Channel<SP>, ChannelError)> {
9419
+ let holder_commitment_point = match self.unfunded_context.holder_commitment_point {
9420
+ Some(point) => point,
9421
+ None => {
9422
+ let channel_id = self.context.channel_id();
9423
+ return Err((self, ChannelError::close(
9424
+ format!("Expected to have holder commitment points available upon finishing interactive tx construction for channel {}",
9425
+ channel_id))));
9426
+ }
9427
+ };
9428
+ Ok(FundedChannel {
9429
+ context: self.context,
9430
+ interactive_tx_signing_session: self.interactive_tx_signing_session,
9431
+ holder_commitment_point,
9432
+ is_v2_established: true,
9433
+ })
9434
+ }
9407
9435
}
9408
9436
9409
9437
// Unfunded channel utilities
0 commit comments