@@ -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());
@@ -3424,7 +3424,14 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3424
3424
!self.channel_state.is_pre_funded_state() &&
3425
3425
!matches!(self.channel_state, ChannelState::AwaitingChannelReady(flags) if flags.is_set(AwaitingChannelReadyFlags::WAITING_FOR_BATCH))
3426
3426
}
3427
+ }
3427
3428
3429
+ impl<C, F, SP: Deref> ScopedChannelContext<C, F, SP>
3430
+ where
3431
+ C: Deref<Target = ChannelContext<SP>>,
3432
+ F: Deref<Target = FundingScope>,
3433
+ SP::Target: SignerProvider,
3434
+ {
3428
3435
/// Transaction nomenclature is somewhat confusing here as there are many different cases - a
3429
3436
/// transaction is referred to as "a's transaction" implying that a will be able to broadcast
3430
3437
/// the transaction. Thus, b will generally be sending a signature over such a transaction to
@@ -3595,7 +3602,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3595
3602
// AwaitingRemoteRevokeToRemove or AwaitingRemovedRemoteRevoke) we may have allowed them to
3596
3603
// "violate" their reserve value by couting those against it. Thus, we have to convert
3597
3604
// 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;
3605
+ 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;
3599
3606
assert!(value_to_remote_msat >= 0);
3600
3607
3601
3608
#[cfg(debug_assertions)]
@@ -3673,7 +3680,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3673
3680
outbound_htlc_preimages,
3674
3681
}
3675
3682
}
3683
+ }
3676
3684
3685
+ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3677
3686
#[inline]
3678
3687
/// Creates a set of keys for build_commitment_transaction to generate a transaction which our
3679
3688
/// counterparty will sign (ie DO NOT send signatures over a transaction created by this to
@@ -4510,7 +4519,14 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4510
4519
msg_name);
4511
4520
}
4512
4521
}
4522
+ }
4513
4523
4524
+ impl<C, F, SP: Deref> ScopedChannelContext<C, F, SP>
4525
+ where
4526
+ C: Deref<Target = ChannelContext<SP>>,
4527
+ F: Deref<Target = FundingScope>,
4528
+ SP::Target: SignerProvider,
4529
+ {
4514
4530
fn get_initial_counterparty_commitment_signature<L: Deref>(
4515
4531
&self, logger: &L
4516
4532
) -> Result<Signature, ChannelError>
@@ -4537,7 +4553,14 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4537
4553
_ => todo!(),
4538
4554
}
4539
4555
}
4556
+ }
4540
4557
4558
+ impl<C, F, SP: Deref> ScopedChannelContext<C, F, SP>
4559
+ where
4560
+ C: DerefMut<Target = ChannelContext<SP>>,
4561
+ F: DerefMut<Target = FundingScope>,
4562
+ SP::Target: SignerProvider,
4563
+ {
4541
4564
fn get_initial_commitment_signed<L: Deref>(
4542
4565
&mut self, logger: &L
4543
4566
) -> Result<msgs::CommitmentSigned, ChannelError>
@@ -5527,7 +5550,8 @@ impl<SP: Deref> FundedChannel<SP> where
5527
5550
5528
5551
let keys = self.context.build_holder_transaction_keys(self.holder_commitment_point.current_point());
5529
5552
5530
- let commitment_stats = self.context.build_commitment_transaction(self.holder_commitment_point.transaction_number(), &keys, true, false, logger);
5553
+ let funding_context = self.context();
5554
+ let commitment_stats = funding_context.build_commitment_transaction(self.holder_commitment_point.transaction_number(), &keys, true, false, logger);
5531
5555
let commitment_txid = {
5532
5556
let trusted_tx = commitment_stats.tx.trust();
5533
5557
let bitcoin_tx = trusted_tx.built_transaction();
@@ -6279,7 +6303,8 @@ impl<SP: Deref> FundedChannel<SP> where
6279
6303
let dust_exposure_limiting_feerate = self.context.get_dust_exposure_limiting_feerate(&fee_estimator);
6280
6304
let htlc_stats = self.context.get_pending_htlc_stats(Some(feerate_per_kw), dust_exposure_limiting_feerate);
6281
6305
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);
6306
+ let funding_context = self.context();
6307
+ let commitment_stats = funding_context.build_commitment_transaction(self.holder_commitment_point.transaction_number(), &keys, true, true, logger);
6283
6308
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
6309
let holder_balance_msat = commitment_stats.local_balance_msat - htlc_stats.outbound_holding_cell_msat;
6285
6310
if holder_balance_msat < buffer_fee_msat + self.context.counterparty_selected_channel_reserve_satoshis.unwrap() * 1000 {
@@ -6580,7 +6605,7 @@ impl<SP: Deref> FundedChannel<SP> where
6580
6605
}
6581
6606
let funding_signed = if self.context.signer_pending_funding && !self.context.is_outbound() {
6582
6607
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;
6608
+ let counterparty_initial_commitment_tx = self.context() .build_commitment_transaction(self.context.cur_counterparty_commitment_transaction_number + 1, &counterparty_keys, false, false, logger).tx;
6584
6609
self.context.get_funding_signed_msg(logger, counterparty_initial_commitment_tx)
6585
6610
} else { None };
6586
6611
// Provide a `channel_ready` message if we need to, but only if we're _not_ still pending
@@ -8506,7 +8531,8 @@ impl<SP: Deref> FundedChannel<SP> where
8506
8531
where L::Target: Logger
8507
8532
{
8508
8533
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);
8534
+ let funding_context = self.context();
8535
+ let commitment_stats = funding_context.build_commitment_transaction(self.context.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, true, logger);
8510
8536
let counterparty_commitment_tx = commitment_stats.tx;
8511
8537
8512
8538
#[cfg(any(test, fuzzing))]
@@ -8538,7 +8564,8 @@ impl<SP: Deref> FundedChannel<SP> where
8538
8564
self.build_commitment_no_state_update(logger);
8539
8565
8540
8566
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);
8567
+ let funding_context = self.context();
8568
+ let commitment_stats = funding_context.build_commitment_transaction(self.context.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, true, logger);
8542
8569
let counterparty_commitment_txid = commitment_stats.tx.trust().txid();
8543
8570
8544
8571
match &self.context.holder_signer {
@@ -8815,7 +8842,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
8815
8842
/// Only allowed after [`ChannelContext::channel_transaction_parameters`] is set.
8816
8843
fn get_funding_created_msg<L: Deref>(&mut self, logger: &L) -> Option<msgs::FundingCreated> where L::Target: Logger {
8817
8844
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;
8845
+ let counterparty_initial_commitment_tx = self.context() .build_commitment_transaction(self.context.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, false, logger).tx;
8819
8846
let signature = match &self.context.holder_signer {
8820
8847
// TODO (taproot|arik): move match into calling method for Taproot
8821
8848
ChannelSignerType::Ecdsa(ecdsa) => {
0 commit comments