Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find htlc by id method #1266

Merged
merged 7 commits into from
Jan 16, 2020
Merged

Find htlc by id method #1266

merged 7 commits into from
Jan 16, 2020

Conversation

akumaigorodski
Copy link
Contributor

Another minor change to move a somewhat tricky HTLC search logic to a separate method.

} yield htlc_in.add
}
def getHtlcCrossSigned(commitments: Commitments, directionRelativeToLocal: Direction, htlcId: Long): Option[UpdateAddHtlc] = for {
_ <- commitments.remoteNextCommitInfo.left.toOption.map(_.nextRemoteCommit).getOrElse(commitments.remoteCommit).spec.findHtlcById(htlcId, directionRelativeToLocal.opposite)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You inverted the place where we look in the remote commit and the one where we look in the local one.
That deserves a closer look, I'd like @pm47 to verify that this isn't an issue (maybe we're missing a test if it is).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remote signs our local commitment, so yes , that's a regression. Agree that this probably means we are missing a non-reg test on this method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regression in a sense that a name is wrong? It was remoteSigned <- commitments.localCommit ... and now it's localSigned <- commitments.localCommit ..., this is something I've missed indeed. An order of checks is also changed but is it important?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'a regression only in the sense that the naming was accurate and it's not anymore. I thought there could be something more, but upon deeper inspection it doesn't appear to be the case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To remove ambiguity we could rewrite to:

  def getHtlcCrossSigned(commitments: Commitments, directionRelativeToLocal: Direction, htlcId: Long): Option[UpdateAddHtlc] = for {
    localSigned <- commitments.remoteNextCommitInfo.left.toOption.map(_.nextRemoteCommit).getOrElse(commitments.remoteCommit).spec.findHtlcById(htlcId, directionRelativeToLocal.opposite)
    remoteSigned <- commitments.localCommit.spec.findHtlcById(htlcId, directionRelativeToLocal)
  } yield {
    require(localSigned.add == remoteSigned.add)
    localSigned.add
  }

Copy link
Member

@t-bast t-bast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@pm47 pm47 merged commit b81bf20 into ACINQ:master Jan 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants