mirror of
https://github.com/lightningnetwork/lnd.git
synced 2026-08-13 12:32:48 +02:00
graph/db: version DeleteChannelEdges, IsPublicNode, IsZombieEdge
Propagate the gossip version parameter through DeleteChannelEdges,
IsPublicNode, and IsZombieEdge on ChannelGraph, passing it down to the
underlying Store. Previously these methods hard-coded GossipVersion1
internally; surfacing the parameter lets callers operate on the version
appropriate for the channel.
Also fix two call sites that were still passing *ChannelGraph where a
version-aware interface was expected:
- rpcserver.go AddInvoice now uses s.v1Graph (a *VersionedGraph) so
that the invoicesrpc.GraphSource interface—whose IsPublicNode method
does not take a version parameter—is satisfied.
- subrpcserver_config.go wraps graphDB in NewVersionedGraph with
GossipVersion1 when populating the invoicesrpc config Graph field
via reflection, for the same reason.
This commit is contained in:
parent
3c06daed8b
commit
084bac6e1e
4 changed files with 37 additions and 20 deletions
|
|
@ -395,11 +395,11 @@ func (c *ChannelGraph) MarkEdgeLive(ctx context.Context,
|
|||
// that resurrects the channel from its zombie state. The markZombie bool
|
||||
// denotes whether to mark the channel as a zombie.
|
||||
func (c *ChannelGraph) DeleteChannelEdges(ctx context.Context,
|
||||
strictZombiePruning, markZombie bool, chanIDs ...uint64) error {
|
||||
v lnwire.GossipVersion, strictZombiePruning, markZombie bool,
|
||||
chanIDs ...uint64) error {
|
||||
|
||||
infos, err := c.db.DeleteChannelEdges(
|
||||
ctx, lnwire.GossipVersion1, strictZombiePruning, markZombie,
|
||||
chanIDs...,
|
||||
ctx, v, strictZombiePruning, markZombie, chanIDs...,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -656,11 +656,12 @@ func (c *ChannelGraph) HasV1Node(ctx context.Context,
|
|||
return c.db.HasV1Node(ctx, nodePub)
|
||||
}
|
||||
|
||||
// IsPublicNode determines whether the node is seen as public in the graph.
|
||||
// IsPublicNode determines whether the node is seen as public in the graph for
|
||||
// the given gossip version.
|
||||
func (c *ChannelGraph) IsPublicNode(ctx context.Context,
|
||||
pubKey [33]byte) (bool, error) {
|
||||
v lnwire.GossipVersion, pubKey [33]byte) (bool, error) {
|
||||
|
||||
return c.db.IsPublicNode(ctx, lnwire.GossipVersion1, pubKey)
|
||||
return c.db.IsPublicNode(ctx, v, pubKey)
|
||||
}
|
||||
|
||||
// ForEachChannel iterates through all channel edges stored within the graph.
|
||||
|
|
@ -774,11 +775,13 @@ func (c *ChannelGraph) ChannelView(ctx context.Context) ([]EdgePoint, error) {
|
|||
return c.db.ChannelView(ctx)
|
||||
}
|
||||
|
||||
// IsZombieEdge returns whether the edge is considered zombie.
|
||||
// IsZombieEdge returns whether the edge is considered zombie for the given
|
||||
// gossip version.
|
||||
func (c *ChannelGraph) IsZombieEdge(ctx context.Context,
|
||||
chanID uint64) (bool, [33]byte, [33]byte, error) {
|
||||
v lnwire.GossipVersion, chanID uint64) (bool, [33]byte, [33]byte,
|
||||
error) {
|
||||
|
||||
return c.db.IsZombieEdge(ctx, lnwire.GossipVersion1, chanID)
|
||||
return c.db.IsZombieEdge(ctx, v, chanID)
|
||||
}
|
||||
|
||||
// NumZombies returns the current number of zombie channels in the graph.
|
||||
|
|
|
|||
|
|
@ -2955,7 +2955,7 @@ func TestFilterKnownChanIDsZombieRevival(t *testing.T) {
|
|||
|
||||
isZombie := func(scid lnwire.ShortChannelID) bool {
|
||||
zombie, _, _, err := graph.IsZombieEdge(
|
||||
ctx, scid.ToUint64(),
|
||||
ctx, lnwire.GossipVersion1, scid.ToUint64(),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
@ -3082,7 +3082,8 @@ func TestFilterKnownChanIDs(t *testing.T) {
|
|||
)
|
||||
require.NoError(t, graph.AddChannelEdge(ctx, channel))
|
||||
err := graph.DeleteChannelEdges(
|
||||
ctx, false, true, channel.ChannelID,
|
||||
ctx, lnwire.GossipVersion1, false, true,
|
||||
channel.ChannelID,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
@ -3423,7 +3424,8 @@ func TestStressTestChannelGraphAPI(t *testing.T) {
|
|||
}
|
||||
|
||||
err := graph.DeleteChannelEdges(
|
||||
ctx, strictPruning, markZombie,
|
||||
ctx, lnwire.GossipVersion1,
|
||||
strictPruning, markZombie,
|
||||
chanIDs...,
|
||||
)
|
||||
if err != nil &&
|
||||
|
|
@ -4384,7 +4386,9 @@ func BenchmarkIsPublicNode(b *testing.B) {
|
|||
// Query random nodes to avoid query caching and better
|
||||
// represent real-world query patterns.
|
||||
nodePub := nodes[rng.Intn(len(nodes))].PubKeyBytes
|
||||
_, err := graph.IsPublicNode(b.Context(), nodePub)
|
||||
_, err := graph.IsPublicNode(
|
||||
b.Context(), lnwire.GossipVersion1, nodePub,
|
||||
)
|
||||
require.NoError(b, err)
|
||||
}
|
||||
}
|
||||
|
|
@ -4615,17 +4619,21 @@ func TestGraphZombieIndex(t *testing.T) {
|
|||
|
||||
// Since the edge is known the graph and it isn't a zombie, IsZombieEdge
|
||||
// should not report the channel as a zombie.
|
||||
isZombie, _, _, err := graph.IsZombieEdge(ctx, edge.ChannelID)
|
||||
isZombie, _, _, err := graph.IsZombieEdge(
|
||||
ctx, lnwire.GossipVersion1, edge.ChannelID,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
require.False(t, isZombie)
|
||||
assertNumZombies(t, graph, 0)
|
||||
|
||||
// If we delete the edge and mark it as a zombie, then we should expect
|
||||
// to see it within the index.
|
||||
err = graph.DeleteChannelEdges(ctx, false, true, edge.ChannelID)
|
||||
err = graph.DeleteChannelEdges(
|
||||
ctx, lnwire.GossipVersion1, false, true, edge.ChannelID,
|
||||
)
|
||||
require.NoError(t, err, "unable to mark edge as zombie")
|
||||
isZombie, pubKey1, pubKey2, err := graph.IsZombieEdge(
|
||||
ctx, edge.ChannelID,
|
||||
ctx, lnwire.GossipVersion1, edge.ChannelID,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
require.True(t, isZombie)
|
||||
|
|
@ -4647,7 +4655,9 @@ func TestGraphZombieIndex(t *testing.T) {
|
|||
ErrZombieEdgeNotFound,
|
||||
)
|
||||
|
||||
isZombie, _, _, err = graph.IsZombieEdge(ctx, edge.ChannelID)
|
||||
isZombie, _, _, err = graph.IsZombieEdge(
|
||||
ctx, lnwire.GossipVersion1, edge.ChannelID,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
require.False(t, isZombie)
|
||||
|
||||
|
|
@ -4661,7 +4671,9 @@ func TestGraphZombieIndex(t *testing.T) {
|
|||
)
|
||||
require.NoError(t, err, "unable to mark edge as zombie")
|
||||
|
||||
isZombie, _, _, err = graph.IsZombieEdge(ctx, edge.ChannelID)
|
||||
isZombie, _, _, err = graph.IsZombieEdge(
|
||||
ctx, lnwire.GossipVersion1, edge.ChannelID,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
require.True(t, isZombie)
|
||||
assertNumZombies(t, graph, 1)
|
||||
|
|
|
|||
|
|
@ -6462,7 +6462,7 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
|
|||
NodeSigner: r.server.nodeSigner,
|
||||
DefaultCLTVExpiry: defaultDelta,
|
||||
ChanDB: r.server.chanStateDB,
|
||||
Graph: r.server.graphDB,
|
||||
Graph: r.server.v1Graph,
|
||||
GenInvoiceFeatures: func() *lnwire.FeatureVector {
|
||||
v := r.server.featureMgr.Get(feature.SetInvoice)
|
||||
|
||||
|
|
|
|||
|
|
@ -265,7 +265,9 @@ func (s *subRPCServerConfigs) PopulateDependencies(cfg *Config,
|
|||
reflect.ValueOf(defaultDelta),
|
||||
)
|
||||
subCfgValue.FieldByName("Graph").Set(
|
||||
reflect.ValueOf(graphDB),
|
||||
reflect.ValueOf(graphdb.NewVersionedGraph(
|
||||
graphDB, lnwire.GossipVersion1,
|
||||
)),
|
||||
)
|
||||
subCfgValue.FieldByName("ChanStateDB").Set(
|
||||
reflect.ValueOf(chanStateDB),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue