Skip to content

Commit

Permalink
Add diagnostics for invalid commit sig during splice (#543)
Browse files Browse the repository at this point in the history
Only displayed in the failure case.
  • Loading branch information
pm47 authored Sep 27, 2023
1 parent c01a4ac commit eed767f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -767,14 +767,21 @@ data class InteractiveTxSigningSession(
is Either.Right -> localCommit.value.publishableTxs.commitTx.input
}

fun receiveCommitSig(channelKeys: KeyManager.ChannelKeys, channelParams: ChannelParams, remoteCommitSig: CommitSig, currentBlockHeight: Long): Pair<InteractiveTxSigningSession, InteractiveTxSigningSessionAction> {
fun receiveCommitSig(channelKeys: KeyManager.ChannelKeys, channelParams: ChannelParams, remoteCommitSig: CommitSig, currentBlockHeight: Long, logger: MDCLogger): Pair<InteractiveTxSigningSession, InteractiveTxSigningSessionAction> {
return when (localCommit) {
is Either.Left -> {
val fundingKey = channelKeys.fundingKey(fundingTxIndex)
val localSigOfLocalTx = Transactions.sign(localCommit.value.commitTx, fundingKey)
val signedLocalCommitTx = Transactions.addSigs(localCommit.value.commitTx, fundingKey.publicKey(), fundingParams.remoteFundingPubkey, localSigOfLocalTx, remoteCommitSig.signature)
when (Transactions.checkSpendable(signedLocalCommitTx)) {
is Try.Failure -> Pair(this, InteractiveTxSigningSessionAction.AbortFundingAttempt(InvalidCommitmentSignature(fundingParams.channelId, signedLocalCommitTx.tx.txid)))
is Try.Failure -> {
logger.info { "interactiveTxSession=$this"}
logger.info { "channelParams=$channelParams"}
logger.info { "fundingKey=${fundingKey.publicKey()}"}
logger.info { "localSigOfLocalTx=$localSigOfLocalTx"}
logger.info { "signedLocalCommitTx=$signedLocalCommitTx"}
Pair(this, InteractiveTxSigningSessionAction.AbortFundingAttempt(InvalidCommitmentSignature(fundingParams.channelId, signedLocalCommitTx.tx.txid)))
}
is Try.Success -> {
val signedLocalCommit = LocalCommit(localCommit.value.index, localCommit.value.spec, PublishableTxs(signedLocalCommitTx, listOf()))
if (shouldSignFirst(channelParams, fundingTx.tx)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ data class Normal(
Pair(this@Normal, listOf())
}
spliceStatus is SpliceStatus.WaitingForSigs -> {
val (signingSession1, action) = spliceStatus.session.receiveCommitSig(channelKeys(), commitments.params, cmd.message, currentBlockHeight.toLong())
val (signingSession1, action) = spliceStatus.session.receiveCommitSig(channelKeys(), commitments.params, cmd.message, currentBlockHeight.toLong(), logger)
when (action) {
is InteractiveTxSigningSessionAction.AbortFundingAttempt -> {
logger.warning { "splice attempt failed: ${action.reason.message} (fundingTxId=${spliceStatus.session.fundingTx.txId})" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ data class WaitForFundingConfirmed(
}
is CommitSig -> when (rbfStatus) {
is RbfStatus.WaitingForSigs -> {
val (signingSession1, action) = rbfStatus.session.receiveCommitSig(channelKeys(), commitments.params, cmd.message, currentBlockHeight.toLong())
val (signingSession1, action) = rbfStatus.session.receiveCommitSig(channelKeys(), commitments.params, cmd.message, currentBlockHeight.toLong(), logger)
when (action) {
is InteractiveTxSigningSessionAction.AbortFundingAttempt -> {
logger.warning { "rbf attempt failed: ${action.reason.message}" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ data class WaitForFundingSigned(
return when (cmd) {
is ChannelCommand.MessageReceived -> when (cmd.message) {
is CommitSig -> {
val (signingSession1, action) = signingSession.receiveCommitSig(channelParams.localParams.channelKeys(keyManager), channelParams, cmd.message, currentBlockHeight.toLong())
val (signingSession1, action) = signingSession.receiveCommitSig(channelParams.localParams.channelKeys(keyManager), channelParams, cmd.message, currentBlockHeight.toLong(), logger)
when (action) {
is InteractiveTxSigningSessionAction.AbortFundingAttempt -> handleLocalError(cmd, action.reason)
// No need to store their commit_sig, they will re-send it if we disconnect.
Expand Down

0 comments on commit eed767f

Please sign in to comment.