mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-28 22:50:58 +02:00
htlcswitch: don't pass pending update counts into quiescer
This change simplifies some of the quiescer responsibilities in favor of making the link check whether or not it has a clean state to be able to send or receive an stfu. This change was made on the basis that the only use the quiescer makes of this information is to assess that it is or is not zero. Further the difficulty of checking this condition in the link is barely more burdensome than selecting the proper information to pass to the quiescer anyway.
This commit is contained in:
@@ -1529,17 +1529,15 @@ func (l *channelLink) htlcManager() {
|
|||||||
case qReq := <-l.quiescenceReqs:
|
case qReq := <-l.quiescenceReqs:
|
||||||
l.quiescer.InitStfu(qReq)
|
l.quiescer.InitStfu(qReq)
|
||||||
|
|
||||||
pendingOnLocal := l.channel.NumPendingUpdates(
|
if l.noDanglingUpdates(lntypes.Local) {
|
||||||
lntypes.Local, lntypes.Local,
|
err := l.quiescer.SendOwedStfu()
|
||||||
)
|
if err != nil {
|
||||||
pendingOnRemote := l.channel.NumPendingUpdates(
|
l.stfuFailf(
|
||||||
lntypes.Local, lntypes.Remote,
|
"SendOwedStfu: %s", err.Error(),
|
||||||
)
|
)
|
||||||
if err := l.quiescer.SendOwedStfu(
|
res := fn.Err[lntypes.ChannelParty](err)
|
||||||
pendingOnLocal + pendingOnRemote,
|
qReq.Resolve(res)
|
||||||
); err != nil {
|
}
|
||||||
l.stfuFailf("%s", err.Error())
|
|
||||||
qReq.Resolve(fn.Err[lntypes.ChannelParty](err))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case <-l.Quit:
|
case <-l.Quit:
|
||||||
@@ -2436,15 +2434,11 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
|
|||||||
|
|
||||||
// If we need to send out an Stfu, this would be the time to do
|
// If we need to send out an Stfu, this would be the time to do
|
||||||
// so.
|
// so.
|
||||||
pendingOnLocal := l.channel.NumPendingUpdates(
|
if l.noDanglingUpdates(lntypes.Local) {
|
||||||
lntypes.Local, lntypes.Local,
|
err = l.quiescer.SendOwedStfu()
|
||||||
)
|
if err != nil {
|
||||||
pendingOnRemote := l.channel.NumPendingUpdates(
|
l.stfuFailf("sendOwedStfu: %v", err.Error())
|
||||||
lntypes.Local, lntypes.Remote,
|
}
|
||||||
)
|
|
||||||
err = l.quiescer.SendOwedStfu(pendingOnLocal + pendingOnRemote)
|
|
||||||
if err != nil {
|
|
||||||
l.stfuFailf("sendOwedStfu: %v", err.Error())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now that we have finished processing the incoming CommitSig
|
// Now that we have finished processing the incoming CommitSig
|
||||||
@@ -2635,26 +2629,20 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
|
|||||||
// handleStfu implements the top-level logic for handling the Stfu message from
|
// handleStfu implements the top-level logic for handling the Stfu message from
|
||||||
// our peer.
|
// our peer.
|
||||||
func (l *channelLink) handleStfu(stfu *lnwire.Stfu) error {
|
func (l *channelLink) handleStfu(stfu *lnwire.Stfu) error {
|
||||||
pendingOnLocal := l.channel.NumPendingUpdates(
|
if !l.noDanglingUpdates(lntypes.Remote) {
|
||||||
lntypes.Remote, lntypes.Local,
|
return ErrPendingRemoteUpdates
|
||||||
)
|
}
|
||||||
pendingOnRemote := l.channel.NumPendingUpdates(
|
err := l.quiescer.RecvStfu(*stfu)
|
||||||
lntypes.Remote, lntypes.Remote,
|
|
||||||
)
|
|
||||||
err := l.quiescer.RecvStfu(*stfu, pendingOnLocal+pendingOnRemote)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we can immediately send an Stfu response back, we will.
|
// If we can immediately send an Stfu response back, we will.
|
||||||
pendingOnLocal = l.channel.NumPendingUpdates(
|
if l.noDanglingUpdates(lntypes.Local) {
|
||||||
lntypes.Local, lntypes.Local,
|
return l.quiescer.SendOwedStfu()
|
||||||
)
|
}
|
||||||
pendingOnRemote = l.channel.NumPendingUpdates(
|
|
||||||
lntypes.Local, lntypes.Remote,
|
|
||||||
)
|
|
||||||
|
|
||||||
return l.quiescer.SendOwedStfu(pendingOnLocal + pendingOnRemote)
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// stfuFailf fails the link in the case where the requirements of the quiescence
|
// stfuFailf fails the link in the case where the requirements of the quiescence
|
||||||
@@ -2669,6 +2657,19 @@ func (l *channelLink) stfuFailf(format string, args ...interface{}) {
|
|||||||
}, format, args...)
|
}, format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// noDanglingUpdates returns true when there are 0 updates that were originally
|
||||||
|
// issued by whose on either the Local or Remote commitment transaction.
|
||||||
|
func (l *channelLink) noDanglingUpdates(whose lntypes.ChannelParty) bool {
|
||||||
|
pendingOnLocal := l.channel.NumPendingUpdates(
|
||||||
|
whose, lntypes.Local,
|
||||||
|
)
|
||||||
|
pendingOnRemote := l.channel.NumPendingUpdates(
|
||||||
|
whose, lntypes.Remote,
|
||||||
|
)
|
||||||
|
|
||||||
|
return pendingOnLocal == 0 && pendingOnRemote == 0
|
||||||
|
}
|
||||||
|
|
||||||
// ackDownStreamPackets is responsible for removing htlcs from a link's mailbox
|
// ackDownStreamPackets is responsible for removing htlcs from a link's mailbox
|
||||||
// for packets delivered from server, and cleaning up any circuits closed by
|
// for packets delivered from server, and cleaning up any circuits closed by
|
||||||
// signing a previous commitment txn. This method ensures that the circuits are
|
// signing a previous commitment txn. This method ensures that the circuits are
|
||||||
|
@@ -76,7 +76,7 @@ type Quiescer interface {
|
|||||||
InitStfu(req StfuReq)
|
InitStfu(req StfuReq)
|
||||||
|
|
||||||
// RecvStfu is called when we receive an Stfu message from the remote.
|
// RecvStfu is called when we receive an Stfu message from the remote.
|
||||||
RecvStfu(stfu lnwire.Stfu, numRemotePendingUpdates uint64) error
|
RecvStfu(stfu lnwire.Stfu) error
|
||||||
|
|
||||||
// CanRecvUpdates returns true if we haven't yet received an Stfu which
|
// CanRecvUpdates returns true if we haven't yet received an Stfu which
|
||||||
// would mark the end of the remote's ability to send updates.
|
// would mark the end of the remote's ability to send updates.
|
||||||
@@ -88,7 +88,7 @@ type Quiescer interface {
|
|||||||
|
|
||||||
// SendOwedStfu sends Stfu if it owes one. It returns an error if the
|
// SendOwedStfu sends Stfu if it owes one. It returns an error if the
|
||||||
// state machine is in an invalid state.
|
// state machine is in an invalid state.
|
||||||
SendOwedStfu(numPendingLocalUpdates uint64) error
|
SendOwedStfu() error
|
||||||
|
|
||||||
// OnResume accepts a no return closure that will run when the quiescer
|
// OnResume accepts a no return closure that will run when the quiescer
|
||||||
// is resumed.
|
// is resumed.
|
||||||
@@ -175,19 +175,15 @@ func NewQuiescer(cfg QuiescerCfg) Quiescer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RecvStfu is called when we receive an Stfu message from the remote.
|
// RecvStfu is called when we receive an Stfu message from the remote.
|
||||||
func (q *QuiescerLive) RecvStfu(msg lnwire.Stfu,
|
func (q *QuiescerLive) RecvStfu(msg lnwire.Stfu) error {
|
||||||
numPendingRemoteUpdates uint64) error {
|
|
||||||
|
|
||||||
q.Lock()
|
q.Lock()
|
||||||
defer q.Unlock()
|
defer q.Unlock()
|
||||||
|
|
||||||
return q.recvStfu(msg, numPendingRemoteUpdates)
|
return q.recvStfu(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// recvStfu is called when we receive an Stfu message from the remote.
|
// recvStfu is called when we receive an Stfu message from the remote.
|
||||||
func (q *QuiescerLive) recvStfu(msg lnwire.Stfu,
|
func (q *QuiescerLive) recvStfu(msg lnwire.Stfu) error {
|
||||||
numPendingRemoteUpdates uint64) error {
|
|
||||||
|
|
||||||
// At the time of this writing, this check that we have already received
|
// At the time of this writing, this check that we have already received
|
||||||
// an Stfu is not strictly necessary, according to the specification.
|
// an Stfu is not strictly necessary, according to the specification.
|
||||||
// However, it is fishy if we do and it is unclear how we should handle
|
// However, it is fishy if we do and it is unclear how we should handle
|
||||||
@@ -203,7 +199,7 @@ func (q *QuiescerLive) recvStfu(msg lnwire.Stfu,
|
|||||||
q.cfg.chanID)
|
q.cfg.chanID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !q.canRecvStfu(numPendingRemoteUpdates) {
|
if !q.canRecvStfu() {
|
||||||
return fmt.Errorf("%w for channel %v", ErrPendingRemoteUpdates,
|
return fmt.Errorf("%w for channel %v", ErrPendingRemoteUpdates,
|
||||||
q.cfg.chanID)
|
q.cfg.chanID)
|
||||||
}
|
}
|
||||||
@@ -228,26 +224,22 @@ func (q *QuiescerLive) recvStfu(msg lnwire.Stfu,
|
|||||||
|
|
||||||
// MakeStfu is called when we are ready to send an Stfu message. It returns the
|
// MakeStfu is called when we are ready to send an Stfu message. It returns the
|
||||||
// Stfu message to be sent.
|
// Stfu message to be sent.
|
||||||
func (q *QuiescerLive) MakeStfu(
|
func (q *QuiescerLive) MakeStfu() fn.Result[lnwire.Stfu] {
|
||||||
numPendingLocalUpdates uint64) fn.Result[lnwire.Stfu] {
|
|
||||||
|
|
||||||
q.RLock()
|
q.RLock()
|
||||||
defer q.RUnlock()
|
defer q.RUnlock()
|
||||||
|
|
||||||
return q.makeStfu(numPendingLocalUpdates)
|
return q.makeStfu()
|
||||||
}
|
}
|
||||||
|
|
||||||
// makeStfu is called when we are ready to send an Stfu message. It returns the
|
// makeStfu is called when we are ready to send an Stfu message. It returns the
|
||||||
// Stfu message to be sent.
|
// Stfu message to be sent.
|
||||||
func (q *QuiescerLive) makeStfu(
|
func (q *QuiescerLive) makeStfu() fn.Result[lnwire.Stfu] {
|
||||||
numPendingLocalUpdates uint64) fn.Result[lnwire.Stfu] {
|
|
||||||
|
|
||||||
if q.sent {
|
if q.sent {
|
||||||
return fn.Errf[lnwire.Stfu]("%w for channel %v",
|
return fn.Errf[lnwire.Stfu]("%w for channel %v",
|
||||||
ErrStfuAlreadySent, q.cfg.chanID)
|
ErrStfuAlreadySent, q.cfg.chanID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !q.canSendStfu(numPendingLocalUpdates) {
|
if !q.canSendStfu() {
|
||||||
return fn.Errf[lnwire.Stfu]("%w for channel %v",
|
return fn.Errf[lnwire.Stfu]("%w for channel %v",
|
||||||
ErrPendingLocalUpdates, q.cfg.chanID)
|
ErrPendingLocalUpdates, q.cfg.chanID)
|
||||||
}
|
}
|
||||||
@@ -380,44 +372,44 @@ func (q *QuiescerLive) CanSendStfu(numPendingLocalUpdates uint64) bool {
|
|||||||
q.RLock()
|
q.RLock()
|
||||||
defer q.RUnlock()
|
defer q.RUnlock()
|
||||||
|
|
||||||
return q.canSendStfu(numPendingLocalUpdates)
|
return q.canSendStfu()
|
||||||
}
|
}
|
||||||
|
|
||||||
// canSendStfu returns true if we can send an Stfu.
|
// canSendStfu returns true if we can send an Stfu.
|
||||||
func (q *QuiescerLive) canSendStfu(numPendingLocalUpdates uint64) bool {
|
func (q *QuiescerLive) canSendStfu() bool {
|
||||||
return numPendingLocalUpdates == 0 && !q.sent
|
return !q.sent
|
||||||
}
|
}
|
||||||
|
|
||||||
// CanRecvStfu returns true if we can receive an Stfu.
|
// CanRecvStfu returns true if we can receive an Stfu.
|
||||||
func (q *QuiescerLive) CanRecvStfu(numPendingRemoteUpdates uint64) bool {
|
func (q *QuiescerLive) CanRecvStfu() bool {
|
||||||
q.RLock()
|
q.RLock()
|
||||||
defer q.RUnlock()
|
defer q.RUnlock()
|
||||||
|
|
||||||
return q.canRecvStfu(numPendingRemoteUpdates)
|
return q.canRecvStfu()
|
||||||
}
|
}
|
||||||
|
|
||||||
// canRecvStfu returns true if we can receive an Stfu.
|
// canRecvStfu returns true if we can receive an Stfu.
|
||||||
func (q *QuiescerLive) canRecvStfu(numPendingRemoteUpdates uint64) bool {
|
func (q *QuiescerLive) canRecvStfu() bool {
|
||||||
return numPendingRemoteUpdates == 0 && !q.received
|
return !q.received
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendOwedStfu sends Stfu if it owes one. It returns an error if the state
|
// SendOwedStfu sends Stfu if it owes one. It returns an error if the state
|
||||||
// machine is in an invalid state.
|
// machine is in an invalid state.
|
||||||
func (q *QuiescerLive) SendOwedStfu(numPendingLocalUpdates uint64) error {
|
func (q *QuiescerLive) SendOwedStfu() error {
|
||||||
q.Lock()
|
q.Lock()
|
||||||
defer q.Unlock()
|
defer q.Unlock()
|
||||||
|
|
||||||
return q.sendOwedStfu(numPendingLocalUpdates)
|
return q.sendOwedStfu()
|
||||||
}
|
}
|
||||||
|
|
||||||
// sendOwedStfu sends Stfu if it owes one. It returns an error if the state
|
// sendOwedStfu sends Stfu if it owes one. It returns an error if the state
|
||||||
// machine is in an invalid state.
|
// machine is in an invalid state.
|
||||||
func (q *QuiescerLive) sendOwedStfu(numPendingLocalUpdates uint64) error {
|
func (q *QuiescerLive) sendOwedStfu() error {
|
||||||
if !q.oweStfu() || !q.canSendStfu(numPendingLocalUpdates) {
|
if !q.oweStfu() || !q.canSendStfu() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err := q.makeStfu(numPendingLocalUpdates).Sink(q.cfg.sendMsg)
|
err := q.makeStfu().Sink(q.cfg.sendMsg)
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
q.sent = true
|
q.sent = true
|
||||||
@@ -561,13 +553,13 @@ var _ Quiescer = (*quiescerNoop)(nil)
|
|||||||
func (q *quiescerNoop) InitStfu(req StfuReq) {
|
func (q *quiescerNoop) InitStfu(req StfuReq) {
|
||||||
req.Resolve(fn.Errf[lntypes.ChannelParty]("quiescence not supported"))
|
req.Resolve(fn.Errf[lntypes.ChannelParty]("quiescence not supported"))
|
||||||
}
|
}
|
||||||
func (q *quiescerNoop) RecvStfu(_ lnwire.Stfu, _ uint64) error { return nil }
|
func (q *quiescerNoop) RecvStfu(_ lnwire.Stfu) error { return nil }
|
||||||
func (q *quiescerNoop) CanRecvUpdates() bool { return true }
|
func (q *quiescerNoop) CanRecvUpdates() bool { return true }
|
||||||
func (q *quiescerNoop) CanSendUpdates() bool { return true }
|
func (q *quiescerNoop) CanSendUpdates() bool { return true }
|
||||||
func (q *quiescerNoop) SendOwedStfu(_ uint64) error { return nil }
|
func (q *quiescerNoop) SendOwedStfu() error { return nil }
|
||||||
func (q *quiescerNoop) IsQuiescent() bool { return false }
|
func (q *quiescerNoop) IsQuiescent() bool { return false }
|
||||||
func (q *quiescerNoop) OnResume(hook func()) { hook() }
|
func (q *quiescerNoop) OnResume(hook func()) { hook() }
|
||||||
func (q *quiescerNoop) Resume() {}
|
func (q *quiescerNoop) Resume() {}
|
||||||
func (q *quiescerNoop) QuiescenceInitiator() fn.Result[lntypes.ChannelParty] {
|
func (q *quiescerNoop) QuiescenceInitiator() fn.Result[lntypes.ChannelParty] {
|
||||||
return fn.Err[lntypes.ChannelParty](ErrNoQuiescenceInitiator)
|
return fn.Err[lntypes.ChannelParty](ErrNoQuiescenceInitiator)
|
||||||
}
|
}
|
||||||
|
@@ -14,9 +14,8 @@ import (
|
|||||||
var cid = lnwire.ChannelID(bytes.Repeat([]byte{0x00}, 32))
|
var cid = lnwire.ChannelID(bytes.Repeat([]byte{0x00}, 32))
|
||||||
|
|
||||||
type quiescerTestHarness struct {
|
type quiescerTestHarness struct {
|
||||||
pendingUpdates lntypes.Dual[uint64]
|
quiescer *QuiescerLive
|
||||||
quiescer *QuiescerLive
|
conn <-chan lnwire.Stfu
|
||||||
conn <-chan lnwire.Stfu
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func initQuiescerTestHarness(
|
func initQuiescerTestHarness(
|
||||||
@@ -24,8 +23,7 @@ func initQuiescerTestHarness(
|
|||||||
|
|
||||||
conn := make(chan lnwire.Stfu, 1)
|
conn := make(chan lnwire.Stfu, 1)
|
||||||
harness := &quiescerTestHarness{
|
harness := &quiescerTestHarness{
|
||||||
pendingUpdates: lntypes.Dual[uint64]{},
|
conn: conn,
|
||||||
conn: conn,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
quiescer, _ := NewQuiescer(QuiescerCfg{
|
quiescer, _ := NewQuiescer(QuiescerCfg{
|
||||||
@@ -54,30 +52,12 @@ func TestQuiescerDoubleRecvInvalid(t *testing.T) {
|
|||||||
Initiator: true,
|
Initiator: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := harness.quiescer.RecvStfu(msg, harness.pendingUpdates.Remote)
|
err := harness.quiescer.RecvStfu(msg)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
err = harness.quiescer.RecvStfu(msg, harness.pendingUpdates.Remote)
|
err = harness.quiescer.RecvStfu(msg)
|
||||||
require.Error(t, err, ErrStfuAlreadyRcvd)
|
require.Error(t, err, ErrStfuAlreadyRcvd)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestQuiescerPendingUpdatesRecvInvalid ensures that we get an error if we
|
|
||||||
// receive the Stfu message while the Remote party has panding updates on the
|
|
||||||
// channel.
|
|
||||||
func TestQuiescerPendingUpdatesRecvInvalid(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
harness := initQuiescerTestHarness(lntypes.Local)
|
|
||||||
|
|
||||||
msg := lnwire.Stfu{
|
|
||||||
ChanID: cid,
|
|
||||||
Initiator: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
harness.pendingUpdates.SetForParty(lntypes.Remote, 1)
|
|
||||||
err := harness.quiescer.RecvStfu(msg, harness.pendingUpdates.Remote)
|
|
||||||
require.ErrorIs(t, err, ErrPendingRemoteUpdates)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestQuiescenceRemoteInit ensures that we can successfully traverse the state
|
// TestQuiescenceRemoteInit ensures that we can successfully traverse the state
|
||||||
// graph of quiescence beginning with the Remote party initiating quiescence.
|
// graph of quiescence beginning with the Remote party initiating quiescence.
|
||||||
func TestQuiescenceRemoteInit(t *testing.T) {
|
func TestQuiescenceRemoteInit(t *testing.T) {
|
||||||
@@ -90,22 +70,10 @@ func TestQuiescenceRemoteInit(t *testing.T) {
|
|||||||
Initiator: true,
|
Initiator: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
harness.pendingUpdates.SetForParty(lntypes.Local, 1)
|
err := harness.quiescer.RecvStfu(msg)
|
||||||
|
|
||||||
err := harness.quiescer.RecvStfu(msg, harness.pendingUpdates.Remote)
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = harness.quiescer.SendOwedStfu(harness.pendingUpdates.Local)
|
err = harness.quiescer.SendOwedStfu()
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
select {
|
|
||||||
case <-harness.conn:
|
|
||||||
t.Fatalf("stfu sent when not expected")
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
|
|
||||||
harness.pendingUpdates.SetForParty(lntypes.Local, 0)
|
|
||||||
err = harness.quiescer.SendOwedStfu(harness.pendingUpdates.Local)
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
@@ -125,25 +93,13 @@ func TestQuiescenceLocalInit(t *testing.T) {
|
|||||||
ChanID: cid,
|
ChanID: cid,
|
||||||
Initiator: true,
|
Initiator: true,
|
||||||
}
|
}
|
||||||
harness.pendingUpdates.SetForParty(lntypes.Local, 1)
|
|
||||||
|
|
||||||
stfuReq, stfuRes := fn.NewReq[fn.Unit, fn.Result[lntypes.ChannelParty]](
|
stfuReq, stfuRes := fn.NewReq[fn.Unit, fn.Result[lntypes.ChannelParty]](
|
||||||
fn.Unit{},
|
fn.Unit{},
|
||||||
)
|
)
|
||||||
harness.quiescer.InitStfu(stfuReq)
|
harness.quiescer.InitStfu(stfuReq)
|
||||||
|
|
||||||
harness.pendingUpdates.SetForParty(lntypes.Local, 1)
|
err := harness.quiescer.SendOwedStfu()
|
||||||
err := harness.quiescer.SendOwedStfu(harness.pendingUpdates.Local)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
select {
|
|
||||||
case <-harness.conn:
|
|
||||||
t.Fatalf("stfu sent when not expected")
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
|
|
||||||
harness.pendingUpdates.SetForParty(lntypes.Local, 0)
|
|
||||||
err = harness.quiescer.SendOwedStfu(harness.pendingUpdates.Local)
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
@@ -153,7 +109,7 @@ func TestQuiescenceLocalInit(t *testing.T) {
|
|||||||
t.Fatalf("stfu not sent when expected")
|
t.Fatalf("stfu not sent when expected")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = harness.quiescer.RecvStfu(msg, harness.pendingUpdates.Remote)
|
err = harness.quiescer.RecvStfu(msg)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
@@ -178,17 +134,11 @@ func TestQuiescenceInitiator(t *testing.T) {
|
|||||||
ChanID: cid,
|
ChanID: cid,
|
||||||
Initiator: true,
|
Initiator: true,
|
||||||
}
|
}
|
||||||
require.NoError(
|
require.NoError(t, harness.quiescer.RecvStfu(msg))
|
||||||
t, harness.quiescer.RecvStfu(
|
|
||||||
msg, harness.pendingUpdates.Remote,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
require.True(t, harness.quiescer.QuiescenceInitiator().IsErr())
|
require.True(t, harness.quiescer.QuiescenceInitiator().IsErr())
|
||||||
|
|
||||||
// Send
|
// Send
|
||||||
require.NoError(
|
require.NoError(t, harness.quiescer.SendOwedStfu())
|
||||||
t, harness.quiescer.SendOwedStfu(harness.pendingUpdates.Local),
|
|
||||||
)
|
|
||||||
require.Equal(
|
require.Equal(
|
||||||
t, harness.quiescer.QuiescenceInitiator(),
|
t, harness.quiescer.QuiescenceInitiator(),
|
||||||
fn.Ok(lntypes.Remote),
|
fn.Ok(lntypes.Remote),
|
||||||
@@ -214,7 +164,7 @@ func TestQuiescenceInitiator(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
require.NoError(
|
require.NoError(
|
||||||
t, harness.quiescer.sendOwedStfu(harness.pendingUpdates.Local),
|
t, harness.quiescer.sendOwedStfu(),
|
||||||
)
|
)
|
||||||
require.True(t, harness.quiescer.quiescenceInitiator().IsErr())
|
require.True(t, harness.quiescer.quiescenceInitiator().IsErr())
|
||||||
|
|
||||||
@@ -222,11 +172,7 @@ func TestQuiescenceInitiator(t *testing.T) {
|
|||||||
ChanID: cid,
|
ChanID: cid,
|
||||||
Initiator: false,
|
Initiator: false,
|
||||||
}
|
}
|
||||||
require.NoError(
|
require.NoError(t, harness.quiescer.recvStfu(msg))
|
||||||
t, harness.quiescer.recvStfu(
|
|
||||||
msg, harness.pendingUpdates.Remote,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
require.True(t, harness.quiescer.quiescenceInitiator().IsOk())
|
require.True(t, harness.quiescer.quiescenceInitiator().IsOk())
|
||||||
|
|
||||||
select {
|
select {
|
||||||
@@ -249,11 +195,7 @@ func TestQuiescenceCantReceiveUpdatesAfterStfu(t *testing.T) {
|
|||||||
ChanID: cid,
|
ChanID: cid,
|
||||||
Initiator: true,
|
Initiator: true,
|
||||||
}
|
}
|
||||||
require.NoError(
|
require.NoError(t, harness.quiescer.RecvStfu(msg))
|
||||||
t, harness.quiescer.RecvStfu(
|
|
||||||
msg, harness.pendingUpdates.Remote,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
require.False(t, harness.quiescer.CanRecvUpdates())
|
require.False(t, harness.quiescer.CanRecvUpdates())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,10 +212,10 @@ func TestQuiescenceCantSendUpdatesAfterStfu(t *testing.T) {
|
|||||||
Initiator: true,
|
Initiator: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := harness.quiescer.RecvStfu(msg, harness.pendingUpdates.Remote)
|
err := harness.quiescer.RecvStfu(msg)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = harness.quiescer.SendOwedStfu(harness.pendingUpdates.Local)
|
err = harness.quiescer.SendOwedStfu()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
require.False(t, harness.quiescer.CanSendUpdates())
|
require.False(t, harness.quiescer.CanSendUpdates())
|
||||||
@@ -293,11 +235,7 @@ func TestQuiescenceStfuNotNeededAfterRecv(t *testing.T) {
|
|||||||
}
|
}
|
||||||
require.False(t, harness.quiescer.NeedStfu())
|
require.False(t, harness.quiescer.NeedStfu())
|
||||||
|
|
||||||
require.NoError(
|
require.NoError(t, harness.quiescer.RecvStfu(msg))
|
||||||
t, harness.quiescer.RecvStfu(
|
|
||||||
msg, harness.pendingUpdates.Remote,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
require.False(t, harness.quiescer.NeedStfu())
|
require.False(t, harness.quiescer.NeedStfu())
|
||||||
}
|
}
|
||||||
@@ -309,38 +247,15 @@ func TestQuiescenceInappropriateMakeStfuReturnsErr(t *testing.T) {
|
|||||||
|
|
||||||
harness := initQuiescerTestHarness(lntypes.Local)
|
harness := initQuiescerTestHarness(lntypes.Local)
|
||||||
|
|
||||||
harness.pendingUpdates.SetForParty(lntypes.Local, 1)
|
|
||||||
|
|
||||||
require.True(
|
|
||||||
t, harness.quiescer.MakeStfu(
|
|
||||||
harness.pendingUpdates.Local,
|
|
||||||
).IsErr(),
|
|
||||||
)
|
|
||||||
|
|
||||||
harness.pendingUpdates.SetForParty(lntypes.Local, 0)
|
|
||||||
msg := lnwire.Stfu{
|
msg := lnwire.Stfu{
|
||||||
ChanID: cid,
|
ChanID: cid,
|
||||||
Initiator: true,
|
Initiator: true,
|
||||||
}
|
}
|
||||||
require.NoError(
|
require.NoError(t, harness.quiescer.RecvStfu(msg))
|
||||||
t, harness.quiescer.RecvStfu(
|
require.True(t, harness.quiescer.MakeStfu().IsOk())
|
||||||
msg, harness.pendingUpdates.Remote,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
require.True(
|
|
||||||
t, harness.quiescer.MakeStfu(
|
|
||||||
harness.pendingUpdates.Local,
|
|
||||||
).IsOk(),
|
|
||||||
)
|
|
||||||
|
|
||||||
require.NoError(
|
require.NoError(t, harness.quiescer.SendOwedStfu())
|
||||||
t, harness.quiescer.SendOwedStfu(harness.pendingUpdates.Local),
|
require.True(t, harness.quiescer.MakeStfu().IsErr())
|
||||||
)
|
|
||||||
require.True(
|
|
||||||
t, harness.quiescer.MakeStfu(
|
|
||||||
harness.pendingUpdates.Local,
|
|
||||||
).IsErr(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestQuiescerTieBreaker ensures that if both parties attempt to claim the
|
// TestQuiescerTieBreaker ensures that if both parties attempt to claim the
|
||||||
@@ -364,16 +279,8 @@ func TestQuiescerTieBreaker(t *testing.T) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
harness.quiescer.InitStfu(req)
|
harness.quiescer.InitStfu(req)
|
||||||
require.NoError(
|
require.NoError(t, harness.quiescer.RecvStfu(msg))
|
||||||
t, harness.quiescer.RecvStfu(
|
require.NoError(t, harness.quiescer.SendOwedStfu())
|
||||||
msg, harness.pendingUpdates.Remote,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
require.NoError(
|
|
||||||
t, harness.quiescer.SendOwedStfu(
|
|
||||||
harness.pendingUpdates.Local,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case party := <-res:
|
case party := <-res:
|
||||||
@@ -396,16 +303,8 @@ func TestQuiescerResume(t *testing.T) {
|
|||||||
Initiator: true,
|
Initiator: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
require.NoError(
|
require.NoError(t, harness.quiescer.RecvStfu(msg))
|
||||||
t, harness.quiescer.RecvStfu(
|
require.NoError(t, harness.quiescer.SendOwedStfu())
|
||||||
msg, harness.pendingUpdates.Remote,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
require.NoError(
|
|
||||||
t, harness.quiescer.SendOwedStfu(
|
|
||||||
harness.pendingUpdates.Local,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
require.True(t, harness.quiescer.IsQuiescent())
|
require.True(t, harness.quiescer.IsQuiescent())
|
||||||
var resumeHooksCalled = false
|
var resumeHooksCalled = false
|
||||||
@@ -434,9 +333,9 @@ func TestQuiescerTimeoutTriggers(t *testing.T) {
|
|||||||
harness.quiescer.cfg.timeoutDuration = time.Second
|
harness.quiescer.cfg.timeoutDuration = time.Second
|
||||||
harness.quiescer.cfg.onTimeout = func() { close(timeoutGate) }
|
harness.quiescer.cfg.onTimeout = func() { close(timeoutGate) }
|
||||||
|
|
||||||
err := harness.quiescer.RecvStfu(msg, harness.pendingUpdates.Remote)
|
err := harness.quiescer.RecvStfu(msg)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
err = harness.quiescer.SendOwedStfu(harness.pendingUpdates.Local)
|
err = harness.quiescer.SendOwedStfu()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
@@ -461,9 +360,9 @@ func TestQuiescerTimeoutAborts(t *testing.T) {
|
|||||||
harness.quiescer.cfg.timeoutDuration = time.Second
|
harness.quiescer.cfg.timeoutDuration = time.Second
|
||||||
harness.quiescer.cfg.onTimeout = func() { close(timeoutGate) }
|
harness.quiescer.cfg.onTimeout = func() { close(timeoutGate) }
|
||||||
|
|
||||||
err := harness.quiescer.RecvStfu(msg, harness.pendingUpdates.Remote)
|
err := harness.quiescer.RecvStfu(msg)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
err = harness.quiescer.SendOwedStfu(harness.pendingUpdates.Local)
|
err = harness.quiescer.SendOwedStfu()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
harness.quiescer.Resume()
|
harness.quiescer.Resume()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user