Skip to content

Commit 1adb816

Browse files
committed
Make channel_parameters explicit to build_counterparty_commitment_tx
It's best to let the caller decide what the appropriate `ChannelTransactionParameters` are as it has the most context.
1 parent 1dc0a7d commit 1adb816

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4202,8 +4202,14 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
42024202
to_countersignatory_value,
42034203
)| {
42044204
let nondust_htlcs = vec![];
4205+
// Since we're expected to only reach here during the initial persistence of a
4206+
// monitor (i.e., via [`Persist::persist_new_channel`]), we expect to only have
4207+
// one `FundingScope` present.
4208+
debug_assert!(self.pending_funding.is_empty());
4209+
let channel_parameters = &self.funding.channel_parameters;
42054210

42064211
let commitment_tx = self.build_counterparty_commitment_tx(
4212+
channel_parameters,
42074213
INITIAL_COMMITMENT_NUMBER,
42084214
&their_per_commitment_point,
42094215
to_broadcaster_value,
@@ -4221,11 +4227,12 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
42214227

42224228
#[rustfmt::skip]
42234229
fn build_counterparty_commitment_tx(
4224-
&self, commitment_number: u64, their_per_commitment_point: &PublicKey,
4225-
to_broadcaster_value: u64, to_countersignatory_value: u64, feerate_per_kw: u32,
4230+
&self, channel_parameters: &ChannelTransactionParameters, commitment_number: u64,
4231+
their_per_commitment_point: &PublicKey, to_broadcaster_value: u64,
4232+
to_countersignatory_value: u64, feerate_per_kw: u32,
42264233
nondust_htlcs: Vec<HTLCOutputInCommitment>
42274234
) -> CommitmentTransaction {
4228-
let channel_parameters = &self.funding.channel_parameters.as_counterparty_broadcastable();
4235+
let channel_parameters = &channel_parameters.as_counterparty_broadcastable();
42294236
CommitmentTransaction::new(commitment_number, their_per_commitment_point,
42304237
to_broadcaster_value, to_countersignatory_value, feerate_per_kw, nondust_htlcs, channel_parameters, &self.onchain_tx_handler.secp_ctx)
42314238
}
@@ -4247,9 +4254,20 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
42474254
htlc.transaction_output_index.map(|_| htlc).cloned()
42484255
}).collect::<Vec<_>>();
42494256

4250-
let commitment_tx = self.build_counterparty_commitment_tx(commitment_number,
4251-
&their_per_commitment_point, to_broadcaster_value,
4252-
to_countersignatory_value, feerate_per_kw, nondust_htlcs);
4257+
// This monitor update variant is only applicable while there's a single
4258+
// `FundingScope` active, otherwise we expect to see
4259+
// `LatestCounterpartyCommitment` instead.
4260+
debug_assert!(self.pending_funding.is_empty());
4261+
let channel_parameters = &self.funding.channel_parameters;
4262+
let commitment_tx = self.build_counterparty_commitment_tx(
4263+
channel_parameters,
4264+
commitment_number,
4265+
&their_per_commitment_point,
4266+
to_broadcaster_value,
4267+
to_countersignatory_value,
4268+
feerate_per_kw,
4269+
nondust_htlcs,
4270+
);
42534271

42544272
debug_assert_eq!(commitment_tx.trust().txid(), commitment_txid);
42554273

0 commit comments

Comments
 (0)