Skip to content

Commit d6345f5

Browse files
committed
f dry up no commitment advancement check
1 parent 27a3559 commit d6345f5

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

lightning/src/ln/channel.rs

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,7 +1653,7 @@ impl<SP: Deref> InteractivelyFunded<SP> for InboundV2Channel<SP> where SP::Targe
16531653
}
16541654
}
16551655

1656-
impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
1656+
impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
16571657
fn new_for_inbound_channel<'a, ES: Deref, F: Deref, L: Deref>(
16581658
fee_estimator: &'a LowerBoundedFeeEstimator<F>,
16591659
entropy_source: &'a ES,
@@ -3747,6 +3747,15 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
37473747
self.channel_transaction_parameters.channel_type_features = self.channel_type.clone();
37483748
Ok(())
37493749
}
3750+
3751+
/// Panics if the commitment tx numbers have advanced from their initial number.
3752+
fn assert_no_commitment_advancement(&self) {
3753+
if self.commitment_secrets.get_min_seen_secret() != (1 << 48) ||
3754+
self.cur_counterparty_commitment_transaction_number != INITIAL_COMMITMENT_NUMBER ||
3755+
self.holder_commitment_point.transaction_number() != INITIAL_COMMITMENT_NUMBER {
3756+
panic!("Should not have advanced channel commitment tx numbers prior to funding_created");
3757+
}
3758+
}
37503759
}
37513760

37523761
// Internal utility functions for channels
@@ -4679,11 +4688,7 @@ impl<SP: Deref> Channel<SP> where
46794688
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
46804689
)));
46814690
}
4682-
if self.context.commitment_secrets.get_min_seen_secret() != (1 << 48) ||
4683-
self.context.cur_counterparty_commitment_transaction_number != INITIAL_COMMITMENT_NUMBER ||
4684-
self.context.holder_commitment_point.transaction_number() != INITIAL_COMMITMENT_NUMBER {
4685-
panic!("Should not have advanced channel commitment tx numbers prior to funding_created");
4686-
}
4691+
self.context.assert_no_commitment_advancement();
46874692

46884693
let funding_script = self.context.get_funding_redeemscript();
46894694

@@ -7987,11 +7992,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
79877992
) {
79887993
panic!("Tried to get a funding_created messsage at a time other than immediately after initial handshake completion (or tried to get funding_created twice)");
79897994
}
7990-
if self.context.commitment_secrets.get_min_seen_secret() != (1 << 48) ||
7991-
self.context.cur_counterparty_commitment_transaction_number != INITIAL_COMMITMENT_NUMBER ||
7992-
self.context.holder_commitment_point.transaction_number() != INITIAL_COMMITMENT_NUMBER {
7993-
panic!("Should not have advanced channel commitment tx numbers prior to funding_created");
7994-
}
7995+
self.context.assert_no_commitment_advancement();
79957996

79967997
self.context.channel_transaction_parameters.funding_outpoint = Some(funding_txo);
79977998
self.context.holder_signer.as_mut().provide_channel_parameters(&self.context.channel_transaction_parameters);
@@ -8115,11 +8116,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
81158116
if !matches!(self.context.channel_state, ChannelState::FundingNegotiated) {
81168117
return Err((self, ChannelError::close("Received funding_signed in strange state!".to_owned())));
81178118
}
8118-
if self.context.commitment_secrets.get_min_seen_secret() != (1 << 48) ||
8119-
self.context.cur_counterparty_commitment_transaction_number != INITIAL_COMMITMENT_NUMBER ||
8120-
self.context.holder_commitment_point.transaction_number() != INITIAL_COMMITMENT_NUMBER {
8121-
panic!("Should not have advanced channel commitment tx numbers prior to funding_created");
8122-
}
8119+
self.context.assert_no_commitment_advancement();
81238120

81248121
let funding_script = self.context.get_funding_redeemscript();
81258122

@@ -8411,11 +8408,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
84118408
// channel.
84128409
return Err((self, ChannelError::close("Received funding_created after we got the channel!".to_owned())));
84138410
}
8414-
if self.context.commitment_secrets.get_min_seen_secret() != (1 << 48) ||
8415-
self.context.cur_counterparty_commitment_transaction_number != INITIAL_COMMITMENT_NUMBER ||
8416-
self.context.holder_commitment_point.transaction_number() != INITIAL_COMMITMENT_NUMBER {
8417-
panic!("Should not have advanced channel commitment tx numbers prior to funding_created");
8418-
}
8411+
self.context.assert_no_commitment_advancement();
84198412

84208413
let funding_txo = OutPoint { txid: msg.funding_txid, index: msg.funding_output_index };
84218414
self.context.channel_transaction_parameters.funding_outpoint = Some(funding_txo);

0 commit comments

Comments
 (0)