@@ -1984,7 +1984,7 @@ trait InitialRemoteCommitmentReceiver<SP: Deref> where SP::Target: SignerProvide
1984
1984
let funding_script = self.context().get_funding_redeemscript();
1985
1985
1986
1986
let keys = self.context().build_holder_transaction_keys(holder_commitment_point.current_point());
1987
- let initial_commitment_tx = self.context().build_commitment_transaction(holder_commitment_point.transaction_number(), &keys, true, false, logger).tx;
1987
+ let initial_commitment_tx = self.context().build_commitment_transaction(&self.context().funding, holder_commitment_point.transaction_number(), &keys, true, false, logger).tx;
1988
1988
let trusted_tx = initial_commitment_tx.trust();
1989
1989
let initial_commitment_bitcoin_tx = trusted_tx.built_transaction();
1990
1990
let sighash = initial_commitment_bitcoin_tx.get_sighash_all(&funding_script, self.context().channel_value_satoshis());
@@ -2022,7 +2022,7 @@ trait InitialRemoteCommitmentReceiver<SP: Deref> where SP::Target: SignerProvide
2022
2022
};
2023
2023
let mut context = self.context_mut();
2024
2024
let counterparty_keys = context.build_remote_transaction_keys();
2025
- let counterparty_initial_commitment_tx = context.build_commitment_transaction(context.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, false, logger).tx;
2025
+ let counterparty_initial_commitment_tx = context.build_commitment_transaction(&context.funding, context.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, false, logger).tx;
2026
2026
let counterparty_trusted_tx = counterparty_initial_commitment_tx.trust();
2027
2027
let counterparty_initial_bitcoin_tx = counterparty_trusted_tx.built_transaction();
2028
2028
@@ -2259,7 +2259,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2259
2259
self.context.holder_signer.as_mut().provide_channel_parameters(&self.context.channel_transaction_parameters);
2260
2260
2261
2261
self.context.assert_no_commitment_advancement(transaction_number, "initial commitment_signed");
2262
- let commitment_signed = self.context .get_initial_commitment_signed(logger);
2262
+ let commitment_signed = self.context_mut() .get_initial_commitment_signed(logger);
2263
2263
let commitment_signed = match commitment_signed {
2264
2264
Ok(commitment_signed) => {
2265
2265
self.context.funding_transaction = Some(signing_session.unsigned_tx.build_unsigned_tx());
@@ -3440,8 +3440,12 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3440
3440
/// which peer generated this transaction and "to whom" this transaction flows.
3441
3441
// PASS IN SCOPE
3442
3442
#[inline]
3443
- fn build_commitment_transaction<L: Deref>(&self, commitment_number: u64, keys: &TxCreationKeys, local: bool, generated_by_local: bool, logger: &L) -> CommitmentStats
3444
- where L::Target: Logger
3443
+ fn build_commitment_transaction<L: Deref>(
3444
+ &self, funding: &FundingScope, commitment_number: u64, keys: &TxCreationKeys, local: bool,
3445
+ generated_by_local: bool, logger: &L,
3446
+ ) -> CommitmentStats
3447
+ where
3448
+ L::Target: Logger,
3445
3449
{
3446
3450
let mut included_dust_htlcs: Vec<(HTLCOutputInCommitment, Option<&HTLCSource>)> = Vec::new();
3447
3451
let num_htlcs = self.pending_inbound_htlcs.len() + self.pending_outbound_htlcs.len();
@@ -3595,7 +3599,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3595
3599
// AwaitingRemoteRevokeToRemove or AwaitingRemovedRemoteRevoke) we may have allowed them to
3596
3600
// "violate" their reserve value by couting those against it. Thus, we have to convert
3597
3601
// everything to i64 before subtracting as otherwise we can overflow.
3598
- let value_to_remote_msat: i64 = (self .channel_value_satoshis * 1000) as i64 - (self.value_to_self_msat as i64) - (remote_htlc_total_msat as i64) - value_to_self_msat_offset;
3602
+ let value_to_remote_msat: i64 = (funding .channel_value_satoshis * 1000) as i64 - (self.value_to_self_msat as i64) - (remote_htlc_total_msat as i64) - value_to_self_msat_offset;
3599
3603
assert!(value_to_remote_msat >= 0);
3600
3604
3601
3605
#[cfg(debug_assertions)]
@@ -4510,7 +4514,14 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4510
4514
msg_name);
4511
4515
}
4512
4516
}
4517
+ }
4513
4518
4519
+ impl<C, F, SP: Deref> ScopedChannelContext<C, F, SP>
4520
+ where
4521
+ C: Deref<Target = ChannelContext<SP>>,
4522
+ F: Deref<Target = FundingScope>,
4523
+ SP::Target: SignerProvider,
4524
+ {
4514
4525
fn get_initial_counterparty_commitment_signature<L: Deref>(
4515
4526
&self, logger: &L
4516
4527
) -> Result<Signature, ChannelError>
@@ -4520,7 +4531,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4520
4531
{
4521
4532
let counterparty_keys = self.build_remote_transaction_keys();
4522
4533
let counterparty_initial_commitment_tx = self.build_commitment_transaction(
4523
- self.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, false, logger).tx;
4534
+ &self.funding, self.cur_counterparty_commitment_transaction_number, &counterparty_keys,
4535
+ false, false, logger,
4536
+ ).tx;
4524
4537
match self.holder_signer {
4525
4538
// TODO (taproot|arik): move match into calling method for Taproot
4526
4539
ChannelSignerType::Ecdsa(ref ecdsa) => {
@@ -4537,7 +4550,14 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4537
4550
_ => todo!(),
4538
4551
}
4539
4552
}
4553
+ }
4540
4554
4555
+ impl<C, F, SP: Deref> ScopedChannelContext<C, F, SP>
4556
+ where
4557
+ C: DerefMut<Target = ChannelContext<SP>>,
4558
+ F: DerefMut<Target = FundingScope>,
4559
+ SP::Target: SignerProvider,
4560
+ {
4541
4561
fn get_initial_commitment_signed<L: Deref>(
4542
4562
&mut self, logger: &L
4543
4563
) -> Result<msgs::CommitmentSigned, ChannelError>
@@ -5527,7 +5547,7 @@ impl<SP: Deref> FundedChannel<SP> where
5527
5547
5528
5548
let keys = self.context.build_holder_transaction_keys(self.holder_commitment_point.current_point());
5529
5549
5530
- let commitment_stats = self.context.build_commitment_transaction(self.holder_commitment_point.transaction_number(), &keys, true, false, logger);
5550
+ let commitment_stats = self.context.build_commitment_transaction(&self.funding, self.holder_commitment_point.transaction_number(), &keys, true, false, logger);
5531
5551
let commitment_txid = {
5532
5552
let trusted_tx = commitment_stats.tx.trust();
5533
5553
let bitcoin_tx = trusted_tx.built_transaction();
@@ -6279,7 +6299,7 @@ impl<SP: Deref> FundedChannel<SP> where
6279
6299
let dust_exposure_limiting_feerate = self.context.get_dust_exposure_limiting_feerate(&fee_estimator);
6280
6300
let htlc_stats = self.context.get_pending_htlc_stats(Some(feerate_per_kw), dust_exposure_limiting_feerate);
6281
6301
let keys = self.context.build_holder_transaction_keys(self.holder_commitment_point.current_point());
6282
- let commitment_stats = self.context.build_commitment_transaction(self.holder_commitment_point.transaction_number(), &keys, true, true, logger);
6302
+ let commitment_stats = self.context.build_commitment_transaction(&self.funding, self.holder_commitment_point.transaction_number(), &keys, true, true, logger);
6283
6303
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;
6284
6304
let holder_balance_msat = commitment_stats.local_balance_msat - htlc_stats.outbound_holding_cell_msat;
6285
6305
if holder_balance_msat < buffer_fee_msat + self.context.counterparty_selected_channel_reserve_satoshis.unwrap() * 1000 {
@@ -6580,7 +6600,7 @@ impl<SP: Deref> FundedChannel<SP> where
6580
6600
}
6581
6601
let funding_signed = if self.context.signer_pending_funding && !self.context.is_outbound() {
6582
6602
let counterparty_keys = self.context.build_remote_transaction_keys();
6583
- let counterparty_initial_commitment_tx = self.context.build_commitment_transaction(self.context.cur_counterparty_commitment_transaction_number + 1, &counterparty_keys, false, false, logger).tx;
6603
+ let counterparty_initial_commitment_tx = self.context.build_commitment_transaction(&self.funding, self.context.cur_counterparty_commitment_transaction_number + 1, &counterparty_keys, false, false, logger).tx;
6584
6604
self.context.get_funding_signed_msg(logger, counterparty_initial_commitment_tx)
6585
6605
} else { None };
6586
6606
// Provide a `channel_ready` message if we need to, but only if we're _not_ still pending
@@ -8506,7 +8526,7 @@ impl<SP: Deref> FundedChannel<SP> where
8506
8526
where L::Target: Logger
8507
8527
{
8508
8528
let counterparty_keys = self.context.build_remote_transaction_keys();
8509
- let commitment_stats = self.context.build_commitment_transaction(self.context.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, true, logger);
8529
+ let commitment_stats = self.context.build_commitment_transaction(&self.funding, self.context.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, true, logger);
8510
8530
let counterparty_commitment_tx = commitment_stats.tx;
8511
8531
8512
8532
#[cfg(any(test, fuzzing))]
@@ -8538,7 +8558,7 @@ impl<SP: Deref> FundedChannel<SP> where
8538
8558
self.build_commitment_no_state_update(logger);
8539
8559
8540
8560
let counterparty_keys = self.context.build_remote_transaction_keys();
8541
- let commitment_stats = self.context.build_commitment_transaction(self.context.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, true, logger);
8561
+ let commitment_stats = self.context.build_commitment_transaction(&self.funding, self.context.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, true, logger);
8542
8562
let counterparty_commitment_txid = commitment_stats.tx.trust().txid();
8543
8563
8544
8564
match &self.context.holder_signer {
@@ -8815,7 +8835,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
8815
8835
/// Only allowed after [`ChannelContext::channel_transaction_parameters`] is set.
8816
8836
fn get_funding_created_msg<L: Deref>(&mut self, logger: &L) -> Option<msgs::FundingCreated> where L::Target: Logger {
8817
8837
let counterparty_keys = self.context.build_remote_transaction_keys();
8818
- let counterparty_initial_commitment_tx = self.context.build_commitment_transaction(self.context.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, false, logger).tx;
8838
+ let counterparty_initial_commitment_tx = self.context.build_commitment_transaction(&self.funding, self.context.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, false, logger).tx;
8819
8839
let signature = match &self.context.holder_signer {
8820
8840
// TODO (taproot|arik): move match into calling method for Taproot
8821
8841
ChannelSignerType::Ecdsa(ecdsa) => {
0 commit comments