mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-21 06:12:38 +02:00
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.
This commit is contained in:
parent
9b86ee53db
commit
e7988a2c2b
@ -31,7 +31,7 @@ var (
|
|||||||
//
|
//
|
||||||
// TODO(roasbeef): move inmpl to main package?
|
// TODO(roasbeef): move inmpl to main package?
|
||||||
type databaseChannelGraph struct {
|
type databaseChannelGraph struct {
|
||||||
db *graphdb.ChannelGraph
|
db GraphSource
|
||||||
}
|
}
|
||||||
|
|
||||||
// A compile time assertion to ensure databaseChannelGraph meets the
|
// A compile time assertion to ensure databaseChannelGraph meets the
|
||||||
@ -39,8 +39,8 @@ type databaseChannelGraph struct {
|
|||||||
var _ ChannelGraph = (*databaseChannelGraph)(nil)
|
var _ ChannelGraph = (*databaseChannelGraph)(nil)
|
||||||
|
|
||||||
// ChannelGraphFromDatabase returns an instance of the autopilot.ChannelGraph
|
// ChannelGraphFromDatabase returns an instance of the autopilot.ChannelGraph
|
||||||
// backed by a live, open channeldb instance.
|
// backed by a GraphSource.
|
||||||
func ChannelGraphFromDatabase(db *graphdb.ChannelGraph) ChannelGraph {
|
func ChannelGraphFromDatabase(db GraphSource) ChannelGraph {
|
||||||
return &databaseChannelGraph{
|
return &databaseChannelGraph{
|
||||||
db: db,
|
db: db,
|
||||||
}
|
}
|
||||||
@ -136,7 +136,7 @@ func (d *databaseChannelGraph) ForEachNode(cb func(Node) error) error {
|
|||||||
// databaseChannelGraphCached wraps a channeldb.ChannelGraph instance with the
|
// databaseChannelGraphCached wraps a channeldb.ChannelGraph instance with the
|
||||||
// necessary API to properly implement the autopilot.ChannelGraph interface.
|
// necessary API to properly implement the autopilot.ChannelGraph interface.
|
||||||
type databaseChannelGraphCached struct {
|
type databaseChannelGraphCached struct {
|
||||||
db *graphdb.ChannelGraph
|
db GraphSource
|
||||||
}
|
}
|
||||||
|
|
||||||
// A compile time assertion to ensure databaseChannelGraphCached meets the
|
// A compile time assertion to ensure databaseChannelGraphCached meets the
|
||||||
@ -145,7 +145,7 @@ var _ ChannelGraph = (*databaseChannelGraphCached)(nil)
|
|||||||
|
|
||||||
// ChannelGraphFromCachedDatabase returns an instance of the
|
// ChannelGraphFromCachedDatabase returns an instance of the
|
||||||
// autopilot.ChannelGraph backed by a live, open channeldb instance.
|
// autopilot.ChannelGraph backed by a live, open channeldb instance.
|
||||||
func ChannelGraphFromCachedDatabase(db *graphdb.ChannelGraph) ChannelGraph {
|
func ChannelGraphFromCachedDatabase(db GraphSource) ChannelGraph {
|
||||||
return &databaseChannelGraphCached{
|
return &databaseChannelGraphCached{
|
||||||
db: db,
|
db: db,
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,9 @@ import (
|
|||||||
"github.com/btcsuite/btcd/btcec/v2"
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
|
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultConfTarget is the default confirmation target for autopilot channels.
|
// DefaultConfTarget is the default confirmation target for autopilot channels.
|
||||||
@ -216,3 +218,20 @@ type ChannelController interface {
|
|||||||
// TODO(roasbeef): add force option?
|
// TODO(roasbeef): add force option?
|
||||||
CloseChannel(chanPoint *wire.OutPoint) error
|
CloseChannel(chanPoint *wire.OutPoint) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GraphSource represents read access to the channel graph.
|
||||||
|
type GraphSource interface {
|
||||||
|
// ForEachNode iterates through all the stored vertices/nodes in the
|
||||||
|
// graph, executing the passed callback with each node encountered. If
|
||||||
|
// the callback returns an error, then the transaction is aborted and
|
||||||
|
// the iteration stops early. Any operations performed on the NodeTx
|
||||||
|
// passed to the call-back are executed under the same read transaction.
|
||||||
|
ForEachNode(func(graphdb.NodeRTx) error) error
|
||||||
|
|
||||||
|
// ForEachNodeCached is similar to ForEachNode, but it utilizes the
|
||||||
|
// channel graph cache if one is available. It is less consistent than
|
||||||
|
// ForEachNode since any further calls are made across multiple
|
||||||
|
// transactions.
|
||||||
|
ForEachNodeCached(cb func(node route.Vertex,
|
||||||
|
chans map[uint64]*graphdb.DirectedChannel) error) error
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user