diff --git a/lntest/itest/lnd_mpp_test.go b/lntest/itest/lnd_mpp_test.go index 15a95d316..8fd1f752d 100644 --- a/lntest/itest/lnd_mpp_test.go +++ b/lntest/itest/lnd_mpp_test.go @@ -346,9 +346,9 @@ func (c *mppTestContext) waitForChannels() { ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) err = node.WaitForNetworkChannelOpen(ctxt, chanPoint) if err != nil { - c.t.Fatalf("(%d): timeout waiting for "+ + c.t.Fatalf("(%v:%d): timeout waiting for "+ "channel(%s) open: %v", - node.NodeID, point, err) + node.Cfg.Name, node.NodeID, point, err) } } } diff --git a/lntest/node.go b/lntest/node.go index 06359b0ed..f9703b7d7 100644 --- a/lntest/node.go +++ b/lntest/node.go @@ -1225,6 +1225,27 @@ func getChanPointFundingTxid(chanPoint *lnrpc.ChannelPoint) ([]byte, error) { return txid, nil } +func checkChanPointInGraph(ctx context.Context, + node *HarnessNode, chanPoint wire.OutPoint) bool { + + ctxt, cancel := context.WithTimeout(ctx, DefaultTimeout) + defer cancel() + chanGraph, err := node.DescribeGraph(ctxt, &lnrpc.ChannelGraphRequest{}) + if err != nil { + return false + } + + targetChanPoint := chanPoint.String() + for _, chanEdge := range chanGraph.Edges { + candidateChanPoint := chanEdge.ChanPoint + if targetChanPoint == candidateChanPoint { + return true + } + } + + return false +} + // lightningNetworkWatcher is a goroutine which is able to dispatch // notifications once it has been observed that a target channel has been // closed or opened within the network. In order to dispatch these @@ -1337,6 +1358,21 @@ func (hn *HarnessNode) lightningNetworkWatcher(subscribed chan error) { continue } + // Before we add the channel to our set of open + // clients, we'll check to see if the channel + // is already in the channel graph of the + // target node. This lets us handle the case + // where a node has already seen a channel + // before a notification has been requested, + // causing us to miss it. + chanFound := checkChanPointInGraph( + context.Background(), hn, targetChan, + ) + if chanFound { + close(watchRequest.eventChan) + continue + } + // Otherwise, we'll add this to the list of // watch open clients for this out point. hn.openClients[targetChan] = append(