@@ -1276,7 +1276,9 @@ impl OutboundContext {
1276
1276
}
1277
1277
}
1278
1278
1279
- struct FundingTransaction {
1279
+ /// Represents a funding transaction used in the establishment [`Channel`]
1280
+ #[derive(Clone)]
1281
+ pub struct FundingTransaction {
1280
1282
funding_transaction: Transaction,
1281
1283
outpoint: OutPoint,
1282
1284
is_batch_funding: bool,
@@ -7316,6 +7318,27 @@ impl<SP: Deref> Channel<SP> where
7316
7318
}
7317
7319
}
7318
7320
7321
+ /// Represents whether the associated [`FundingTransaction`] instance is newly created
7322
+ /// or was generated during a previous channel handshake.
7323
+ #[allow(unused)]
7324
+ pub enum TransactionEnum {
7325
+ New(FundingTransaction),
7326
+ Old(FundingTransaction),
7327
+ }
7328
+
7329
+ impl TransactionEnum {
7330
+ /// Creates a new `TransactionEnum::New` variant representing a newly created funding transaction.
7331
+ pub fn new_funding_transaction(transaction: Transaction, txo: OutPoint, is_batch_funding: bool) -> Self {
7332
+ TransactionEnum::New(
7333
+ FundingTransaction {
7334
+ funding_transaction: transaction,
7335
+ outpoint: txo,
7336
+ is_batch_funding
7337
+ }
7338
+ )
7339
+ }
7340
+ }
7341
+
7319
7342
/// A not-yet-funded outbound (from holder) channel using V1 channel establishment.
7320
7343
pub(super) struct OutboundV1Channel<SP: Deref> where SP::Target: SignerProvider {
7321
7344
pub context: ChannelContext<SP>,
@@ -7408,7 +7431,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
7408
7431
/// Note that channel_id changes during this call!
7409
7432
/// Do NOT broadcast the funding transaction until after a successful funding_signed call!
7410
7433
/// If an Err is returned, it is a ChannelError::Close.
7411
- pub fn get_funding_created<L: Deref>(&mut self, funding_transaction: Transaction, funding_txo: OutPoint, is_batch_funding: bool , logger: &L)
7434
+ pub fn get_funding_created<L: Deref>(&mut self, transaction: TransactionEnum , logger: &L)
7412
7435
-> Result<Option<msgs::FundingCreated>, (Self, ChannelError)> where L::Target: Logger {
7413
7436
if !self.context.is_outbound() {
7414
7437
panic!("Tried to create outbound funding_created message on an inbound channel!");
@@ -7425,6 +7448,39 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
7425
7448
panic!("Should not have advanced channel commitment tx numbers prior to funding_created");
7426
7449
}
7427
7450
7451
+ let (funding_transaction, funding_txo, is_batch_funding) = match transaction {
7452
+ TransactionEnum::New(tx) => {
7453
+ self.outbound_context.created_funding_transaction = Some(tx.clone());
7454
+ (tx.funding_transaction, tx.outpoint, tx.is_batch_funding)
7455
+ },
7456
+ TransactionEnum::Old(tx) => {
7457
+ // Sanity checks
7458
+ if self.context.channel_id != ChannelId::v1_from_funding_outpoint(tx.outpoint) {
7459
+ panic!("Previously saved funding_transaction in channel parameter does not match funding_txo saved in outbound channel parameters.")
7460
+ }
7461
+ if self.context.funding_transaction != Some(tx.funding_transaction) {
7462
+ panic!("Previously saved funding_transaction in channel parameter does not match funding_transaction saved in outbound channel parameters.")
7463
+ }
7464
+ if self.context.is_batch_funding != Some(()).filter(|_| tx.is_batch_funding) {
7465
+ panic!("Previously saved funding_transaction in channel parameter does not match is_batch_funding saved in outbound channel parameters.")
7466
+ }
7467
+
7468
+ let funding_created = self.get_funding_created_msg(logger);
7469
+ if funding_created.is_none() {
7470
+ #[cfg(not(async_signing))] {
7471
+ panic!("Failed to get signature for new funding creation");
7472
+ }
7473
+ #[cfg(async_signing)] {
7474
+ if !self.context.signer_pending_funding {
7475
+ log_trace!(logger, "funding_created awaiting signer; setting signer_pending_funding");
7476
+ self.context.signer_pending_funding = true;
7477
+ }
7478
+ }
7479
+ }
7480
+ return Ok(funding_created);
7481
+ }
7482
+ };
7483
+
7428
7484
self.context.channel_transaction_parameters.funding_outpoint = Some(funding_txo);
7429
7485
self.context.holder_signer.as_mut().provide_channel_parameters(&self.context.channel_transaction_parameters);
7430
7486
@@ -9382,7 +9438,7 @@ mod tests {
9382
9438
use crate::ln::{PaymentHash, PaymentPreimage};
9383
9439
use crate::ln::channel_keys::{RevocationKey, RevocationBasepoint};
9384
9440
use crate::ln::channelmanager::{self, HTLCSource, PaymentId};
9385
- use crate::ln::channel::InitFeatures;
9441
+ use crate::ln::channel::{ InitFeatures, TransactionEnum} ;
9386
9442
use crate::ln::channel::{AwaitingChannelReadyFlags, Channel, ChannelState, InboundHTLCOutput, OutboundV1Channel, InboundV1Channel, OutboundHTLCOutput, InboundHTLCState, OutboundHTLCState, HTLCCandidate, HTLCInitiator, HTLCUpdateAwaitingACK, commit_tx_fee_msat};
9387
9443
use crate::ln::channel::{MAX_FUNDING_SATOSHIS_NO_WUMBO, TOTAL_BITCOIN_SUPPLY_SATOSHIS, MIN_THEIR_CHAN_RESERVE_SATOSHIS};
9388
9444
use crate::ln::features::{ChannelFeatures, ChannelTypeFeatures, NodeFeatures};
@@ -9568,7 +9624,9 @@ mod tests {
9568
9624
value: 10000000, script_pubkey: output_script.clone(),
9569
9625
}]};
9570
9626
let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 };
9571
- let funding_created_msg = node_a_chan.get_funding_created(tx.clone(), funding_outpoint, false, &&logger).map_err(|_| ()).unwrap();
9627
+
9628
+ let funding_transaction = TransactionEnum::new_funding_transaction(tx, funding_outpoint, false);
9629
+ let funding_created_msg = node_a_chan.get_funding_created(funding_transaction, &&logger).map_err(|_| ()).unwrap();
9572
9630
let (_, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg.unwrap(), best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
9573
9631
9574
9632
// Node B --> Node A: funding signed
@@ -9697,7 +9755,8 @@ mod tests {
9697
9755
value: 10000000, script_pubkey: output_script.clone(),
9698
9756
}]};
9699
9757
let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 };
9700
- let funding_created_msg = node_a_chan.get_funding_created(tx.clone(), funding_outpoint, false, &&logger).map_err(|_| ()).unwrap();
9758
+ let transaction = TransactionEnum::new_funding_transaction(tx, funding_outpoint, false);
9759
+ let funding_created_msg = node_a_chan.get_funding_created(transaction, &&logger).map_err(|_| ()).unwrap();
9701
9760
let (mut node_b_chan, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg.unwrap(), best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
9702
9761
9703
9762
// Node B --> Node A: funding signed
@@ -9886,7 +9945,8 @@ mod tests {
9886
9945
value: 10000000, script_pubkey: output_script.clone(),
9887
9946
}]};
9888
9947
let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 };
9889
- let funding_created_msg = node_a_chan.get_funding_created(tx.clone(), funding_outpoint, false, &&logger).map_err(|_| ()).unwrap();
9948
+ let transaction = TransactionEnum::new_funding_transaction(tx.clone(), funding_outpoint, false);
9949
+ let funding_created_msg = node_a_chan.get_funding_created(transaction, &&logger).map_err(|_| ()).unwrap();
9890
9950
let (_, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg.unwrap(), best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
9891
9951
9892
9952
// Node B --> Node A: funding signed
@@ -9953,7 +10013,8 @@ mod tests {
9953
10013
value: 10000000, script_pubkey: outbound_chan.context.get_funding_redeemscript(),
9954
10014
}]};
9955
10015
let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 };
9956
- let funding_created = outbound_chan.get_funding_created(tx.clone(), funding_outpoint, false, &&logger).map_err(|_| ()).unwrap().unwrap();
10016
+ let transaction = TransactionEnum::new_funding_transaction(tx.clone(), funding_outpoint, false);
10017
+ let funding_created = outbound_chan.get_funding_created(transaction, &&logger).map_err(|_| ()).unwrap().unwrap();
9957
10018
let mut chan = match inbound_chan.funding_created(&funding_created, best_block, &&keys_provider, &&logger) {
9958
10019
Ok((chan, _, _)) => chan,
9959
10020
Err((_, e)) => panic!("{}", e),
@@ -11085,8 +11146,9 @@ mod tests {
11085
11146
},
11086
11147
]};
11087
11148
let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 };
11149
+ let transaction = TransactionEnum::new_funding_transaction(tx.clone(), funding_outpoint, true);
11088
11150
let funding_created_msg = node_a_chan.get_funding_created(
11089
- tx.clone(), funding_outpoint, true , &&logger,
11151
+ transaction , &&logger,
11090
11152
).map_err(|_| ()).unwrap();
11091
11153
let (mut node_b_chan, funding_signed_msg, _) = node_b_chan.funding_created(
11092
11154
&funding_created_msg.unwrap(),
0 commit comments