From ae7c6c7e8f66fd02c1b501531882e10393d5f826 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Sat, 18 Nov 2017 16:38:30 -0800 Subject: [PATCH 1/3] networktest: wait for channel to become active before attempting close --- networktest.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/networktest.go b/networktest.go index ace148e9..0022d530 100644 --- a/networktest.go +++ b/networktest.go @@ -1270,6 +1270,45 @@ func (n *networkHarness) CloseChannel(ctx context.Context, lnNode *lightningNode, cp *lnrpc.ChannelPoint, force bool) (lnrpc.Lightning_CloseChannelClient, *chainhash.Hash, error) { + // Create a channel outpoint that we can use to compare to channels + // from the ListChannelsResponse. + fundingTxID, err := chainhash.NewHash(cp.FundingTxid) + if err != nil { + return nil, nil, err + } + chanPoint := wire.OutPoint{ + Hash: *fundingTxID, + Index: cp.OutputIndex, + } + + // If we are not force closing the channel, wait for channel to become + // active before attempting to close it. + numTries := 10 +CheckActive: + for i := 0; !force && i < numTries; i++ { + listReq := &lnrpc.ListChannelsRequest{} + listResp, err := lnNode.ListChannels(ctx, listReq) + if err != nil { + return nil, nil, fmt.Errorf("unable fetch node's "+ + "channels: %v", err) + } + + for _, c := range listResp.Channels { + if c.ChannelPoint == chanPoint.String() && c.Active { + break CheckActive + } + } + + if i == numTries-1 { + // Last iteration, and channel is still not active. + return nil, nil, fmt.Errorf("channel did not become " + + "active") + } + + // Sleep, and try again. + time.Sleep(300 * time.Millisecond) + } + closeReq := &lnrpc.CloseChannelRequest{ ChannelPoint: cp, Force: force, From 6065c763e691af0b02b05cd89cf5c1882a0ccade Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Sat, 18 Nov 2017 16:30:51 -0800 Subject: [PATCH 2/3] rpcserver: only set channel Active=true if added to htlcswitch For a calls to ListChannels we now only set the ActiveChannel.Active=true if the link is found by the htlcswitch. This is done to be able to make it possible to tell if a newly opened channel has been added to the htlcswitch, such that we can synchronize on this during tests before we attempt to close the channel. --- rpcserver.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/rpcserver.go b/rpcserver.go index 46e9869b..25f553e1 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -1333,6 +1333,12 @@ func (r *rpcServer) ListChannels(ctx context.Context, peerOnline = true } + channelID := lnwire.NewChanIDFromOutPoint(&chanPoint) + var linkActive bool + if _, err := r.server.htlcSwitch.GetLink(channelID); err == nil { + linkActive = true + } + // As this is required for display purposes, we'll calculate // the weight of the commitment transaction. We also add on the // estimated weight of the witness to calculate the weight of @@ -1344,7 +1350,7 @@ func (r *rpcServer) ListChannels(ctx context.Context, commitWeight := commitBaseWeight + lnwallet.WitnessCommitmentTxWeight channel := &lnrpc.ActiveChannel{ - Active: peerOnline, + Active: peerOnline && linkActive, RemotePubkey: nodeID, ChannelPoint: chanPoint.String(), ChanId: chanID, From 3a0d4e78aec125c54ef37aa7001f23c5b6057c2d Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Mon, 20 Nov 2017 13:56:00 -0800 Subject: [PATCH 3/3] travis.yml: build btcd version from glide.yaml for use in integration tests --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 268da43a..07169dbb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,10 +8,12 @@ install: - GLIDE_DOWNLOAD="https://github.com/Masterminds/glide/releases/download/$GLIDE_TAG/glide-$GLIDE_TAG-linux-amd64.tar.gz" - curl -L $GLIDE_DOWNLOAD | tar -xvz - export PATH=$PATH:$PWD/linux-amd64/ + - BTCD_VERSION=$(cat glide.yaml | grep -A1 btcd | tail -n1 | awk '{ print $2}') - mkdir -p $GOPATH/src/github.com/roasbeef/ - pushd $GOPATH/src/github.com/roasbeef/ - git clone https://github.com/roasbeef/btcd - pushd btcd + - git checkout $BTCD_VERSION - glide install - go install . ./cmd/... - popd