Skip to content

Commit 7d29237

Browse files
authored
Revert serializable FinalFailure (#241)
Changes from cba7e7e are reverted. If Phoenix needs to serialize objects from eclair-kmp, it should handle that itself. Eclair-kmp does not need to know about it. ChannelClosingType hierarchy is also simplified.
1 parent cba7e7e commit 7d29237

File tree

5 files changed

+25
-26
lines changed

5 files changed

+25
-26
lines changed

src/commonMain/kotlin/fr/acinq/eclair/channel/Channel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import fr.acinq.eclair.channel.Helpers.Closing.overriddenOutgoingHtlcs
1616
import fr.acinq.eclair.channel.Helpers.Closing.timedOutHtlcs
1717
import fr.acinq.eclair.crypto.KeyManager
1818
import fr.acinq.eclair.crypto.ShaChain
19-
import fr.acinq.eclair.db.OutgoingPayment.Status.Completed.Succeeded.OnChain.ChannelClosingType
19+
import fr.acinq.eclair.db.ChannelClosingType
2020
import fr.acinq.eclair.router.Announcements
2121
import fr.acinq.eclair.serialization.Serialization
2222
import fr.acinq.eclair.transactions.CommitmentSpec
@@ -97,7 +97,7 @@ sealed class ChannelAction {
9797
data class GetHtlcInfos(val revokedCommitTxId: ByteVector32, val commitmentNumber: Long) : Storage()
9898
data class StoreIncomingAmount(val amount: MilliSatoshi, val origin: ChannelOrigin?) : Storage()
9999
data class StoreChannelClosing(val amount: MilliSatoshi, val closingAddress: String, val isSentToDefaultAddress: Boolean) : Storage()
100-
data class StoreChannelClosed(val txids: List<ByteVector32>, val claimed: Satoshi, val type: ChannelClosingType) : Storage()
100+
data class StoreChannelClosed(val txids: List<ByteVector32>, val claimed: Satoshi, val closingType: ChannelClosingType) : Storage()
101101
}
102102

103103
data class ProcessIncomingHtlc(val add: UpdateAddHtlc) : ChannelAction()

src/commonMain/kotlin/fr/acinq/eclair/db/PaymentsDb.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import fr.acinq.eclair.payment.FinalFailure
1111
import fr.acinq.eclair.payment.PaymentRequest
1212
import fr.acinq.eclair.utils.*
1313
import fr.acinq.eclair.wire.FailureMessage
14+
import kotlinx.serialization.Serializable
1415

1516
interface PaymentsDb : IncomingPaymentsDb, OutgoingPaymentsDb {
1617
/** List sent and received payments (with most recent payments first). */
@@ -226,13 +227,9 @@ data class OutgoingPayment(val id: UUID, val recipientAmount: MilliSatoshi, val
226227
// In the future, we plan on storing the closing btc transactions as parts.
227228
// Then we can use those parts to calculate the fees, and provide more details to the user.
228229
val claimed: Satoshi,
229-
val type: ChannelClosingType,
230+
val closingType: ChannelClosingType,
230231
override val completedAt: Long = currentTimestampMillis()
231-
) : Succeeded() {
232-
enum class ChannelClosingType {
233-
Mutual, Local, Remote, Revoked, Other
234-
}
235-
}
232+
) : Succeeded()
236233
}
237234
}
238235
}
@@ -262,6 +259,10 @@ data class OutgoingPayment(val id: UUID, val recipientAmount: MilliSatoshi, val
262259
}
263260
}
264261

