@@ -4953,7 +4953,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4953
4953
return true;
4954
4954
}
4955
4955
4956
- fn check_for_funding_tx <L: Deref>(
4956
+ fn check_for_funding_tx_confirmed <L: Deref>(
4957
4957
&mut self, funding: &mut FundingScope, block_hash: &BlockHash, height: u32,
4958
4958
index_in_block: usize, tx: &mut ConfirmedTransaction, logger: &L,
4959
4959
) -> Result<bool, ClosureReason>
@@ -4968,7 +4968,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4968
4968
},
4969
4969
};
4970
4970
4971
- let mut is_confirmed_funding_tx = false;
4971
+ let mut is_funding_tx_confirmed = false;
4972
4972
4973
4973
// Check if the transaction is the expected funding transaction, and if it is,
4974
4974
// check that it pays the right amount to the right script.
@@ -5019,17 +5019,39 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
5019
5019
};
5020
5020
}
5021
5021
5022
- is_confirmed_funding_tx = true;
5022
+ is_funding_tx_confirmed = true;
5023
5023
}
5024
5024
}
5025
- for inp in tx.tx().input.iter() {
5026
- if inp.previous_output == funding_txo.into_bitcoin_outpoint() {
5027
- log_info!(logger, "Detected channel-closing tx {} spending {}:{}, closing channel {}", tx.txid(), inp.previous_output.txid, inp.previous_output.vout, &self.channel_id());
5025
+
5026
+ Ok(is_funding_tx_confirmed)
5027
+ }
5028
+
5029
+ fn check_for_funding_tx_spent<L: Deref>(
5030
+ &mut self, funding: &FundingScope, tx: &Transaction, logger: &L,
5031
+ ) -> Result<(), ClosureReason>
5032
+ where
5033
+ L::Target: Logger
5034
+ {
5035
+ let funding_txo = match funding.get_funding_txo() {
5036
+ Some(funding_txo) => funding_txo,
5037
+ None => {
5038
+ debug_assert!(false);
5039
+ return Ok(());
5040
+ },
5041
+ };
5042
+
5043
+ for input in tx.input.iter() {
5044
+ if input.previous_output == funding_txo.into_bitcoin_outpoint() {
5045
+ log_info!(
5046
+ logger, "Detected channel-closing tx {} spending {}:{}, closing channel {}",
5047
+ tx.compute_txid(), input.previous_output.txid, input.previous_output.vout,
5048
+ &self.channel_id(),
5049
+ );
5028
5050
return Err(ClosureReason::CommitmentTxConfirmed);
5029
5051
}
5030
5052
}
5031
5053
5032
- Ok(is_confirmed_funding_tx )
5054
+ Ok(() )
5033
5055
}
5034
5056
}
5035
5057
@@ -8357,11 +8379,15 @@ impl<SP: Deref> FundedChannel<SP> where
8357
8379
// If we allow 1-conf funding, we may need to check for channel_ready or splice_locked here
8358
8380
// and send it immediately instead of waiting for a best_block_updated call (which may have
8359
8381
// already happened for this block).
8360
- let is_confirmed_funding_tx = self.context.check_for_funding_tx (
8382
+ let is_funding_tx_confirmed = self.context.check_for_funding_tx_confirmed (
8361
8383
&mut self.funding, block_hash, height, index_in_block, &mut confirmed_tx, logger,
8362
8384
)?;
8363
8385
8364
- if is_confirmed_funding_tx {
8386
+ if is_funding_tx_confirmed {
8387
+ for &(_, tx) in txdata.iter() {
8388
+ self.context.check_for_funding_tx_spent(&self.funding, tx, logger)?;
8389
+ }
8390
+
8365
8391
if let Some(channel_ready) = self.check_get_channel_ready(height, logger) {
8366
8392
log_info!(logger, "Sending a channel_ready to our peer for channel {}", &self.context.channel_id);
8367
8393
let announcement_sigs = self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger);
@@ -8373,7 +8399,9 @@ impl<SP: Deref> FundedChannel<SP> where
8373
8399
let mut confirmed_funding = None;
8374
8400
#[cfg(splicing)]
8375
8401
for funding in self.pending_funding.iter_mut() {
8376
- if self.context.check_for_funding_tx(funding, block_hash, height, index_in_block, &mut confirmed_tx, logger)? {
8402
+ if self.context.check_for_funding_tx_confirmed(
8403
+ funding, block_hash, height, index_in_block, &mut confirmed_tx, logger,
8404
+ )? {
8377
8405
if confirmed_funding.is_some() {
8378
8406
let err_reason = "splice tx of another pending funding already confirmed";
8379
8407
return Err(ClosureReason::ProcessingError { err: err_reason.to_owned() });
@@ -8395,6 +8423,10 @@ impl<SP: Deref> FundedChannel<SP> where
8395
8423
},
8396
8424
};
8397
8425
8426
+ for &(_, tx) in txdata.iter() {
8427
+ self.context.check_for_funding_tx_spent(funding, tx, logger)?;
8428
+ }
8429
+
8398
8430
if let Some(splice_locked) = self.context.check_get_splice_locked(pending_splice, funding, height, logger) {
8399
8431
log_info!(logger, "Sending a splice_locked to our peer for channel {}", &self.context.channel_id);
8400
8432
@@ -8409,6 +8441,9 @@ impl<SP: Deref> FundedChannel<SP> where
8409
8441
return Ok((Some(FundingConfirmedMessage::Splice(splice_locked)), None));
8410
8442
}
8411
8443
}
8444
+
8445
+ self.context.check_for_funding_tx_spent(&self.funding, tx, logger)?;
8446
+
8412
8447
}
8413
8448
8414
8449
Ok((None, None))
0 commit comments