Skip to content

Commit e7988a2

Browse files
committed
autopilot: remove access to *graphdb.ChannelGraph
Define a new GraphSource interface that describes the access required by the autopilot server. Let its constructor take this interface instead of a raw pointer to the graphdb.ChannelGraph.
1 parent 9b86ee5 commit e7988a2

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

autopilot/graph.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ var (
3131
//
3232
// TODO(roasbeef): move inmpl to main package?
3333
type databaseChannelGraph struct {
34-
db *graphdb.ChannelGraph
34+
db GraphSource
3535
}
3636

3737
// A compile time assertion to ensure databaseChannelGraph meets the
3838
// autopilot.ChannelGraph interface.
3939
var _ ChannelGraph = (*databaseChannelGraph)(nil)
4040

4141
// ChannelGraphFromDatabase returns an instance of the autopilot.ChannelGraph
42-
// backed by a live, open channeldb instance.
43-
func ChannelGraphFromDatabase(db *graphdb.ChannelGraph) ChannelGraph {
42+
// backed by a GraphSource.
43+
func ChannelGraphFromDatabase(db GraphSource) ChannelGraph {
4444
return &databaseChannelGraph{
4545
db: db,
4646
}
@@ -136,7 +136,7 @@ func (d *databaseChannelGraph) ForEachNode(cb func(Node) error) error {
136136
// databaseChannelGraphCached wraps a channeldb.ChannelGraph instance with the
137137
// necessary API to properly implement the autopilot.ChannelGraph interface.
138138
type databaseChannelGraphCached struct {
139-
db *graphdb.ChannelGraph
139+
db GraphSource
140140
}
141141

142142
// A compile time assertion to ensure databaseChannelGraphCached meets the
@@ -145,7 +145,7 @@ var _ ChannelGraph = (*databaseChannelGraphCached)(nil)
145145

146146
// ChannelGraphFromCachedDatabase returns an instance of the
147147
// autopilot.ChannelGraph backed by a live, open channeldb instance.
148-
func ChannelGraphFromCachedDatabase(db *graphdb.ChannelGraph) ChannelGraph {
148+
func ChannelGraphFromCachedDatabase(db GraphSource) ChannelGraph {
149149
return &databaseChannelGraphCached{
150150
db: db,
151151
}

autopilot/interface.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import (
66
"github.com/btcsuite/btcd/btcec/v2"
77
"github.com/btcsuite/btcd/btcutil"
88
"github.com/btcsuite/btcd/wire"
9+
graphdb "github.com/lightningnetwork/lnd/graph/db"
910
"github.com/lightningnetwork/lnd/lnwire"
11+
"github.com/lightningnetwork/lnd/routing/route"
1012
)
1113

1214
// DefaultConfTarget is the default confirmation target for autopilot channels.
@@ -216,3 +218,20 @@ type ChannelController interface {
216218
// TODO(roasbeef): add force option?
217219
CloseChannel(chanPoint *wire.OutPoint) error
218220
}
221+
222+
// GraphSource represents read access to the channel graph.
223+
type GraphSource interface {
224+
// ForEachNode iterates through all the stored vertices/nodes in the
225+
// graph, executing the passed callback with each node encountered. If
226+
// the callback returns an error, then the transaction is aborted and
227+
// the iteration stops early. Any operations performed on the NodeTx
228+
// passed to the call-back are executed under the same read transaction.
229+
ForEachNode(func(graphdb.NodeRTx) error) error
230+
231+
// ForEachNodeCached is similar to ForEachNode, but it utilizes the
232+
// channel graph cache if one is available. It is less consistent than
233+
// ForEachNode since any further calls are made across multiple
234+
// transactions.
235+
ForEachNodeCached(cb func(node route.Vertex,
236+
chans map[uint64]*graphdb.DirectedChannel) error) error
237+
}

0 commit comments

Comments
 (0)