Skip to content

Commit d5a7051

Browse files
committed
Remove unnecessary FundedChannel::pending_splice checks
Now that PendingFunding directly contains the negotiated candidates, some unnecessary checks can be removed.
1 parent 152f6ef commit d5a7051

File tree

1 file changed

+77
-93
lines changed

1 file changed

+77
-93
lines changed

lightning/src/ln/channel.rs

Lines changed: 77 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -10623,12 +10623,11 @@ where
1062310623
}
1062410624
}
1062510625

10626-
#[cfg(splicing)]
10627-
let mut confirmed_funding_index = None;
10628-
#[cfg(splicing)]
10629-
let mut funding_already_confirmed = false;
1063010626
#[cfg(splicing)]
1063110627
if let Some(pending_splice) = &mut self.pending_splice {
10628+
let mut confirmed_funding_index = None;
10629+
let mut funding_already_confirmed = false;
10630+
1063210631
for (index, funding) in pending_splice.negotiated_candidates.iter_mut().enumerate() {
1063310632
if self.context.check_for_funding_tx_confirmed(
1063410633
funding, block_hash, height, index_in_block, &mut confirmed_tx, logger,
@@ -10643,41 +10642,36 @@ where
1064310642
funding_already_confirmed = true;
1064410643
}
1064510644
}
10646-
}
10647-
10648-
#[cfg(splicing)]
10649-
if let Some(confirmed_funding_index) = confirmed_funding_index {
10650-
let pending_splice = match self.pending_splice.as_mut() {
10651-
Some(pending_splice) => pending_splice,
10652-
None => {
10653-
// TODO: Move pending_funding into pending_splice
10654-
debug_assert!(false);
10655-
let err = "expected a pending splice".to_string();
10656-
return Err(ClosureReason::ProcessingError { err });
10657-
},
10658-
};
1065910645

10660-
if let Some(splice_locked) = pending_splice.check_get_splice_locked(&self.context, confirmed_funding_index, height) {
10661-
log_info!(
10662-
logger,
10663-
"Sending splice_locked txid {} to our peer for channel {}",
10664-
splice_locked.splice_txid,
10665-
&self.context.channel_id,
10666-
);
10646+
if let Some(confirmed_funding_index) = confirmed_funding_index {
10647+
if let Some(splice_locked) = pending_splice.check_get_splice_locked(
10648+
&self.context,
10649+
confirmed_funding_index,
10650+
height,
10651+
) {
1066710652

10668-
let (funding_txo, monitor_update, announcement_sigs, discarded_funding) =
10669-
self.maybe_promote_splice_funding(
10670-
node_signer, chain_hash, user_config, height, logger,
10671-
).map(|splice_promotion| (
10672-
Some(splice_promotion.funding_txo),
10673-
splice_promotion.monitor_update,
10674-
splice_promotion.announcement_sigs,
10675-
splice_promotion.discarded_funding,
10676-
)).unwrap_or((None, None, None, Vec::new()));
10653+
log_info!(
10654+
logger,
10655+
"Sending splice_locked txid {} to our peer for channel {}",
10656+
splice_locked.splice_txid,
10657+
&self.context.channel_id,
10658+
);
1067710659

10678-
return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo, monitor_update, discarded_funding)), announcement_sigs));
10660+
let (funding_txo, monitor_update, announcement_sigs, discarded_funding) =
10661+
self.maybe_promote_splice_funding(
10662+
node_signer, chain_hash, user_config, height, logger,
10663+
).map(|splice_promotion| (
10664+
Some(splice_promotion.funding_txo),
10665+
splice_promotion.monitor_update,
10666+
splice_promotion.announcement_sigs,
10667+
splice_promotion.discarded_funding,
10668+
)).unwrap_or((None, None, None, Vec::new()));
10669+
10670+
return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo, monitor_update, discarded_funding)), announcement_sigs));
10671+
}
1067910672
}
1068010673
}
10674+
1068110675
}
1068210676

1068310677
Ok((None, None))
@@ -10781,72 +10775,62 @@ where
1078110775
}
1078210776

