@@ -1478,32 +1478,67 @@ 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
+ 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
- };
1498
-
1499
- debug_assert!(!matches!(self.phase, ChannelPhase::Undefined));
1500
- result
1486
+ }
1501
1487
}
1502
1488
1503
1489
pub fn force_shutdown(&mut self, should_broadcast: bool, closure_reason: ClosureReason) -> ShutdownResult {
1504
1490
let (funding, context) = self.funding_and_context_mut();
1505
1491
context.force_shutdown(funding, should_broadcast, closure_reason)
1506
1492
}
1493
+
1494
+ pub fn commitment_signed<L: Deref>(
1495
+ &mut self, msg: &msgs::CommitmentSigned, best_block: BestBlock, signer_provider: &SP, logger: &L
1496
+ ) -> Result<(Option<ChannelMonitor<<SP::Target as SignerProvider>::EcdsaSigner>>, Option<ChannelMonitorUpdate>), ChannelError>
1497
+ where
1498
+ L::Target: Logger
1499
+ {
1500
+ let phase = core::mem::replace(&mut self.phase, ChannelPhase::Undefined);
1501
+ match phase {
1502
+ ChannelPhase::UnfundedV2(chan) => {
1503
+ let holder_commitment_point = match chan.unfunded_context.holder_commitment_point {
1504
+ Some(point) => point,
1505
+ None => {
1506
+ let channel_id = chan.context.channel_id();
1507
+ // TODO(dual_funding): Add async signing support.
1508
+ return Err( ChannelError::close(
1509
+ format!("Expected to have holder commitment points available upon finishing interactive tx construction for channel {}",
1510
+ channel_id)));
1511
+ }
1512
+ };
1513
+ let mut funded_channel = FundedChannel {
1514
+ funding: chan.funding,
1515
+ context: chan.context,
1516
+ interactive_tx_signing_session: chan.interactive_tx_signing_session,
1517
+ holder_commitment_point,
1518
+ is_v2_established: true,
1519
+ };
1520
+ let res = funded_channel.commitment_signed_initial_v2(msg, best_block, signer_provider, logger)
1521
+ .map(|monitor| (Some(monitor), None))
1522
+ // TODO: Change to `inspect_err` when MSRV is high enough.
1523
+ .map_err(|err| {
1524
+ // We always expect a `ChannelError` close.
1525
+ debug_assert!(matches!(err, ChannelError::Close(_)));
1526
+ err
1527
+ });
1528
+ self.phase = ChannelPhase::Funded(funded_channel);
1529
+ res
1530
+ },
1531
+ ChannelPhase::Funded(mut funded_channel) => {
1532
+ let res = funded_channel.commitment_signed(msg, logger).map(|monitor_update_opt| (None, monitor_update_opt));
1533
+ self.phase = ChannelPhase::Funded(funded_channel);
1534
+ res
1535
+ },
1536
+ _ => {
1537
+ debug_assert!(!matches!(self.phase, ChannelPhase::Undefined));
1538
+ Err(ChannelError::close("Got a commitment_signed message for an unfunded V1 channel!".into()))
1539
+ }
1540
+ }
1541
+ }
1507
1542
}
1508
1543
1509
1544
impl<SP: Deref> From<OutboundV1Channel<SP>> for Channel<SP>
@@ -2194,8 +2229,8 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2194
2229
}
2195
2230
2196
2231
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) >
2232
+ & mut self, mut signing_session: InteractiveTxSigningSession, logger: &L
2233
+ ) -> Result<(msgs::CommitmentSigned, Option<Event>), ChannelError>
2199
2234
where
2200
2235
L::Target: Logger
2201
2236
{
@@ -2211,7 +2246,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2211
2246
(
2212
2247
"Multiple outputs matched the expected script and value".to_owned(),
2213
2248
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
2214
- ))).map_err(|e| (self, e)) ;
2249
+ )));
2215
2250
}
2216
2251
output_index = Some(idx as u16);
2217
2252
}
@@ -2223,7 +2258,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2223
2258
(
2224
2259
"No output matched the funding script_pubkey".to_owned(),
2225
2260
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
2226
- ))).map_err(|e| (self, e)) ;
2261
+ )));
2227
2262
};
2228
2263
self.context.channel_transaction_parameters.funding_outpoint = Some(outpoint);
2229
2264
self.context.holder_signer.as_mut().provide_channel_parameters(&self.context.channel_transaction_parameters);
@@ -2237,8 +2272,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2237
2272
},
2238
2273
Err(err) => {
2239
2274
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));
2275
+ return Err(ChannelError::Close((err.to_string(), ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) })));
2242
2276
},
2243
2277
};
2244
2278
@@ -2249,10 +2283,10 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2249
2283
false,
2250
2284
"Zero inputs were provided & zero witnesses were provided, but a count mismatch was somehow found",
2251
2285
);
2252
- return Err((self, ChannelError::Close((
2286
+ return Err(ChannelError::Close((
2253
2287
"V2 channel rejected due to sender error".into(),
2254
2288
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) }
2255
- )))) ;
2289
+ )));
2256
2290
}
2257
2291
None
2258
2292
} else {
@@ -2274,37 +2308,19 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2274
2308
false,
2275
2309
"We don't support users providing inputs but somehow we had more than zero inputs",
2276
2310
);
2277
- return Err((self, ChannelError::Close((
2311
+ return Err(ChannelError::Close((
2278
2312
"V2 channel rejected due to sender error".into(),
2279
2313
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) }
2280
- )))) ;
2314
+ )));
2281
2315
};
2282
2316
2283
2317
self.context.channel_state = ChannelState::FundingNegotiated;
2284
2318
2285
2319
// Clear the interactive transaction constructor
2286
2320
self.interactive_tx_constructor.take();
2321
+ self.interactive_tx_signing_session = Some(signing_session);
2287
2322
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
- }
2323
+ Ok((commitment_signed, funding_ready_for_sig_event))
2308
2324
}
2309
2325
}
2310
2326
@@ -9511,6 +9527,8 @@ pub(super) struct PendingV2Channel<SP: Deref> where SP::Target: SignerProvider {
9511
9527
pub dual_funding_context: DualFundingChannelContext,
9512
9528
/// The current interactive transaction construction session under negotiation.
9513
9529
pub interactive_tx_constructor: Option<InteractiveTxConstructor>,
9530
+ /// The signing session created after `tx_complete` handling
9531
+ pub interactive_tx_signing_session: Option<InteractiveTxSigningSession>,
9514
9532
}
9515
9533
9516
9534
impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
@@ -9576,6 +9594,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
9576
9594
our_funding_inputs: funding_inputs,
9577
9595
},
9578
9596
interactive_tx_constructor: None,
9597
+ interactive_tx_signing_session: None,
9579
9598
};
9580
9599
Ok(chan)
9581
9600
}
@@ -9747,6 +9766,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
9747
9766
context,
9748
9767
dual_funding_context,
9749
9768
interactive_tx_constructor,
9769
+ interactive_tx_signing_session: None,
9750
9770
unfunded_context,
9751
9771
})
9752
9772
}
0 commit comments