mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-29 10:09:08 +02:00
channeldb+routing: extend edge lookup methods with zombie index check
In this commit, we extend the graph's FetchChannelEdgesByID and HasChannelEdge methods to also check the zombie index whenever the edge to be looked up doesn't exist within the edge index. We do this to signal to callers that the edge is known, but only as a zombie, and the only information that we have about the edge are the node public keys of the two parties involved in the edge. In the event that an edge does exist within the zombie index, we make an additional check on edge policies to ensure they are not within the router's pruning window, indicating that it is a fresh update.
This commit is contained in:
@ -1549,21 +1549,27 @@ func TestWakeUpOnStaleBranch(t *testing.T) {
|
||||
}
|
||||
|
||||
// Check that the fundingTxs are in the graph db.
|
||||
_, _, has, err := ctx.graph.HasChannelEdge(chanID1)
|
||||
_, _, has, isZombie, err := ctx.graph.HasChannelEdge(chanID1)
|
||||
if err != nil {
|
||||
t.Fatalf("error looking for edge: %v", chanID1)
|
||||
}
|
||||
if !has {
|
||||
t.Fatalf("could not find edge in graph")
|
||||
}
|
||||
if isZombie {
|
||||
t.Fatal("edge was marked as zombie")
|
||||
}
|
||||
|
||||
_, _, has, err = ctx.graph.HasChannelEdge(chanID2)
|
||||
_, _, has, isZombie, err = ctx.graph.HasChannelEdge(chanID2)
|
||||
if err != nil {
|
||||
t.Fatalf("error looking for edge: %v", chanID2)
|
||||
}
|
||||
if !has {
|
||||
t.Fatalf("could not find edge in graph")
|
||||
}
|
||||
if isZombie {
|
||||
t.Fatal("edge was marked as zombie")
|
||||
}
|
||||
|
||||
// Stop the router, so we can reorg the chain while its offline.
|
||||
if err := ctx.router.Stop(); err != nil {
|
||||
@ -1607,22 +1613,27 @@ func TestWakeUpOnStaleBranch(t *testing.T) {
|
||||
// The channel with chanID2 should not be in the database anymore,
|
||||
// since it is not confirmed on the longest chain. chanID1 should
|
||||
// still be.
|
||||
_, _, has, err = ctx.graph.HasChannelEdge(chanID1)
|
||||
_, _, has, isZombie, err = ctx.graph.HasChannelEdge(chanID1)
|
||||
if err != nil {
|
||||
t.Fatalf("error looking for edge: %v", chanID1)
|
||||
}
|
||||
if !has {
|
||||
t.Fatalf("did not find edge in graph")
|
||||
}
|
||||
if isZombie {
|
||||
t.Fatal("edge was marked as zombie")
|
||||
}
|
||||
|
||||
_, _, has, err = ctx.graph.HasChannelEdge(chanID2)
|
||||
_, _, has, isZombie, err = ctx.graph.HasChannelEdge(chanID2)
|
||||
if err != nil {
|
||||
t.Fatalf("error looking for edge: %v", chanID2)
|
||||
}
|
||||
if has {
|
||||
t.Fatalf("found edge in graph")
|
||||
}
|
||||
|
||||
if isZombie {
|
||||
t.Fatal("reorged edge should not be marked as zombie")
|
||||
}
|
||||
}
|
||||
|
||||
// TestDisconnectedBlocks checks that the router handles a reorg happening when
|
||||
@ -1755,21 +1766,27 @@ func TestDisconnectedBlocks(t *testing.T) {
|
||||
}
|
||||
|
||||
// Check that the fundingTxs are in the graph db.
|
||||
_, _, has, err := ctx.graph.HasChannelEdge(chanID1)
|
||||
_, _, has, isZombie, err := ctx.graph.HasChannelEdge(chanID1)
|
||||
if err != nil {
|
||||
t.Fatalf("error looking for edge: %v", chanID1)
|
||||
}
|
||||
if !has {
|
||||
t.Fatalf("could not find edge in graph")
|
||||
}
|
||||
if isZombie {
|
||||
t.Fatal("edge was marked as zombie")
|
||||
}
|
||||
|
||||
_, _, has, err = ctx.graph.HasChannelEdge(chanID2)
|
||||
_, _, has, isZombie, err = ctx.graph.HasChannelEdge(chanID2)
|
||||
if err != nil {
|
||||
t.Fatalf("error looking for edge: %v", chanID2)
|
||||
}
|
||||
if !has {
|
||||
t.Fatalf("could not find edge in graph")
|
||||
}
|
||||
if isZombie {
|
||||
t.Fatal("edge was marked as zombie")
|
||||
}
|
||||
|
||||
// Create a 15 block fork. We first let the chainView notify the router
|
||||
// about stale blocks, before sending the now connected blocks. We do
|
||||
@ -1796,22 +1813,27 @@ func TestDisconnectedBlocks(t *testing.T) {
|
||||
|
||||
// chanID2 should not be in the database anymore, since it is not
|
||||
// confirmed on the longest chain. chanID1 should still be.
|
||||
_, _, has, err = ctx.graph.HasChannelEdge(chanID1)
|
||||
_, _, has, isZombie, err = ctx.graph.HasChannelEdge(chanID1)
|
||||
if err != nil {
|
||||
t.Fatalf("error looking for edge: %v", chanID1)
|
||||
}
|
||||
if !has {
|
||||
t.Fatalf("did not find edge in graph")
|
||||
}
|
||||
if isZombie {
|
||||
t.Fatal("edge was marked as zombie")
|
||||
}
|
||||
|
||||
_, _, has, err = ctx.graph.HasChannelEdge(chanID2)
|
||||
_, _, has, isZombie, err = ctx.graph.HasChannelEdge(chanID2)
|
||||
if err != nil {
|
||||
t.Fatalf("error looking for edge: %v", chanID2)
|
||||
}
|
||||
if has {
|
||||
t.Fatalf("found edge in graph")
|
||||
}
|
||||
|
||||
if isZombie {
|
||||
t.Fatal("reorged edge should not be marked as zombie")
|
||||
}
|
||||
}
|
||||
|
||||
// TestChansClosedOfflinePruneGraph tests that if channels we know of are
|
||||
@ -1876,13 +1898,16 @@ func TestRouterChansClosedOfflinePruneGraph(t *testing.T) {
|
||||
}
|
||||
|
||||
// The router should now be aware of the channel we created above.
|
||||
_, _, hasChan, err := ctx.graph.HasChannelEdge(chanID1.ToUint64())
|
||||
_, _, hasChan, isZombie, err := ctx.graph.HasChannelEdge(chanID1.ToUint64())
|
||||
if err != nil {
|
||||
t.Fatalf("error looking for edge: %v", chanID1)
|
||||
}
|
||||
if !hasChan {
|
||||
t.Fatalf("could not find edge in graph")
|
||||
}
|
||||
if isZombie {
|
||||
t.Fatal("edge was marked as zombie")
|
||||
}
|
||||
|
||||
// With the transaction included, and the router's database state
|
||||
// updated, we'll now mine 5 additional blocks on top of it.
|
||||
@ -1957,13 +1982,16 @@ func TestRouterChansClosedOfflinePruneGraph(t *testing.T) {
|
||||
|
||||
// At this point, the channel that was pruned should no longer be known
|
||||
// by the router.
|
||||
_, _, hasChan, err = ctx.graph.HasChannelEdge(chanID1.ToUint64())
|
||||
_, _, hasChan, isZombie, err = ctx.graph.HasChannelEdge(chanID1.ToUint64())
|
||||
if err != nil {
|
||||
t.Fatalf("error looking for edge: %v", chanID1)
|
||||
}
|
||||
if hasChan {
|
||||
t.Fatalf("channel was found in graph but shouldn't have been")
|
||||
}
|
||||
if isZombie {
|
||||
t.Fatal("closed channel should not be marked as zombie")
|
||||
}
|
||||
}
|
||||
|
||||
// TestFindPathFeeWeighting tests that the findPath method will properly prefer
|
||||
|
Reference in New Issue
Block a user