1078310777
#[cfg(splicing)]
10784-
let mut confirmed_funding_index = None;
10785-
#[cfg(splicing)]
10786-
for (index, funding) in self.pending_funding().iter().enumerate() {
10787-
if funding.funding_tx_confirmation_height != 0 {
10788-
if confirmed_funding_index.is_some() {
10789-
let err_reason = "splice tx of another pending funding already confirmed";
10790-
return Err(ClosureReason::ProcessingError { err: err_reason.to_owned() });
10791-
}
10778+
if let Some(pending_splice) = &mut self.pending_splice {
10779+
let mut confirmed_funding_index = None;
1079210780

10793-
confirmed_funding_index = Some(index);
10781+
for (index, funding) in pending_splice.negotiated_candidates.iter().enumerate() {
10782+
if funding.funding_tx_confirmation_height != 0 {
10783+
if confirmed_funding_index.is_some() {
10784+
let err_reason = "splice tx of another pending funding already confirmed";
10785+
return Err(ClosureReason::ProcessingError { err: err_reason.to_owned() });
10786+
}
10787+
10788+
confirmed_funding_index = Some(index);
10789+
}
1079410790
}
10795-
}
1079610791

10797-
#[cfg(splicing)]
10798-
if let Some(confirmed_funding_index) = confirmed_funding_index {
10799-
let pending_splice = match self.pending_splice.as_mut() {
10800-
Some(pending_splice) => pending_splice,
10801-
None => {
10802-
// TODO: Move pending_funding into pending_splice
10803-
debug_assert!(false);
10804-
let err = "expected a pending splice".to_string();
10805-
return Err(ClosureReason::ProcessingError { err });
10806-
},
10807-
};
10808-
let funding = &mut pending_splice.negotiated_candidates[confirmed_funding_index];
10809-
10810-
// Check if the splice funding transaction was unconfirmed
10811-
if funding.get_funding_tx_confirmations(height) == 0 {
10812-
funding.funding_tx_confirmation_height = 0;
10813-
if let Some(sent_funding_txid) = pending_splice.sent_funding_txid {
10814-
if Some(sent_funding_txid) == funding.get_funding_txid() {
10815-
log_warn!(
10816-
logger,
10817-
"Unconfirming sent splice_locked txid {} for channel {}",
10818-
sent_funding_txid,
10819-
&self.context.channel_id,
10820-
);
10821-
pending_splice.sent_funding_txid = None;
10792+
if let Some(confirmed_funding_index) = confirmed_funding_index {
10793+
let funding = &mut pending_splice.negotiated_candidates[confirmed_funding_index];
10794+
10795+
// Check if the splice funding transaction was unconfirmed
10796+
if funding.get_funding_tx_confirmations(height) == 0 {
10797+
funding.funding_tx_confirmation_height = 0;
10798+
if let Some(sent_funding_txid) = pending_splice.sent_funding_txid {
10799+
if Some(sent_funding_txid) == funding.get_funding_txid() {
10800+
log_warn!(
10801+
logger,
10802+
"Unconfirming sent splice_locked txid {} for channel {}",
10803+
sent_funding_txid,
10804+
&self.context.channel_id,
10805+
);
10806+
pending_splice.sent_funding_txid = None;
10807+
}
1082210808
}
1082310809
}
10824-
}
1082510810

10826-
let pending_splice = self.pending_splice.as_mut().unwrap();
10827-
if let Some(splice_locked) = pending_splice.check_get_splice_locked(
10828-
&self.context,
10829-
confirmed_funding_index,
10830-
height,
10831-
) {
10832-
log_info!(logger, "Sending a splice_locked to our peer for channel {}", &self.context.channel_id);
10833-
debug_assert!(chain_node_signer.is_some());
10834-
10835-
let (funding_txo, monitor_update, announcement_sigs, discarded_funding) = chain_node_signer
10836-
.and_then(|(chain_hash, node_signer, user_config)| {
10837-
// We can only promote on blocks connected, which is when we expect
10838-
// `chain_node_signer` to be `Some`.
10839-
self.maybe_promote_splice_funding(node_signer, chain_hash, user_config, height, logger)
10840-
})
10841-
.map(|splice_promotion| (
10842-
Some(splice_promotion.funding_txo),
10843-
splice_promotion.monitor_update,
10844-
splice_promotion.announcement_sigs,
10845-
splice_promotion.discarded_funding,
10846-
))
10847-
.unwrap_or((None, None, None, Vec::new()));
10811+
if let Some(splice_locked) = pending_splice.check_get_splice_locked(
10812+
&self.context,
10813+
confirmed_funding_index,
10814+
height,
10815+
) {
10816+
log_info!(logger, "Sending a splice_locked to our peer for channel {}", &self.context.channel_id);
10817+
10818+
let (funding_txo, monitor_update, announcement_sigs, discarded_funding) = chain_node_signer
10819+
.and_then(|(chain_hash, node_signer, user_config)| {
10820+
// We can only promote on blocks connected, which is when we expect
10821+
// `chain_node_signer` to be `Some`.
10822+
self.maybe_promote_splice_funding(node_signer, chain_hash, user_config, height, logger)
10823+
})
10824+
.map(|splice_promotion| (
10825+
Some(splice_promotion.funding_txo),
10826+
splice_promotion.monitor_update,
10827+
splice_promotion.announcement_sigs,
10828+
splice_promotion.discarded_funding,
10829+
))
10830+
.unwrap_or((None, None, None, Vec::new()));
1084810831

10849-
return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo, monitor_update, discarded_funding)), timed_out_htlcs, announcement_sigs));
10832+
return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo, monitor_update, discarded_funding)), timed_out_htlcs, announcement_sigs));
10833+
}
1085010834
}
1085110835
}
1085210836

0 commit comments

Comments
 (0)