Merge pull request #5428 from wpaulino/enforce-anchor-reserve

lnwallet: prevent anchor reserve enforcement on legacy inbound channel
This commit is contained in:
Olaoluwa Osuntokun authored and GitHub committed 2021-06-28 16:08:43 -07:00
commit 44e461b233
2 files changed
+88 -69

No files matched your search

+41 -13
View File
@@ -179,7 +179,8 @@ func testAnchorReservedValue(net *lntest.NetworkHarness, t *harnessTest) {
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
net.ConnectNodes(ctxt, t.t, alice, bob)
// 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
@@ -205,20 +206,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
@@ -316,7 +342,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 {
@@ -338,11 +366,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.