Skip to content

Commit adb038a

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 e72431a commit adb038a

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,
@@ -7606,7 +7609,8 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
76067609
panic!("Tried to send an open_channel for a channel that has already advanced");
76077610
}
76087611

7609-
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);
7612+
debug_assert!(self.context.holder_commitment_point.is_available());
7613+
let first_per_commitment_point = self.context.holder_commitment_point.current_point();
76107614
let keys = self.context.get_holder_pubkeys();
76117615

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

7804-
let holder_signer = self.context.build_holder_transaction_keys(self.context.holder_commitment_point.transaction_number());
7808+
let holder_signer = self.context.build_holder_transaction_keys();
78057809
let initial_commitment_tx = self.context.build_commitment_transaction(self.context.holder_commitment_point.transaction_number(), &holder_signer, true, false, logger).tx;
78067810
{
78077811
let trusted_tx = initial_commitment_tx.trust();
@@ -8004,7 +8008,8 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
80048008
///
80058009
/// [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel
80068010
fn generate_accept_channel_message(&self) -> msgs::AcceptChannel {
8007-
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);
8011+
debug_assert!(self.context.holder_commitment_point.is_available());
8012+
let first_per_commitment_point = self.context.holder_commitment_point.current_point();
80088013
let keys = self.context.get_holder_pubkeys();
80098014

80108015
msgs::AcceptChannel {
@@ -8046,7 +8051,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
80468051
fn check_funding_created_signature<L: Deref>(&mut self, sig: &Signature, logger: &L) -> Result<CommitmentTransaction, ChannelError> where L::Target: Logger {
80478052
let funding_script = self.context.get_funding_redeemscript();
80488053

8049-
let keys = self.context.build_holder_transaction_keys(self.context.holder_commitment_point.transaction_number());
8054+
let keys = self.context.build_holder_transaction_keys();
80508055
let initial_commitment_tx = self.context.build_commitment_transaction(self.context.holder_commitment_point.transaction_number(), &keys, true, false, logger).tx;
80518056
let trusted_tx = initial_commitment_tx.trust();
80528057
let initial_commitment_bitcoin_tx = trusted_tx.built_transaction();

0 commit comments

Comments
 (0)