mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-01-19 05:45:21 +01:00
lntemp+itest: refactor testAbandonChannel
This commit is contained in:
parent
2c12c8a77c
commit
b1b989afae
@ -1455,3 +1455,27 @@ func (h *HarnessTest) assertHTLCError(hn *node.HarnessNode,
|
|||||||
|
|
||||||
require.NoError(h, err, "timeout checking HTLC error")
|
require.NoError(h, err, "timeout checking HTLC error")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AssertZombieChannel asserts that a given channel found using the chanID is
|
||||||
|
// marked as zombie.
|
||||||
|
func (h *HarnessTest) AssertZombieChannel(hn *node.HarnessNode, chanID uint64) {
|
||||||
|
ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
err := wait.NoError(func() error {
|
||||||
|
_, err := hn.RPC.LN.GetChanInfo(
|
||||||
|
ctxt, &lnrpc.ChanInfoRequest{ChanId: chanID},
|
||||||
|
)
|
||||||
|
if err == nil {
|
||||||
|
return fmt.Errorf("expected error but got nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.Contains(err.Error(), "marked as zombie") {
|
||||||
|
return fmt.Errorf("expected error to contain '%s' but "+
|
||||||
|
"was '%v'", "marked as zombie", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}, DefaultTimeout)
|
||||||
|
require.NoError(h, err, "timeout while checking zombie channel")
|
||||||
|
}
|
||||||
|
@ -107,4 +107,8 @@ var allTestCasesTemp = []*lntemp.TestCase{
|
|||||||
Name: "list addresses",
|
Name: "list addresses",
|
||||||
TestFunc: testListAddresses,
|
TestFunc: testListAddresses,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "abandonchannel",
|
||||||
|
TestFunc: testAbandonChannel,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
package itest
|
package itest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
"github.com/btcsuite/btcwallet/wallet"
|
"github.com/btcsuite/btcwallet/wallet"
|
||||||
@ -19,7 +17,6 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
|
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
|
||||||
"github.com/lightningnetwork/lnd/lntemp"
|
"github.com/lightningnetwork/lnd/lntemp"
|
||||||
"github.com/lightningnetwork/lnd/lntemp/node"
|
"github.com/lightningnetwork/lnd/lntemp/node"
|
||||||
"github.com/lightningnetwork/lnd/lntest"
|
|
||||||
"github.com/lightningnetwork/lnd/lntest/wait"
|
"github.com/lightningnetwork/lnd/lntest/wait"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
@ -670,116 +667,52 @@ func testNodeSignVerify(ht *lntemp.HarnessTest) {
|
|||||||
ht.CloseChannel(alice, aliceBobCh)
|
ht.CloseChannel(alice, aliceBobCh)
|
||||||
}
|
}
|
||||||
|
|
||||||
// testAbandonChannel abandones a channel and asserts that it is no
|
// testAbandonChannel abandons a channel and asserts that it is no longer open
|
||||||
// longer open and not in one of the pending closure states. It also
|
// and not in one of the pending closure states. It also verifies that the
|
||||||
// verifies that the abandoned channel is reported as closed with close
|
// abandoned channel is reported as closed with close type 'abandoned'.
|
||||||
// type 'abandoned'.
|
func testAbandonChannel(ht *lntemp.HarnessTest) {
|
||||||
func testAbandonChannel(net *lntest.NetworkHarness, t *harnessTest) {
|
alice, bob := ht.Alice, ht.Bob
|
||||||
ctxb := context.Background()
|
|
||||||
|
|
||||||
// First establish a channel between Alice and Bob.
|
// First establish a channel between Alice and Bob.
|
||||||
channelParam := lntest.OpenChannelParams{
|
channelParam := lntemp.OpenChannelParams{
|
||||||
Amt: funding.MaxBtcFundingAmount,
|
Amt: funding.MaxBtcFundingAmount,
|
||||||
PushAmt: btcutil.Amount(100000),
|
PushAmt: btcutil.Amount(100000),
|
||||||
}
|
}
|
||||||
|
chanPoint := ht.OpenChannel(alice, bob, channelParam)
|
||||||
chanPoint := openChannelAndAssert(
|
|
||||||
t, net, net.Alice, net.Bob, channelParam,
|
|
||||||
)
|
|
||||||
txid, err := lnrpc.GetChanPointFundingTxid(chanPoint)
|
|
||||||
require.NoError(t.t, err, "alice bob get channel funding txid")
|
|
||||||
chanPointStr := fmt.Sprintf("%v:%v", txid, chanPoint.OutputIndex)
|
|
||||||
|
|
||||||
// Wait for channel to be confirmed open.
|
|
||||||
err = net.Alice.WaitForNetworkChannelOpen(chanPoint)
|
|
||||||
require.NoError(t.t, err, "alice wait for network channel open")
|
|
||||||
err = net.Bob.WaitForNetworkChannelOpen(chanPoint)
|
|
||||||
require.NoError(t.t, err, "bob wait for network channel open")
|
|
||||||
|
|
||||||
// Now that the channel is open, we'll obtain its channel ID real quick
|
// Now that the channel is open, we'll obtain its channel ID real quick
|
||||||
// so we can use it to query the graph below.
|
// so we can use it to query the graph below.
|
||||||
listReq := &lnrpc.ListChannelsRequest{}
|
chanID := ht.QueryChannelByChanPoint(alice, chanPoint).ChanId
|
||||||
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
|
||||||
aliceChannelList, err := net.Alice.ListChannels(ctxt, listReq)
|
|
||||||
require.NoError(t.t, err)
|
|
||||||
var chanID uint64
|
|
||||||
for _, channel := range aliceChannelList.Channels {
|
|
||||||
if channel.ChannelPoint == chanPointStr {
|
|
||||||
chanID = channel.ChanId
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
require.NotZero(t.t, chanID, "unable to find channel")
|
// To make sure the channel is removed from the backup file as well
|
||||||
|
// when being abandoned, grab a backup snapshot so we can compare it
|
||||||
// To make sure the channel is removed from the backup file as well when
|
// with the later state.
|
||||||
// being abandoned, grab a backup snapshot so we can compare it with the
|
bkupBefore, err := ioutil.ReadFile(alice.Cfg.ChanBackupPath())
|
||||||
// later state.
|
require.NoError(ht, err, "channel backup before abandoning channel")
|
||||||
bkupBefore, err := ioutil.ReadFile(net.Alice.ChanBackupPath())
|
|
||||||
require.NoError(t.t, err, "channel backup before abandoning channel")
|
|
||||||
|
|
||||||
// Send request to abandon channel.
|
// Send request to abandon channel.
|
||||||
abandonChannelRequest := &lnrpc.AbandonChannelRequest{
|
abandonChannelRequest := &lnrpc.AbandonChannelRequest{
|
||||||
ChannelPoint: chanPoint,
|
ChannelPoint: chanPoint,
|
||||||
}
|
}
|
||||||
|
alice.RPC.AbandonChannel(abandonChannelRequest)
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
|
||||||
_, err = net.Alice.AbandonChannel(ctxt, abandonChannelRequest)
|
|
||||||
require.NoError(t.t, err, "abandon channel")
|
|
||||||
|
|
||||||
// Assert that channel in no longer open.
|
// Assert that channel in no longer open.
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
ht.AssertNodeNumChannels(alice, 0)
|
||||||
aliceChannelList, err = net.Alice.ListChannels(ctxt, listReq)
|
|
||||||
require.NoError(t.t, err, "list channels")
|
|
||||||
require.Zero(t.t, len(aliceChannelList.Channels), "alice open channels")
|
|
||||||
|
|
||||||
// Assert that channel is not pending closure.
|
// Assert that channel is not pending closure.
|
||||||
pendingReq := &lnrpc.PendingChannelsRequest{}
|
ht.AssertNumWaitingClose(alice, 0)
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
|
||||||
alicePendingList, err := net.Alice.PendingChannels(ctxt, pendingReq)
|
|
||||||
require.NoError(t.t, err, "alice list pending channels")
|
|
||||||
require.Zero(
|
|
||||||
t.t, len(alicePendingList.PendingClosingChannels), //nolint:staticcheck
|
|
||||||
"alice pending channels",
|
|
||||||
)
|
|
||||||
require.Zero(
|
|
||||||
t.t, len(alicePendingList.PendingForceClosingChannels),
|
|
||||||
"alice pending force close channels",
|
|
||||||
)
|
|
||||||
require.Zero(
|
|
||||||
t.t, len(alicePendingList.WaitingCloseChannels),
|
|
||||||
"alice waiting close channels",
|
|
||||||
)
|
|
||||||
|
|
||||||
// Assert that channel is listed as abandoned.
|
// Assert that channel is listed as abandoned.
|
||||||
closedReq := &lnrpc.ClosedChannelsRequest{
|
req := &lnrpc.ClosedChannelsRequest{Abandoned: true}
|
||||||
Abandoned: true,
|
aliceClosedList := alice.RPC.ClosedChannels(req)
|
||||||
}
|
require.Len(ht, aliceClosedList.Channels, 1, "alice closed channels")
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
|
||||||
aliceClosedList, err := net.Alice.ClosedChannels(ctxt, closedReq)
|
|
||||||
require.NoError(t.t, err, "alice list closed channels")
|
|
||||||
require.Len(t.t, aliceClosedList.Channels, 1, "alice closed channels")
|
|
||||||
|
|
||||||
// Ensure that the channel can no longer be found in the channel graph.
|
// Ensure that the channel can no longer be found in the channel graph.
|
||||||
err = wait.NoError(func() error {
|
ht.AssertZombieChannel(alice, chanID)
|
||||||
_, err := net.Alice.GetChanInfo(ctxb, &lnrpc.ChanInfoRequest{
|
|
||||||
ChanId: chanID,
|
|
||||||
})
|
|
||||||
if err == nil {
|
|
||||||
return fmt.Errorf("expected error but got nil")
|
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.Contains(err.Error(), "marked as zombie") {
|
|
||||||
return fmt.Errorf("expected error to contain '%s' but "+
|
|
||||||
"was '%v'", "marked as zombie", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}, defaultTimeout)
|
|
||||||
require.NoError(t.t, err, "marked as zombie")
|
|
||||||
|
|
||||||
// Make sure the channel is no longer in the channel backup list.
|
// Make sure the channel is no longer in the channel backup list.
|
||||||
err = wait.NoError(func() error {
|
err = wait.NoError(func() error {
|
||||||
bkupAfter, err := ioutil.ReadFile(net.Alice.ChanBackupPath())
|
bkupAfter, err := ioutil.ReadFile(alice.Cfg.ChanBackupPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not get channel backup "+
|
return fmt.Errorf("could not get channel backup "+
|
||||||
"before abandoning channel: %v", err)
|
"before abandoning channel: %v", err)
|
||||||
@ -792,21 +725,16 @@ func testAbandonChannel(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}, defaultTimeout)
|
}, defaultTimeout)
|
||||||
require.NoError(t.t, err, "channel removed from backup file")
|
require.NoError(ht, err, "channel removed from backup file")
|
||||||
|
|
||||||
// Calling AbandonChannel again, should result in no new errors, as the
|
// Calling AbandonChannel again, should result in no new errors, as the
|
||||||
// channel has already been removed.
|
// channel has already been removed.
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
alice.RPC.AbandonChannel(abandonChannelRequest)
|
||||||
_, err = net.Alice.AbandonChannel(ctxt, abandonChannelRequest)
|
|
||||||
require.NoError(t.t, err, "abandon channel second time")
|
|
||||||
|
|
||||||
// Now that we're done with the test, the channel can be closed. This
|
// Now that we're done with the test, the channel can be closed. This
|
||||||
// is necessary to avoid unexpected outcomes of other tests that use
|
// is necessary to avoid unexpected outcomes of other tests that use
|
||||||
// Bob's lnd instance.
|
// Bob's lnd instance.
|
||||||
closeChannelAndAssert(t, net, net.Bob, chanPoint, true)
|
ht.ForceCloseChannel(bob, chanPoint)
|
||||||
|
|
||||||
// Cleanup by mining the force close and sweep transaction.
|
|
||||||
cleanupForceClose(t, net, net.Bob, chanPoint)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// testSweepAllCoins tests that we're able to properly sweep all coins from the
|
// testSweepAllCoins tests that we're able to properly sweep all coins from the
|
||||||
|
@ -167,10 +167,6 @@ var allTestCases = []*testCase{
|
|||||||
name: "failing link",
|
name: "failing link",
|
||||||
test: testFailingChannel,
|
test: testFailingChannel,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "abandonchannel",
|
|
||||||
test: testAbandonChannel,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "revoked uncooperative close retribution zero value remote output",
|
name: "revoked uncooperative close retribution zero value remote output",
|
||||||
test: testRevokedCloseRetributionZeroValueRemoteOutput,
|
test: testRevokedCloseRetributionZeroValueRemoteOutput,
|
||||||
|
Loading…
Reference in New Issue
Block a user