Skip to content

Commit a74a915

Browse files
authored
Remove legacy backup code (#811)
This is a follow-up to #807. Note that we cannot remove some legacy classes such as `EncryptedChannelData`, due to the legacy v2/v3 serialization depending on it.
1 parent f8ab4e9 commit a74a915

File tree

9 files changed

+13
-242
lines changed

9 files changed

+13
-242
lines changed

modules/core/src/commonMain/kotlin/fr/acinq/lightning/io/Peer.kt

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import fr.acinq.lightning.payment.*
2323
import fr.acinq.lightning.serialization.channel.Encryption.from
2424
import fr.acinq.lightning.serialization.channel.Encryption.fromEncryptedPeerStorage
2525
import fr.acinq.lightning.serialization.channel.Serialization.PeerStorageDeserializationResult
26-
import fr.acinq.lightning.serialization.channel.Serialization.DeserializationResult
2726
import fr.acinq.lightning.transactions.Scripts
2827
import fr.acinq.lightning.transactions.Transactions
2928
import fr.acinq.lightning.utils.*
@@ -1249,40 +1248,6 @@ class Peer(
12491248
logger.warning { "received unwanted peer storage" }
12501249
}
12511250
}
1252-
is ChannelReestablish -> {
1253-
val backup: DeserializationResult? = msg.legacyChannelData.takeIf { !it.isEmpty() }?.let { channelData ->
1254-
PersistedChannelState
1255-
.from(nodeParams.nodePrivateKey, channelData)
1256-
.onFailure { logger.warning(it) { "unreadable backup" } }
1257-
.getOrNull()
1258-
}
1259-
val state: ChannelState? = when {
1260-
backup == null -> _channels[msg.channelId]
1261-
backup is DeserializationResult.UnknownVersion -> {
1262-
logger.warning { "peer sent a reestablish with a backup generated by a more recent version of phoenix: version=${backup.version}." }
1263-
// In this corner case, we do not want to return an error to the peer, because they will force-close and we will be unable to
1264-
// do anything as we can't read the data. Best thing is to not answer, and tell the user to upgrade the app.
1265-
logger.error { "need to upgrade your app!" }
1266-
nodeParams._nodeEvents.emit(UpgradeRequired)
1267-
null
1268-
}
1269-
backup is DeserializationResult.Success && backup.state.channelId == msg.channelId -> {
1270-
maybeRestoreBackup(backup.state)
1271-
}
1272-
else -> {
1273-
logger.warning { "peer sent a reestablish with a backup for a different channel" }
1274-
_channels[msg.channelId]
1275-
}
1276-
}
1277-
if (state == null) {
1278-
logger.warning { "peer sent a reestablish for an unknown channel with no or undecipherable backup" }
1279-
peerConnection?.send(Error(msg.channelId, "unknown channel"))
1280-
} else {
1281-
val (state1, actions1) = state.process(ChannelCommand.MessageReceived(msg))
1282-
processActions(msg.channelId, peerConnection, actions1, state1)
1283-
_channels = _channels + (msg.channelId to state1)
1284-
}
1285-
}
12861251
is HasTemporaryChannelId -> {
12871252
_channels[msg.temporaryChannelId]?.let { state ->
12881253
logger.info { "received ${msg::class.simpleName} for temporary channel ${msg.temporaryChannelId}" }

modules/core/src/commonMain/kotlin/fr/acinq/lightning/serialization/channel/Encryption.kt

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import fr.acinq.lightning.logging.MDCLogger
1010
import fr.acinq.lightning.serialization.InputExtensions.readCollection
1111
import fr.acinq.lightning.serialization.InputExtensions.readDelimitedByteArray
1212
import fr.acinq.lightning.utils.toByteVector
13-
import fr.acinq.lightning.wire.EncryptedChannelData
1413
import fr.acinq.lightning.wire.EncryptedPeerStorage
1514

1615
/**
@@ -34,27 +33,6 @@ object Encryption {
3433
return ChaCha20Poly1305.decrypt(key.toByteArray(), nonce.toByteArray(), ciphertext.toByteArray(), ByteArray(0), tag.toByteArray())
3534
}
3635

37-
/**
38-
* Convenience method that builds an [EncryptedChannelData] from a [PersistedChannelState]
39-
*/
40-
fun EncryptedChannelData.Companion.from(key: PrivateKey, state: PersistedChannelState): EncryptedChannelData {
41-
val bin = Serialization.serialize(state)
42-
val encrypted = encrypt(key.value, bin)
43-
// we copy the first 2 bytes as meta-info on the serialization version
44-
val data = bin.copyOfRange(0, 2) + encrypted
45-
return EncryptedChannelData(data.toByteVector())
46-
}
47-
48-
/**
49-
* Convenience method that decrypts and deserializes a [PersistedChannelState] from an [EncryptedChannelData]
50-
*/
51-
fun PersistedChannelState.Companion.from(key: PrivateKey, encryptedChannelData: EncryptedChannelData): Result<Serialization.DeserializationResult> {
52-
// we first assume that channel data is prefixed by 2 bytes of serialization meta-info
53-
return runCatching { decrypt(key.value, encryptedChannelData.data.drop(2).toByteArray()) }
54-
.recoverCatching { decrypt(key.value, encryptedChannelData.data.toByteArray()) }
55-
.map { Serialization.deserialize(it) }
56-
}
57-
5836
/**
5937
* Convenience method that builds an [EncryptedPeerStorage] from a list of [PersistedChannelState]
6038
*/

modules/core/src/commonMain/kotlin/fr/acinq/lightning/wire/ChannelTlv.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ sealed class ChannelReestablishTlv : Tlv {
170170
}
171171
}
172172

173-
// Legacy TLV needed to deserialize old backups
173+
/** Legacy TLV needed to deserialize old backups */
174174
data class ChannelData(val ecb: EncryptedChannelData) : ChannelReestablishTlv() {
175175
override val tag: Long get() = ChannelData.tag
176176
override fun write(out: Output) = LightningCodecs.writeBytes(ecb.data, out)
@@ -183,7 +183,7 @@ sealed class ChannelReestablishTlv : Tlv {
183183
}
184184

185185
sealed class ShutdownTlv : Tlv {
186-
// Legacy TLV needed to deserialize old backups
186+
/** Legacy TLV needed to deserialize old backups */
187187
data class ChannelData(val ecb: EncryptedChannelData) : ShutdownTlv() {
188188
override val tag: Long get() = ChannelData.tag
189189
override fun write(out: Output) = LightningCodecs.writeBytes(ecb.data, out)

modules/core/src/commonMain/kotlin/fr/acinq/lightning/wire/LightningMessages.kt

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -156,18 +156,8 @@ interface HasChainHash : LightningMessage {
156156

157157
interface ForbiddenMessageDuringSplice : LightningMessage
158158

159-
/**
160-
* Legacy format to backup channel state.
161-
* It is only kept to restore old channels. New backups now use EncryptedPeerStorage.
162-
*/
159+
/** Legacy format for channel backup, needed to deserialize old backups */
163160
data class EncryptedChannelData(val data: ByteVector) {
164-
/** We don't want to log the encrypted channel backups, they take a lot of space. We only keep the first bytes to help correlate mobile/server backups. */
165-
override fun toString(): String {
166-
val bytes = data.take(min(data.size(), 10))
167-
return if (bytes.isEmpty()) "" else "$bytes (truncated)"
168-
}
169-
170-
fun isEmpty(): Boolean = data.isEmpty()
171161

172162
companion object {
173163
val empty: EncryptedChannelData = EncryptedChannelData(ByteVector.empty)
@@ -1329,8 +1319,6 @@ data class ChannelReestablish(
13291319
override val type: Long get() = ChannelReestablish.type
13301320

13311321
val nextFundingTxId: TxId? = tlvStream.get<ChannelReestablishTlv.NextFunding>()?.txId
1332-
// Legacy channel backup present only on old inactive channels, will be replaced by peer storage next time this channel data is updated.
1333-
val legacyChannelData: EncryptedChannelData get() = tlvStream.get<ChannelReestablishTlv.ChannelData>()?.ecb ?: EncryptedChannelData.empty
13341322

13351323
override fun write(out: Output) {
13361324
LightningCodecs.writeBytes(channelId, out)

modules/core/src/commonTest/kotlin/fr/acinq/lightning/channel/states/LegacyWaitForFundingConfirmedTestsCommon.kt

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)