Skip to content

Commit e947e84

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 74a0b48 commit e947e84

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
@@ -2750,8 +2750,8 @@ 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();
27552755
let delayed_payment_base = &self.get_holder_pubkeys().delayed_payment_basepoint;
27562756
let htlc_basepoint = &self.get_holder_pubkeys().htlc_basepoint;
27572757
let counterparty_pubkeys = self.get_counterparty_pubkeys();
@@ -4447,7 +4447,7 @@ impl<SP: Deref> Channel<SP> where
44474447

44484448
let funding_script = self.context.get_funding_redeemscript();
44494449

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

44524452
let commitment_stats = self.context.build_commitment_transaction(self.context.holder_commitment_point.transaction_number(), &keys, true, false, logger);
44534453
let commitment_txid = {
@@ -5123,7 +5123,7 @@ impl<SP: Deref> Channel<SP> where
51235123
// Before proposing a feerate update, check that we can actually afford the new fee.
51245124
let dust_exposure_limiting_feerate = self.context.get_dust_exposure_limiting_feerate(&fee_estimator);
51255125
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());
5126+
let keys = self.context.build_holder_transaction_keys();
51275127
let commitment_stats = self.context.build_commitment_transaction(self.context.holder_commitment_point.transaction_number(), &keys, true, true, logger);
51285128
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;
51295129
let holder_balance_msat = commitment_stats.local_balance_msat - htlc_stats.outbound_holding_cell_msat;
@@ -5408,7 +5408,10 @@ impl<SP: Deref> Channel<SP> where
54085408
}
54095409

54105410
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);
5411+
debug_assert!(self.context.holder_commitment_point.transaction_number() <= INITIAL_COMMITMENT_NUMBER + 2);
5412+
// TODO: handle non-available case when get_per_commitment_point becomes async
5413+
debug_assert!(self.context.holder_commitment_point.is_available());
5414+
let next_per_commitment_point = self.context.holder_commitment_point.current_point();
54125415
let per_commitment_secret = self.context.holder_signer.as_ref().release_commitment_secret(self.context.holder_commitment_point.transaction_number() + 2);
54135416
msgs::RevokeAndACK {
54145417
channel_id: self.context.channel_id,
@@ -7610,7 +7613,8 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
76107613
panic!("Tried to send an open_channel for a channel that has already advanced");
76117614
}
76127615

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);
7616+
debug_assert!(self.context.holder_commitment_point.is_available());
7617+
let first_per_commitment_point = self.context.holder_commitment_point.current_point();
76147618
let keys = self.context.get_holder_pubkeys();
76157619

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

7808-
let holder_signer = self.context.build_holder_transaction_keys(self.context.holder_commitment_point.transaction_number());
7812+
let holder_signer = self.context.build_holder_transaction_keys();
78097813
let initial_commitment_tx = self.context.build_commitment_transaction(self.context.holder_commitment_point.transaction_number(), &holder_signer, true, false, logger).tx;
78107814
{
78117815
let trusted_tx = initial_commitment_tx.trust();
@@ -8008,7 +8012,8 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
80088012
///
80098013
/// [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel
80108014
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);
8015+
debug_assert!(self.context.holder_commitment_point.is_available());
8016+
let first_per_commitment_point = self.context.holder_commitment_point.current_point();
80128017
let keys = self.context.get_holder_pubkeys();
80138018

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

8053-
let keys = self.context.build_holder_transaction_keys(self.context.holder_commitment_point.transaction_number());
8058+
let keys = self.context.build_holder_transaction_keys();
80548059
let initial_commitment_tx = self.context.build_commitment_transaction(self.context.holder_commitment_point.transaction_number(), &keys, true, false, logger).tx;
80558060
let trusted_tx = initial_commitment_tx.trust();
80568061
let initial_commitment_bitcoin_tx = trusted_tx.built_transaction();

0 commit comments

Comments
 (0)