mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-13 19:16:56 +01:00
protofsm: add an upfront check for SendWhen predicates
In this commit, we add an upfront check for `SendWhen` predicates before deciding to launch a goroutine. This ensures that when a message comes along that is already ready to send, we do the send in a synchronous manner.
This commit is contained in:
parent
dacc5dfb1f
commit
f331e2cc35
1 changed files with 13 additions and 11 deletions
|
@ -377,9 +377,18 @@ func (s *StateMachine[Event, Env]) executeDaemonEvent(ctx context.Context,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this doesn't have a SendWhen predicate, then we can just
|
canSend := func() bool {
|
||||||
// send it off right away.
|
return fn.MapOptionZ(
|
||||||
if !daemonEvent.SendWhen.IsSome() {
|
daemonEvent.SendWhen,
|
||||||
|
func(pred SendPredicate) bool {
|
||||||
|
return pred()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// If this doesn't have a SendWhen predicate, or if it's already
|
||||||
|
// true, then we can just send it off right away.
|
||||||
|
if !daemonEvent.SendWhen.IsSome() || canSend() {
|
||||||
return sendAndCleanUp()
|
return sendAndCleanUp()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,14 +406,7 @@ func (s *StateMachine[Event, Env]) executeDaemonEvent(ctx context.Context,
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-predicateTicker.C:
|
case <-predicateTicker.C:
|
||||||
canSend := fn.MapOptionZ(
|
if canSend() {
|
||||||
daemonEvent.SendWhen,
|
|
||||||
func(pred SendPredicate) bool {
|
|
||||||
return pred()
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
if canSend {
|
|
||||||
s.log.InfoS(ctx, "Send active predicate")
|
s.log.InfoS(ctx, "Send active predicate")
|
||||||
|
|
||||||
err := sendAndCleanUp()
|
err := sendAndCleanUp()
|
||||||
|
|
Loading…
Add table
Reference in a new issue