Skip to content

Commit

Permalink
Stay in Offline and Syncing on splice published (#539)
Browse files Browse the repository at this point in the history
When a splice transaction is published, it triggers a BITCOIN_FUNDING_SPENT
event that we should ignore, because this isn't a force-close.

If that event is received while we're in Offline or Syncing, we need to
stay in those "wrapper" states.
  • Loading branch information
t-bast authored Sep 26, 2023
1 parent 4d20dd1 commit a1fe22d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,14 @@ data class Offline(val state: PersistedChannelState) : ChannelState() {
)
Pair(nextState, actions)
}
else -> state.run { handlePotentialForceClose(watch) }
else -> {
val (nextState, actions) = state.run { handlePotentialForceClose(watch) }
when (nextState) {
is Closing -> Pair(nextState, actions)
is Closed -> Pair(nextState, actions)
else -> Pair(Offline(nextState), actions)
}
}
}
}
is WaitForFundingSigned -> Pair(this@Offline, listOf())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,14 @@ data class Syncing(val state: PersistedChannelState, val channelReestablishSent:
)
Pair(nextState, actions)
}
else -> state.run { handlePotentialForceClose(watch) }
else -> {
val (nextState, actions) = state.run { handlePotentialForceClose(watch) }
when (nextState) {
is Closing -> Pair(nextState, actions)
is Closed -> Pair(nextState, actions)
else -> Pair(Syncing(nextState, channelReestablishSent), actions)
}
}
}
is WatchEventConfirmed -> {
if (watch.event is BITCOIN_FUNDING_DEPTHOK) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,25 @@ class SpliceTestsCommon : LightningTestSuite() {
actionsBob6.contains(ChannelAction.Storage.SetLocked(spliceTx1.txid))
}

@Test
fun `disconnect -- splice tx published`() {
val (alice, bob) = reachNormalWithConfirmedFundingTx()
val (alice1, bob1) = spliceOut(alice, bob, 40_000.sat)
val spliceTx = alice1.commitments.latest.localFundingStatus.signedTx!!

val (alice2, _) = alice1.process(ChannelCommand.Disconnected)
val (bob2, _) = bob1.process(ChannelCommand.Disconnected)
assertIs<Offline>(alice2.state)
assertIs<Offline>(bob2.state)

val (alice3, actionsAlice3) = alice2.process(ChannelCommand.WatchReceived(WatchEventSpent(alice.channelId, BITCOIN_FUNDING_SPENT, spliceTx)))
assertIs<Offline>(alice3.state)
assertTrue(actionsAlice3.isEmpty())
val (bob3, actionsBob3) = bob2.process(ChannelCommand.WatchReceived(WatchEventSpent(bob.channelId, BITCOIN_FUNDING_SPENT, spliceTx)))
assertIs<Offline>(bob3.state)
assertTrue(actionsBob3.isEmpty())
}

@Test
fun `force-close -- latest active commitment`() {
val (alice, bob) = reachNormalWithConfirmedFundingTx()
Expand Down

0 comments on commit a1fe22d

Please sign in to comment.