Skip to content

Commit

Permalink
f dry up no commitment advancement check
Browse files Browse the repository at this point in the history
  • Loading branch information
dunxen committed Jul 11, 2024
1 parent 27a3559 commit d6345f5
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1653,7 +1653,7 @@ impl<SP: Deref> InteractivelyFunded<SP> for InboundV2Channel<SP> where SP::Targe
}
}

impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
fn new_for_inbound_channel<'a, ES: Deref, F: Deref, L: Deref>(
fee_estimator: &'a LowerBoundedFeeEstimator<F>,
entropy_source: &'a ES,
Expand Down Expand Up @@ -3747,6 +3747,15 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
self.channel_transaction_parameters.channel_type_features = self.channel_type.clone();
Ok(())
}

/// Panics if the commitment tx numbers have advanced from their initial number.
fn assert_no_commitment_advancement(&self) {
if self.commitment_secrets.get_min_seen_secret() != (1 << 48) ||
self.cur_counterparty_commitment_transaction_number != INITIAL_COMMITMENT_NUMBER ||
self.holder_commitment_point.transaction_number() != INITIAL_COMMITMENT_NUMBER {
panic!("Should not have advanced channel commitment tx numbers prior to funding_created");
}
}
}

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

let funding_script = self.context.get_funding_redeemscript();

Expand Down Expand Up @@ -7987,11 +7992,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
) {
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)");
}
if self.context.commitment_secrets.get_min_seen_secret() != (1 << 48) ||
self.context.cur_counterparty_commitment_transaction_number != INITIAL_COMMITMENT_NUMBER ||
self.context.holder_commitment_point.transaction_number() != INITIAL_COMMITMENT_NUMBER {
panic!("Should not have advanced channel commitment tx numbers prior to funding_created");
}
self.context.assert_no_commitment_advancement();

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

let funding_script = self.context.get_funding_redeemscript();

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

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

0 comments on commit d6345f5

Please sign in to comment.