Skip to content

Commit 4c758a8

Browse files
committed
Move holder_commitment_point advancement
Now that validate_commitment_signed encapsulates all funding-specific checks, move the holder_commitment_point advancement immediately following the call to it. While there should be any early returns at that point, it's good to have move it earlier in case of future changes.
1 parent 780ee68 commit 4c758a8

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

lightning/src/ln/channel.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -5646,6 +5646,20 @@ impl<SP: Deref> FundedChannel<SP> where
56465646

56475647
let commitment_tx_info = self.context.validate_commitment_signed(&self.funding, &self.holder_commitment_point, msg, logger)?;
56485648

5649+
if self.holder_commitment_point.advance(&self.context.holder_signer, &self.context.secp_ctx, logger).is_err() {
5650+
// We only fail to advance our commitment point/number if we're currently
5651+
// waiting for our signer to unblock and provide a commitment point.
5652+
// During post-funding channel operation, we only advance our point upon
5653+
// receiving a commitment_signed, and our counterparty cannot send us
5654+
// another commitment signed until we've provided a new commitment point
5655+
// in revoke_and_ack, which requires unblocking our signer and completing
5656+
// the advance to the next point. This should be unreachable since
5657+
// a new commitment_signed should fail at our signature checks in
5658+
// validate_commitment_signed.
5659+
debug_assert!(false, "We should be ready to advance our commitment point by the time we receive commitment_signed");
5660+
return Err(ChannelError::close("Failed to advance our commitment point".to_owned()));
5661+
}
5662+
56495663
// Update state now that we've passed all the can-fail calls...
56505664
let mut need_commitment = false;
56515665
if let &mut Some((_, ref mut update_state)) = &mut self.context.pending_update_fee {
@@ -5701,18 +5715,6 @@ impl<SP: Deref> FundedChannel<SP> where
57015715
channel_id: Some(self.context.channel_id()),
57025716
};
57035717

5704-
if self.holder_commitment_point.advance(&self.context.holder_signer, &self.context.secp_ctx, logger).is_err() {
5705-
// We only fail to advance our commitment point/number if we're currently
5706-
// waiting for our signer to unblock and provide a commitment point.
5707-
// During post-funding channel operation, we only advance our point upon
5708-
// receiving a commitment_signed, and our counterparty cannot send us
5709-
// another commitment signed until we've provided a new commitment point
5710-
// in revoke_and_ack, which requires unblocking our signer and completing
5711-
// the advance to the next point. This should be unreachable since
5712-
// a new commitment_signed should fail at our signature checks above.
5713-
debug_assert!(false, "We should be ready to advance our commitment point by the time we receive commitment_signed");
5714-
return Err(ChannelError::close("Failed to advance our commitment point".to_owned()));
5715-
}
57165718
self.context.expecting_peer_commitment_signed = false;
57175719
// Note that if we need_commitment & !AwaitingRemoteRevoke we'll call
57185720
// build_commitment_no_status_check() next which will reset this to RAAFirst.

0 commit comments

Comments
 (0)