Skip to content

Commit f81b63f

Browse files
committed
Return an Option from ChannelContext::get_initial_commitment_signed
When ChannelContext::get_initial_commitment_signed is called for V2 channel establishment, any errors should result in closing the channel. However, in the future, when this is used for splicing it should abort instead of closing the channel. Move the error construction to the call sites in anticipation of this.
1 parent 01ba29d commit f81b63f

File tree

1 file changed

+32
-40
lines changed

1 file changed

+32
-40
lines changed

lightning/src/ln/channel.rs

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,16 +1009,6 @@ impl ChannelError {
10091009
pub(super) fn close(err: String) -> Self {
10101010
ChannelError::Close((err.clone(), ClosureReason::ProcessingError { err }))
10111011
}
1012-
1013-
pub(super) fn message(&self) -> &str {
1014-
match self {
1015-
&ChannelError::Ignore(ref e) => &e,
1016-
&ChannelError::Warn(ref e) => &e,
1017-
&ChannelError::WarnAndDisconnect(ref e) => &e,
1018-
&ChannelError::Close((ref e, _)) => &e,
1019-
&ChannelError::SendError(ref e) => &e,
1020-
}
1021-
}
10221012
}
10231013

10241014
pub(super) struct WithChannelContext<'a, L: Deref>
@@ -5535,12 +5525,12 @@ where
55355525

55365526
let commitment_signed = self.get_initial_commitment_signed(&funding, logger);
55375527
let commitment_signed = match commitment_signed {
5538-
Ok(commitment_signed) => commitment_signed,
5539-
Err(e) => {
5528+
Some(commitment_signed) => commitment_signed,
5529+
None => {
55405530
funding.channel_transaction_parameters.funding_outpoint = None;
55415531
return Err(msgs::TxAbort {
55425532
channel_id: self.channel_id(),
5543-
data: e.message().to_owned().into_bytes(),
5533+
data: "Failed to get signature for commitment_signed".to_owned().into_bytes(),
55445534
});
55455535
},
55465536
};
@@ -5601,7 +5591,7 @@ where
56015591
#[rustfmt::skip]
56025592
fn get_initial_counterparty_commitment_signature<L: Deref>(
56035593
&self, funding: &FundingScope, logger: &L
5604-
) -> Result<Signature, ChannelError>
5594+
) -> Option<Signature>
56055595
where
56065596
SP::Target: SignerProvider,
56075597
L::Target: Logger
@@ -5616,11 +5606,7 @@ where
56165606
let channel_parameters = &funding.channel_transaction_parameters;
56175607
ecdsa.sign_counterparty_commitment(channel_parameters, &counterparty_initial_commitment_tx, Vec::new(), Vec::new(), &self.secp_ctx)
56185608
.map(|(signature, _)| signature)
5619-
.map_err(|()| {
5620-
let msg = "Failed to get signatures for new commitment_signed";
5621-
let reason = ClosureReason::ProcessingError { err: msg.to_owned() };
5622-
ChannelError::Close((msg.to_owned(), reason))
5623-
})
5609+
.ok()
56245610
},
56255611
// TODO (taproot|arik)
56265612
#[cfg(taproot)]
@@ -5631,38 +5617,35 @@ where
56315617
#[rustfmt::skip]
56325618
fn get_initial_commitment_signed<L: Deref>(
56335619
&mut self, funding: &FundingScope, logger: &L
5634-
) -> Result<msgs::CommitmentSigned, ChannelError>
5620+
) -> Option<msgs::CommitmentSigned>
56355621
where
56365622
SP::Target: SignerProvider,
56375623
L::Target: Logger
56385624
{
56395625
assert!(matches!(self.channel_state, ChannelState::FundingNegotiated(_)));
56405626

5641-
let signature = match self.get_initial_counterparty_commitment_signature(funding, logger) {
5642-
Ok(res) => res,
5643-
Err(e) => {
5644-
log_error!(logger, "Got bad signatures: {:?}!", e);
5645-
return Err(e);
5646-
}
5647-
};
5648-
5649-
log_info!(logger, "Generated commitment_signed for peer for channel {}", &self.channel_id());
5650-
5651-
Ok(msgs::CommitmentSigned {
5652-
channel_id: self.channel_id,
5653-
htlc_signatures: vec![],
5654-
signature,
5655-
funding_txid: funding.get_funding_txo().map(|funding_txo| funding_txo.txid),
5656-
#[cfg(taproot)]
5657-
partial_signature_with_nonce: None,
5658-
})
5627+
let signature = self.get_initial_counterparty_commitment_signature(funding, logger);
5628+
if let Some(signature) = signature {
5629+
log_info!(logger, "Generated commitment_signed for peer for channel {}", &self.channel_id());
5630+
Some(msgs::CommitmentSigned {
5631+
channel_id: self.channel_id,
5632+
htlc_signatures: vec![],
5633+
signature,
5634+
funding_txid: funding.get_funding_txo().map(|funding_txo| funding_txo.txid),
5635+
#[cfg(taproot)]
5636+
partial_signature_with_nonce: None,
5637+
})
5638+
} else {
5639+
// TODO: Support async signing
5640+
None
5641+
}
56595642
}
56605643

56615644
#[cfg(all(test))]
56625645
pub fn get_initial_counterparty_commitment_signature_for_test<L: Deref>(
56635646
&mut self, funding: &mut FundingScope, logger: &L,
56645647
counterparty_cur_commitment_point_override: PublicKey,
5665-
) -> Result<Signature, ChannelError>
5648+
) -> Option<Signature>
56665649
where
56675650
SP::Target: SignerProvider,
56685651
L::Target: Logger,
@@ -8815,7 +8798,16 @@ where
88158798
// if it has not received tx_signatures for that funding transaction AND
88168799
// if next_commitment_number is zero:
88178800
// MUST retransmit its commitment_signed for that funding transaction.
8818-
let commitment_signed = self.context.get_initial_commitment_signed(&self.funding, logger)?;
8801+
let commitment_signed = self.context.get_initial_commitment_signed(&self.funding, logger)
8802+
// TODO Support async signing
8803+
.ok_or_else(|| {
8804+
let message = "Failed to get signatures for new commitment_signed".to_owned();
8805+
ChannelError::Close(
8806+
(
8807+
message.clone(),
8808+
ClosureReason::HolderForceClosed { message, broadcasted_latest_txn: Some(false) },
8809+
)
8810+
)})?;
88198811
Some(msgs::CommitmentUpdate {
88208812
commitment_signed: vec![commitment_signed],
88218813
update_add_htlcs: vec![],

0 commit comments

Comments
 (0)