262+
enum class ChannelClosingType {
263+
Mutual, Local, Remote, Revoked, Other;
264+
}
265+
265266
data class HopDesc(val nodeId: PublicKey, val nextNodeId: PublicKey, val shortChannelId: ShortChannelId? = null) {
266267
override fun toString(): String = when (shortChannelId) {
267268
null -> "$nodeId->$nextNodeId"

src/commonMain/kotlin/fr/acinq/eclair/io/Peer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ class Peer(
427427
}
428428
action is ChannelAction.Storage.StoreChannelClosed -> {
429429
val dbId = UUID.fromBytes(channelId.take(16).toByteArray())
430-
val completed = OutgoingPayment.Status.Completed.Succeeded.OnChain(action.txids, action.claimed, action.type)
430+
val completed = OutgoingPayment.Status.Completed.Succeeded.OnChain(action.txids, action.claimed, action.closingType)
431431
db.payments.completeOutgoingPayment(dbId, completed)
432432
listenerEventChannel.send(ChannelClosing(channelId))
433433
}

src/commonMain/kotlin/fr/acinq/eclair/payment/OutgoingPaymentFailure.kt

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,23 @@ import fr.acinq.eclair.db.OutgoingPayment
55
import fr.acinq.eclair.utils.Either
66
import fr.acinq.eclair.utils.currentTimestampMillis
77
import fr.acinq.eclair.wire.*
8-
import kotlinx.serialization.Serializable
98

109
/** A fatal failure that stops payment attempts. */
11-
@Serializable
1210
sealed class FinalFailure {
1311

1412
/** Use this function when no payment attempts have been made (e.g. when a precondition failed). */
1513
fun toPaymentFailure(): OutgoingPaymentFailure = OutgoingPaymentFailure(this, listOf<OutgoingPayment.Part.Status.Failed>())
1614

1715
// @formatter:off
18-
@Serializable object InvalidPaymentAmount : FinalFailure() { override fun toString(): String = "payment amount must be positive" }
19-
@Serializable object InvalidPaymentId : FinalFailure() { override fun toString(): String = "payment ID must be unique" }
20-
@Serializable object NoAvailableChannels : FinalFailure() { override fun toString(): String = "no channels available to send payment" }
21-
@Serializable object InsufficientBalance : FinalFailure() { override fun toString(): String = "not enough funds in wallet to afford payment" }
22-
@Serializable object NoRouteToRecipient : FinalFailure() { override fun toString(): String = "unable to route payment to recipient" }
23-
@Serializable object RecipientUnreachable : FinalFailure() { override fun toString(): String = "the recipient was offline or did not have enough liquidity to receive the payment" }
24-
@Serializable object RetryExhausted: FinalFailure() { override fun toString(): String = "payment attempts exhausted without success" }
25-
@Serializable object WalletRestarted: FinalFailure() { override fun toString(): String = "wallet restarted while a payment was ongoing" }
26-
@Serializable object UnknownError : FinalFailure() { override fun toString(): String = "an unknown error occurred" }
16+
object InvalidPaymentAmount : FinalFailure() { override fun toString(): String = "payment amount must be positive" }
17+
object InvalidPaymentId : FinalFailure() { override fun toString(): String = "payment ID must be unique" }
18+
object NoAvailableChannels : FinalFailure() { override fun toString(): String = "no channels available to send payment" }
19+
object InsufficientBalance : FinalFailure() { override fun toString(): String = "not enough funds in wallet to afford payment" }
20+
object NoRouteToRecipient : FinalFailure() { override fun toString(): String = "unable to route payment to recipient" }
21+
object RecipientUnreachable : FinalFailure() { override fun toString(): String = "the recipient was offline or did not have enough liquidity to receive the payment" }
22+
object RetryExhausted: FinalFailure() { override fun toString(): String = "payment attempts exhausted without success" }
23+
object WalletRestarted: FinalFailure() { override fun toString(): String = "wallet restarted while a payment was ongoing" }
24+
object UnknownError : FinalFailure() { override fun toString(): String = "an unknown error occurred" }
2725
// @formatter:on
2826
}
2927

src/commonTest/kotlin/fr/acinq/eclair/channel/states/ClosingTestsCommon.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import fr.acinq.eclair.channel.TestsHelper.mutualClose
2020
import fr.acinq.eclair.channel.TestsHelper.processEx
2121
import fr.acinq.eclair.channel.TestsHelper.reachNormal
2222
import fr.acinq.eclair.channel.TestsHelper.remoteClose
23-
import fr.acinq.eclair.db.OutgoingPayment.Status.Completed.Succeeded.OnChain.ChannelClosingType
23+
import fr.acinq.eclair.db.ChannelClosingType
2424
import fr.acinq.eclair.tests.TestConstants
2525
import fr.acinq.eclair.tests.utils.EclairTestSuite
2626
import fr.acinq.eclair.transactions.Scripts
@@ -111,7 +111,7 @@ class ClosingTestsCommon : EclairTestSuite() {
111111
assertTrue { alice6 is Closed }
112112
val storeChannelClosed = aliceActions6.filterIsInstance<ChannelAction.Storage.StoreChannelClosed>().firstOrNull()
113113
assertNotNull(storeChannelClosed)
114-
assertTrue { storeChannelClosed.type == ChannelClosingType.Mutual }
114+
assertTrue { storeChannelClosed.closingType == ChannelClosingType.Mutual }
115115
assertTrue { storeChannelClosed.txids == listOf(mutualCloseTx.tx.txid) }
116116
}
117117

@@ -125,7 +125,7 @@ class ClosingTestsCommon : EclairTestSuite() {
125125
assertTrue { alice1 is Closed }
126126
val storeChannelClosed = actions1.filterIsInstance<ChannelAction.Storage.StoreChannelClosed>().firstOrNull()
127127
assertNotNull(storeChannelClosed)
128-
assertTrue { storeChannelClosed.type == ChannelClosingType.Mutual }
128+
assertTrue { storeChannelClosed.closingType == ChannelClosingType.Mutual }
129129
assertTrue { storeChannelClosed.txids == listOf(mutualCloseTx.tx.txid) }
130130
}
131131

@@ -222,7 +222,7 @@ class ClosingTestsCommon : EclairTestSuite() {
222222
)
223223
val storeChannelClosed = actions.filterIsInstance<ChannelAction.Storage.StoreChannelClosed>().firstOrNull()
224224
assertNotNull(storeChannelClosed)
225-
assertTrue { storeChannelClosed.type == ChannelClosingType.Local }
225+
assertTrue { storeChannelClosed.closingType == ChannelClosingType.Local }
226226
assertTrue {
227227
storeChannelClosed.txids.toSet() ==
228228
listOfNotNull(
@@ -564,7 +564,7 @@ class ClosingTestsCommon : EclairTestSuite() {
564564
assertTrue(actions.contains(ChannelAction.Storage.StoreState(aliceClosed)))
565565
val storeChannelClosed = actions.filterIsInstance<ChannelAction.Storage.StoreChannelClosed>().firstOrNull()
566566
assertNotNull(storeChannelClosed)
567-
assertTrue { storeChannelClosed.type == ChannelClosingType.Remote }
567+
assertTrue { storeChannelClosed.closingType == ChannelClosingType.Remote }
568568
assertTrue {
569569
storeChannelClosed.txids.toSet() ==
570570
listOfNotNull(
@@ -1142,7 +1142,7 @@ class ClosingTestsCommon : EclairTestSuite() {
11421142
)
11431143
val storeChannelClosed = aliceActions5.filterIsInstance<ChannelAction.Storage.StoreChannelClosed>().firstOrNull()
11441144
assertNotNull(storeChannelClosed)
1145-
assertTrue { storeChannelClosed.type == ChannelClosingType.Remote }
1145+
assertTrue { storeChannelClosed.closingType == ChannelClosingType.Remote }
11461146
assertTrue { storeChannelClosed.txids.toSet() == aliceTxs.map { it.txid }.toSet() }
11471147
}
11481148

0 commit comments

Comments
 (0)