mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-23 06:35:07 +01:00
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:
commit
945c0fa0df
2 changed files with 38 additions and 2 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Add table
Reference in a new issue