Skip to content

Commit

Permalink
store restored channel immediately
Browse files Browse the repository at this point in the history
When we restore a channel from a peer backup, we need to store the
channel in database as soon as possible, so we are exactly in the same
state as if the channel was restored from local db.

This applies whether we are restoring from empty or outdated local db.
  • Loading branch information
pm47 committed Mar 30, 2023
1 parent b39d772 commit 626deed
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/commonMain/kotlin/fr/acinq/lightning/channel/Syncing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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>(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)
Expand Down
1 change: 1 addition & 0 deletions src/commonMain/kotlin/fr/acinq/lightning/io/Peer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 626deed

Please sign in to comment.