itest: extend testAnchorReservedValue to open additional channels

We do this to trigger a bug that will be resolved in a follow-up commit.
This bug prevents inbound legacy channels from being rejected by the
recipient if they have at least one anchor channel already opened
without an on-chain balance.
This commit is contained in:
Wilmer Paulino 2021-06-23 18:03:34 -07:00
parent 1287328678
commit d7299802d4
No known key found for this signature in database
GPG Key ID: 6DF57B9F9514972F

View File

@ -180,7 +180,8 @@ func testAnchorReservedValue(net *lntest.NetworkHarness, t *harnessTest) {
err := net.ConnectNodes(ctxt, alice, bob)
require.NoError(t.t, err)
// Send just enough coins for Alice to open a channel without a change output.
// Send just enough coins for Alice to open a channel without a change
// output.
const (
chanAmt = 1000000
feeEst = 8000
@ -206,20 +207,45 @@ func testAnchorReservedValue(net *lntest.NetworkHarness, t *harnessTest) {
// Alice opens a smaller channel. This works since it will have a
// change output.
ctxt, _ = context.WithTimeout(context.Background(), defaultTimeout)
aliceChanPoint := openChannelAndAssert(
aliceChanPoint1 := openChannelAndAssert(
ctxt, t, net, alice, bob,
lntest.OpenChannelParams{
Amt: chanAmt / 2,
Amt: chanAmt / 4,
},
)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = alice.WaitForNetworkChannelOpen(ctxt, aliceChanPoint)
require.NoError(t.t, err)
// If Alice tries to open another anchor channel to Bob, Bob should not
// reject it as he is not contributing any funds.
aliceChanPoint2 := openChannelAndAssert(
ctxt, t, net, alice, bob, lntest.OpenChannelParams{
Amt: chanAmt / 4,
},
)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = bob.WaitForNetworkChannelOpen(ctxt, aliceChanPoint)
// Similarly, if Alice tries to open a legacy channel to Bob, Bob should
// not reject it as he is not contributing any funds. We'll restart Bob
// to remove his support for anchors.
err = net.RestartNode(bob, nil)
require.NoError(t.t, err)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
aliceChanPoint3 := openChannelAndAssert(
ctxt, t, net, alice, bob, lntest.OpenChannelParams{
Amt: chanAmt / 4,
},
)
chanPoints := []*lnrpc.ChannelPoint{
aliceChanPoint1, aliceChanPoint2, aliceChanPoint3,
}
for _, chanPoint := range chanPoints {
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = alice.WaitForNetworkChannelOpen(ctxt, chanPoint)
require.NoError(t.t, err)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = bob.WaitForNetworkChannelOpen(ctxt, chanPoint)
require.NoError(t.t, err)
}
// Alice tries to send all coins to an internal address. This is
// allowed, since the final wallet balance will still be above the
@ -317,7 +343,9 @@ func testAnchorReservedValue(net *lntest.NetworkHarness, t *harnessTest) {
// Alice closes channel, should now be allowed to send everything to an
// external address.
closeChannelAndAssert(ctxt, t, net, alice, aliceChanPoint, false)
for _, chanPoint := range chanPoints {
closeChannelAndAssert(ctxt, t, net, alice, chanPoint, false)
}
newBalance := waitForConfirmedBalance()
if newBalance <= aliceBalance {
@ -339,11 +367,11 @@ func testAnchorReservedValue(net *lntest.NetworkHarness, t *harnessTest) {
// generated above.
block = mineBlocks(t, net, 1, 1)[0]
// The sweep transaction should have two inputs, the change output from
// the previous sweep, and the output from the coop closed channel.
// The sweep transaction should have four inputs, the change output from
// the previous sweep, and the outputs from the coop closed channels.
sweepTx = block.Transactions[1]
if len(sweepTx.TxIn) != 2 {
t.Fatalf("expected 2 inputs instead have %v", len(sweepTx.TxIn))
if len(sweepTx.TxIn) != 4 {
t.Fatalf("expected 4 inputs instead have %v", len(sweepTx.TxIn))
}
// It should have a single output.