@@ -1478,32 +1478,56 @@ impl<SP: Deref> Channel<SP> where
1478
1478
where
1479
1479
L::Target: Logger
1480
1480
{
1481
- let phase = core::mem::replace(&mut self.phase, ChannelPhase::Undefined);
1482
- let result = if let ChannelPhase::UnfundedV2(chan) = phase {
1481
+ let result = if let ChannelPhase::UnfundedV2(chan) = &mut self.phase {
1483
1482
let logger = WithChannelContext::from(logger, &chan.context, None);
1484
- match chan.funding_tx_constructed(signing_session, &&logger) {
1485
- Ok((chan, commitment_signed, event)) => {
1486
- self.phase = ChannelPhase::Funded(chan);
1487
- Ok((commitment_signed, event))
1488
- },
1489
- Err((chan, e)) => {
1490
- self.phase = ChannelPhase::UnfundedV2(chan);
1491
- Err(e)
1492
- },
1493
- }
1483
+ chan.funding_tx_constructed(signing_session, &&logger)
1494
1484
} else {
1495
- self.phase = phase;
1496
1485
Err(ChannelError::Warn("Got a tx_complete message with no interactive transaction construction expected or in-progress".to_owned()))
1497
1486
};
1498
1487
1499
- debug_assert!(!matches!(self.phase, ChannelPhase::Undefined));
1500
1488
result
1501
1489
}
1502
1490
1503
1491
pub fn force_shutdown(&mut self, should_broadcast: bool, closure_reason: ClosureReason) -> ShutdownResult {
1504
1492
let (funding, context) = self.funding_and_context_mut();
1505
1493
context.force_shutdown(funding, should_broadcast, closure_reason)
1506
1494
}
1495
+
1496
+ pub fn commitment_signed<L: Deref>(
1497
+ &mut self, msg: &msgs::CommitmentSigned, best_block: BestBlock, signer_provider: &SP, logger: &L
1498
+ ) -> Result<(Option<ChannelMonitor<<SP::Target as SignerProvider>::EcdsaSigner>>, Option<ChannelMonitorUpdate>), ChannelError>
1499
+ where
1500
+ L::Target: Logger
1501
+ {
1502
+ let phase = core::mem::replace(&mut self.phase, ChannelPhase::Undefined);
1503
+ match phase {
1504
+ ChannelPhase::UnfundedV2(chan) => {
1505
+ let mut funded_channel = match chan.into_funded_channel() {
1506
+ Ok(funded_channel) => funded_channel,
1507
+ Err((pending_channel, err)) => {
1508
+ self.phase = ChannelPhase::UnfundedV2(pending_channel);
1509
+ return Err(err);
1510
+ }
1511
+ };
1512
+ let res = match funded_channel.commitment_signed_initial_v2(msg, best_block, signer_provider, logger) {
1513
+ Ok(monitor) => {
1514
+ Ok((Some(monitor), None))
1515
+ },
1516
+ Err(err) => {
1517
+ Err(err)
1518
+ }
1519
+ };
1520
+ self.phase = ChannelPhase::Funded(funded_channel);
1521
+ res
1522
+ },
1523
+ ChannelPhase::Funded(mut funded_channel) => {
1524
+ let res = funded_channel.commitment_signed(msg, logger).map(|monitor_update_opt| (None, monitor_update_opt));
1525
+ self.phase = ChannelPhase::Funded(funded_channel);
1526
+ res
1527
+ },
1528
+ _ => Err(ChannelError::close("Got a commitment_signed message for an unfunded V1 channel!".into())),
1529
+ }
1530
+ }
1507
1531
}
1508
1532
1509
1533
impl<SP: Deref> From<OutboundV1Channel<SP>> for Channel<SP>
@@ -2194,8 +2218,8 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2194
2218
}
2195
2219
2196
2220
pub fn funding_tx_constructed<L: Deref>(
2197
- mut self, mut signing_session: InteractiveTxSigningSession, logger: &L
2198
- ) -> Result<(FundedChannel<SP>, msgs::CommitmentSigned, Option<Event>), (PendingV2Channel<SP>, ChannelError) >
2221
+ & mut self, mut signing_session: InteractiveTxSigningSession, logger: &L
2222
+ ) -> Result<(msgs::CommitmentSigned, Option<Event>), ChannelError>
2199
2223
where
2200
2224
L::Target: Logger
2201
2225
{
@@ -2211,7 +2235,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2211
2235
(
2212
2236
"Multiple outputs matched the expected script and value".to_owned(),
2213
2237
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
2214
- ))).map_err(|e| (self, e)) ;
2238
+ )));
2215
2239
}
2216
2240
output_index = Some(idx as u16);
2217
2241
}
@@ -2223,7 +2247,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2223
2247
(
2224
2248
"No output matched the funding script_pubkey".to_owned(),
2225
2249
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
2226
- ))).map_err(|e| (self, e)) ;
2250
+ )));
2227
2251
};
2228
2252
self.context.channel_transaction_parameters.funding_outpoint = Some(outpoint);
2229
2253
self.context.holder_signer.as_mut().provide_channel_parameters(&self.context.channel_transaction_parameters);
@@ -2237,8 +2261,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2237
2261
},
2238
2262
Err(err) => {
2239
2263
self.context.channel_transaction_parameters.funding_outpoint = None;
2240
- return Err(ChannelError::Close((err.to_string(), ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) })))
2241
- .map_err(|e| (self, e));
2264
+ return Err(ChannelError::Close((err.to_string(), ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) })));
2242
2265
},
2243
2266
};
2244
2267
@@ -2249,10 +2272,10 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2249
2272
false,
2250
2273
"Zero inputs were provided & zero witnesses were provided, but a count mismatch was somehow found",
2251
2274
);
2252
- return Err((self, ChannelError::Close((
2275
+ return Err(ChannelError::Close((
2253
2276
"V2 channel rejected due to sender error".into(),
2254
2277
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) }
2255
- )))) ;
2278
+ )));
2256
2279
}
2257
2280
None
2258
2281
} else {
@@ -2274,37 +2297,19 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2274
2297
false,
2275
2298
"We don't support users providing inputs but somehow we had more than zero inputs",
2276
2299
);
2277
- return Err((self, ChannelError::Close((
2300
+ return Err(ChannelError::Close((
2278
2301
"V2 channel rejected due to sender error".into(),
2279
2302
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) }
2280
- )))) ;
2303
+ )));
2281
2304
};
2282
2305
2283
2306
self.context.channel_state = ChannelState::FundingNegotiated;
2284
2307
2285
2308
// Clear the interactive transaction constructor
2286
2309
self.interactive_tx_constructor.take();
2310
+ self.interactive_tx_signing_session = Some(signing_session);
2287
2311
2288
- match self.unfunded_context.holder_commitment_point {
2289
- Some(holder_commitment_point) => {
2290
- let funded_chan = FundedChannel {
2291
- funding: self.funding,
2292
- context: self.context,
2293
- interactive_tx_signing_session: Some(signing_session),
2294
- holder_commitment_point,
2295
- is_v2_established: true,
2296
- };
2297
- Ok((funded_chan, commitment_signed, funding_ready_for_sig_event))
2298
- },
2299
- None => {
2300
- Err(ChannelError::close(
2301
- format!(
2302
- "Expected to have holder commitment points available upon finishing interactive tx construction for channel {}",
2303
- self.context.channel_id(),
2304
- )))
2305
- .map_err(|e| (self, e))
2306
- },
2307
- }
2312
+ Ok((commitment_signed, funding_ready_for_sig_event))
2308
2313
}
2309
2314
}
2310
2315
@@ -9511,6 +9516,8 @@ pub(super) struct PendingV2Channel<SP: Deref> where SP::Target: SignerProvider {
9511
9516
pub dual_funding_context: DualFundingChannelContext,
9512
9517
/// The current interactive transaction construction session under negotiation.
9513
9518
pub interactive_tx_constructor: Option<InteractiveTxConstructor>,
9519
+ /// The signing session created after `tx_complete` handling
9520
+ pub interactive_tx_signing_session: Option<InteractiveTxSigningSession>,
9514
9521
}
9515
9522
9516
9523
impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
@@ -9576,6 +9583,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
9576
9583
our_funding_inputs: funding_inputs,
9577
9584
},
9578
9585
interactive_tx_constructor: None,
9586
+ interactive_tx_signing_session: None,
9579
9587
};
9580
9588
Ok(chan)
9581
9589
}
@@ -9747,6 +9755,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
9747
9755
context,
9748
9756
dual_funding_context,
9749
9757
interactive_tx_constructor,
9758
+ interactive_tx_signing_session: None,
9750
9759
unfunded_context,
9751
9760
})
9752
9761
}
@@ -9824,6 +9833,25 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
9824
9833
pub fn get_accept_channel_v2_message(&self) -> msgs::AcceptChannelV2 {
9825
9834
self.generate_accept_channel_v2_message()
9826
9835
}
9836
+
9837
+ pub fn into_funded_channel(self) -> Result<FundedChannel<SP>, (PendingV2Channel<SP>, ChannelError)> {
9838
+ let holder_commitment_point = match self.unfunded_context.holder_commitment_point {
9839
+ Some(point) => point,
9840
+ None => {
9841
+ let channel_id = self.context.channel_id();
9842
+ return Err((self, ChannelError::close(
9843
+ format!("Expected to have holder commitment points available upon finishing interactive tx construction for channel {}",
9844
+ channel_id))));
9845
+ }
9846
+ };
9847
+ Ok(FundedChannel {
9848
+ funding: self.funding,
9849
+ context: self.context,
9850
+ interactive_tx_signing_session: self.interactive_tx_signing_session,
9851
+ holder_commitment_point,
9852
+ is_v2_established: true,
9853
+ })
9854
+ }
9827
9855
}
9828
9856
9829
9857
// Unfunded channel utilities
0 commit comments