htlcswitch: defer processRemoteAdds when quiescent

In this commit we defer processRemoteAdds using a new mechanism on
the quiescer where we capture a closure that needs to be run. We
do this because we need to avoid the scenario where we send back
immediate resolutions to the newly added HTLCs when quiescent as
it is a protocol violation. It is not enough for us to simply defer
sending the messages since the purpose of quiescence itself is to
have well-defined and agreed upon channel state. If, for whatever
reason, the node (or connection) is restarted between when these
hooks are captured and when they are ultimately run, they will
be resolved by the resolveFwdPkgs logic when the link comes back
up.

In a future commit we will explicitly call the quiescer's resume
method when it is OK for htlc traffic to commence.
This commit is contained in:
Keagan McClelland
2024-04-08 18:17:00 -07:00
parent 77fd8c6a21
commit 4fbab45a5f
3 changed files with 94 additions and 1 deletions

View File

@@ -380,3 +380,38 @@ func TestQuiescerTieBreaker(t *testing.T) {
}
}
}
// TestQuiescerResume ensures that the hooks that are attached to the quiescer
// are called when we call the resume method and no earlier.
func TestQuiescerResume(t *testing.T) {
t.Parallel()
harness := initQuiescerTestHarness(lntypes.Local)
msg := lnwire.Stfu{
ChanID: cid,
Initiator: true,
}
require.NoError(
t, harness.quiescer.RecvStfu(
msg, harness.pendingUpdates.Remote,
),
)
require.NoError(
t, harness.quiescer.SendOwedStfu(
harness.pendingUpdates.Local,
),
)
require.True(t, harness.quiescer.IsQuiescent())
var resumeHooksCalled = false
harness.quiescer.OnResume(func() {
resumeHooksCalled = true
})
require.False(t, resumeHooksCalled)
harness.quiescer.Resume()
require.True(t, resumeHooksCalled)
require.False(t, harness.quiescer.IsQuiescent())
}