Skip to content

Commit 4169de1

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 f18d7e7 commit 4169de1

File tree

1 file changed

+35
-30
lines changed

1 file changed

+35
-30
lines changed

lightning/src/ln/channel.rs

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2965,10 +2965,15 @@ where
29652965
self.context.assert_no_commitment_advancement(transaction_number, "initial commitment_signed");
29662966
let commitment_signed = self.context.get_initial_commitment_signed(&self.funding, logger);
29672967
let commitment_signed = match commitment_signed {
2968-
Ok(commitment_signed) => commitment_signed,
2969-
Err(err) => {
2968+
Some(commitment_signed) => commitment_signed,
2969+
None => {
29702970
self.funding.channel_transaction_parameters.funding_outpoint = None;
2971-
return Err(ChannelError::Close((err.to_string(), ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) })));
2971+
return Err(ChannelError::Close(
2972+
(
2973+
"Failed to get signatures for new commitment_signed".to_owned(),
2974+
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
2975+
)
2976+
));
29722977
},
29732978
};
29742979

@@ -5494,7 +5499,7 @@ where
54945499
#[rustfmt::skip]
54955500
fn get_initial_counterparty_commitment_signature<L: Deref>(
54965501
&self, funding: &FundingScope, logger: &L
5497-
) -> Result<Signature, ChannelError>
5502+
) -> Option<Signature>
54985503
where
54995504
SP::Target: SignerProvider,
55005505
L::Target: Logger
@@ -5509,11 +5514,7 @@ where
55095514
let channel_parameters = &funding.channel_transaction_parameters;
55105515
ecdsa.sign_counterparty_commitment(channel_parameters, &counterparty_initial_commitment_tx, Vec::new(), Vec::new(), &self.secp_ctx)
55115516
.map(|(signature, _)| signature)
5512-
.map_err(|_| ChannelError::Close(
5513-
(
5514-
"Failed to get signatures for new commitment_signed".to_owned(),
5515-
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
5516-
)))
5517+
.ok()
55175518
},
55185519
// TODO (taproot|arik)
55195520
#[cfg(taproot)]
@@ -5524,38 +5525,35 @@ where
55245525
#[rustfmt::skip]
55255526
fn get_initial_commitment_signed<L: Deref>(
55265527
&mut self, funding: &FundingScope, logger: &L
5527-
) -> Result<msgs::CommitmentSigned, ChannelError>
5528+
) -> Option<msgs::CommitmentSigned>
55285529
where
55295530
SP::Target: SignerProvider,
55305531
L::Target: Logger
55315532
{
55325533
assert!(matches!(self.channel_state, ChannelState::FundingNegotiated(_)));
55335534

5534-
let signature = match self.get_initial_counterparty_commitment_signature(funding, logger) {
5535-
Ok(res) => res,
5536-
Err(e) => {
5537-
log_error!(logger, "Got bad signatures: {:?}!", e);
5538-
return Err(e);
5539-
}
5540-
};
5541-
5542-
log_info!(logger, "Generated commitment_signed for peer for channel {}", &self.channel_id());
5543-
5544-
Ok(msgs::CommitmentSigned {
5545-
channel_id: self.channel_id,
5546-
htlc_signatures: vec![],
5547-
signature,
5548-
funding_txid: funding.get_funding_txo().map(|funding_txo| funding_txo.txid),
5549-
#[cfg(taproot)]
5550-
partial_signature_with_nonce: None,
5551-
})
5535+
let signature = self.get_initial_counterparty_commitment_signature(funding, logger);
5536+
if let Some(signature) = signature {
5537+
log_info!(logger, "Generated commitment_signed for peer for channel {}", &self.channel_id());
5538+
Some(msgs::CommitmentSigned {
5539+
channel_id: self.channel_id,
5540+
htlc_signatures: vec![],
5541+
signature,
5542+
funding_txid: funding.get_funding_txo().map(|funding_txo| funding_txo.txid),
5543+
#[cfg(taproot)]
5544+
partial_signature_with_nonce: None,
5545+
})
5546+
} else {
5547+
// TODO: Support async signing
5548+
None
5549+
}
55525550
}
55535551

55545552
#[cfg(all(test))]
55555553
pub fn get_initial_counterparty_commitment_signature_for_test<L: Deref>(
55565554
&mut self, funding: &mut FundingScope, logger: &L,
55575555
counterparty_cur_commitment_point_override: PublicKey,
5558-
) -> Result<Signature, ChannelError>
5556+
) -> Option<Signature>
55595557
where
55605558
SP::Target: SignerProvider,
55615559
L::Target: Logger,
@@ -8426,7 +8424,14 @@ where
84268424
// if it has not received tx_signatures for that funding transaction AND
84278425
// if next_commitment_number is zero:
84288426
// MUST retransmit its commitment_signed for that funding transaction.
8429-
let commitment_signed = self.context.get_initial_commitment_signed(&self.funding, logger)?;
8427+
let commitment_signed = self.context.get_initial_commitment_signed(&self.funding, logger)
8428+
// TODO Support async signing
8429+
.ok_or_else(|| ChannelError::Close(
8430+
(
8431+
"Failed to get signatures for new commitment_signed".to_owned(),
8432+
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
8433+
)
8434+
))?;
84308435
Some(msgs::CommitmentUpdate {
84318436
commitment_signed: vec![commitment_signed],
84328437
update_add_htlcs: vec![],

0 commit comments

Comments
 (0)