Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 0 additions & 35 deletions modules/core/src/commonMain/kotlin/fr/acinq/lightning/io/Peer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import fr.acinq.lightning.payment.*
import fr.acinq.lightning.serialization.channel.Encryption.from
import fr.acinq.lightning.serialization.channel.Encryption.fromEncryptedPeerStorage
import fr.acinq.lightning.serialization.channel.Serialization.PeerStorageDeserializationResult
import fr.acinq.lightning.serialization.channel.Serialization.DeserializationResult
import fr.acinq.lightning.transactions.Scripts
import fr.acinq.lightning.transactions.Transactions
import fr.acinq.lightning.utils.*
Expand Down Expand Up @@ -1249,40 +1248,6 @@ class Peer(
logger.warning { "received unwanted peer storage" }
}
}
is ChannelReestablish -> {
val backup: DeserializationResult? = msg.legacyChannelData.takeIf { !it.isEmpty() }?.let { channelData ->
PersistedChannelState
.from(nodeParams.nodePrivateKey, channelData)
.onFailure { logger.warning(it) { "unreadable backup" } }
.getOrNull()
}
val state: ChannelState? = when {
backup == null -> _channels[msg.channelId]
backup is DeserializationResult.UnknownVersion -> {
logger.warning { "peer sent a reestablish with a backup generated by a more recent version of phoenix: version=${backup.version}." }
// 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
// do anything as we can't read the data. Best thing is to not answer, and tell the user to upgrade the app.
logger.error { "need to upgrade your app!" }
nodeParams._nodeEvents.emit(UpgradeRequired)
null
}
backup is DeserializationResult.Success && backup.state.channelId == msg.channelId -> {
maybeRestoreBackup(backup.state)
}
else -> {
logger.warning { "peer sent a reestablish with a backup for a different channel" }
_channels[msg.channelId]
}
}
if (state == null) {
logger.warning { "peer sent a reestablish for an unknown channel with no or undecipherable backup" }
peerConnection?.send(Error(msg.channelId, "unknown channel"))
} else {
val (state1, actions1) = state.process(ChannelCommand.MessageReceived(msg))
processActions(msg.channelId, peerConnection, actions1, state1)
_channels = _channels + (msg.channelId to state1)
}
}
is HasTemporaryChannelId -> {
_channels[msg.temporaryChannelId]?.let { state ->
logger.info { "received ${msg::class.simpleName} for temporary channel ${msg.temporaryChannelId}" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import fr.acinq.lightning.logging.MDCLogger
import fr.acinq.lightning.serialization.InputExtensions.readCollection
import fr.acinq.lightning.serialization.InputExtensions.readDelimitedByteArray
import fr.acinq.lightning.utils.toByteVector
import fr.acinq.lightning.wire.EncryptedChannelData
import fr.acinq.lightning.wire.EncryptedPeerStorage

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

/**
* Convenience method that builds an [EncryptedChannelData] from a [PersistedChannelState]
*/
fun EncryptedChannelData.Companion.from(key: PrivateKey, state: PersistedChannelState): EncryptedChannelData {
val bin = Serialization.serialize(state)
val encrypted = encrypt(key.value, bin)
// we copy the first 2 bytes as meta-info on the serialization version
val data = bin.copyOfRange(0, 2) + encrypted
return EncryptedChannelData(data.toByteVector())
}

/**
* Convenience method that decrypts and deserializes a [PersistedChannelState] from an [EncryptedChannelData]
*/
fun PersistedChannelState.Companion.from(key: PrivateKey, encryptedChannelData: EncryptedChannelData): Result<Serialization.DeserializationResult> {
// we first assume that channel data is prefixed by 2 bytes of serialization meta-info
return runCatching { decrypt(key.value, encryptedChannelData.data.drop(2).toByteArray()) }
.recoverCatching { decrypt(key.value, encryptedChannelData.data.toByteArray()) }
.map { Serialization.deserialize(it) }
}

/**
* Convenience method that builds an [EncryptedPeerStorage] from a list of [PersistedChannelState]
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ sealed class ChannelReestablishTlv : Tlv {
}
}

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

sealed class ShutdownTlv : Tlv {
// Legacy TLV needed to deserialize old backups
/** Legacy TLV needed to deserialize old backups */
data class ChannelData(val ecb: EncryptedChannelData) : ShutdownTlv() {
override val tag: Long get() = ChannelData.tag
override fun write(out: Output) = LightningCodecs.writeBytes(ecb.data, out)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,8 @@ interface HasChainHash : LightningMessage {

interface ForbiddenMessageDuringSplice : LightningMessage

/**
* Legacy format to backup channel state.
* It is only kept to restore old channels. New backups now use EncryptedPeerStorage.
*/
/** Legacy format for channel backup, needed to deserialize old backups */
data class EncryptedChannelData(val data: ByteVector) {
/** 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. */
override fun toString(): String {
val bytes = data.take(min(data.size(), 10))
return if (bytes.isEmpty()) "" else "$bytes (truncated)"
}

fun isEmpty(): Boolean = data.isEmpty()

companion object {
val empty: EncryptedChannelData = EncryptedChannelData(ByteVector.empty)
Expand Down Expand Up @@ -1329,8 +1319,6 @@ data class ChannelReestablish(
override val type: Long get() = ChannelReestablish.type

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

override fun write(out: Output) {
LightningCodecs.writeBytes(channelId, out)
Expand Down

This file was deleted.

Loading