@@ -1474,32 +1474,56 @@ impl<SP: Deref> Channel<SP> where
1474
1474
where
1475
1475
L::Target: Logger
1476
1476
{
1477
- let phase = core::mem::replace(&mut self.phase, ChannelPhase::Undefined);
1478
- let result = if let ChannelPhase::UnfundedV2(chan) = phase {
1477
+ let result = if let ChannelPhase::UnfundedV2(chan) = &mut self.phase {
1479
1478
let logger = WithChannelContext::from(logger, &chan.context, None);
1480
- match chan.funding_tx_constructed(signing_session, &&logger) {
1481
- Ok((chan, commitment_signed, event)) => {
1482
- self.phase = ChannelPhase::Funded(chan);
1483
- Ok((commitment_signed, event))
1484
- },
1485
- Err((chan, e)) => {
1486
- self.phase = ChannelPhase::UnfundedV2(chan);
1487
- Err(e)
1488
- },
1489
- }
1479
+ chan.funding_tx_constructed(signing_session, &&logger)
1490
1480
} else {
1491
- self.phase = phase;
1492
1481
Err(ChannelError::Warn("Got a tx_complete message with no interactive transaction construction expected or in-progress".to_owned()))
1493
1482
};
1494
1483
1495
- debug_assert!(!matches!(self.phase, ChannelPhase::Undefined));
1496
1484
result
1497
1485
}
1498
1486
1499
1487
pub fn force_shutdown(&mut self, should_broadcast: bool, closure_reason: ClosureReason) -> ShutdownResult {
1500
1488
let (funding, context) = self.funding_and_context_mut();
1501
1489
context.force_shutdown(funding, should_broadcast, closure_reason)
1502
1490
}
1491
+
1492
+ pub fn commitment_signed<L: Deref>(
1493
+ &mut self, msg: &msgs::CommitmentSigned, best_block: BestBlock, signer_provider: &SP, logger: &L
1494
+ ) -> Result<(Option<ChannelMonitor<<SP::Target as SignerProvider>::EcdsaSigner>>, Option<ChannelMonitorUpdate>), ChannelError>
1495
+ where
1496
+ L::Target: Logger
1497
+ {
1498
+ let phase = core::mem::replace(&mut self.phase, ChannelPhase::Undefined);
1499
+ match phase {
1500
+ ChannelPhase::UnfundedV2(chan) => {
1501
+ let mut funded_channel = match chan.into_funded_channel() {
1502
+ Ok(funded_channel) => funded_channel,
1503
+ Err((pending_channel, err)) => {
1504
+ self.phase = ChannelPhase::UnfundedV2(pending_channel);
1505
+ return Err(err);
1506
+ }
1507
+ };
1508
+ let res = match funded_channel.commitment_signed_initial_v2(msg, best_block, signer_provider, logger) {
1509
+ Ok(monitor) => {
1510
+ Ok((Some(monitor), None))
1511
+ },
1512
+ Err(err) => {
1513
+ Err(err)
1514
+ }
1515
+ };
1516
+ self.phase = ChannelPhase::Funded(funded_channel);
1517
+ res
1518
+ },
1519
+ ChannelPhase::Funded(mut funded_channel) => {
1520
+ let res = funded_channel.commitment_signed(msg, logger).map(|monitor_update_opt| (None, monitor_update_opt));
1521
+ self.phase = ChannelPhase::Funded(funded_channel);
1522
+ res
1523
+ },
1524
+ _ => Err(ChannelError::close("Got a commitment_signed message for an unfunded V1 channel!".into())),
1525
+ }
1526
+ }
1503
1527
}
1504
1528
1505
1529
impl<SP: Deref> From<OutboundV1Channel<SP>> for Channel<SP>
@@ -2190,8 +2214,8 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2190
2214
}
2191
2215
2192
2216
pub fn funding_tx_constructed<L: Deref>(
2193
- mut self, mut signing_session: InteractiveTxSigningSession, logger: &L
2194
- ) -> Result<(FundedChannel<SP>, msgs::CommitmentSigned, Option<Event>), (PendingV2Channel<SP>, ChannelError) >
2217
+ & mut self, mut signing_session: InteractiveTxSigningSession, logger: &L
2218
+ ) -> Result<(msgs::CommitmentSigned, Option<Event>), ChannelError>
2195
2219
where
2196
2220
L::Target: Logger
2197
2221
{
@@ -2207,7 +2231,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2207
2231
(
2208
2232
"Multiple outputs matched the expected script and value".to_owned(),
2209
2233
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
2210
- ))).map_err(|e| (self, e)) ;
2234
+ )));
2211
2235
}
2212
2236
output_index = Some(idx as u16);
2213
2237
}
@@ -2219,7 +2243,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2219
2243
(
2220
2244
"No output matched the funding script_pubkey".to_owned(),
2221
2245
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
2222
- ))).map_err(|e| (self, e)) ;
2246
+ )));
2223
2247
};
2224
2248
self.context.channel_transaction_parameters.funding_outpoint = Some(outpoint);
2225
2249
self.context.holder_signer.as_mut().provide_channel_parameters(&self.context.channel_transaction_parameters);
@@ -2233,8 +2257,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2233
2257
},
2234
2258
Err(err) => {
2235
2259
self.context.channel_transaction_parameters.funding_outpoint = None;
2236
- return Err(ChannelError::Close((err.to_string(), ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) })))
2237
- .map_err(|e| (self, e));
2260
+ return Err(ChannelError::Close((err.to_string(), ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) })));
2238
2261
},
2239
2262
};
2240
2263
@@ -2245,10 +2268,10 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2245
2268
false,
2246
2269
"Zero inputs were provided & zero witnesses were provided, but a count mismatch was somehow found",
2247
2270
);
2248
- return Err((self, ChannelError::Close((
2271
+ return Err(ChannelError::Close((
2249
2272
"V2 channel rejected due to sender error".into(),
2250
2273
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) }
2251
- )))) ;
2274
+ )));
2252
2275
}
2253
2276
None
2254
2277
} else {
@@ -2270,37 +2293,19 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2270
2293
false,
2271
2294
"We don't support users providing inputs but somehow we had more than zero inputs",
2272
2295
);
2273
- return Err((self, ChannelError::Close((
2296
+ return Err(ChannelError::Close((
2274
2297
"V2 channel rejected due to sender error".into(),
2275
2298
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) }
2276
- )))) ;
2299
+ )));
2277
2300
};
2278
2301
2279
2302
self.context.channel_state = ChannelState::FundingNegotiated;
2280
2303
2281
2304
// Clear the interactive transaction constructor
2282
2305
self.interactive_tx_constructor.take();
2306
+ self.interactive_tx_signing_session = Some(signing_session);
2283
2307
2284
- match self.unfunded_context.holder_commitment_point {
2285
- Some(holder_commitment_point) => {
2286
- let funded_chan = FundedChannel {
2287
- funding: self.funding,
2288
- context: self.context,
2289
- interactive_tx_signing_session: Some(signing_session),
2290
- holder_commitment_point,
2291
- is_v2_established: true,
2292
- };
2293
- Ok((funded_chan, commitment_signed, funding_ready_for_sig_event))
2294
- },
2295
- None => {
2296
- Err(ChannelError::close(
2297
- format!(
2298
- "Expected to have holder commitment points available upon finishing interactive tx construction for channel {}",
2299
- self.context.channel_id(),
2300
- )))
2301
- .map_err(|e| (self, e))
2302
- },
2303
- }
2308
+ Ok((commitment_signed, funding_ready_for_sig_event))
2304
2309
}
2305
2310
}
2306
2311
@@ -9527,6 +9532,8 @@ pub(super) struct PendingV2Channel<SP: Deref> where SP::Target: SignerProvider {
9527
9532
pub dual_funding_context: DualFundingChannelContext,
9528
9533
/// The current interactive transaction construction session under negotiation.
9529
9534
pub interactive_tx_constructor: Option<InteractiveTxConstructor>,
9535
+ /// The signing session created after `tx_complete` handling
9536
+ pub interactive_tx_signing_session: Option<InteractiveTxSigningSession>,
9530
9537
}
9531
9538
9532
9539
impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
@@ -9592,6 +9599,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
9592
9599
our_funding_inputs: funding_inputs,
9593
9600
},
9594
9601
interactive_tx_constructor: None,
9602
+ interactive_tx_signing_session: None,
9595
9603
};
9596
9604
Ok(chan)
9597
9605
}
@@ -9763,6 +9771,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
9763
9771
context,
9764
9772
dual_funding_context,
9765
9773
interactive_tx_constructor,
9774
+ interactive_tx_signing_session: None,
9766
9775
unfunded_context,
9767
9776
})
9768
9777
}
@@ -9840,6 +9849,25 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
9840
9849
pub fn get_accept_channel_v2_message(&self) -> msgs::AcceptChannelV2 {
9841
9850
self.generate_accept_channel_v2_message()
9842
9851
}
9852
+
9853
+ pub fn into_funded_channel(self) -> Result<FundedChannel<SP>, (PendingV2Channel<SP>, ChannelError)> {
9854
+ let holder_commitment_point = match self.unfunded_context.holder_commitment_point {
9855
+ Some(point) => point,
9856
+ None => {
9857
+ let channel_id = self.context.channel_id();
9858
+ return Err((self, ChannelError::close(
9859
+ format!("Expected to have holder commitment points available upon finishing interactive tx construction for channel {}",
9860
+ channel_id))));
9861
+ }
9862
+ };
9863
+ Ok(FundedChannel {
9864
+ funding: self.funding,
9865
+ context: self.context,
9866
+ interactive_tx_signing_session: self.interactive_tx_signing_session,
9867
+ holder_commitment_point,
9868
+ is_v2_established: true,
9869
+ })
9870
+ }
9843
9871
}
9844
9872
9845
9873
// Unfunded channel utilities
0 commit comments