Skip to content

Commit 516e5e6

Browse files
committed
Split HolderCommitmentPoint::advance off into separate function
1 parent 6035c83 commit 516e5e6

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

lightning/src/ln/channel.rs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,34 @@ impl HolderCommitmentPoint {
992992
}
993993
}
994994

995+
/// If we are pending the next commitment point, this method tries asking the signer again,
996+
/// and transitions to the next state if successful.
997+
///
998+
/// This method is used for the following transitions:
999+
/// - `PendingNext` -> `Available`
1000+
pub fn try_resolve_pending<SP: Deref, L: Deref>(&mut self, signer: &ChannelSignerType<SP>, secp_ctx: &Secp256k1<secp256k1::All>, logger: &L)
1001+
where SP::Target: SignerProvider, L::Target: Logger
1002+
{
1003+
if let HolderCommitmentPoint::PendingNext { transaction_number, current } = self {
1004+
let next = signer.as_ref().get_per_commitment_point(*transaction_number - 1, secp_ctx);
1005+
log_trace!(logger, "Retrieved next per-commitment point {}", *transaction_number - 1);
1006+
*self = HolderCommitmentPoint::Available { transaction_number: *transaction_number, current: *current, next };
1007+
}
1008+
}
1009+
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.
1012+
///
1013+
/// If our signer is not ready to provide the next commitment point, we will
1014+
/// only advance to `PendingNext`, and should be tried again later in `signer_unblocked`
1015+
/// via `try_resolve_pending`.
1016+
///
1017+
/// If our signer is ready to provide the next commitment point, we will advance all the
1018+
/// way to `Available`.
1019+
///
1020+
/// This method is used for the following transitions:
1021+
/// - `Available` -> `PendingNext`
1022+
/// - `Available` -> `PendingNext` -> `Available` (in one fell swoop)
9951023
pub fn advance<SP: Deref, L: Deref>(&mut self, signer: &ChannelSignerType<SP>, secp_ctx: &Secp256k1<secp256k1::All>, logger: &L)
9961024
where SP::Target: SignerProvider, L::Target: Logger
9971025
{
@@ -1000,12 +1028,7 @@ impl HolderCommitmentPoint {
10001028
transaction_number: *transaction_number - 1,
10011029
current: *next,
10021030
};
1003-
}
1004-
1005-
if let HolderCommitmentPoint::PendingNext { transaction_number, current } = self {
1006-
let next = signer.as_ref().get_per_commitment_point(*transaction_number - 1, secp_ctx);
1007-
log_trace!(logger, "Retrieved next per-commitment point {}", *transaction_number - 1);
1008-
*self = HolderCommitmentPoint::Available { transaction_number: *transaction_number, current: *current, next };
1031+
self.try_resolve_pending(signer, secp_ctx, logger);
10091032
}
10101033
}
10111034
}

0 commit comments

Comments
 (0)