• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 12583319996

02 Jan 2025 01:38PM UTC coverage: 57.522% (-1.1%) from 58.598%
12583319996

Pull #9361

github

starius
fn/ContextGuard: use context.AfterFunc to wait

Simplifies context cancellation handling by using context.AfterFunc instead of a
goroutine to wait for context cancellation. This approach avoids the overhead of
a goroutine during the waiting period.

For ctxQuitUnsafe, since g.quit is closed only in the Quit method (which also
cancels all associated contexts), waiting on context cancellation ensures the
same behavior without unnecessary dependency on g.quit.

Added a test to ensure that the Create method does not launch any goroutines.
Pull Request #9361: fn: optimize context guard

102587 of 178344 relevant lines covered (57.52%)

24734.33 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/routing/graph.go
1
package routing
2

3
import (
4
        "fmt"
5

6
        "github.com/btcsuite/btcd/btcutil"
7
        graphdb "github.com/lightningnetwork/lnd/graph/db"
8
        "github.com/lightningnetwork/lnd/lnwire"
9
        "github.com/lightningnetwork/lnd/routing/route"
10
)
11

12
// Graph is an abstract interface that provides information about nodes and
13
// edges to pathfinding.
14
type Graph interface {
15
        // ForEachNodeChannel calls the callback for every channel of the given
16
        // node.
17
        ForEachNodeChannel(nodePub route.Vertex,
18
                cb func(channel *graphdb.DirectedChannel) error) error
19

20
        // FetchNodeFeatures returns the features of the given node.
21
        FetchNodeFeatures(nodePub route.Vertex) (*lnwire.FeatureVector, error)
22
}
23

24
// GraphSessionFactory can be used to produce a new Graph instance which can
25
// then be used for a path-finding session. Depending on the implementation,
26
// the Graph session will represent a DB connection where a read-lock is being
27
// held across calls to the backing Graph.
28
type GraphSessionFactory interface {
29
        // NewGraphSession will produce a new Graph to use for a path-finding
30
        // session. It returns the Graph along with a call-back that must be
31
        // called once Graph access is complete. This call-back will close any
32
        // read-only transaction that was created at Graph construction time.
33
        NewGraphSession() (Graph, func() error, error)
34
}
35

36
// FetchAmountPairCapacity determines the maximal public capacity between two
37
// nodes depending on the amount we try to send.
38
func FetchAmountPairCapacity(graph Graph, source, nodeFrom, nodeTo route.Vertex,
39
        amount lnwire.MilliSatoshi) (btcutil.Amount, error) {
×
40

×
41
        // Create unified edges for all incoming connections.
×
42
        //
×
43
        // Note: Inbound fees are not used here because this method is only used
×
44
        // by a deprecated router rpc.
×
45
        u := newNodeEdgeUnifier(source, nodeTo, false, nil)
×
46

×
47
        err := u.addGraphPolicies(graph)
×
48
        if err != nil {
×
49
                return 0, err
×
50
        }
×
51

52
        edgeUnifier, ok := u.edgeUnifiers[nodeFrom]
×
53
        if !ok {
×
54
                return 0, fmt.Errorf("no edge info for node pair %v -> %v",
×
55
                        nodeFrom, nodeTo)
×
56
        }
×
57

58
        edge := edgeUnifier.getEdgeNetwork(amount, 0)
×
59
        if edge == nil {
×
60
                return 0, fmt.Errorf("no edge for node pair %v -> %v "+
×
61
                        "(amount %v)", nodeFrom, nodeTo, amount)
×
62
        }
×
63

64
        return edge.capacity, nil
×
65
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc