Merge pull request #5521 from Roasbeef/amp-test-flake-chan-open
lntest: fix possible race condition re asserting channel propagation
This commit is contained in:
2 files changed
+38
-2
No files matched your search
@@ -346,9 +346,9 @@ func (c *mppTestContext) waitForChannels() {
|
|||||||
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
||||||
err = node.WaitForNetworkChannelOpen(ctxt, chanPoint)
|
err = node.WaitForNetworkChannelOpen(ctxt, chanPoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.t.Fatalf("(%d): timeout waiting for "+
|
c.t.Fatalf("(%v:%d): timeout waiting for "+
|
||||||
"channel(%s) open: %v",
|
"channel(%s) open: %v",
|
||||||
node.NodeID, point, err)
|
node.Cfg.Name, node.NodeID, point, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1225,6 +1225,27 @@ func getChanPointFundingTxid(chanPoint *lnrpc.ChannelPoint) ([]byte, error) {
|
|||||||
return txid, nil
|
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
|
// lightningNetworkWatcher is a goroutine which is able to dispatch
|
||||||
// notifications once it has been observed that a target channel has been
|
// notifications once it has been observed that a target channel has been
|
||||||
// closed or opened within the network. In order to dispatch these
|
// closed or opened within the network. In order to dispatch these
|
||||||
@@ -1337,6 +1358,21 @@ func (hn *HarnessNode) lightningNetworkWatcher(subscribed chan error) {
|
|||||||
continue
|
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
|
// Otherwise, we'll add this to the list of
|
||||||
// watch open clients for this out point.
|
// watch open clients for this out point.
|
||||||
hn.openClients[targetChan] = append(
|
hn.openClients[targetChan] = append(
|
||||||
|
|||||||
Reference in new issue
Block a user