Skip to content

Commit 65b3898

Browse files
committed
Get per commitment point everywhere else with HolderCommitmentPoint
This includes when building TxCreationKeys, as well as for open_channel and accept_channel messages. Note: this is only for places where we are retrieving the current per commitment point, which excludes channel_reestablish.
1 parent d6d2671 commit 65b3898

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

lightning/src/ln/channel.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -2760,8 +2760,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
27602760
/// our counterparty!)
27612761
/// The result is a transaction which we can revoke broadcastership of (ie a "local" transaction)
27622762
/// TODO Some magic rust shit to compile-time check this?
2763-
fn build_holder_transaction_keys(&self, commitment_number: u64) -> TxCreationKeys {
2764-
let per_commitment_point = self.holder_signer.as_ref().get_per_commitment_point(commitment_number, &self.secp_ctx);
2763+
fn build_holder_transaction_keys(&self) -> TxCreationKeys {
2764+
let per_commitment_point = self.holder_commitment_point.current_point()
2765+
.expect("Should not build commitment transaction before retrieving first commitment point");
27652766
let delayed_payment_base = &self.get_holder_pubkeys().delayed_payment_basepoint;
27662767
let htlc_basepoint = &self.get_holder_pubkeys().htlc_basepoint;
27672768
let counterparty_pubkeys = self.get_counterparty_pubkeys();
@@ -4457,7 +4458,7 @@ impl<SP: Deref> Channel<SP> where
44574458

44584459
let funding_script = self.context.get_funding_redeemscript();
44594460

4460-
let keys = self.context.build_holder_transaction_keys(self.context.holder_commitment_point.transaction_number());
4461+
let keys = self.context.build_holder_transaction_keys();
44614462

44624463
let commitment_stats = self.context.build_commitment_transaction(self.context.holder_commitment_point.transaction_number(), &keys, true, false, logger);
44634464
let commitment_txid = {
@@ -5133,7 +5134,7 @@ impl<SP: Deref> Channel<SP> where
51335134
// Before proposing a feerate update, check that we can actually afford the new fee.
51345135
let dust_exposure_limiting_feerate = self.context.get_dust_exposure_limiting_feerate(&fee_estimator);
51355136
let htlc_stats = self.context.get_pending_htlc_stats(Some(feerate_per_kw), dust_exposure_limiting_feerate);
5136-
let keys = self.context.build_holder_transaction_keys(self.context.holder_commitment_point.transaction_number());
5137+
let keys = self.context.build_holder_transaction_keys();
51375138
let commitment_stats = self.context.build_commitment_transaction(self.context.holder_commitment_point.transaction_number(), &keys, true, true, logger);
51385139
let buffer_fee_msat = commit_tx_fee_sat(feerate_per_kw, commitment_stats.num_nondust_htlcs + htlc_stats.on_holder_tx_outbound_holding_cell_htlcs_count as usize + CONCURRENT_INBOUND_HTLC_FEE_BUFFER as usize, self.context.get_channel_type()) * 1000;
51395140
let holder_balance_msat = commitment_stats.local_balance_msat - htlc_stats.outbound_holding_cell_msat;
@@ -5418,7 +5419,11 @@ impl<SP: Deref> Channel<SP> where
54185419
}
54195420

54205421
fn get_last_revoke_and_ack(&self) -> msgs::RevokeAndACK {
5421-
let next_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(self.context.holder_commitment_point.transaction_number(), &self.context.secp_ctx);
5422+
debug_assert!(self.context.holder_commitment_point.transaction_number() <= INITIAL_COMMITMENT_NUMBER + 2);
5423+
// TODO: handle non-available case when get_per_commitment_point becomes async
5424+
debug_assert!(self.context.holder_commitment_point.is_available());
5425+
let next_per_commitment_point = self.context.holder_commitment_point.current_point()
5426+
.expect("TODO");
54225427
let per_commitment_secret = self.context.holder_signer.as_ref().release_commitment_secret(self.context.holder_commitment_point.transaction_number() + 2);
54235428
msgs::RevokeAndACK {
54245429
channel_id: self.context.channel_id,
@@ -7623,7 +7628,8 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
76237628
panic!("Tried to send an open_channel for a channel that has already advanced");
76247629
}
76257630

7626-
let first_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(self.context.holder_commitment_point.transaction_number(), &self.context.secp_ctx);
7631+
debug_assert!(self.context.holder_commitment_point.is_available());
7632+
let first_per_commitment_point = self.context.holder_commitment_point.current_point().expect("TODO");
76277633
let keys = self.context.get_holder_pubkeys();
76287634

76297635
msgs::OpenChannel {
@@ -7818,7 +7824,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
78187824
log_trace!(logger, "Initial counterparty tx for channel {} is: txid {} tx {}",
78197825
&self.context.channel_id(), counterparty_initial_bitcoin_tx.txid, encode::serialize_hex(&counterparty_initial_bitcoin_tx.transaction));
78207826

7821-
let holder_signer = self.context.build_holder_transaction_keys(self.context.holder_commitment_point.transaction_number());
7827+
let holder_signer = self.context.build_holder_transaction_keys();
78227828
let initial_commitment_tx = self.context.build_commitment_transaction(self.context.holder_commitment_point.transaction_number(), &holder_signer, true, false, logger).tx;
78237829
{
78247830
let trusted_tx = initial_commitment_tx.trust();
@@ -8021,7 +8027,8 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
80218027
///
80228028
/// [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel
80238029
fn generate_accept_channel_message(&self) -> msgs::AcceptChannel {
8024-
let first_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(self.context.holder_commitment_point.transaction_number(), &self.context.secp_ctx);
8030+
debug_assert!(self.context.holder_commitment_point.is_available());
8031+
let first_per_commitment_point = self.context.holder_commitment_point.current_point().expect("TODO");
80258032
let keys = self.context.get_holder_pubkeys();
80268033

80278034
msgs::AcceptChannel {
@@ -8063,7 +8070,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
80638070
fn check_funding_created_signature<L: Deref>(&mut self, sig: &Signature, logger: &L) -> Result<CommitmentTransaction, ChannelError> where L::Target: Logger {
80648071
let funding_script = self.context.get_funding_redeemscript();
80658072

8066-
let keys = self.context.build_holder_transaction_keys(self.context.holder_commitment_point.transaction_number());
8073+
let keys = self.context.build_holder_transaction_keys();
80678074
let initial_commitment_tx = self.context.build_commitment_transaction(self.context.holder_commitment_point.transaction_number(), &keys, true, false, logger).tx;
80688075
let trusted_tx = initial_commitment_tx.trust();
80698076
let initial_commitment_bitcoin_tx = trusted_tx.built_transaction();

0 commit comments

Comments
 (0)