mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-12-11 21:32:06 +01:00
multi+refactor: let FetchChanInfos not take tx
In preparation for having a clean graph DB interface, refactor FetchChanInfos so that no transaction can be provided.
This commit is contained in:
@@ -2374,10 +2374,19 @@ func (c *ChannelGraph) FilterChannelRange(startHeight,
|
||||
// skipped and the result will contain only those edges that exist at the time
|
||||
// of the query. This can be used to respond to peer queries that are seeking to
|
||||
// fill in gaps in their view of the channel graph.
|
||||
func (c *ChannelGraph) FetchChanInfos(chanIDs []uint64) ([]ChannelEdge, error) {
|
||||
return c.fetchChanInfos(nil, chanIDs)
|
||||
}
|
||||
|
||||
// fetchChanInfos returns the set of channel edges that correspond to the passed
|
||||
// channel ID's. If an edge is the query is unknown to the database, it will
|
||||
// skipped and the result will contain only those edges that exist at the time
|
||||
// of the query. This can be used to respond to peer queries that are seeking to
|
||||
// fill in gaps in their view of the channel graph.
|
||||
//
|
||||
// NOTE: An optional transaction may be provided. If none is provided, then a
|
||||
// new one will be created.
|
||||
func (c *ChannelGraph) FetchChanInfos(tx kvdb.RTx, chanIDs []uint64) (
|
||||
func (c *ChannelGraph) fetchChanInfos(tx kvdb.RTx, chanIDs []uint64) (
|
||||
[]ChannelEdge, error) {
|
||||
// TODO(roasbeef): sort cids?
|
||||
|
||||
@@ -2958,8 +2967,8 @@ func (c *ChannelGraph) isPublic(tx kvdb.RTx, nodePub route.Vertex,
|
||||
// key. If the node isn't found in the database, then ErrGraphNodeNotFound is
|
||||
// returned. An optional transaction may be provided. If none is provided, then
|
||||
// a new one will be created.
|
||||
func (c *ChannelGraph) FetchLightningNode(tx kvdb.RTx, nodePub route.Vertex) (
|
||||
*LightningNode, error) {
|
||||
func (c *ChannelGraph) FetchLightningNode(tx kvdb.RTx,
|
||||
nodePub route.Vertex) (*LightningNode, error) {
|
||||
|
||||
var node *LightningNode
|
||||
fetch := func(tx kvdb.RTx) error {
|
||||
@@ -3705,7 +3714,7 @@ func (c *ChannelGraph) markEdgeLiveUnsafe(tx kvdb.RwTx, chanID uint64) error {
|
||||
// We need to add the channel back into our graph cache, otherwise we
|
||||
// won't use it for path finding.
|
||||
if c.graphCache != nil {
|
||||
edgeInfos, err := c.FetchChanInfos(tx, []uint64{chanID})
|
||||
edgeInfos, err := c.fetchChanInfos(tx, []uint64{chanID})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -2685,7 +2685,7 @@ func TestFetchChanInfos(t *testing.T) {
|
||||
// We'll now attempt to query for the range of channel ID's we just
|
||||
// inserted into the database. We should get the exact same set of
|
||||
// edges back.
|
||||
resp, err := graph.FetchChanInfos(nil, edgeQuery)
|
||||
resp, err := graph.FetchChanInfos(edgeQuery)
|
||||
require.NoError(t, err, "unable to fetch chan edges")
|
||||
if len(resp) != len(edges) {
|
||||
t.Fatalf("expected %v edges, instead got %v", len(edges),
|
||||
|
||||
@@ -249,7 +249,7 @@ func (c *ChanSeries) FetchChanAnns(chain chainhash.Hash,
|
||||
chanIDs = append(chanIDs, chanID.ToUint64())
|
||||
}
|
||||
|
||||
channels, err := c.graph.FetchChanInfos(nil, chanIDs)
|
||||
channels, err := c.graph.FetchChanInfos(chanIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1023,7 +1023,7 @@ func (r *ChannelRouter) pruneZombieChans() error {
|
||||
}
|
||||
|
||||
disabledEdges, err := r.cfg.Graph.FetchChanInfos(
|
||||
nil, disabledChanIDs,
|
||||
disabledChanIDs,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to fetch disabled channels "+
|
||||
|
||||
Reference in New Issue
Block a user