From 64c4415991895c6918cc872c72e918912275a82d Mon Sep 17 00:00:00 2001 From: Pierre-Marie Padiou Date: Tue, 5 Sep 2023 10:31:59 +0200 Subject: [PATCH] Add `fundingTxIndex` to `commitments.isMoreRecent` (#525) 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. --- .../kotlin/fr/acinq/lightning/channel/Commitments.kt | 3 ++- .../fr/acinq/lightning/channel/states/SpliceTestsCommon.kt | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/commonMain/kotlin/fr/acinq/lightning/channel/Commitments.kt b/src/commonMain/kotlin/fr/acinq/lightning/channel/Commitments.kt index 0ed485ee9..b0df8848e 100644 --- a/src/commonMain/kotlin/fr/acinq/lightning/channel/Commitments.kt +++ b/src/commonMain/kotlin/fr/acinq/lightning/channel/Commitments.kt @@ -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 diff --git a/src/commonTest/kotlin/fr/acinq/lightning/channel/states/SpliceTestsCommon.kt b/src/commonTest/kotlin/fr/acinq/lightning/channel/states/SpliceTestsCommon.kt index 72e6e1922..4690d9bfb 100644 --- a/src/commonTest/kotlin/fr/acinq/lightning/channel/states/SpliceTestsCommon.kt +++ b/src/commonTest/kotlin/fr/acinq/lightning/channel/states/SpliceTestsCommon.kt @@ -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>(alice2) assertIs>(bob2) return Pair(alice2, bob2)