Skip to content

Commit

Permalink
Clarify crossSign helper functions (#1578)
Browse files Browse the repository at this point in the history
It's important in particular to highlight the case where an HTLC is
half-fulfilled or half-failed.
  • Loading branch information
t-bast authored Oct 22, 2020
1 parent 98508f3 commit e74f345
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ case class Commitments(channelVersion: ChannelVersion,
remoteNextCommitInfo.left.toSeq.flatMap(_.nextRemoteCommit.spec.htlcs.collect(incoming).filter(expired).toSet)
}

/**
* Return the outgoing HTLC with the given id if it is:
* - signed by us in their commitment transaction (remote)
* - signed by them in our commitment transaction (local)
* NB: if we're in the middle of fulfilling or failing that HTLC, it will not be returned by this function.
*/
def getOutgoingHtlcCrossSigned(htlcId: Long): Option[UpdateAddHtlc] = for {
localSigned <- remoteNextCommitInfo.left.toOption.map(_.nextRemoteCommit).getOrElse(remoteCommit).spec.findIncomingHtlcById(htlcId)
remoteSigned <- localCommit.spec.findOutgoingHtlcById(htlcId)
Expand All @@ -114,6 +120,12 @@ case class Commitments(channelVersion: ChannelVersion,
localSigned.add
}

/**
* Return the incoming HTLC with the given id if it is:
* - signed by us in their commitment transaction (remote)
* - signed by them in our commitment transaction (local)
* NB: if we're in the middle of fulfilling or failing that HTLC, it will not be returned by this function.
*/
def getIncomingHtlcCrossSigned(htlcId: Long): Option[UpdateAddHtlc] = for {
localSigned <- remoteNextCommitInfo.left.toOption.map(_.nextRemoteCommit).getOrElse(remoteCommit).spec.findOutgoingHtlcById(htlcId)
remoteSigned <- localCommit.spec.findIncomingHtlcById(htlcId)
Expand Down

0 comments on commit e74f345

Please sign in to comment.