Merge pull request #434 from halseth/close-channel-active
Only consider channel active if added to switch
This commit is contained in:
commit
56c5959ee5
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user