mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-19 13:20:55 +02:00
lntest+itest: finalize moving miner methods
This commit is contained in:
parent
6bd8baea38
commit
be4dba5da6
@ -393,7 +393,7 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
|
|||||||
|
|
||||||
// Fetch the sweep transaction, all input it's spending should be from
|
// Fetch the sweep transaction, all input it's spending should be from
|
||||||
// the commitment transaction which was broadcast on-chain.
|
// the commitment transaction which was broadcast on-chain.
|
||||||
sweepTx := ht.Miner.GetRawTransaction(sweepingTXID)
|
sweepTx := ht.GetRawTransaction(sweepingTXID)
|
||||||
for _, txIn := range sweepTx.MsgTx().TxIn {
|
for _, txIn := range sweepTx.MsgTx().TxIn {
|
||||||
require.Equal(ht, &txIn.PreviousOutPoint.Hash, closingTxID,
|
require.Equal(ht, &txIn.PreviousOutPoint.Hash, closingTxID,
|
||||||
"sweep transaction not spending from commit")
|
"sweep transaction not spending from commit")
|
||||||
@ -567,7 +567,7 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
|
|||||||
// on-chain. In case of an anchor type channel, we expect one
|
// on-chain. In case of an anchor type channel, we expect one
|
||||||
// extra input that is not spending from the commitment, that
|
// extra input that is not spending from the commitment, that
|
||||||
// is added for fees.
|
// is added for fees.
|
||||||
htlcTx := ht.Miner.GetRawTransaction(htlcTxID)
|
htlcTx := ht.GetRawTransaction(htlcTxID)
|
||||||
|
|
||||||
// Ensure the htlc transaction has the expected number of
|
// Ensure the htlc transaction has the expected number of
|
||||||
// inputs.
|
// inputs.
|
||||||
@ -736,7 +736,7 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
|
|||||||
htlcSweepTxID := ht.AssertNumTxsInMempool(1)[0]
|
htlcSweepTxID := ht.AssertNumTxsInMempool(1)[0]
|
||||||
|
|
||||||
// Fetch the htlc sweep transaction from the mempool.
|
// Fetch the htlc sweep transaction from the mempool.
|
||||||
htlcSweepTx := ht.Miner.GetRawTransaction(htlcSweepTxID)
|
htlcSweepTx := ht.GetRawTransaction(htlcSweepTxID)
|
||||||
|
|
||||||
// Ensure the htlc sweep transaction only has one input for each htlc
|
// Ensure the htlc sweep transaction only has one input for each htlc
|
||||||
// Alice extended before force closing.
|
// Alice extended before force closing.
|
||||||
|
@ -15,7 +15,6 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type chanFundMaxTestCase struct {
|
type chanFundMaxTestCase struct {
|
||||||
@ -317,8 +316,7 @@ func fundingFee(numInput int, change bool) btcutil.Amount {
|
|||||||
// sweepNodeWalletAndAssert sweeps funds from a node wallet.
|
// sweepNodeWalletAndAssert sweeps funds from a node wallet.
|
||||||
func sweepNodeWalletAndAssert(ht *lntest.HarnessTest, node *node.HarnessNode) {
|
func sweepNodeWalletAndAssert(ht *lntest.HarnessTest, node *node.HarnessNode) {
|
||||||
// New miner address we will sweep all funds to.
|
// New miner address we will sweep all funds to.
|
||||||
minerAddr, err := ht.Miner.NewAddress()
|
minerAddr := ht.NewMinerAddress()
|
||||||
require.NoError(ht, err)
|
|
||||||
|
|
||||||
// Send all funds back to the miner node.
|
// Send all funds back to the miner node.
|
||||||
node.RPC.SendCoins(&lnrpc.SendCoinsRequest{
|
node.RPC.SendCoins(&lnrpc.SendCoinsRequest{
|
||||||
|
@ -1053,7 +1053,7 @@ func testBatchChanFunding(ht *lntest.HarnessTest) {
|
|||||||
ht.AssertTopologyChannelOpen(alice, chanPoint3)
|
ht.AssertTopologyChannelOpen(alice, chanPoint3)
|
||||||
|
|
||||||
// Check if the change type from the batch_open_channel funding is P2TR.
|
// Check if the change type from the batch_open_channel funding is P2TR.
|
||||||
rawTx := ht.Miner.GetRawTransaction(txHash)
|
rawTx := ht.GetRawTransaction(txHash)
|
||||||
require.Len(ht, rawTx.MsgTx().TxOut, 5)
|
require.Len(ht, rawTx.MsgTx().TxOut, 5)
|
||||||
|
|
||||||
// For calculating the change output index we use the formula for the
|
// For calculating the change output index we use the formula for the
|
||||||
@ -1182,9 +1182,9 @@ func deriveFundingShim(ht *lntest.HarnessTest, carol, dave *node.HarnessNode,
|
|||||||
var txid *chainhash.Hash
|
var txid *chainhash.Hash
|
||||||
targetOutputs := []*wire.TxOut{fundingOutput}
|
targetOutputs := []*wire.TxOut{fundingOutput}
|
||||||
if publish {
|
if publish {
|
||||||
txid = ht.Miner.SendOutputsWithoutChange(targetOutputs, 5)
|
txid = ht.SendOutputsWithoutChange(targetOutputs, 5)
|
||||||
} else {
|
} else {
|
||||||
tx := ht.Miner.CreateTransaction(targetOutputs, 5)
|
tx := ht.CreateTransaction(targetOutputs, 5)
|
||||||
|
|
||||||
txHash := tx.TxHash()
|
txHash := tx.TxHash()
|
||||||
txid = &txHash
|
txid = &txHash
|
||||||
|
@ -823,14 +823,14 @@ func testSweepAllCoins(ht *lntest.HarnessTest) {
|
|||||||
// Send coins to a compatible address without specifying fee rate or
|
// Send coins to a compatible address without specifying fee rate or
|
||||||
// conf target.
|
// conf target.
|
||||||
// ainz.RPC.SendCoinsAssertErr(&lnrpc.SendCoinsRequest{
|
// ainz.RPC.SendCoinsAssertErr(&lnrpc.SendCoinsRequest{
|
||||||
// Addr: ht.Miner.NewMinerAddress().String(),
|
// Addr: ht.NewMinerAddress().String(),
|
||||||
// SendAll: true,
|
// SendAll: true,
|
||||||
// Label: sendCoinsLabel,
|
// Label: sendCoinsLabel,
|
||||||
// })
|
// })
|
||||||
|
|
||||||
// Send coins to a compatible address.
|
// Send coins to a compatible address.
|
||||||
ainz.RPC.SendCoins(&lnrpc.SendCoinsRequest{
|
ainz.RPC.SendCoins(&lnrpc.SendCoinsRequest{
|
||||||
Addr: ht.Miner.NewMinerAddress().String(),
|
Addr: ht.NewMinerAddress().String(),
|
||||||
SendAll: true,
|
SendAll: true,
|
||||||
Label: sendCoinsLabel,
|
Label: sendCoinsLabel,
|
||||||
TargetConf: 6,
|
TargetConf: 6,
|
||||||
@ -930,7 +930,7 @@ func testSweepAllCoins(ht *lntest.HarnessTest) {
|
|||||||
// If we try again, but this time specifying an amount, then the call
|
// If we try again, but this time specifying an amount, then the call
|
||||||
// should fail.
|
// should fail.
|
||||||
ainz.RPC.SendCoinsAssertErr(&lnrpc.SendCoinsRequest{
|
ainz.RPC.SendCoinsAssertErr(&lnrpc.SendCoinsRequest{
|
||||||
Addr: ht.Miner.NewMinerAddress().String(),
|
Addr: ht.NewMinerAddress().String(),
|
||||||
Amount: 10000,
|
Amount: 10000,
|
||||||
SendAll: true,
|
SendAll: true,
|
||||||
Label: sendCoinsLabel,
|
Label: sendCoinsLabel,
|
||||||
|
@ -339,7 +339,7 @@ func runMultiHopHtlcLocalTimeout(ht *lntest.HarnessTest,
|
|||||||
// TODO(yy): remove this once `blockbeat` is in place.
|
// TODO(yy): remove this once `blockbeat` is in place.
|
||||||
numExpected := 1
|
numExpected := 1
|
||||||
err := wait.NoError(func() error {
|
err := wait.NoError(func() error {
|
||||||
mem := ht.Miner.GetRawMempool()
|
mem := ht.GetRawMempool()
|
||||||
if len(mem) == 2 {
|
if len(mem) == 2 {
|
||||||
numExpected = 2
|
numExpected = 2
|
||||||
return nil
|
return nil
|
||||||
@ -2120,7 +2120,7 @@ func runMultiHopHtlcAggregation(ht *lntest.HarnessTest,
|
|||||||
// TODO(yy): remove this once `blockbeat` is in place.
|
// TODO(yy): remove this once `blockbeat` is in place.
|
||||||
numExpected := 1
|
numExpected := 1
|
||||||
err := wait.NoError(func() error {
|
err := wait.NoError(func() error {
|
||||||
mem := ht.Miner.GetRawMempool()
|
mem := ht.GetRawMempool()
|
||||||
if len(mem) == numExpected {
|
if len(mem) == numExpected {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ func testNonStdSweepInner(ht *lntest.HarnessTest, address string) {
|
|||||||
|
|
||||||
// Fetch the txid so we can grab the raw transaction.
|
// Fetch the txid so we can grab the raw transaction.
|
||||||
txid := ht.AssertNumTxsInMempool(1)[0]
|
txid := ht.AssertNumTxsInMempool(1)[0]
|
||||||
tx := ht.Miner.GetRawTransaction(txid)
|
tx := ht.GetRawTransaction(txid)
|
||||||
|
|
||||||
msgTx := tx.MsgTx()
|
msgTx := tx.MsgTx()
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ func testNonStdSweepInner(ht *lntest.HarnessTest, address string) {
|
|||||||
for _, inp := range msgTx.TxIn {
|
for _, inp := range msgTx.TxIn {
|
||||||
// Fetch the previous outpoint's value.
|
// Fetch the previous outpoint's value.
|
||||||
prevOut := inp.PreviousOutPoint
|
prevOut := inp.PreviousOutPoint
|
||||||
ptx := ht.Miner.GetRawTransaction(&prevOut.Hash)
|
ptx := ht.GetRawTransaction(&prevOut.Hash)
|
||||||
|
|
||||||
pout := ptx.MsgTx().TxOut[prevOut.Index]
|
pout := ptx.MsgTx().TxOut[prevOut.Index]
|
||||||
inputVal += int(pout.Value)
|
inputVal += int(pout.Value)
|
||||||
|
@ -321,7 +321,7 @@ func testAnchorReservedValue(ht *lntest.HarnessTest) {
|
|||||||
|
|
||||||
// Alice tries to send all funds to an external address, the reserved
|
// Alice tries to send all funds to an external address, the reserved
|
||||||
// value must stay in her wallet.
|
// value must stay in her wallet.
|
||||||
minerAddr := ht.Miner.NewMinerAddress()
|
minerAddr := ht.NewMinerAddress()
|
||||||
|
|
||||||
sweepReq = &lnrpc.SendCoinsRequest{
|
sweepReq = &lnrpc.SendCoinsRequest{
|
||||||
Addr: minerAddr.String(),
|
Addr: minerAddr.String(),
|
||||||
@ -544,7 +544,7 @@ func testAnchorThirdPartySpend(ht *lntest.HarnessTest) {
|
|||||||
// With the anchor output located, and the main commitment mined we'll
|
// 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
|
// instruct the wallet to send all coins in the wallet to a new address
|
||||||
// (to the miner), including unconfirmed change.
|
// (to the miner), including unconfirmed change.
|
||||||
minerAddr := ht.Miner.NewMinerAddress()
|
minerAddr := ht.NewMinerAddress()
|
||||||
sweepReq := &lnrpc.SendCoinsRequest{
|
sweepReq := &lnrpc.SendCoinsRequest{
|
||||||
Addr: minerAddr.String(),
|
Addr: minerAddr.String(),
|
||||||
SendAll: true,
|
SendAll: true,
|
||||||
@ -574,7 +574,7 @@ func testAnchorThirdPartySpend(ht *lntest.HarnessTest) {
|
|||||||
// mine a transaction that double spends the output.
|
// mine a transaction that double spends the output.
|
||||||
thirdPartyAnchorSweep := genAnchorSweep(ht, aliceSweep, anchor.Outpoint)
|
thirdPartyAnchorSweep := genAnchorSweep(ht, aliceSweep, anchor.Outpoint)
|
||||||
ht.Logf("Third party tx=%v", thirdPartyAnchorSweep.TxHash())
|
ht.Logf("Third party tx=%v", thirdPartyAnchorSweep.TxHash())
|
||||||
ht.Miner.MineBlockWithTx(thirdPartyAnchorSweep)
|
ht.MineBlockWithTx(thirdPartyAnchorSweep)
|
||||||
|
|
||||||
// At this point, we should no longer find Alice's transaction that
|
// At this point, we should no longer find Alice's transaction that
|
||||||
// tried to sweep the anchor in her wallet.
|
// tried to sweep the anchor in her wallet.
|
||||||
@ -673,7 +673,7 @@ func genAnchorSweep(ht *lntest.HarnessTest, aliceSweep *wire.MsgTx,
|
|||||||
aliceAnchorTxIn.Witness[0] = nil
|
aliceAnchorTxIn.Witness[0] = nil
|
||||||
aliceAnchorTxIn.Sequence = 16
|
aliceAnchorTxIn.Sequence = 16
|
||||||
|
|
||||||
minerAddr := ht.Miner.NewMinerAddress()
|
minerAddr := ht.NewMinerAddress()
|
||||||
addrScript, err := txscript.PayToAddrScript(minerAddr)
|
addrScript, err := txscript.PayToAddrScript(minerAddr)
|
||||||
require.NoError(ht, err, "unable to gen addr script")
|
require.NoError(ht, err, "unable to gen addr script")
|
||||||
|
|
||||||
@ -766,7 +766,7 @@ func testRemoveTx(ht *lntest.HarnessTest) {
|
|||||||
// Mine a block and make sure the transaction previously broadcasted
|
// Mine a block and make sure the transaction previously broadcasted
|
||||||
// shows up in alice's wallet although we removed the transaction from
|
// shows up in alice's wallet although we removed the transaction from
|
||||||
// the wallet when it was unconfirmed.
|
// the wallet when it was unconfirmed.
|
||||||
block := ht.Miner.MineBlocks(1)[0]
|
block := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
|
||||||
ht.AssertTxInBlock(block, txID)
|
ht.AssertTxInBlock(block, txID)
|
||||||
|
|
||||||
// Verify that alice has 2 confirmed unspent utxos in her default
|
// Verify that alice has 2 confirmed unspent utxos in her default
|
||||||
|
@ -30,7 +30,7 @@ func testOpenChannelAfterReorg(ht *lntest.HarnessTest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a temp miner.
|
// Create a temp miner.
|
||||||
tempMiner := ht.Miner.SpawnTempMiner()
|
tempMiner := ht.SpawnTempMiner()
|
||||||
|
|
||||||
miner := ht.Miner
|
miner := ht.Miner
|
||||||
alice, bob := ht.Alice, ht.Bob
|
alice, bob := ht.Alice, ht.Bob
|
||||||
|
@ -464,7 +464,7 @@ func runPsbtChanFundingExternal(ht *lntest.HarnessTest, carol,
|
|||||||
require.NoError(ht, err)
|
require.NoError(ht, err)
|
||||||
|
|
||||||
txHash := finalTx.TxHash()
|
txHash := finalTx.TxHash()
|
||||||
_, err = ht.Miner.Client.SendRawTransaction(&finalTx, false)
|
_, err = ht.SendRawTransaction(&finalTx, false)
|
||||||
require.NoError(ht, err)
|
require.NoError(ht, err)
|
||||||
|
|
||||||
// Now we can mine a block to get the transaction confirmed, then wait
|
// Now we can mine a block to get the transaction confirmed, then wait
|
||||||
|
@ -252,7 +252,7 @@ func testOnchainFundRecovery(ht *lntest.HarnessTest) {
|
|||||||
promptChangeAddr := func(node *node.HarnessNode) {
|
promptChangeAddr := func(node *node.HarnessNode) {
|
||||||
ht.Helper()
|
ht.Helper()
|
||||||
|
|
||||||
minerAddr := ht.Miner.NewMinerAddress()
|
minerAddr := ht.NewMinerAddress()
|
||||||
req := &lnrpc.SendCoinsRequest{
|
req := &lnrpc.SendCoinsRequest{
|
||||||
Addr: minerAddr.String(),
|
Addr: minerAddr.String(),
|
||||||
Amount: minerAmt,
|
Amount: minerAmt,
|
||||||
|
@ -570,13 +570,13 @@ func revokedCloseRetributionRemoteHodlCase(ht *lntest.HarnessTest,
|
|||||||
var justiceTxid *chainhash.Hash
|
var justiceTxid *chainhash.Hash
|
||||||
errNotFound := errors.New("justice tx not found")
|
errNotFound := errors.New("justice tx not found")
|
||||||
findJusticeTx := func() (*chainhash.Hash, error) {
|
findJusticeTx := func() (*chainhash.Hash, error) {
|
||||||
mempool := ht.Miner.GetRawMempool()
|
mempool := ht.GetRawMempool()
|
||||||
|
|
||||||
for _, txid := range mempool {
|
for _, txid := range mempool {
|
||||||
// Check that the justice tx has the appropriate number
|
// Check that the justice tx has the appropriate number
|
||||||
// of inputs.
|
// of inputs.
|
||||||
//
|
//
|
||||||
// NOTE: We don't use `ht.Miner.GetRawTransaction`
|
// NOTE: We don't use `ht.GetRawTransaction`
|
||||||
// which asserts a txid must be found as the HTLC
|
// which asserts a txid must be found as the HTLC
|
||||||
// spending txes might be aggregated.
|
// spending txes might be aggregated.
|
||||||
tx, err := ht.Miner.Client.GetRawTransaction(txid)
|
tx, err := ht.Miner.Client.GetRawTransaction(txid)
|
||||||
@ -626,14 +626,14 @@ func revokedCloseRetributionRemoteHodlCase(ht *lntest.HarnessTest,
|
|||||||
}
|
}
|
||||||
require.NoError(ht, err, "timeout finding justice tx")
|
require.NoError(ht, err, "timeout finding justice tx")
|
||||||
|
|
||||||
justiceTx := ht.Miner.GetRawTransaction(justiceTxid)
|
justiceTx := ht.GetRawTransaction(justiceTxid)
|
||||||
|
|
||||||
// isSecondLevelSpend checks that the passed secondLevelTxid is a
|
// isSecondLevelSpend checks that the passed secondLevelTxid is a
|
||||||
// potentitial second level spend spending from the commit tx.
|
// potentitial second level spend spending from the commit tx.
|
||||||
isSecondLevelSpend := func(commitTxid,
|
isSecondLevelSpend := func(commitTxid,
|
||||||
secondLevelTxid *chainhash.Hash) bool {
|
secondLevelTxid *chainhash.Hash) bool {
|
||||||
|
|
||||||
secondLevel := ht.Miner.GetRawTransaction(secondLevelTxid)
|
secondLevel := ht.GetRawTransaction(secondLevelTxid)
|
||||||
|
|
||||||
// A second level spend should have only one input, and one
|
// A second level spend should have only one input, and one
|
||||||
// output.
|
// output.
|
||||||
|
@ -1010,7 +1010,7 @@ func testErrorHandlingOnChainFailure(ht *lntest.HarnessTest) {
|
|||||||
ht.MineBlocks(node.DefaultCSV - 1)
|
ht.MineBlocks(node.DefaultCSV - 1)
|
||||||
ht.AssertNumPendingSweeps(ht.Bob, 1)
|
ht.AssertNumPendingSweeps(ht.Bob, 1)
|
||||||
ht.MineEmptyBlocks(1)
|
ht.MineEmptyBlocks(1)
|
||||||
ht.Miner.MineBlocksAndAssertNumTxes(1, 1)
|
ht.MineBlocksAndAssertNumTxes(1, 1)
|
||||||
|
|
||||||
// Restart bob so that we can test that he's able to recover everything
|
// Restart bob so that we can test that he's able to recover everything
|
||||||
// he needs to claim a blinded HTLC.
|
// he needs to claim a blinded HTLC.
|
||||||
@ -1026,8 +1026,8 @@ func testErrorHandlingOnChainFailure(ht *lntest.HarnessTest) {
|
|||||||
// Wait for Bob's timeout transaction in the mempool, since we've
|
// Wait for Bob's timeout transaction in the mempool, since we've
|
||||||
// suspended Carol we don't need to account for her commitment output
|
// suspended Carol we don't need to account for her commitment output
|
||||||
// claim.
|
// claim.
|
||||||
ht.Miner.MineBlocksAndAssertNumTxes(1, 1)
|
|
||||||
ht.AssertNumPendingSweeps(ht.Bob, 0)
|
ht.AssertNumPendingSweeps(ht.Bob, 0)
|
||||||
|
ht.MineBlocksAndAssertNumTxes(1, 1)
|
||||||
|
|
||||||
// Assert that the HTLC has cleared.
|
// Assert that the HTLC has cleared.
|
||||||
ht.WaitForBlockchainSync(ht.Bob)
|
ht.WaitForBlockchainSync(ht.Bob)
|
||||||
@ -1049,7 +1049,7 @@ func testErrorHandlingOnChainFailure(ht *lntest.HarnessTest) {
|
|||||||
// Clean up the rest of our force close: mine blocks so that Bob's CSV
|
// Clean up the rest of our force close: mine blocks so that Bob's CSV
|
||||||
// expires plus one block to trigger his sweep and then mine it.
|
// expires plus one block to trigger his sweep and then mine it.
|
||||||
ht.MineBlocks(node.DefaultCSV + 1)
|
ht.MineBlocks(node.DefaultCSV + 1)
|
||||||
ht.Miner.MineBlocksAndAssertNumTxes(1, 1)
|
ht.MineBlocksAndAssertNumTxes(1, 1)
|
||||||
|
|
||||||
// Bring carol back up so that we can close out the rest of our
|
// Bring carol back up so that we can close out the rest of our
|
||||||
// channels cooperatively. She requires an interceptor to start up
|
// channels cooperatively. She requires an interceptor to start up
|
||||||
|
@ -168,7 +168,7 @@ func testSweepCPFPAnchorOutgoingTimeout(ht *lntest.HarnessTest) {
|
|||||||
ht.MineEmptyBlocks(int(numBlocks))
|
ht.MineEmptyBlocks(int(numBlocks))
|
||||||
|
|
||||||
// Assert Bob's force closing tx has been broadcast.
|
// Assert Bob's force closing tx has been broadcast.
|
||||||
closeTxid := ht.Miner.AssertNumTxsInMempool(1)[0]
|
closeTxid := ht.AssertNumTxsInMempool(1)[0]
|
||||||
|
|
||||||
// Remember the force close height so we can calculate the deadline
|
// Remember the force close height so we can calculate the deadline
|
||||||
// height.
|
// height.
|
||||||
@ -517,7 +517,7 @@ func testSweepCPFPAnchorIncomingTimeout(ht *lntest.HarnessTest) {
|
|||||||
ht.MineEmptyBlocks(int(numBlocks))
|
ht.MineEmptyBlocks(int(numBlocks))
|
||||||
|
|
||||||
// Assert Bob's force closing tx has been broadcast.
|
// Assert Bob's force closing tx has been broadcast.
|
||||||
closeTxid := ht.Miner.AssertNumTxsInMempool(1)[0]
|
closeTxid := ht.AssertNumTxsInMempool(1)[0]
|
||||||
|
|
||||||
// Bob should have two pending sweeps,
|
// Bob should have two pending sweeps,
|
||||||
// - anchor sweeping from his local commitment.
|
// - anchor sweeping from his local commitment.
|
||||||
@ -546,7 +546,7 @@ func testSweepCPFPAnchorIncomingTimeout(ht *lntest.HarnessTest) {
|
|||||||
//
|
//
|
||||||
// We should see Bob's anchor sweeping tx triggered by the above
|
// We should see Bob's anchor sweeping tx triggered by the above
|
||||||
// block, along with his force close tx.
|
// block, along with his force close tx.
|
||||||
txns := ht.Miner.GetNumTxsFromMempool(2)
|
txns := ht.GetNumTxsFromMempool(2)
|
||||||
|
|
||||||
// Find the sweeping tx.
|
// Find the sweeping tx.
|
||||||
sweepTx := ht.FindSweepingTxns(txns, 1, *closeTxid)[0]
|
sweepTx := ht.FindSweepingTxns(txns, 1, *closeTxid)[0]
|
||||||
@ -598,12 +598,12 @@ func testSweepCPFPAnchorIncomingTimeout(ht *lntest.HarnessTest) {
|
|||||||
|
|
||||||
// Make sure Bob's old sweeping tx has been removed from the
|
// Make sure Bob's old sweeping tx has been removed from the
|
||||||
// mempool.
|
// mempool.
|
||||||
ht.Miner.AssertTxNotInMempool(sweepTx.TxHash())
|
ht.AssertTxNotInMempool(sweepTx.TxHash())
|
||||||
|
|
||||||
// We expect to see two txns in the mempool,
|
// We expect to see two txns in the mempool,
|
||||||
// - Bob's force close tx.
|
// - Bob's force close tx.
|
||||||
// - Bob's anchor sweep tx.
|
// - Bob's anchor sweep tx.
|
||||||
ht.Miner.AssertNumTxsInMempool(2)
|
ht.AssertNumTxsInMempool(2)
|
||||||
|
|
||||||
// We expect the fees to increase by i*delta.
|
// We expect the fees to increase by i*delta.
|
||||||
expectedFee := startFeeAnchor + feeDelta.MulF64(float64(i))
|
expectedFee := startFeeAnchor + feeDelta.MulF64(float64(i))
|
||||||
@ -613,7 +613,7 @@ func testSweepCPFPAnchorIncomingTimeout(ht *lntest.HarnessTest) {
|
|||||||
|
|
||||||
// We should see Bob's anchor sweeping tx being fee bumped
|
// We should see Bob's anchor sweeping tx being fee bumped
|
||||||
// since it's not confirmed, along with his force close tx.
|
// since it's not confirmed, along with his force close tx.
|
||||||
txns = ht.Miner.GetNumTxsFromMempool(2)
|
txns = ht.GetNumTxsFromMempool(2)
|
||||||
|
|
||||||
// Find the sweeping tx.
|
// Find the sweeping tx.
|
||||||
sweepTx = ht.FindSweepingTxns(txns, 1, *closeTxid)[0]
|
sweepTx = ht.FindSweepingTxns(txns, 1, *closeTxid)[0]
|
||||||
@ -648,11 +648,11 @@ func testSweepCPFPAnchorIncomingTimeout(ht *lntest.HarnessTest) {
|
|||||||
ht.MineEmptyBlocks(1)
|
ht.MineEmptyBlocks(1)
|
||||||
|
|
||||||
// Make sure Bob's old sweeping tx has been removed from the mempool.
|
// Make sure Bob's old sweeping tx has been removed from the mempool.
|
||||||
ht.Miner.AssertTxNotInMempool(sweepTx.TxHash())
|
ht.AssertTxNotInMempool(sweepTx.TxHash())
|
||||||
|
|
||||||
// Get the last sweeping tx - we should see two txns here, Bob's anchor
|
// Get the last sweeping tx - we should see two txns here, Bob's anchor
|
||||||
// sweeping tx and his force close tx.
|
// sweeping tx and his force close tx.
|
||||||
txns = ht.Miner.GetNumTxsFromMempool(2)
|
txns = ht.GetNumTxsFromMempool(2)
|
||||||
|
|
||||||
// Find the sweeping tx.
|
// Find the sweeping tx.
|
||||||
sweepTx = ht.FindSweepingTxns(txns, 1, *closeTxid)[0]
|
sweepTx = ht.FindSweepingTxns(txns, 1, *closeTxid)[0]
|
||||||
@ -673,7 +673,7 @@ func testSweepCPFPAnchorIncomingTimeout(ht *lntest.HarnessTest) {
|
|||||||
//
|
//
|
||||||
// We expect two txns here, one for the anchor sweeping, the other for
|
// We expect two txns here, one for the anchor sweeping, the other for
|
||||||
// the force close tx.
|
// the force close tx.
|
||||||
txns = ht.Miner.GetNumTxsFromMempool(2)
|
txns = ht.GetNumTxsFromMempool(2)
|
||||||
|
|
||||||
// Find the sweeping tx.
|
// Find the sweeping tx.
|
||||||
currentSweepTx := ht.FindSweepingTxns(txns, 1, *closeTxid)[0]
|
currentSweepTx := ht.FindSweepingTxns(txns, 1, *closeTxid)[0]
|
||||||
@ -1029,7 +1029,7 @@ func testSweepHTLCs(ht *lntest.HarnessTest) {
|
|||||||
// We don't care the behavior of the anchor sweep in this test, so we
|
// We don't care the behavior of the anchor sweep in this test, so we
|
||||||
// mine the force close tx to trigger Bob's contractcourt to offer his
|
// mine the force close tx to trigger Bob's contractcourt to offer his
|
||||||
// incoming HTLC to his sweeper.
|
// incoming HTLC to his sweeper.
|
||||||
ht.Miner.MineBlockWithTx(closeTx)
|
ht.MineBlockWithTx(closeTx)
|
||||||
|
|
||||||
// Update Bob's fee function position.
|
// Update Bob's fee function position.
|
||||||
outgoingFuncPosition++
|
outgoingFuncPosition++
|
||||||
@ -1088,7 +1088,7 @@ func testSweepHTLCs(ht *lntest.HarnessTest) {
|
|||||||
incomingFuncPosition := int32(0)
|
incomingFuncPosition := int32(0)
|
||||||
|
|
||||||
// Mine the anchor sweeping tx to reduce noise in this test.
|
// Mine the anchor sweeping tx to reduce noise in this test.
|
||||||
ht.Miner.MineBlockWithTxes([]*btcutil.Tx{btcutil.NewTx(anchorSweep)})
|
ht.MineBlockWithTx(anchorSweep)
|
||||||
|
|
||||||
// Update the fee function's positions.
|
// Update the fee function's positions.
|
||||||
outgoingFuncPosition++
|
outgoingFuncPosition++
|
||||||
@ -1456,7 +1456,7 @@ func testSweepCommitOutputAndAnchor(ht *lntest.HarnessTest) {
|
|||||||
aliceStartPosition := 0
|
aliceStartPosition := 0
|
||||||
var aliceFirstSweepTx *wire.MsgTx
|
var aliceFirstSweepTx *wire.MsgTx
|
||||||
err := wait.NoError(func() error {
|
err := wait.NoError(func() error {
|
||||||
mem := ht.Miner.GetRawMempool()
|
mem := ht.GetRawMempool()
|
||||||
if len(mem) != 2 {
|
if len(mem) != 2 {
|
||||||
return fmt.Errorf("want 2, got %v in mempool: %v",
|
return fmt.Errorf("want 2, got %v in mempool: %v",
|
||||||
len(mem), mem)
|
len(mem), mem)
|
||||||
@ -1486,7 +1486,7 @@ func testSweepCommitOutputAndAnchor(ht *lntest.HarnessTest) {
|
|||||||
// block would trigger an RBF. We now need to assert the mempool has
|
// block would trigger an RBF. We now need to assert the mempool has
|
||||||
// removed the replaced tx.
|
// removed the replaced tx.
|
||||||
if aliceFirstSweepTx != nil {
|
if aliceFirstSweepTx != nil {
|
||||||
ht.Miner.AssertTxNotInMempool(aliceFirstSweepTx.TxHash())
|
ht.AssertTxNotInMempool(aliceFirstSweepTx.TxHash())
|
||||||
}
|
}
|
||||||
|
|
||||||
// We also remember the positions of fee functions used by Alice and
|
// We also remember the positions of fee functions used by Alice and
|
||||||
@ -1604,7 +1604,7 @@ func testSweepCommitOutputAndAnchor(ht *lntest.HarnessTest) {
|
|||||||
|
|
||||||
// Make sure Alice's old sweeping tx has been removed from the
|
// Make sure Alice's old sweeping tx has been removed from the
|
||||||
// mempool.
|
// mempool.
|
||||||
ht.Miner.AssertTxNotInMempool(aliceSweepTx.TxHash())
|
ht.AssertTxNotInMempool(aliceSweepTx.TxHash())
|
||||||
|
|
||||||
// We should see two txns in the mempool:
|
// We should see two txns in the mempool:
|
||||||
// - Alice's sweeping tx, which sweeps both her anchor and
|
// - Alice's sweeping tx, which sweeps both her anchor and
|
||||||
|
@ -1850,7 +1850,7 @@ func testTaprootCoopClose(ht *lntest.HarnessTest) {
|
|||||||
// assertTaprootDeliveryUsed returns true if a Taproot addr was used in
|
// assertTaprootDeliveryUsed returns true if a Taproot addr was used in
|
||||||
// the co-op close transaction.
|
// the co-op close transaction.
|
||||||
assertTaprootDeliveryUsed := func(closingTxid *chainhash.Hash) bool {
|
assertTaprootDeliveryUsed := func(closingTxid *chainhash.Hash) bool {
|
||||||
tx := ht.Miner.GetRawTransaction(closingTxid)
|
tx := ht.GetRawTransaction(closingTxid)
|
||||||
for _, txOut := range tx.MsgTx().TxOut {
|
for _, txOut := range tx.MsgTx().TxOut {
|
||||||
if !txscript.IsPayToTaproot(txOut.PkScript) {
|
if !txscript.IsPayToTaproot(txOut.PkScript) {
|
||||||
return false
|
return false
|
||||||
|
@ -86,7 +86,7 @@ func testTowerClientTowerAndSessionManagement(ht *lntest.HarnessTest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if mineOnFail {
|
if mineOnFail {
|
||||||
ht.Miner.MineBlocksSlow(1)
|
ht.MineBlocks(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Errorf("expected %d sessions, got %d",
|
return fmt.Errorf("expected %d sessions, got %d",
|
||||||
@ -515,7 +515,7 @@ func testRevokedCloseRetributionAltruistWatchtowerCase(ht *lntest.HarnessTest,
|
|||||||
// Query for the mempool transaction found above. Then assert that all
|
// Query for the mempool transaction found above. Then assert that all
|
||||||
// the inputs of this transaction are spending outputs generated by
|
// the inputs of this transaction are spending outputs generated by
|
||||||
// Carol's breach transaction above.
|
// Carol's breach transaction above.
|
||||||
justiceTx := ht.Miner.GetRawTransaction(justiceTXID)
|
justiceTx := ht.GetRawTransaction(justiceTXID)
|
||||||
for _, txIn := range justiceTx.MsgTx().TxIn {
|
for _, txIn := range justiceTx.MsgTx().TxIn {
|
||||||
require.Equal(ht, breachTXID[:], txIn.PreviousOutPoint.Hash[:],
|
require.Equal(ht, breachTXID[:], txIn.PreviousOutPoint.Hash[:],
|
||||||
"justice tx not spending commitment utxo")
|
"justice tx not spending commitment utxo")
|
||||||
@ -702,7 +702,7 @@ func assertNumBackups(ht *lntest.HarnessTest, node *rpc.HarnessRPC,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if mineOnFail {
|
if mineOnFail {
|
||||||
ht.Miner.MineBlocksSlow(1)
|
ht.MineBlocks(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Errorf("expected %d backups, got %d",
|
return fmt.Errorf("expected %d backups, got %d",
|
||||||
|
@ -950,7 +950,7 @@ func testZeroConfReorg(ht *lntest.HarnessTest) {
|
|||||||
// exists in the graph.
|
// exists in the graph.
|
||||||
//
|
//
|
||||||
// First, we'll setup a new miner that we can use to cause a reorg.
|
// First, we'll setup a new miner that we can use to cause a reorg.
|
||||||
tempMiner := ht.Miner.SpawnTempMiner()
|
tempMiner := ht.SpawnTempMiner()
|
||||||
|
|
||||||
// We now cause a fork, by letting our original miner mine 1 block and
|
// We now cause a fork, by letting our original miner mine 1 block and
|
||||||
// our new miner will mine 2. We also expect the funding transition to
|
// our new miner will mine 2. We also expect the funding transition to
|
||||||
@ -959,7 +959,7 @@ func testZeroConfReorg(ht *lntest.HarnessTest) {
|
|||||||
tempMiner.MineEmptyBlocks(2)
|
tempMiner.MineEmptyBlocks(2)
|
||||||
|
|
||||||
// Ensure the temp miner is one block ahead.
|
// Ensure the temp miner is one block ahead.
|
||||||
ht.Miner.AssertMinerBlockHeightDelta(tempMiner, 1)
|
ht.AssertMinerBlockHeightDelta(tempMiner, 1)
|
||||||
|
|
||||||
// Wait for Carol to sync to the original miner's chain.
|
// Wait for Carol to sync to the original miner's chain.
|
||||||
_, minerHeight := ht.GetBestBlock()
|
_, minerHeight := ht.GetBestBlock()
|
||||||
@ -972,14 +972,14 @@ func testZeroConfReorg(ht *lntest.HarnessTest) {
|
|||||||
|
|
||||||
// Connecting to the temporary miner should cause the original miner to
|
// Connecting to the temporary miner should cause the original miner to
|
||||||
// reorg to the longer chain.
|
// reorg to the longer chain.
|
||||||
ht.Miner.ConnectMiner(tempMiner)
|
ht.ConnectToMiner(tempMiner)
|
||||||
|
|
||||||
// They should now be on the same chain.
|
// They should now be on the same chain.
|
||||||
ht.Miner.AssertMinerBlockHeightDelta(tempMiner, 0)
|
ht.AssertMinerBlockHeightDelta(tempMiner, 0)
|
||||||
|
|
||||||
// Now we disconnect the two miners and reconnect our original chain
|
// Now we disconnect the two miners and reconnect our original chain
|
||||||
// backend.
|
// backend.
|
||||||
ht.Miner.DisconnectMiner(tempMiner)
|
ht.DisconnectFromMiner(tempMiner)
|
||||||
|
|
||||||
ht.ConnectMiner()
|
ht.ConnectMiner()
|
||||||
|
|
||||||
|
@ -4,8 +4,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/blockchain"
|
"github.com/btcsuite/btcd/blockchain"
|
||||||
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
|
"github.com/lightningnetwork/lnd/lntest/miner"
|
||||||
"github.com/lightningnetwork/lnd/lntest/node"
|
"github.com/lightningnetwork/lnd/lntest/node"
|
||||||
"github.com/lightningnetwork/lnd/lntest/wait"
|
"github.com/lightningnetwork/lnd/lntest/wait"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@ -223,3 +225,77 @@ func (h *HarnessTest) GetNumTxsFromMempool(n int) []*wire.MsgTx {
|
|||||||
func (h *HarnessTest) GetBestBlock() (*chainhash.Hash, int32) {
|
func (h *HarnessTest) GetBestBlock() (*chainhash.Hash, int32) {
|
||||||
return h.Miner.GetBestBlock()
|
return h.Miner.GetBestBlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MineBlockWithTx mines a single block to include the specifies tx only.
|
||||||
|
func (h *HarnessTest) MineBlockWithTx(tx *wire.MsgTx) *wire.MsgBlock {
|
||||||
|
return h.Miner.MineBlockWithTx(tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ConnectToMiner connects the miner to a temp miner.
|
||||||
|
func (h *HarnessTest) ConnectToMiner(tempMiner *miner.HarnessMiner) {
|
||||||
|
h.Miner.ConnectMiner(tempMiner)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DisconnectFromMiner disconnects the miner from the temp miner.
|
||||||
|
func (h *HarnessTest) DisconnectFromMiner(tempMiner *miner.HarnessMiner) {
|
||||||
|
h.Miner.DisconnectMiner(tempMiner)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRawMempool makes a RPC call to the miner's GetRawMempool and
|
||||||
|
// asserts.
|
||||||
|
func (h *HarnessTest) GetRawMempool() []*chainhash.Hash {
|
||||||
|
return h.Miner.GetRawMempool()
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRawTransaction makes a RPC call to the miner's GetRawTransaction and
|
||||||
|
// asserts.
|
||||||
|
func (h *HarnessTest) GetRawTransaction(txid *chainhash.Hash) *btcutil.Tx {
|
||||||
|
return h.Miner.GetRawTransaction(txid)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMinerAddress creates a new address for the miner and asserts.
|
||||||
|
func (h *HarnessTest) NewMinerAddress() btcutil.Address {
|
||||||
|
return h.Miner.NewMinerAddress()
|
||||||
|
}
|
||||||
|
|
||||||
|
// SpawnTempMiner creates a temp miner and syncs it with the current miner.
|
||||||
|
// Once miners are synced, the temp miner is disconnected from the original
|
||||||
|
// miner and returned.
|
||||||
|
func (h *HarnessTest) SpawnTempMiner() *miner.HarnessMiner {
|
||||||
|
return h.Miner.SpawnTempMiner()
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateTransaction uses the miner to create a transaction using the given
|
||||||
|
// outputs using the specified fee rate and returns the transaction.
|
||||||
|
func (h *HarnessTest) CreateTransaction(outputs []*wire.TxOut,
|
||||||
|
feeRate btcutil.Amount) *wire.MsgTx {
|
||||||
|
|
||||||
|
return h.Miner.CreateTransaction(outputs, feeRate)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendOutputsWithoutChange uses the miner to send the given outputs using the
|
||||||
|
// specified fee rate and returns the txid.
|
||||||
|
func (h *HarnessTest) SendOutputsWithoutChange(outputs []*wire.TxOut,
|
||||||
|
feeRate btcutil.Amount) *chainhash.Hash {
|
||||||
|
|
||||||
|
return h.Miner.SendOutputsWithoutChange(outputs, feeRate)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AssertMinerBlockHeightDelta ensures that tempMiner is 'delta' blocks ahead
|
||||||
|
// of miner.
|
||||||
|
func (h *HarnessTest) AssertMinerBlockHeightDelta(
|
||||||
|
tempMiner *miner.HarnessMiner, delta int32) {
|
||||||
|
|
||||||
|
h.Miner.AssertMinerBlockHeightDelta(tempMiner, delta)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendRawTransaction submits the encoded transaction to the server which will
|
||||||
|
// then relay it to the network.
|
||||||
|
func (h *HarnessTest) SendRawTransaction(tx *wire.MsgTx,
|
||||||
|
allowHighFees bool) (chainhash.Hash, error) {
|
||||||
|
|
||||||
|
txid, err := h.Miner.Client.SendRawTransaction(tx, allowHighFees)
|
||||||
|
require.NoError(h, err)
|
||||||
|
|
||||||
|
return *txid, nil
|
||||||
|
}
|
||||||
|
@ -410,7 +410,7 @@ func (h *HarnessMiner) AssertOutpointInMempool(op wire.OutPoint) *wire.MsgTx {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, txid := range mempool {
|
for _, txid := range mempool {
|
||||||
// We don't use `ht.Miner.GetRawTransaction` which
|
// We don't use `ht.GetRawTransaction` which
|
||||||
// asserts a txid must be found. While iterating here,
|
// asserts a txid must be found. While iterating here,
|
||||||
// the actual mempool state might have been changed,
|
// the actual mempool state might have been changed,
|
||||||
// causing a given txid being removed and cannot be
|
// causing a given txid being removed and cannot be
|
||||||
|
Loading…
x
Reference in New Issue
Block a user