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

lightningnetwork / lnd / 11216766535

07 Oct 2024 01:37PM UTC coverage: 57.817% (-1.0%) from 58.817%
11216766535

Pull #9148

github

ProofOfKeags
lnwire: remove kickoff feerate from propose/commit
Pull Request #9148: DynComms [2/n]: lnwire: add authenticated wire messages for Dyn*

571 of 879 new or added lines in 16 files covered. (64.96%)

23253 existing lines in 251 files now uncovered.

99022 of 171268 relevant lines covered (57.82%)

38420.67 hits per line

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

0.0
/channeldb/graphsession/graph_session.go
1
package graphsession
2

3
import (
4
        "fmt"
5

6
        "github.com/lightningnetwork/lnd/channeldb"
7
        "github.com/lightningnetwork/lnd/kvdb"
8
        "github.com/lightningnetwork/lnd/lnwire"
9
        "github.com/lightningnetwork/lnd/routing"
10
        "github.com/lightningnetwork/lnd/routing/route"
11
)
12

13
// Factory implements the routing.GraphSessionFactory and can be used to start
14
// a session with a ReadOnlyGraph.
15
type Factory struct {
16
        graph ReadOnlyGraph
17
}
18

19
// NewGraphSessionFactory constructs a new Factory which can then be used to
20
// start a new session.
UNCOV
21
func NewGraphSessionFactory(graph ReadOnlyGraph) routing.GraphSessionFactory {
×
UNCOV
22
        return &Factory{
×
UNCOV
23
                graph: graph,
×
UNCOV
24
        }
×
UNCOV
25
}
×
26

27
// NewGraphSession will produce a new Graph to use for a path-finding session.
28
// It returns the Graph along with a call-back that must be called once Graph
29
// access is complete. This call-back will close any read-only transaction that
30
// was created at Graph construction time.
31
//
32
// NOTE: This is part of the routing.GraphSessionFactory interface.
UNCOV
33
func (g *Factory) NewGraphSession() (routing.Graph, func() error, error) {
×
UNCOV
34
        tx, err := g.graph.NewPathFindTx()
×
UNCOV
35
        if err != nil {
×
36
                return nil, nil, err
×
37
        }
×
38

UNCOV
39
        session := &session{
×
UNCOV
40
                graph: g.graph,
×
UNCOV
41
                tx:    tx,
×
UNCOV
42
        }
×
UNCOV
43

×
UNCOV
44
        return session, session.close, nil
×
45
}
46

47
// A compile-time check to ensure that Factory implements the
48
// routing.GraphSessionFactory interface.
49
var _ routing.GraphSessionFactory = (*Factory)(nil)
50

51
// session is an implementation of the routing.Graph interface where the same
52
// read-only transaction is held across calls to the graph and can be used to
53
// access the backing channel graph.
54
type session struct {
55
        graph graph
56
        tx    kvdb.RTx
57
}
58

59
// NewRoutingGraph constructs a session that which does not first start a
60
// read-only transaction and so each call on the routing.Graph will create a
61
// new transaction.
UNCOV
62
func NewRoutingGraph(graph ReadOnlyGraph) routing.Graph {
×
UNCOV
63
        return &session{
×
UNCOV
64
                graph: graph,
×
UNCOV
65
        }
×
UNCOV
66
}
×
67

68
// close closes the read-only transaction being used to access the backing
69
// graph. If no transaction was started then this is a no-op.
UNCOV
70
func (g *session) close() error {
×
UNCOV
71
        if g.tx == nil {
×
UNCOV
72
                return nil
×
UNCOV
73
        }
×
74

75
        err := g.tx.Rollback()
×
76
        if err != nil {
×
77
                return fmt.Errorf("error closing db tx: %w", err)
×
78
        }
×
79

80
        return nil
×
81
}
82

83
// ForEachNodeChannel calls the callback for every channel of the given node.
84
//
85
// NOTE: Part of the routing.Graph interface.
86
func (g *session) ForEachNodeChannel(nodePub route.Vertex,
UNCOV
87
        cb func(channel *channeldb.DirectedChannel) error) error {
×
UNCOV
88

×
UNCOV
89
        return g.graph.ForEachNodeDirectedChannel(g.tx, nodePub, cb)
×
UNCOV
90
}
×
91

92
// FetchNodeFeatures returns the features of the given node. If the node is
93
// unknown, assume no additional features are supported.
94
//
95
// NOTE: Part of the routing.Graph interface.
96
func (g *session) FetchNodeFeatures(nodePub route.Vertex) (
UNCOV
97
        *lnwire.FeatureVector, error) {
×
UNCOV
98

×
UNCOV
99
        return g.graph.FetchNodeFeatures(nodePub)
×
UNCOV
100
}
×
101

102
// A compile-time check to ensure that *session implements the
103
// routing.Graph interface.
104
var _ routing.Graph = (*session)(nil)
105

106
// ReadOnlyGraph is a graph extended with a call to create a new read-only
107
// transaction that can then be used to make further queries to the graph.
108
type ReadOnlyGraph interface {
109
        // NewPathFindTx returns a new read transaction that can be used for a
110
        // single path finding session. Will return nil if the graph cache is
111
        // enabled.
112
        NewPathFindTx() (kvdb.RTx, error)
113

114
        graph
115
}
116

117
// graph describes the API necessary for a graph source to have access to on a
118
// database implementation, like channeldb.ChannelGraph, in order to be used by
119
// the Router for pathfinding.
120
type graph interface {
121
        // ForEachNodeDirectedChannel iterates through all channels of a given
122
        // node, executing the passed callback on the directed edge representing
123
        // the channel and its incoming policy. If the callback returns an
124
        // error, then the iteration is halted with the error propagated back
125
        // up to the caller.
126
        //
127
        // Unknown policies are passed into the callback as nil values.
128
        //
129
        // NOTE: if a nil tx is provided, then it is expected that the
130
        // implementation create a read only tx.
131
        ForEachNodeDirectedChannel(tx kvdb.RTx, node route.Vertex,
132
                cb func(channel *channeldb.DirectedChannel) error) error
133

134
        // FetchNodeFeatures returns the features of a given node. If no
135
        // features are known for the node, an empty feature vector is returned.
136
        FetchNodeFeatures(node route.Vertex) (*lnwire.FeatureVector, error)
137
}
138

139
// A compile-time check to ensure that *channeldb.ChannelGraph implements the
140
// graph interface.
141
var _ graph = (*channeldb.ChannelGraph)(nil)
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