Skip to content

Commit

Permalink
Add fundingTxIndex to commitments.isMoreRecent (#525)
Browse files Browse the repository at this point in the history
We cannot only rely on the commitment index, because splicing doesn't
change the commitment index. After a restore we could be on the same
commitment index but on a future funding index.
  • Loading branch information
pm47 committed Sep 5, 2023
1 parent 0315535 commit 64c4415
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,8 @@ data class Commitments(
fun isMoreRecent(other: Commitments): Boolean {
return this.localCommitIndex > other.localCommitIndex ||
this.remoteCommitIndex > other.remoteCommitIndex ||
(this.remoteCommitIndex == other.remoteCommitIndex && this.remoteNextCommitInfo.isLeft && other.remoteNextCommitInfo.isRight)
(this.remoteCommitIndex == other.remoteCommitIndex && this.remoteNextCommitInfo.isLeft && other.remoteNextCommitInfo.isRight) ||
this.latest.fundingTxIndex > other.latest.fundingTxIndex
}

// @formatter:off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,10 @@ class SpliceTestsCommon : LightningTestSuite() {

assertEquals(alice.commitments.active.size + 1, alice2.commitments.active.size)
assertEquals(bob.commitments.active.size + 1, bob2.commitments.active.size)

assertTrue { alice2.commitments.isMoreRecent(alice.commitments) }
assertTrue { bob2.commitments.isMoreRecent(bob.commitments) }

assertIs<LNChannel<Normal>>(alice2)
assertIs<LNChannel<Normal>>(bob2)
return Pair(alice2, bob2)
Expand Down

0 comments on commit 64c4415

Please sign in to comment.