Skip to content

Commit 1386bec

Browse files
committed
f - fix test_funding_and_commitment_tx_confirm_same_block
1 parent 9477d43 commit 1386bec

File tree

1 file changed

+45
-10
lines changed

1 file changed

+45
-10
lines changed

lightning/src/ln/channel.rs

+45-10
Original file line numberDiff line numberDiff line change
@@ -4953,7 +4953,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
49534953
return true;
49544954
}
49554955

4956-
fn check_for_funding_tx<L: Deref>(
4956+
fn check_for_funding_tx_confirmed<L: Deref>(
49574957
&mut self, funding: &mut FundingScope, block_hash: &BlockHash, height: u32,
49584958
index_in_block: usize, tx: &mut ConfirmedTransaction, logger: &L,
49594959
) -> Result<bool, ClosureReason>
@@ -4968,7 +4968,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
49684968
},
49694969
};
49704970

4971-
let mut is_confirmed_funding_tx = false;
4971+
let mut is_funding_tx_confirmed = false;
49724972

49734973
// Check if the transaction is the expected funding transaction, and if it is,
49744974
// check that it pays the right amount to the right script.
@@ -5019,17 +5019,39 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
50195019
};
50205020
}
50215021

5022-
is_confirmed_funding_tx = true;
5022+
is_funding_tx_confirmed = true;
50235023
}
50245024
}
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+
);
50285050
return Err(ClosureReason::CommitmentTxConfirmed);
50295051
}
50305052
}
50315053

5032-
Ok(is_confirmed_funding_tx)
5054+
Ok(())
50335055
}
50345056
}
50355057

@@ -8357,11 +8379,15 @@ impl<SP: Deref> FundedChannel<SP> where
83578379
// If we allow 1-conf funding, we may need to check for channel_ready or splice_locked here
83588380
// and send it immediately instead of waiting for a best_block_updated call (which may have
83598381
// 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(
83618383
&mut self.funding, block_hash, height, index_in_block, &mut confirmed_tx, logger,
83628384
)?;
83638385

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+
83658391
if let Some(channel_ready) = self.check_get_channel_ready(height, logger) {
83668392
log_info!(logger, "Sending a channel_ready to our peer for channel {}", &self.context.channel_id);
83678393
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
83738399
let mut confirmed_funding = None;
83748400
#[cfg(splicing)]
83758401
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+
)? {
83778405
if confirmed_funding.is_some() {
83788406
let err_reason = "splice tx of another pending funding already confirmed";
83798407
return Err(ClosureReason::ProcessingError { err: err_reason.to_owned() });
@@ -8395,6 +8423,10 @@ impl<SP: Deref> FundedChannel<SP> where
83958423
},
83968424
};
83978425

8426+
for &(_, tx) in txdata.iter() {
8427+
self.context.check_for_funding_tx_spent(funding, tx, logger)?;
8428+
}
8429+
83988430
if let Some(splice_locked) = self.context.check_get_splice_locked(pending_splice, funding, height, logger) {
83998431
log_info!(logger, "Sending a splice_locked to our peer for channel {}", &self.context.channel_id);
84008432

@@ -8409,6 +8441,9 @@ impl<SP: Deref> FundedChannel<SP> where
84098441
return Ok((Some(FundingConfirmedMessage::Splice(splice_locked)), None));
84108442
}
84118443
}
8444+
8445+
self.context.check_for_funding_tx_spent(&self.funding, tx, logger)?;
8446+
84128447
}
84138448

84148449
Ok((None, None))

0 commit comments

Comments
 (0)