Skip to content

Commit 29081e7

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 48a0862 commit 29081e7

File tree

1 file changed

+33
-40
lines changed

1 file changed

+33
-40
lines changed

lightning/src/ln/channel.rs

Lines changed: 33 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>
@@ -5536,12 +5526,13 @@ where
55365526

55375527
let commitment_signed = self.get_initial_commitment_signed(&funding, logger);
55385528
let commitment_signed = match commitment_signed {
5539-
Ok(commitment_signed) => commitment_signed,
5540-
Err(e) => {
5529+
Some(commitment_signed) => commitment_signed,
5530+
// TODO(splicing): Support async signing
5531+
None => {
55415532
funding.channel_transaction_parameters.funding_outpoint = None;
55425533
return Err(msgs::TxAbort {
55435534
channel_id: self.channel_id(),
5544-
data: e.message().to_owned().into_bytes(),
5535+
data: "Failed to get signature for commitment_signed".to_owned().into_bytes(),
55455536
});
55465537
},
55475538
};
@@ -5600,7 +5591,7 @@ where
56005591
#[rustfmt::skip]
56015592
fn get_initial_counterparty_commitment_signature<L: Deref>(
56025593
&self, funding: &FundingScope, logger: &L
5603-
) -> Result<Signature, ChannelError>
5594+
) -> Option<Signature>
56045595
where
56055596
SP::Target: SignerProvider,
56065597
L::Target: Logger
@@ -5615,11 +5606,7 @@ where
56155606
let channel_parameters = &funding.channel_transaction_parameters;
56165607
ecdsa.sign_counterparty_commitment(channel_parameters, &counterparty_initial_commitment_tx, Vec::new(), Vec::new(), &self.secp_ctx)
56175608
.map(|(signature, _)| signature)
5618-
.map_err(|()| {
5619-
let msg = "Failed to get signatures for new commitment_signed";
5620-
let reason = ClosureReason::ProcessingError { err: msg.to_owned() };
5621-
ChannelError::Close((msg.to_owned(), reason))
5622-
})
5609+
.ok()
56235610
},
56245611
// TODO (taproot|arik)
56255612
#[cfg(taproot)]
@@ -5630,38 +5617,35 @@ where
56305617
#[rustfmt::skip]
56315618
fn get_initial_commitment_signed<L: Deref>(
56325619
&mut self, funding: &FundingScope, logger: &L
5633-
) -> Result<msgs::CommitmentSigned, ChannelError>
5620+
) -> Option<msgs::CommitmentSigned>
56345621
where
56355622
SP::Target: SignerProvider,
56365623
L::Target: Logger
56375624
{
56385625
assert!(matches!(self.channel_state, ChannelState::FundingNegotiated(flags) if flags.is_interactive_signing()));
56395626

5640-
let signature = match self.get_initial_counterparty_commitment_signature(funding, logger) {
5641-
Ok(res) => res,
5642-
Err(e) => {
5643-
log_error!(logger, "Got bad signatures: {:?}!", e);
5644-
return Err(e);
5645-
}
5646-
};
5647-
5648-
log_info!(logger, "Generated commitment_signed for peer for channel {}", &self.channel_id());
5649-
5650-
Ok(msgs::CommitmentSigned {
5651-
channel_id: self.channel_id,
5652-
htlc_signatures: vec![],
5653-
signature,
5654-
funding_txid: funding.get_funding_txo().map(|funding_txo| funding_txo.txid),
5655-
#[cfg(taproot)]
5656-
partial_signature_with_nonce: None,
5657-
})
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(splicing): Support async signing
5640+
None
5641+
}
56585642
}
56595643

56605644
#[cfg(all(test))]
56615645
pub fn get_initial_counterparty_commitment_signature_for_test<L: Deref>(
56625646
&mut self, funding: &mut FundingScope, logger: &L,
56635647
counterparty_cur_commitment_point_override: PublicKey,
5664-
) -> Result<Signature, ChannelError>
5648+
) -> Option<Signature>
56655649
where
56665650
SP::Target: SignerProvider,
56675651
L::Target: Logger,
@@ -8814,7 +8798,16 @@ where
88148798
// if it has not received tx_signatures for that funding transaction AND
88158799
// if next_commitment_number is zero:
88168800
// MUST retransmit its commitment_signed for that funding transaction.
8817-
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(splicing): 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+
)})?;
88188811
Some(msgs::CommitmentUpdate {
88198812
commitment_signed: vec![commitment_signed],
88208813
update_add_htlcs: vec![],

0 commit comments

Comments
 (0)