Skip to content

Commit b1df43f

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 2b015f3 commit b1df43f

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
@@ -2750,8 +2750,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
27502750
/// our counterparty!)
27512751
/// The result is a transaction which we can revoke broadcastership of (ie a "local" transaction)
27522752
/// TODO Some magic rust shit to compile-time check this?
2753-
fn build_holder_transaction_keys(&self, commitment_number: u64) -> TxCreationKeys {
2754-
let per_commitment_point = self.holder_signer.as_ref().get_per_commitment_point(commitment_number, &self.secp_ctx);
2753+
fn build_holder_transaction_keys(&self) -> TxCreationKeys {
2754+
let per_commitment_point = self.holder_commitment_point.current_point()
2755+
.expect("Should not build commitment transaction before retrieving first commitment point");
27552756
let delayed_payment_base = &self.get_holder_pubkeys().delayed_payment_basepoint;
27562757
let htlc_basepoint = &self.get_holder_pubkeys().htlc_basepoint;
27572758
let counterparty_pubkeys = self.get_counterparty_pubkeys();
@@ -4447,7 +4448,7 @@ impl<SP: Deref> Channel<SP> where
44474448

44484449
let funding_script = self.context.get_funding_redeemscript();
44494450

4450-
let keys = self.context.build_holder_transaction_keys(self.context.holder_commitment_point.transaction_number());
4451+
let keys = self.context.build_holder_transaction_keys();
44514452

44524453
let commitment_stats = self.context.build_commitment_transaction(self.context.holder_commitment_point.transaction_number(), &keys, true, false, logger);
44534454
let commitment_txid = {
@@ -5123,7 +5124,7 @@ impl<SP: Deref> Channel<SP> where
51235124
// Before proposing a feerate update, check that we can actually afford the new fee.
51245125
let dust_exposure_limiting_feerate = self.context.get_dust_exposure_limiting_feerate(&fee_estimator);
51255126
let htlc_stats = self.context.get_pending_htlc_stats(Some(feerate_per_kw), dust_exposure_limiting_feerate);
5126-
let keys = self.context.build_holder_transaction_keys(self.context.holder_commitment_point.transaction_number());
5127+
let keys = self.context.build_holder_transaction_keys();
51275128
let commitment_stats = self.context.build_commitment_transaction(self.context.holder_commitment_point.transaction_number(), &keys, true, true, logger);
51285129
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;
51295130
let holder_balance_msat = commitment_stats.local_balance_msat - htlc_stats.outbound_holding_cell_msat;
@@ -5408,7 +5409,11 @@ impl<SP: Deref> Channel<SP> where
54085409
}
54095410

54105411
fn get_last_revoke_and_ack(&self) -> msgs::RevokeAndACK {
5411-
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);
5412+
debug_assert!(self.context.holder_commitment_point.transaction_number() <= INITIAL_COMMITMENT_NUMBER + 2);
5413+
// TODO: handle non-available case when get_per_commitment_point becomes async
5414+
debug_assert!(self.context.holder_commitment_point.is_available());
5415+
let next_per_commitment_point = self.context.holder_commitment_point.current_point()
5416+
.expect("TODO");
54125417
let per_commitment_secret = self.context.holder_signer.as_ref().release_commitment_secret(self.context.holder_commitment_point.transaction_number() + 2);
54135418
msgs::RevokeAndACK {
54145419
channel_id: self.context.channel_id,
@@ -7610,7 +7615,8 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
76107615
panic!("Tried to send an open_channel for a channel that has already advanced");
76117616
}
76127617

7613-
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);
7618+
debug_assert!(self.context.holder_commitment_point.is_available());
7619+
let first_per_commitment_point = self.context.holder_commitment_point.current_point().expect("TODO");
76147620
let keys = self.context.get_holder_pubkeys();
76157621

76167622
msgs::OpenChannel {
@@ -7805,7 +7811,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
78057811
log_trace!(logger, "Initial counterparty tx for channel {} is: txid {} tx {}",
78067812
&self.context.channel_id(), counterparty_initial_bitcoin_tx.txid, encode::serialize_hex(&counterparty_initial_bitcoin_tx.transaction));
78077813

7808-
let holder_signer = self.context.build_holder_transaction_keys(self.context.holder_commitment_point.transaction_number());
7814+
let holder_signer = self.context.build_holder_transaction_keys();
78097815
let initial_commitment_tx = self.context.build_commitment_transaction(self.context.holder_commitment_point.transaction_number(), &holder_signer, true, false, logger).tx;
78107816
{
78117817
let trusted_tx = initial_commitment_tx.trust();
@@ -8008,7 +8014,8 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
80088014
///
80098015
/// [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel
80108016
fn generate_accept_channel_message(&self) -> msgs::AcceptChannel {
8011-
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);
8017+
debug_assert!(self.context.holder_commitment_point.is_available());
8018+
let first_per_commitment_point = self.context.holder_commitment_point.current_point().expect("TODO");
80128019
let keys = self.context.get_holder_pubkeys();
80138020

80148021
msgs::AcceptChannel {
@@ -8050,7 +8057,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
80508057
fn check_funding_created_signature<L: Deref>(&mut self, sig: &Signature, logger: &L) -> Result<CommitmentTransaction, ChannelError> where L::Target: Logger {
80518058
let funding_script = self.context.get_funding_redeemscript();
80528059

8053-
let keys = self.context.build_holder_transaction_keys(self.context.holder_commitment_point.transaction_number());
8060+
let keys = self.context.build_holder_transaction_keys();
80548061
let initial_commitment_tx = self.context.build_commitment_transaction(self.context.holder_commitment_point.transaction_number(), &keys, true, false, logger).tx;
80558062
let trusted_tx = initial_commitment_tx.trust();
80568063
let initial_commitment_bitcoin_tx = trusted_tx.built_transaction();

0 commit comments

Comments
 (0)