|
|
|
@@ -4,7 +4,6 @@ import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/btcsuite/btcd/btcutil"
|
|
|
|
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
|
|
|
@@ -14,6 +13,7 @@ import (
|
|
|
|
|
"github.com/lightningnetwork/lnd/lnrpc/chainrpc"
|
|
|
|
|
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
|
|
|
|
|
"github.com/lightningnetwork/lnd/lntemp"
|
|
|
|
|
"github.com/lightningnetwork/lnd/lntemp/node"
|
|
|
|
|
"github.com/lightningnetwork/lnd/lntest"
|
|
|
|
|
"github.com/lightningnetwork/lnd/lntest/wait"
|
|
|
|
|
"github.com/lightningnetwork/lnd/lnwallet"
|
|
|
|
@@ -396,11 +396,191 @@ func testAnchorReservedValue(ht *lntemp.HarnessTest) {
|
|
|
|
|
assertNumTxInAndTxOut(sweepTx, 4, 1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// testAnchorThirdPartySpend tests that if we force close a channel, but then
|
|
|
|
|
// don't sweep the anchor in time and a 3rd party spends it, that we remove any
|
|
|
|
|
// transactions that are a descendent of that sweep.
|
|
|
|
|
func testAnchorThirdPartySpend(ht *lntemp.HarnessTest) {
|
|
|
|
|
// First, we'll create two new nodes that both default to anchor
|
|
|
|
|
// channels.
|
|
|
|
|
//
|
|
|
|
|
// NOTE: The itests differ here as anchors is default off vs the normal
|
|
|
|
|
// lnd binary.
|
|
|
|
|
args := nodeArgsForCommitType(lnrpc.CommitmentType_ANCHORS)
|
|
|
|
|
alice := ht.NewNode("Alice", args)
|
|
|
|
|
defer ht.Shutdown(alice)
|
|
|
|
|
|
|
|
|
|
bob := ht.NewNode("Bob", args)
|
|
|
|
|
defer ht.Shutdown(bob)
|
|
|
|
|
|
|
|
|
|
ht.EnsureConnected(alice, bob)
|
|
|
|
|
|
|
|
|
|
// We'll fund our Alice with coins, as she'll be opening the channel.
|
|
|
|
|
// We'll fund her with *just* enough coins to open the channel and
|
|
|
|
|
// sweep the anchor.
|
|
|
|
|
const (
|
|
|
|
|
firstChanSize = 1_000_000
|
|
|
|
|
anchorFeeBuffer = 500_000
|
|
|
|
|
)
|
|
|
|
|
ht.FundCoins(firstChanSize+anchorFeeBuffer, alice)
|
|
|
|
|
|
|
|
|
|
// Open the channel between the two nodes and wait for it to confirm
|
|
|
|
|
// fully.
|
|
|
|
|
aliceChanPoint1 := ht.OpenChannel(
|
|
|
|
|
alice, bob, lntemp.OpenChannelParams{
|
|
|
|
|
Amt: firstChanSize,
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Send another UTXO if this is a neutrino backend. When sweeping
|
|
|
|
|
// anchors, there are two transactions created, `local_sweep_tx` for
|
|
|
|
|
// sweeping Alice's anchor on the local commitment, `remote_sweep_tx`
|
|
|
|
|
// for sweeping her anchor on the remote commitment. Whenever the force
|
|
|
|
|
// close transaction is published, Alice will always create these two
|
|
|
|
|
// transactions to sweep her anchor.
|
|
|
|
|
// On the other hand, when creating the sweep txes, the anchor itself
|
|
|
|
|
// is not able to cover the fee, so another wallet UTXO is needed. In
|
|
|
|
|
// our test case, there's a change output that can be used from the
|
|
|
|
|
// above funding process. And it's used by both sweep txes - when `lnd`
|
|
|
|
|
// happens to create the `remote_sweep_tx` first, it will receive an
|
|
|
|
|
// error since its parent tx, the remote commitment, is not known,
|
|
|
|
|
// hence freeing the change output to be used by `local_sweep_tx`.
|
|
|
|
|
// For neutrino client, however, it will consider the transaction which
|
|
|
|
|
// sweeps the remote anchor as an orphan tx, and it will neither send
|
|
|
|
|
// it to the mempool nor return an error to free the change output.
|
|
|
|
|
// Thus, if the change output is already used in `remote_sweep_tx`, we
|
|
|
|
|
// won't have UTXO to create `local_sweep_tx`.
|
|
|
|
|
//
|
|
|
|
|
// NOTE: the order of the sweep requests for the two anchors cannot be
|
|
|
|
|
// guaranteed. If the sweeper happens to sweep the remote anchor first,
|
|
|
|
|
// then the test won't pass without the extra UTXO, which is the source
|
|
|
|
|
// of the flakeness.
|
|
|
|
|
//
|
|
|
|
|
// TODO(yy): make a RPC server for sweeper so we can explicitly check
|
|
|
|
|
// and control its state.
|
|
|
|
|
if ht.IsNeutrinoBackend() {
|
|
|
|
|
ht.FundCoins(anchorFeeBuffer, alice)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// With the channel open, we'll actually immediately force close it. We
|
|
|
|
|
// don't care about network announcements here since there's no routing
|
|
|
|
|
// in this test.
|
|
|
|
|
ht.CloseChannelAssertPending(alice, aliceChanPoint1, true)
|
|
|
|
|
|
|
|
|
|
// Now that the channel has been force closed, it should show up in the
|
|
|
|
|
// PendingChannels RPC under the waiting close section.
|
|
|
|
|
waitingClose := ht.AssertChannelWaitingClose(alice, aliceChanPoint1)
|
|
|
|
|
|
|
|
|
|
// At this point, the channel is waiting close, and we have both the
|
|
|
|
|
// commitment transaction and anchor sweep in the mempool.
|
|
|
|
|
const expectedTxns = 2
|
|
|
|
|
sweepTxns := ht.Miner.GetNumTxsFromMempool(expectedTxns)
|
|
|
|
|
aliceCloseTx := waitingClose.Commitments.LocalTxid
|
|
|
|
|
_, aliceAnchor := ht.FindCommitAndAnchor(sweepTxns, aliceCloseTx)
|
|
|
|
|
|
|
|
|
|
// We'll now mine _only_ the commitment force close transaction, as we
|
|
|
|
|
// want the anchor sweep to stay unconfirmed.
|
|
|
|
|
forceCloseTxID, _ := chainhash.NewHashFromStr(aliceCloseTx)
|
|
|
|
|
commitTxn := ht.Miner.GetRawTransaction(forceCloseTxID)
|
|
|
|
|
ht.Miner.MineBlockWithTxes([]*btcutil.Tx{commitTxn})
|
|
|
|
|
|
|
|
|
|
// With the anchor output located, and the main commitment mined we'll
|
|
|
|
|
// instruct the wallet to send all coins in the wallet to a new address
|
|
|
|
|
// (to the miner), including unconfirmed change.
|
|
|
|
|
minerAddr := ht.Miner.NewMinerAddress()
|
|
|
|
|
sweepReq := &lnrpc.SendCoinsRequest{
|
|
|
|
|
Addr: minerAddr.String(),
|
|
|
|
|
SendAll: true,
|
|
|
|
|
MinConfs: 0,
|
|
|
|
|
SpendUnconfirmed: true,
|
|
|
|
|
}
|
|
|
|
|
sweepAllResp := alice.RPC.SendCoins(sweepReq)
|
|
|
|
|
|
|
|
|
|
// Both the original anchor sweep transaction, as well as the
|
|
|
|
|
// transaction we created to sweep all the coins from Alice's wallet
|
|
|
|
|
// should be found in her transaction store.
|
|
|
|
|
sweepAllTxID, _ := chainhash.NewHashFromStr(sweepAllResp.Txid)
|
|
|
|
|
ht.AssertTransactionInWallet(alice, aliceAnchor.SweepTx.TxHash())
|
|
|
|
|
ht.AssertTransactionInWallet(alice, *sweepAllTxID)
|
|
|
|
|
|
|
|
|
|
// Next, we'll shutdown Alice, and allow 16 blocks to pass so that the
|
|
|
|
|
// anchor output can be swept by anyone. Rather than use the normal API
|
|
|
|
|
// call, we'll generate a series of _empty_ blocks here.
|
|
|
|
|
aliceRestart := ht.SuspendNode(alice)
|
|
|
|
|
const anchorCsv = 16
|
|
|
|
|
ht.MineEmptyBlocks(anchorCsv)
|
|
|
|
|
|
|
|
|
|
// Before we sweep the anchor, we'll restart Alice.
|
|
|
|
|
require.NoErrorf(ht, aliceRestart(), "unable to restart alice")
|
|
|
|
|
|
|
|
|
|
// Now that the channel has been closed, and Alice has an unconfirmed
|
|
|
|
|
// transaction spending the output produced by her anchor sweep, we'll
|
|
|
|
|
// mine a transaction that double spends the output.
|
|
|
|
|
thirdPartyAnchorSweep := genAnchorSweep(ht, aliceAnchor, anchorCsv)
|
|
|
|
|
ht.Miner.MineBlockWithTxes([]*btcutil.Tx{thirdPartyAnchorSweep})
|
|
|
|
|
|
|
|
|
|
// At this point, we should no longer find Alice's transaction that
|
|
|
|
|
// tried to sweep the anchor in her wallet.
|
|
|
|
|
ht.AssertTransactionNotInWallet(alice, aliceAnchor.SweepTx.TxHash())
|
|
|
|
|
|
|
|
|
|
// In addition, the transaction she sent to sweep all her coins to the
|
|
|
|
|
// miner also should no longer be found.
|
|
|
|
|
ht.AssertTransactionNotInWallet(alice, *sweepAllTxID)
|
|
|
|
|
|
|
|
|
|
// The anchor should now show as being "lost", while the force close
|
|
|
|
|
// response is still present.
|
|
|
|
|
assertAnchorOutputLost(ht, alice, aliceChanPoint1)
|
|
|
|
|
|
|
|
|
|
// At this point Alice's CSV output should already be fully spent and
|
|
|
|
|
// the channel marked as being resolved. We mine a block first, as so
|
|
|
|
|
// far we've been generating custom blocks this whole time.
|
|
|
|
|
commitSweepOp := wire.OutPoint{
|
|
|
|
|
Hash: *forceCloseTxID,
|
|
|
|
|
Index: 1,
|
|
|
|
|
}
|
|
|
|
|
ht.Miner.AssertOutpointInMempool(commitSweepOp)
|
|
|
|
|
ht.MineBlocks(1)
|
|
|
|
|
|
|
|
|
|
ht.AssertNumWaitingClose(alice, 0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// assertAnchorOutputLost asserts that the anchor output for the given channel
|
|
|
|
|
// has the state of being lost.
|
|
|
|
|
func assertAnchorOutputLost(ht *lntemp.HarnessTest, hn *node.HarnessNode,
|
|
|
|
|
chanPoint *lnrpc.ChannelPoint) {
|
|
|
|
|
|
|
|
|
|
cp := ht.OutPointFromChannelPoint(chanPoint)
|
|
|
|
|
|
|
|
|
|
expected := lnrpc.PendingChannelsResponse_ForceClosedChannel_LOST
|
|
|
|
|
|
|
|
|
|
err := wait.NoError(func() error {
|
|
|
|
|
resp := hn.RPC.PendingChannels()
|
|
|
|
|
channels := resp.PendingForceClosingChannels
|
|
|
|
|
|
|
|
|
|
for _, c := range channels {
|
|
|
|
|
// Not the wanted channel, skipped.
|
|
|
|
|
if c.Channel.ChannelPoint != cp.String() {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Found the channel, check the anchor state.
|
|
|
|
|
if c.Anchor == expected {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fmt.Errorf("unexpected anchor state, want %v, "+
|
|
|
|
|
"got %v", expected, c.Anchor)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fmt.Errorf("channel not found using cp=%v", cp)
|
|
|
|
|
}, defaultTimeout)
|
|
|
|
|
require.NoError(ht, err, "anchor doesn't show as being lost")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// genAnchorSweep generates a "3rd party" anchor sweeping from an existing one.
|
|
|
|
|
// In practice, we just re-use the existing witness, and track on our own
|
|
|
|
|
// output producing a 1-in-1-out transaction.
|
|
|
|
|
func genAnchorSweep(t *harnessTest, net *lntest.NetworkHarness,
|
|
|
|
|
aliceAnchor *sweptOutput, anchorCsv uint32) *btcutil.Tx {
|
|
|
|
|
func genAnchorSweep(ht *lntemp.HarnessTest,
|
|
|
|
|
aliceAnchor *lntemp.SweptOutput, anchorCsv uint32) *btcutil.Tx {
|
|
|
|
|
|
|
|
|
|
// At this point, we have the transaction that Alice used to try to
|
|
|
|
|
// sweep her anchor. As this is actually just something anyone can
|
|
|
|
@@ -414,7 +594,8 @@ func genAnchorSweep(t *harnessTest, net *lntest.NetworkHarness,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
t.Fatalf("anchor op not found")
|
|
|
|
|
require.FailNow(ht, "anchor op not found")
|
|
|
|
|
|
|
|
|
|
return wire.TxIn{}
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
@@ -423,14 +604,9 @@ func genAnchorSweep(t *harnessTest, net *lntest.NetworkHarness,
|
|
|
|
|
aliceAnchorTxIn.Witness[0] = nil
|
|
|
|
|
aliceAnchorTxIn.Sequence = anchorCsv
|
|
|
|
|
|
|
|
|
|
minerAddr, err := net.Miner.NewAddress()
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("unable to get miner addr: %v", err)
|
|
|
|
|
}
|
|
|
|
|
minerAddr := ht.Miner.NewMinerAddress()
|
|
|
|
|
addrScript, err := txscript.PayToAddrScript(minerAddr)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("unable to gen addr script: %v", err)
|
|
|
|
|
}
|
|
|
|
|
require.NoError(ht, err, "unable to gen addr script")
|
|
|
|
|
|
|
|
|
|
// Now that we have the txIn, we can just make a new transaction that
|
|
|
|
|
// uses a different script for the output.
|
|
|
|
@@ -443,191 +619,3 @@ func genAnchorSweep(t *harnessTest, net *lntest.NetworkHarness,
|
|
|
|
|
|
|
|
|
|
return btcutil.NewTx(tx)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// testAnchorThirdPartySpend tests that if we force close a channel, but then
|
|
|
|
|
// don't sweep the anchor in time and a 3rd party spends it, that we remove any
|
|
|
|
|
// transactions that are a descendent of that sweep.
|
|
|
|
|
func testAnchorThirdPartySpend(net *lntest.NetworkHarness, t *harnessTest) {
|
|
|
|
|
// First, we'll create two new nodes that both default to anchor
|
|
|
|
|
// channels.
|
|
|
|
|
//
|
|
|
|
|
// NOTE: The itests differ here as anchors is default off vs the normal
|
|
|
|
|
// lnd binary.
|
|
|
|
|
args := nodeArgsForCommitType(lnrpc.CommitmentType_ANCHORS)
|
|
|
|
|
alice := net.NewNode(t.t, "Alice", args)
|
|
|
|
|
defer shutdownAndAssert(net, t, alice)
|
|
|
|
|
|
|
|
|
|
bob := net.NewNode(t.t, "Bob", args)
|
|
|
|
|
defer shutdownAndAssert(net, t, bob)
|
|
|
|
|
|
|
|
|
|
ctxb := context.Background()
|
|
|
|
|
net.ConnectNodes(t.t, alice, bob)
|
|
|
|
|
|
|
|
|
|
// We'll fund our Alice with coins, as she'll be opening the channel.
|
|
|
|
|
// We'll fund her with *just* enough coins to open the channel.
|
|
|
|
|
const (
|
|
|
|
|
firstChanSize = 1_000_000
|
|
|
|
|
anchorFeeBuffer = 500_000
|
|
|
|
|
)
|
|
|
|
|
net.SendCoins(t.t, firstChanSize, alice)
|
|
|
|
|
|
|
|
|
|
// We'll give Alice another spare UTXO as well so she can use it to
|
|
|
|
|
// help sweep all coins.
|
|
|
|
|
net.SendCoins(t.t, anchorFeeBuffer, alice)
|
|
|
|
|
|
|
|
|
|
// Open the channel between the two nodes and wait for it to confirm
|
|
|
|
|
// fully.
|
|
|
|
|
aliceChanPoint1 := openChannelAndAssert(
|
|
|
|
|
t, net, alice, bob, lntest.OpenChannelParams{
|
|
|
|
|
Amt: firstChanSize,
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// With the channel open, we'll actually immediately force close it. We
|
|
|
|
|
// don't care about network announcements here since there's no routing
|
|
|
|
|
// in this test.
|
|
|
|
|
_, _, err := net.CloseChannel(alice, aliceChanPoint1, true)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("unable to execute force channel closure: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Now that the channel has been force closed, it should show up in the
|
|
|
|
|
// PendingChannels RPC under the waiting close section.
|
|
|
|
|
pendingChansRequest := &lnrpc.PendingChannelsRequest{}
|
|
|
|
|
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
|
|
|
|
pendingChanResp, err := alice.PendingChannels(ctxt, pendingChansRequest)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("unable to query for pending channels: %v", err)
|
|
|
|
|
}
|
|
|
|
|
err = checkNumWaitingCloseChannels(pendingChanResp, 1)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf(err.Error())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get the normal channel outpoint so we can track it in the set of
|
|
|
|
|
// channels that are waiting to be closed.
|
|
|
|
|
fundingTxID, err := lnrpc.GetChanPointFundingTxid(aliceChanPoint1)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("unable to get txid: %v", err)
|
|
|
|
|
}
|
|
|
|
|
chanPoint := wire.OutPoint{
|
|
|
|
|
Hash: *fundingTxID,
|
|
|
|
|
Index: aliceChanPoint1.OutputIndex,
|
|
|
|
|
}
|
|
|
|
|
waitingClose, err := findWaitingCloseChannel(pendingChanResp, &chanPoint)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf(err.Error())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// At this point, the channel is waiting close, and we have both the
|
|
|
|
|
// commitment transaction and anchor sweep in the mempool.
|
|
|
|
|
const expectedTxns = 2
|
|
|
|
|
sweepTxns, err := getNTxsFromMempool(
|
|
|
|
|
net.Miner.Client, expectedTxns, minerMempoolTimeout,
|
|
|
|
|
)
|
|
|
|
|
require.NoError(t.t, err, "no sweep txns in miner mempool")
|
|
|
|
|
aliceCloseTx := waitingClose.Commitments.LocalTxid
|
|
|
|
|
_, aliceAnchor := findCommitAndAnchor(t, net, sweepTxns, aliceCloseTx)
|
|
|
|
|
|
|
|
|
|
// We'll now mine _only_ the commitment force close transaction, as we
|
|
|
|
|
// want the anchor sweep to stay unconfirmed.
|
|
|
|
|
var emptyTime time.Time
|
|
|
|
|
forceCloseTxID, _ := chainhash.NewHashFromStr(aliceCloseTx)
|
|
|
|
|
commitTxn, err := net.Miner.Client.GetRawTransaction(
|
|
|
|
|
forceCloseTxID,
|
|
|
|
|
)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("unable to get transaction: %v", err)
|
|
|
|
|
}
|
|
|
|
|
_, err = net.Miner.GenerateAndSubmitBlock(
|
|
|
|
|
[]*btcutil.Tx{commitTxn}, -1, emptyTime,
|
|
|
|
|
)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("unable to generate block: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// With the anchor output located, and the main commitment mined we'll
|
|
|
|
|
// instruct the wallet to send all coins in the wallet to a new address
|
|
|
|
|
// (to the miner), including unconfirmed change.
|
|
|
|
|
minerAddr, err := net.Miner.NewAddress()
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("unable to create new miner addr: %v", err)
|
|
|
|
|
}
|
|
|
|
|
sweepReq := &lnrpc.SendCoinsRequest{
|
|
|
|
|
Addr: minerAddr.String(),
|
|
|
|
|
SendAll: true,
|
|
|
|
|
MinConfs: 0,
|
|
|
|
|
SpendUnconfirmed: true,
|
|
|
|
|
}
|
|
|
|
|
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
|
|
|
|
sweepAllResp, err := alice.SendCoins(ctxt, sweepReq)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("unable to sweep coins: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Both the original anchor sweep transaction, as well as the
|
|
|
|
|
// transaction we created to sweep all the coins from Alice's wallet
|
|
|
|
|
// should be found in her transaction store.
|
|
|
|
|
sweepAllTxID, _ := chainhash.NewHashFromStr(sweepAllResp.Txid)
|
|
|
|
|
assertTransactionInWallet(t.t, alice, aliceAnchor.SweepTx.TxHash())
|
|
|
|
|
assertTransactionInWallet(t.t, alice, *sweepAllTxID)
|
|
|
|
|
|
|
|
|
|
// Next, we'll shutdown Alice, and allow 16 blocks to pass so that the
|
|
|
|
|
// anchor output can be swept by anyone. Rather than use the normal API
|
|
|
|
|
// call, we'll generate a series of _empty_ blocks here.
|
|
|
|
|
aliceRestart, err := net.SuspendNode(alice)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("unable to shutdown alice: %v", err)
|
|
|
|
|
}
|
|
|
|
|
const anchorCsv = 16
|
|
|
|
|
for i := 0; i < anchorCsv; i++ {
|
|
|
|
|
_, err := net.Miner.GenerateAndSubmitBlock(nil, -1, emptyTime)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("unable to generate block: %v", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Before we sweep the anchor, we'll restart Alice.
|
|
|
|
|
if err := aliceRestart(); err != nil {
|
|
|
|
|
t.Fatalf("unable to restart alice: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Now that the channel has been closed, and Alice has an unconfirmed
|
|
|
|
|
// transaction spending the output produced by her anchor sweep, we'll
|
|
|
|
|
// mine a transaction that double spends the output.
|
|
|
|
|
thirdPartyAnchorSweep := genAnchorSweep(t, net, aliceAnchor, anchorCsv)
|
|
|
|
|
_, err = net.Miner.GenerateAndSubmitBlock(
|
|
|
|
|
[]*btcutil.Tx{thirdPartyAnchorSweep}, -1, emptyTime,
|
|
|
|
|
)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("unable to generate block: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// At this point, we should no longer find Alice's transaction that
|
|
|
|
|
// tried to sweep the anchor in her wallet.
|
|
|
|
|
assertTransactionNotInWallet(t.t, alice, aliceAnchor.SweepTx.TxHash())
|
|
|
|
|
|
|
|
|
|
// In addition, the transaction she sent to sweep all her coins to the
|
|
|
|
|
// miner also should no longer be found.
|
|
|
|
|
assertTransactionNotInWallet(t.t, alice, *sweepAllTxID)
|
|
|
|
|
|
|
|
|
|
// The anchor should now show as being "lost", while the force close
|
|
|
|
|
// response is still present.
|
|
|
|
|
assertAnchorOutputLost(t, alice, chanPoint)
|
|
|
|
|
|
|
|
|
|
// At this point Alice's CSV output should already be fully spent and
|
|
|
|
|
// the channel marked as being resolved. We mine a block first, as so
|
|
|
|
|
// far we've been generating custom blocks this whole time..
|
|
|
|
|
commitSweepOp := wire.OutPoint{
|
|
|
|
|
Hash: *forceCloseTxID,
|
|
|
|
|
Index: 1,
|
|
|
|
|
}
|
|
|
|
|
assertSpendingTxInMempool(
|
|
|
|
|
t, net.Miner.Client, minerMempoolTimeout, commitSweepOp,
|
|
|
|
|
)
|
|
|
|
|
_, err = net.Miner.Client.Generate(1)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("unable to generate block: %v", err)
|
|
|
|
|
}
|
|
|
|
|
assertNumPendingChannels(t, alice, 0, 0)
|
|
|
|
|
}
|