Skip to content

Commit

Permalink
Proper type for receiveTxSigs (#555)
Browse files Browse the repository at this point in the history
This is a bit heavier, but more correct. I got confused by the
pass-through handlers, which were in fact impossible.
  • Loading branch information
pm47 authored Oct 19, 2023
1 parent 88b4366 commit 1137cfe
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -799,15 +799,15 @@ data class InteractiveTxSigningSession(
}
}

fun receiveTxSigs(channelKeys: KeyManager.ChannelKeys, remoteTxSigs: TxSignatures, currentBlockHeight: Long): InteractiveTxSigningSessionAction {
fun receiveTxSigs(channelKeys: KeyManager.ChannelKeys, remoteTxSigs: TxSignatures, currentBlockHeight: Long): Either<InteractiveTxSigningSessionAction.AbortFundingAttempt, InteractiveTxSigningSessionAction.SendTxSigs> {
return when (localCommit) {
is Either.Left -> InteractiveTxSigningSessionAction.AbortFundingAttempt(UnexpectedFundingSignatures(fundingParams.channelId))
is Either.Left -> Either.Left(InteractiveTxSigningSessionAction.AbortFundingAttempt(UnexpectedFundingSignatures(fundingParams.channelId)))
is Either.Right -> when (val fullySignedTx = fundingTx.addRemoteSigs(channelKeys, fundingParams, remoteTxSigs)) {
null -> InteractiveTxSigningSessionAction.AbortFundingAttempt(InvalidFundingSignature(fundingParams.channelId, fundingTx.txId))
null -> Either.Left(InteractiveTxSigningSessionAction.AbortFundingAttempt(InvalidFundingSignature(fundingParams.channelId, fundingTx.txId)))
else -> {
val fundingStatus = LocalFundingStatus.UnconfirmedFundingTx(fullySignedTx, fundingParams, currentBlockHeight)
val commitment = Commitment(fundingTxIndex, fundingParams.remoteFundingPubkey, fundingStatus, RemoteFundingStatus.NotLocked, localCommit.value, remoteCommit, nextRemoteCommit = null)
InteractiveTxSigningSessionAction.SendTxSigs(fundingStatus, commitment, fundingTx.localSigs)
Either.Right(InteractiveTxSigningSessionAction.SendTxSigs(fundingStatus, commitment, fundingTx.localSigs))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,13 +525,16 @@ data class Normal(
}
is TxSignatures -> when (spliceStatus) {
is SpliceStatus.WaitingForSigs -> {
when (val action = spliceStatus.session.receiveTxSigs(channelKeys(), cmd.message, currentBlockHeight.toLong())) {
is InteractiveTxSigningSessionAction.AbortFundingAttempt -> {
when (val res = spliceStatus.session.receiveTxSigs(channelKeys(), cmd.message, currentBlockHeight.toLong())) {
is Either.Left -> {
val action: InteractiveTxSigningSessionAction.AbortFundingAttempt = res.value
logger.warning { "splice attempt failed: ${action.reason.message}" }
Pair(this@Normal.copy(spliceStatus = SpliceStatus.Aborted), listOf(ChannelAction.Message.Send(TxAbort(channelId, action.reason.message))))
}
InteractiveTxSigningSessionAction.WaitForTxSigs -> Pair(this@Normal, listOf())
is InteractiveTxSigningSessionAction.SendTxSigs -> sendSpliceTxSigs(spliceStatus.origins, action, cmd.message.channelData)
is Either.Right -> {
val action: InteractiveTxSigningSessionAction.SendTxSigs = res.value
sendSpliceTxSigs(spliceStatus.origins, action, cmd.message.channelData)
}
}
}
else -> when (commitments.latest.localFundingStatus) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,16 @@ data class WaitForFundingConfirmed(
}
is FullySignedSharedTransaction -> when (rbfStatus) {
is RbfStatus.WaitingForSigs -> {
when (val action = rbfStatus.session.receiveTxSigs(channelKeys(), cmd.message, currentBlockHeight.toLong())) {
is InteractiveTxSigningSessionAction.AbortFundingAttempt -> {
when (val res = rbfStatus.session.receiveTxSigs(channelKeys(), cmd.message, currentBlockHeight.toLong())) {
is Either.Left -> {
val action: InteractiveTxSigningSessionAction.AbortFundingAttempt = res.value
logger.warning { "rbf attempt failed: ${action.reason.message}" }
Pair(this@WaitForFundingConfirmed.copy(rbfStatus = RbfStatus.RbfAborted), listOf(ChannelAction.Message.Send(TxAbort(channelId, action.reason.message))))
}
InteractiveTxSigningSessionAction.WaitForTxSigs -> Pair(this@WaitForFundingConfirmed, listOf())
is InteractiveTxSigningSessionAction.SendTxSigs -> sendRbfTxSigs(action, cmd.message.channelData)
is Either.Right -> {
val action: InteractiveTxSigningSessionAction.SendTxSigs = res.value
sendRbfTxSigs(action, cmd.message.channelData)
}
}
}
else -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,15 @@ data class WaitForFundingSigned(
}
}
is TxSignatures -> {
when (val action = signingSession.receiveTxSigs(channelParams.localParams.channelKeys(keyManager), cmd.message, currentBlockHeight.toLong())) {
is InteractiveTxSigningSessionAction.AbortFundingAttempt -> handleLocalError(cmd, action.reason)
InteractiveTxSigningSessionAction.WaitForTxSigs -> Pair(this@WaitForFundingSigned, listOf())
is InteractiveTxSigningSessionAction.SendTxSigs -> sendTxSigs(action, cmd.message.channelData)
when (val res = signingSession.receiveTxSigs(channelParams.localParams.channelKeys(keyManager), cmd.message, currentBlockHeight.toLong())) {
is Either.Left -> {
val action: InteractiveTxSigningSessionAction.AbortFundingAttempt = res.value
handleLocalError(cmd, action.reason)
}
is Either.Right -> {
val action: InteractiveTxSigningSessionAction.SendTxSigs = res.value
sendTxSigs(action, cmd.message.channelData)
}
}
}
is TxInitRbf -> {
Expand Down

0 comments on commit 1137cfe

Please sign in to comment.