Skip to content

Commit cf545b4

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 d189cf0 commit cf545b4

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

lightning/src/ln/channel.rs

+14-9
Original file line numberDiff line numberDiff line change
@@ -2759,8 +2759,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
27592759
/// our counterparty!)
27602760
/// The result is a transaction which we can revoke broadcastership of (ie a "local" transaction)
27612761
/// TODO Some magic rust shit to compile-time check this?
2762-
fn build_holder_transaction_keys(&self, commitment_number: u64) -> TxCreationKeys {
2763-
let per_commitment_point = self.holder_signer.as_ref().get_per_commitment_point(commitment_number, &self.secp_ctx);
2762+
fn build_holder_transaction_keys(&self) -> TxCreationKeys {
2763+
let per_commitment_point = self.holder_commitment_point.current_point();
27642764
let delayed_payment_base = &self.get_holder_pubkeys().delayed_payment_basepoint;
27652765
let htlc_basepoint = &self.get_holder_pubkeys().htlc_basepoint;
27662766
let counterparty_pubkeys = self.get_counterparty_pubkeys();
@@ -4456,7 +4456,7 @@ impl<SP: Deref> Channel<SP> where
44564456

44574457
let funding_script = self.context.get_funding_redeemscript();
44584458

4459-
let keys = self.context.build_holder_transaction_keys(self.context.holder_commitment_point.transaction_number());
4459+
let keys = self.context.build_holder_transaction_keys();
44604460

44614461
let commitment_stats = self.context.build_commitment_transaction(self.context.holder_commitment_point.transaction_number(), &keys, true, false, logger);
44624462
let commitment_txid = {
@@ -5132,7 +5132,7 @@ impl<SP: Deref> Channel<SP> where
51325132
// Before proposing a feerate update, check that we can actually afford the new fee.
51335133
let dust_exposure_limiting_feerate = self.context.get_dust_exposure_limiting_feerate(&fee_estimator);
51345134
let htlc_stats = self.context.get_pending_htlc_stats(Some(feerate_per_kw), dust_exposure_limiting_feerate);
5135-
let keys = self.context.build_holder_transaction_keys(self.context.holder_commitment_point.transaction_number());
5135+
let keys = self.context.build_holder_transaction_keys();
51365136
let commitment_stats = self.context.build_commitment_transaction(self.context.holder_commitment_point.transaction_number(), &keys, true, true, logger);
51375137
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;
51385138
let holder_balance_msat = commitment_stats.local_balance_msat - htlc_stats.outbound_holding_cell_msat;
@@ -5417,7 +5417,10 @@ impl<SP: Deref> Channel<SP> where
54175417
}
54185418

54195419
fn get_last_revoke_and_ack(&self) -> msgs::RevokeAndACK {
5420-
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);
5420+
debug_assert!(self.context.holder_commitment_point.transaction_number() <= INITIAL_COMMITMENT_NUMBER + 2);
5421+
// TODO: handle non-available case when get_per_commitment_point becomes async
5422+
debug_assert!(self.context.holder_commitment_point.is_available());
5423+
let next_per_commitment_point = self.context.holder_commitment_point.current_point();
54215424
let per_commitment_secret = self.context.holder_signer.as_ref().release_commitment_secret(self.context.holder_commitment_point.transaction_number() + 2);
54225425
msgs::RevokeAndACK {
54235426
channel_id: self.context.channel_id,
@@ -7615,7 +7618,8 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
76157618
panic!("Tried to send an open_channel for a channel that has already advanced");
76167619
}
76177620

7618-
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);
7621+
debug_assert!(self.context.holder_commitment_point.is_available());
7622+
let first_per_commitment_point = self.context.holder_commitment_point.current_point();
76197623
let keys = self.context.get_holder_pubkeys();
76207624

76217625
msgs::OpenChannel {
@@ -7810,7 +7814,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
78107814
log_trace!(logger, "Initial counterparty tx for channel {} is: txid {} tx {}",
78117815
&self.context.channel_id(), counterparty_initial_bitcoin_tx.txid, encode::serialize_hex(&counterparty_initial_bitcoin_tx.transaction));
78127816

7813-
let holder_signer = self.context.build_holder_transaction_keys(self.context.holder_commitment_point.transaction_number());
7817+
let holder_signer = self.context.build_holder_transaction_keys();
78147818
let initial_commitment_tx = self.context.build_commitment_transaction(self.context.holder_commitment_point.transaction_number(), &holder_signer, true, false, logger).tx;
78157819
{
78167820
let trusted_tx = initial_commitment_tx.trust();
@@ -8013,7 +8017,8 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
80138017
///
80148018
/// [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel
80158019
fn generate_accept_channel_message(&self) -> msgs::AcceptChannel {
8016-
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);
8020+
debug_assert!(self.context.holder_commitment_point.is_available());
8021+
let first_per_commitment_point = self.context.holder_commitment_point.current_point();
80178022
let keys = self.context.get_holder_pubkeys();
80188023

80198024
msgs::AcceptChannel {
@@ -8055,7 +8060,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
80558060
fn check_funding_created_signature<L: Deref>(&mut self, sig: &Signature, logger: &L) -> Result<CommitmentTransaction, ChannelError> where L::Target: Logger {
80568061
let funding_script = self.context.get_funding_redeemscript();
80578062

8058-
let keys = self.context.build_holder_transaction_keys(self.context.holder_commitment_point.transaction_number());
8063+
let keys = self.context.build_holder_transaction_keys();
80598064
let initial_commitment_tx = self.context.build_commitment_transaction(self.context.holder_commitment_point.transaction_number(), &keys, true, false, logger).tx;
80608065
let trusted_tx = initial_commitment_tx.trust();
80618066
let initial_commitment_bitcoin_tx = trusted_tx.built_transaction();

0 commit comments

Comments
 (0)