diff --git a/src/commonMain/kotlin/fr/acinq/lightning/channel/Syncing.kt b/src/commonMain/kotlin/fr/acinq/lightning/channel/Syncing.kt index feba9c9ff..d3e095276 100644 --- a/src/commonMain/kotlin/fr/acinq/lightning/channel/Syncing.kt +++ b/src/commonMain/kotlin/fr/acinq/lightning/channel/Syncing.kt @@ -63,7 +63,13 @@ data class Syncing(val state: ChannelStateWithCommitments, val waitForTheirReest yourLastCommitmentSecret = PrivateKey(yourLastPerCommitmentSecret), myCurrentPerCommitmentPoint = myCurrentPerCommitmentPoint ).withChannelData(nextState.commitments.remoteChannelData) - val actions = listOf(ChannelAction.Message.Send(channelReestablish)) + val actions = buildList { + if (nextState != state) { + // we just restored from backup + add(ChannelAction.Storage.StoreState(nextState)) + } + add(ChannelAction.Message.Send(channelReestablish)) + } // now apply their reestablish message to the restored state val (nextState1, actions1) = Syncing(nextState, waitForTheirReestablishMessage = false).processInternal(event) Pair(nextState1, actions + actions1) diff --git a/src/commonMain/kotlin/fr/acinq/lightning/io/Peer.kt b/src/commonMain/kotlin/fr/acinq/lightning/io/Peer.kt index b4375d170..5e55eb8c6 100644 --- a/src/commonMain/kotlin/fr/acinq/lightning/io/Peer.kt +++ b/src/commonMain/kotlin/fr/acinq/lightning/io/Peer.kt @@ -613,6 +613,7 @@ class Peer( is Try.Success -> { logger.warning { "n:$remoteNodeId restoring channelId=${msg.channelId} from peer backup" } val backup = decrypted.result + db.channels.addOrUpdateChannel(backup) val state = WaitForInit(StaticParams(nodeParams, remoteNodeId), currentTipFlow.filterNotNull().first(), onChainFeeratesFlow.filterNotNull().first()) val event1 = ChannelEvent.Restore(backup as ChannelState) val (state1, actions1) = state.process(event1)