mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-12-08 11:53:16 +01:00
routing: refactor WaitForDependants to allow detailed logging
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package routing
|
package routing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
@@ -177,56 +178,77 @@ func (v *ValidationBarrier) WaitForDependants(job interface{}) error {
|
|||||||
var (
|
var (
|
||||||
signals *validationSignals
|
signals *validationSignals
|
||||||
ok bool
|
ok bool
|
||||||
|
jobDesc string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Acquire a lock to read ValidationBarrier.
|
||||||
v.Lock()
|
v.Lock()
|
||||||
switch msg := job.(type) {
|
|
||||||
|
|
||||||
|
switch msg := job.(type) {
|
||||||
// Any ChannelUpdate or NodeAnnouncement jobs will need to wait on the
|
// Any ChannelUpdate or NodeAnnouncement jobs will need to wait on the
|
||||||
// completion of any active ChannelAnnouncement jobs related to them.
|
// completion of any active ChannelAnnouncement jobs related to them.
|
||||||
case *channeldb.ChannelEdgePolicy:
|
case *channeldb.ChannelEdgePolicy:
|
||||||
shortID := lnwire.NewShortChanIDFromInt(msg.ChannelID)
|
shortID := lnwire.NewShortChanIDFromInt(msg.ChannelID)
|
||||||
signals, ok = v.chanEdgeDependencies[shortID]
|
signals, ok = v.chanEdgeDependencies[shortID]
|
||||||
|
|
||||||
|
jobDesc = fmt.Sprintf("job=lnwire.ChannelEdgePolicy, scid=%v",
|
||||||
|
msg.ChannelID)
|
||||||
|
|
||||||
case *channeldb.LightningNode:
|
case *channeldb.LightningNode:
|
||||||
vertex := route.Vertex(msg.PubKeyBytes)
|
vertex := route.Vertex(msg.PubKeyBytes)
|
||||||
signals, ok = v.nodeAnnDependencies[vertex]
|
signals, ok = v.nodeAnnDependencies[vertex]
|
||||||
|
|
||||||
|
jobDesc = fmt.Sprintf("job=channeldb.LightningNode, pub=%x",
|
||||||
|
vertex)
|
||||||
|
|
||||||
case *lnwire.ChannelUpdate:
|
case *lnwire.ChannelUpdate:
|
||||||
signals, ok = v.chanEdgeDependencies[msg.ShortChannelID]
|
signals, ok = v.chanEdgeDependencies[msg.ShortChannelID]
|
||||||
|
|
||||||
|
jobDesc = fmt.Sprintf("job=lnwire.ChannelUpdate, scid=%v",
|
||||||
|
msg.ShortChannelID.ToUint64())
|
||||||
|
|
||||||
case *lnwire.NodeAnnouncement:
|
case *lnwire.NodeAnnouncement:
|
||||||
vertex := route.Vertex(msg.NodeID)
|
vertex := route.Vertex(msg.NodeID)
|
||||||
signals, ok = v.nodeAnnDependencies[vertex]
|
signals, ok = v.nodeAnnDependencies[vertex]
|
||||||
|
jobDesc = fmt.Sprintf("job=lnwire.NodeAnnouncement, pub=%x",
|
||||||
|
vertex)
|
||||||
|
|
||||||
// Other types of jobs can be executed immediately, so we'll just
|
// Other types of jobs can be executed immediately, so we'll just
|
||||||
// return directly.
|
// return directly.
|
||||||
case *lnwire.AnnounceSignatures:
|
case *lnwire.AnnounceSignatures:
|
||||||
// TODO(roasbeef): need to wait on chan ann?
|
// TODO(roasbeef): need to wait on chan ann?
|
||||||
v.Unlock()
|
|
||||||
return nil
|
|
||||||
case *channeldb.ChannelEdgeInfo:
|
case *channeldb.ChannelEdgeInfo:
|
||||||
v.Unlock()
|
|
||||||
return nil
|
|
||||||
case *lnwire.ChannelAnnouncement:
|
case *lnwire.ChannelAnnouncement:
|
||||||
v.Unlock()
|
}
|
||||||
|
|
||||||
|
// Release the lock once the above read is finished.
|
||||||
|
v.Unlock()
|
||||||
|
|
||||||
|
// If it's not ok, it means either the job is not a dependent type, or
|
||||||
|
// it doesn't have a dependency signal. Either way, we can return
|
||||||
|
// early.
|
||||||
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
v.Unlock()
|
|
||||||
|
log.Debugf("Waiting for dependent on %s", jobDesc)
|
||||||
|
|
||||||
// If we do have an active job, then we'll wait until either the signal
|
// If we do have an active job, then we'll wait until either the signal
|
||||||
// is closed, or the set of jobs exits.
|
// is closed, or the set of jobs exits.
|
||||||
if ok {
|
select {
|
||||||
select {
|
case <-v.quit:
|
||||||
case <-v.quit:
|
return newErrf(ErrVBarrierShuttingDown,
|
||||||
return newErrf(ErrVBarrierShuttingDown,
|
"validation barrier shutting down")
|
||||||
"validation barrier shutting down")
|
|
||||||
case <-signals.deny:
|
|
||||||
return newErrf(ErrParentValidationFailed,
|
|
||||||
"parent validation failed")
|
|
||||||
case <-signals.allow:
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
case <-signals.deny:
|
||||||
|
log.Debugf("Signal deny for %s", jobDesc)
|
||||||
|
return newErrf(ErrParentValidationFailed,
|
||||||
|
"parent validation failed")
|
||||||
|
|
||||||
|
case <-signals.allow:
|
||||||
|
log.Tracef("Signal allow for %s", jobDesc)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SignalDependants will allow/deny any jobs that are dependent on this job that
|
// SignalDependants will allow/deny any jobs that are dependent on this job that
|
||||||
|
|||||||
Reference in New Issue
Block a user