@@ -1008,7 +1008,9 @@ impl HolderCommitmentPoint {
1008
1008
}
1009
1009
1010
1010
/// If we are not pending the next commitment point, this method advances the commitment number
1011
- /// and requests the next commitment point from the signer.
1011
+ /// and requests the next commitment point from the signer. Returns `Ok` if we were at
1012
+ /// `Available` and were able to advance our commitment number (even if we are still pending
1013
+ /// the next commitment point).
1012
1014
///
1013
1015
/// If our signer is not ready to provide the next commitment point, we will
1014
1016
/// only advance to `PendingNext`, and should be tried again later in `signer_unblocked`
@@ -1020,7 +1022,9 @@ impl HolderCommitmentPoint {
1020
1022
/// This method is used for the following transitions:
1021
1023
/// - `Available` -> `PendingNext`
1022
1024
/// - `Available` -> `PendingNext` -> `Available` (in one fell swoop)
1023
- pub fn advance<SP: Deref, L: Deref>(&mut self, signer: &ChannelSignerType<SP>, secp_ctx: &Secp256k1<secp256k1::All>, logger: &L)
1025
+ pub fn advance<SP: Deref, L: Deref>(
1026
+ &mut self, signer: &ChannelSignerType<SP>, secp_ctx: &Secp256k1<secp256k1::All>, logger: &L
1027
+ ) -> Result<(), ()>
1024
1028
where SP::Target: SignerProvider, L::Target: Logger
1025
1029
{
1026
1030
if let HolderCommitmentPoint::Available { transaction_number, next, .. } = self {
@@ -1029,7 +1033,9 @@ impl HolderCommitmentPoint {
1029
1033
current: *next,
1030
1034
};
1031
1035
self.try_resolve_pending(signer, secp_ctx, logger);
1036
+ return Ok(());
1032
1037
}
1038
+ Err(())
1033
1039
}
1034
1040
}
1035
1041
@@ -4618,7 +4624,18 @@ impl<SP: Deref> Channel<SP> where
4618
4624
channel_id: Some(self.context.channel_id()),
4619
4625
};
4620
4626
4621
- self.context.holder_commitment_point.advance(&self.context.holder_signer, &self.context.secp_ctx, logger);
4627
+ if self.context.holder_commitment_point.advance(&self.context.holder_signer, &self.context.secp_ctx, logger).is_err() {
4628
+ // We only fail to advance our commitment point/number if we're currently
4629
+ // waiting for our signer to unblock and provide a commitment point.
4630
+ // During post-funding channel operation, we only advance our point upon
4631
+ // receiving a commitment_signed, and our counterparty cannot send us
4632
+ // another commitment signed until we've provided a new commitment point
4633
+ // in revoke_and_ack, which requires unblocking our signer and completing
4634
+ // the advance to the next point. This should be unreachable since
4635
+ // a new commitment_signed should fail at our signature checks above.
4636
+ debug_assert!(false, "We should be ready to advance our commitment point by the time we receive commitment_signed");
4637
+ return Err(ChannelError::close("Failed to advance our commitment point".to_owned()));
4638
+ }
4622
4639
self.context.expecting_peer_commitment_signed = false;
4623
4640
// Note that if we need_commitment & !AwaitingRemoteRevoke we'll call
4624
4641
// build_commitment_no_status_check() next which will reset this to RAAFirst.
@@ -7799,7 +7816,14 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
7799
7816
} else {
7800
7817
self.context.channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
7801
7818
}
7802
- self.context.holder_commitment_point.advance(&self.context.holder_signer, &self.context.secp_ctx, logger);
7819
+ if self.context.holder_commitment_point.advance(&self.context.holder_signer, &self.context.secp_ctx, logger).is_err() {
7820
+ // We only fail to advance our commitment point/number if we're currently
7821
+ // waiting for our signer to unblock and provide a commitment point.
7822
+ // We cannot send open_channel before this has occurred, so if we
7823
+ // err here by the time we receive funding_signed, something has gone wrong.
7824
+ debug_assert!(false, "We should be ready to advance our commitment point by the time we receive funding_signed");
7825
+ return Err((self, ChannelError::close("Failed to advance holder commitment point".to_owned())));
7826
+ }
7803
7827
self.context.cur_counterparty_commitment_transaction_number -= 1;
7804
7828
7805
7829
log_info!(logger, "Received funding_signed from peer for channel {}", &self.context.channel_id());
@@ -8066,7 +8090,14 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
8066
8090
self.context.channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
8067
8091
self.context.channel_id = ChannelId::v1_from_funding_outpoint(funding_txo);
8068
8092
self.context.cur_counterparty_commitment_transaction_number -= 1;
8069
- self.context.holder_commitment_point.advance(&self.context.holder_signer, &self.context.secp_ctx, logger);
8093
+ if self.context.holder_commitment_point.advance(&self.context.holder_signer, &self.context.secp_ctx, logger).is_err() {
8094
+ // We only fail to advance our commitment point/number if we're currently
8095
+ // waiting for our signer to unblock and provide a commitment point.
8096
+ // We cannot send accept_channel before this has occurred, so if we
8097
+ // err here by the time we receive funding_created, something has gone wrong.
8098
+ debug_assert!(false, "We should be ready to advance our commitment point by the time we receive funding_created");
8099
+ return Err((self, ChannelError::close("Failed to advance holder commitment point".to_owned())));
8100
+ }
8070
8101
8071
8102
let (counterparty_initial_commitment_tx, funding_signed) = self.context.get_funding_signed_msg(logger);
8072
8103
0 commit comments