Merge pull request #5646 from yyforyongyu/fix-context-leak

itest: properly handle the creation of timeout context
This commit is contained in:
Oliver Gugger
2021-08-24 10:44:36 +02:00
committed by GitHub
45 changed files with 705 additions and 1079 deletions

View File

@@ -139,6 +139,9 @@ you.
* [Link channel point logging](https://github.com/lightningnetwork/lnd/pull/5508) * [Link channel point logging](https://github.com/lightningnetwork/lnd/pull/5508)
* [Fixed context leak in integration tests, and properly handled context
timeout](https://github.com/lightningnetwork/lnd/pull/5646).
## Database ## Database
* [Ensure single writer for legacy * [Ensure single writer for legacy

View File

@@ -178,7 +178,7 @@ func (n *NetworkHarness) SetUp(t *testing.T,
// both nodes are fully started since the Connect RPC is guarded behind // both nodes are fully started since the Connect RPC is guarded behind
// the server.Started() flag that waits for all subsystems to be ready. // the server.Started() flag that waits for all subsystems to be ready.
ctxb := context.Background() ctxb := context.Background()
n.ConnectNodes(ctxb, t, n.Alice, n.Bob) n.ConnectNodes(t, n.Alice, n.Bob)
// Load up the wallets of the seeder nodes with 10 outputs of 1 BTC // Load up the wallets of the seeder nodes with 10 outputs of 1 BTC
// each. // each.
@@ -548,8 +548,10 @@ tryconnect:
// behave the same as ConnectNodes. If a pending connection request has already // behave the same as ConnectNodes. If a pending connection request has already
// been made, the method will block until the two nodes appear in each other's // been made, the method will block until the two nodes appear in each other's
// peers list, or until the 15s timeout expires. // peers list, or until the 15s timeout expires.
func (n *NetworkHarness) EnsureConnected(ctx context.Context, func (n *NetworkHarness) EnsureConnected(t *testing.T, a, b *HarnessNode) {
t *testing.T, a, b *HarnessNode) { ctxb := context.Background()
ctx, cancel := context.WithTimeout(ctxb, DefaultTimeout*2)
defer cancel()
// errConnectionRequested is used to signal that a connection was // errConnectionRequested is used to signal that a connection was
// requested successfully, which is distinct from already being // requested successfully, which is distinct from already being
@@ -557,9 +559,7 @@ func (n *NetworkHarness) EnsureConnected(ctx context.Context,
errConnectionRequested := errors.New("connection request in progress") errConnectionRequested := errors.New("connection request in progress")
tryConnect := func(a, b *HarnessNode) error { tryConnect := func(a, b *HarnessNode) error {
ctxt, cancel := context.WithTimeout(ctx, DefaultTimeout) bInfo, err := b.GetInfo(ctx, &lnrpc.GetInfoRequest{})
defer cancel()
bInfo, err := b.GetInfo(ctxt, &lnrpc.GetInfoRequest{})
if err != nil { if err != nil {
return err return err
} }
@@ -637,9 +637,7 @@ func (n *NetworkHarness) EnsureConnected(ctx context.Context,
// If node B is seen in the ListPeers response from node A, // If node B is seen in the ListPeers response from node A,
// then we can exit early as the connection has been fully // then we can exit early as the connection has been fully
// established. // established.
ctxt, cancel := context.WithTimeout(ctx, DefaultTimeout) resp, err := b.ListPeers(ctx, &lnrpc.ListPeersRequest{})
defer cancel()
resp, err := b.ListPeers(ctxt, &lnrpc.ListPeersRequest{})
if err != nil { if err != nil {
return false return false
} }
@@ -670,8 +668,10 @@ func (n *NetworkHarness) EnsureConnected(ctx context.Context,
// //
// NOTE: This function may block for up to 15-seconds as it will not return // NOTE: This function may block for up to 15-seconds as it will not return
// until the new connection is detected as being known to both nodes. // until the new connection is detected as being known to both nodes.
func (n *NetworkHarness) ConnectNodes(ctx context.Context, t *testing.T, func (n *NetworkHarness) ConnectNodes(t *testing.T, a, b *HarnessNode) {
a, b *HarnessNode) { ctxb := context.Background()
ctx, cancel := context.WithTimeout(ctxb, DefaultTimeout)
defer cancel()
bobInfo, err := b.GetInfo(ctx, &lnrpc.GetInfoRequest{}) bobInfo, err := b.GetInfo(ctx, &lnrpc.GetInfoRequest{})
require.NoErrorf( require.NoErrorf(
@@ -719,7 +719,11 @@ func (n *NetworkHarness) ConnectNodes(ctx context.Context, t *testing.T,
// DisconnectNodes disconnects node a from node b by sending RPC message // DisconnectNodes disconnects node a from node b by sending RPC message
// from a node to b node // from a node to b node
func (n *NetworkHarness) DisconnectNodes(ctx context.Context, a, b *HarnessNode) error { func (n *NetworkHarness) DisconnectNodes(a, b *HarnessNode) error {
ctxb := context.Background()
ctx, cancel := context.WithTimeout(ctxb, DefaultTimeout)
defer cancel()
bobInfo, err := b.GetInfo(ctx, &lnrpc.GetInfoRequest{}) bobInfo, err := b.GetInfo(ctx, &lnrpc.GetInfoRequest{})
if err != nil { if err != nil {
return err return err
@@ -906,10 +910,10 @@ func saveProfilesPage(node *HarnessNode) error {
return nil return nil
} }
// WaitForTxInMempool blocks until the target txid is seen in the mempool. If // waitForTxInMempool blocks until the target txid is seen in the mempool. If
// the transaction isn't seen within the network before the passed timeout, // the transaction isn't seen within the network before the passed timeout,
// then an error is returned. // then an error is returned.
func (n *NetworkHarness) WaitForTxInMempool(ctx context.Context, func (n *NetworkHarness) waitForTxInMempool(ctx context.Context,
txid chainhash.Hash) error { txid chainhash.Hash) error {
// Return immediately if harness has been torn down. // Return immediately if harness has been torn down.
@@ -984,9 +988,14 @@ type OpenChannelParams struct {
// if the timeout is reached before the channel pending notification is // if the timeout is reached before the channel pending notification is
// received, an error is returned. The confirmed boolean determines whether we // received, an error is returned. The confirmed boolean determines whether we
// should fund the channel with confirmed outputs or not. // should fund the channel with confirmed outputs or not.
func (n *NetworkHarness) OpenChannel(ctx context.Context, func (n *NetworkHarness) OpenChannel(srcNode, destNode *HarnessNode,
srcNode, destNode *HarnessNode, p OpenChannelParams) ( p OpenChannelParams) (lnrpc.Lightning_OpenChannelClient, error) {
lnrpc.Lightning_OpenChannelClient, error) {
ctxb := context.Background()
// The cancel is intentionally left out here because the returned
// item(open channel client) relies on the context being active. This
// will be fixed once we finish refactoring the NetworkHarness.
ctx, _ := context.WithTimeout(ctxb, ChannelOpenTimeout) // nolint: govet
// Wait until srcNode and destNode have the latest chain synced. // Wait until srcNode and destNode have the latest chain synced.
// Otherwise, we may run into a check within the funding manager that // Otherwise, we may run into a check within the funding manager that
@@ -1058,10 +1067,14 @@ func (n *NetworkHarness) OpenChannel(ctx context.Context,
// passed channel funding parameters. If the passed context has a timeout, then // passed channel funding parameters. If the passed context has a timeout, then
// if the timeout is reached before the channel pending notification is // if the timeout is reached before the channel pending notification is
// received, an error is returned. // received, an error is returned.
func (n *NetworkHarness) OpenPendingChannel(ctx context.Context, func (n *NetworkHarness) OpenPendingChannel(srcNode, destNode *HarnessNode,
srcNode, destNode *HarnessNode, amt btcutil.Amount, amt btcutil.Amount,
pushAmt btcutil.Amount) (*lnrpc.PendingUpdate, error) { pushAmt btcutil.Amount) (*lnrpc.PendingUpdate, error) {
ctxb := context.Background()
ctx, cancel := context.WithTimeout(ctxb, ChannelOpenTimeout)
defer cancel()
// Wait until srcNode and destNode have blockchain synced // Wait until srcNode and destNode have blockchain synced
if err := srcNode.WaitForBlockchainSync(ctx); err != nil { if err := srcNode.WaitForBlockchainSync(ctx); err != nil {
return nil, fmt.Errorf("unable to sync srcNode chain: %v", err) return nil, fmt.Errorf("unable to sync srcNode chain: %v", err)
@@ -1119,9 +1132,13 @@ func (n *NetworkHarness) OpenPendingChannel(ctx context.Context,
// consuming a message from the past open channel stream. If the passed context // consuming a message from the past open channel stream. If the passed context
// has a timeout, then if the timeout is reached before the channel has been // has a timeout, then if the timeout is reached before the channel has been
// opened, then an error is returned. // opened, then an error is returned.
func (n *NetworkHarness) WaitForChannelOpen(ctx context.Context, func (n *NetworkHarness) WaitForChannelOpen(
openChanStream lnrpc.Lightning_OpenChannelClient) (*lnrpc.ChannelPoint, error) { openChanStream lnrpc.Lightning_OpenChannelClient) (*lnrpc.ChannelPoint, error) {
ctxb := context.Background()
ctx, cancel := context.WithTimeout(ctxb, ChannelOpenTimeout)
defer cancel()
errChan := make(chan error) errChan := make(chan error)
respChan := make(chan *lnrpc.ChannelPoint) respChan := make(chan *lnrpc.ChannelPoint)
go func() { go func() {
@@ -1155,10 +1172,16 @@ func (n *NetworkHarness) WaitForChannelOpen(ctx context.Context,
// passed channel point, initiated by the passed lnNode. If the passed context // passed channel point, initiated by the passed lnNode. If the passed context
// has a timeout, an error is returned if that timeout is reached before the // has a timeout, an error is returned if that timeout is reached before the
// channel close is pending. // channel close is pending.
func (n *NetworkHarness) CloseChannel(ctx context.Context, func (n *NetworkHarness) CloseChannel(lnNode *HarnessNode,
lnNode *HarnessNode, cp *lnrpc.ChannelPoint, cp *lnrpc.ChannelPoint,
force bool) (lnrpc.Lightning_CloseChannelClient, *chainhash.Hash, error) { force bool) (lnrpc.Lightning_CloseChannelClient, *chainhash.Hash, error) {
ctxb := context.Background()
// The cancel is intentionally left out here because the returned
// item(close channel client) relies on the context being active. This
// will be fixed once we finish refactoring the NetworkHarness.
ctx, _ := context.WithTimeout(ctxb, ChannelCloseTimeout) // nolint: govet
// Create a channel outpoint that we can use to compare to channels // Create a channel outpoint that we can use to compare to channels
// from the ListChannelsResponse. // from the ListChannelsResponse.
txidHash, err := getChanPointFundingTxid(cp) txidHash, err := getChanPointFundingTxid(cp)
@@ -1268,7 +1291,7 @@ func (n *NetworkHarness) CloseChannel(ctx context.Context,
"%v", err) "%v", err)
return return
} }
if err := n.WaitForTxInMempool(ctx, *closeTxid); err != nil { if err := n.waitForTxInMempool(ctx, *closeTxid); err != nil {
errChan <- fmt.Errorf("error while waiting for "+ errChan <- fmt.Errorf("error while waiting for "+
"broadcast tx: %v", err) "broadcast tx: %v", err)
return return
@@ -1290,9 +1313,13 @@ func (n *NetworkHarness) CloseChannel(ctx context.Context,
// stream that the node has deemed the channel has been fully closed. If the // stream that the node has deemed the channel has been fully closed. If the
// passed context has a timeout, then if the timeout is reached before the // passed context has a timeout, then if the timeout is reached before the
// notification is received then an error is returned. // notification is received then an error is returned.
func (n *NetworkHarness) WaitForChannelClose(ctx context.Context, func (n *NetworkHarness) WaitForChannelClose(
closeChanStream lnrpc.Lightning_CloseChannelClient) (*chainhash.Hash, error) { closeChanStream lnrpc.Lightning_CloseChannelClient) (*chainhash.Hash, error) {
ctxb := context.Background()
ctx, cancel := context.WithTimeout(ctxb, ChannelCloseTimeout)
defer cancel()
errChan := make(chan error) errChan := make(chan error)
updateChan := make(chan *lnrpc.CloseStatusUpdate_ChanClose) updateChan := make(chan *lnrpc.CloseStatusUpdate_ChanClose)
go func() { go func() {
@@ -1330,9 +1357,12 @@ func (n *NetworkHarness) WaitForChannelClose(ctx context.Context,
// assertions using channel's values. These functions are responsible for // assertions using channel's values. These functions are responsible for
// failing the test themselves if they do not pass. // failing the test themselves if they do not pass.
// nolint: interfacer // nolint: interfacer
func (n *NetworkHarness) AssertChannelExists(ctx context.Context, func (n *NetworkHarness) AssertChannelExists(node *HarnessNode,
node *HarnessNode, chanPoint *wire.OutPoint, chanPoint *wire.OutPoint, checks ...func(*lnrpc.Channel)) error {
checks ...func(*lnrpc.Channel)) error {
ctxb := context.Background()
ctx, cancel := context.WithTimeout(ctxb, ChannelCloseTimeout)
defer cancel()
req := &lnrpc.ListChannelsRequest{} req := &lnrpc.ListChannelsRequest{}
@@ -1384,12 +1414,11 @@ func (n *NetworkHarness) DumpLogs(node *HarnessNode) (string, error) {
// SendCoins attempts to send amt satoshis from the internal mining node to the // SendCoins attempts to send amt satoshis from the internal mining node to the
// targeted lightning node using a P2WKH address. 6 blocks are mined after in // targeted lightning node using a P2WKH address. 6 blocks are mined after in
// order to confirm the transaction. // order to confirm the transaction.
func (n *NetworkHarness) SendCoins(ctx context.Context, t *testing.T, func (n *NetworkHarness) SendCoins(t *testing.T, amt btcutil.Amount,
amt btcutil.Amount, target *HarnessNode) { target *HarnessNode) {
err := n.sendCoins( err := n.sendCoins(
ctx, amt, target, lnrpc.AddressType_WITNESS_PUBKEY_HASH, amt, target, lnrpc.AddressType_WITNESS_PUBKEY_HASH, true,
true,
) )
require.NoErrorf(t, err, "unable to send coins for %s", target.Cfg.Name) require.NoErrorf(t, err, "unable to send coins for %s", target.Cfg.Name)
} }
@@ -1397,12 +1426,11 @@ func (n *NetworkHarness) SendCoins(ctx context.Context, t *testing.T,
// SendCoinsUnconfirmed sends coins from the internal mining node to the target // SendCoinsUnconfirmed sends coins from the internal mining node to the target
// lightning node using a P2WPKH address. No blocks are mined after, so the // lightning node using a P2WPKH address. No blocks are mined after, so the
// transaction remains unconfirmed. // transaction remains unconfirmed.
func (n *NetworkHarness) SendCoinsUnconfirmed(ctx context.Context, func (n *NetworkHarness) SendCoinsUnconfirmed(t *testing.T, amt btcutil.Amount,
t *testing.T, amt btcutil.Amount, target *HarnessNode) { target *HarnessNode) {
err := n.sendCoins( err := n.sendCoins(
ctx, amt, target, lnrpc.AddressType_WITNESS_PUBKEY_HASH, amt, target, lnrpc.AddressType_WITNESS_PUBKEY_HASH, false,
false,
) )
require.NoErrorf( require.NoErrorf(
t, err, "unable to send unconfirmed coins for %s", t, err, "unable to send unconfirmed coins for %s",
@@ -1412,12 +1440,11 @@ func (n *NetworkHarness) SendCoinsUnconfirmed(ctx context.Context,
// SendCoinsNP2WKH attempts to send amt satoshis from the internal mining node // SendCoinsNP2WKH attempts to send amt satoshis from the internal mining node
// to the targeted lightning node using a NP2WKH address. // to the targeted lightning node using a NP2WKH address.
func (n *NetworkHarness) SendCoinsNP2WKH(ctx context.Context, func (n *NetworkHarness) SendCoinsNP2WKH(t *testing.T, amt btcutil.Amount,
t *testing.T, amt btcutil.Amount, target *HarnessNode) { target *HarnessNode) {
err := n.sendCoins( err := n.sendCoins(
ctx, amt, target, lnrpc.AddressType_NESTED_PUBKEY_HASH, amt, target, lnrpc.AddressType_NESTED_PUBKEY_HASH, true,
true,
) )
require.NoErrorf( require.NoErrorf(
t, err, "unable to send NP2WKH coins for %s", t, err, "unable to send NP2WKH coins for %s",
@@ -1428,9 +1455,12 @@ func (n *NetworkHarness) SendCoinsNP2WKH(ctx context.Context,
// sendCoins attempts to send amt satoshis from the internal mining node to the // sendCoins attempts to send amt satoshis from the internal mining node to the
// targeted lightning node. The confirmed boolean indicates whether the // targeted lightning node. The confirmed boolean indicates whether the
// transaction that pays to the target should confirm. // transaction that pays to the target should confirm.
func (n *NetworkHarness) sendCoins(ctx context.Context, amt btcutil.Amount, func (n *NetworkHarness) sendCoins(amt btcutil.Amount, target *HarnessNode,
target *HarnessNode, addrType lnrpc.AddressType, addrType lnrpc.AddressType, confirmed bool) error {
confirmed bool) error {
ctxb := context.Background()
ctx, cancel := context.WithTimeout(ctxb, DefaultTimeout)
defer cancel()
balReq := &lnrpc.WalletBalanceRequest{} balReq := &lnrpc.WalletBalanceRequest{}
initialBalance, err := target.WalletBalance(ctx, balReq) initialBalance, err := target.WalletBalance(ctx, balReq)

View File

@@ -37,8 +37,8 @@ func AddToNodeLog(t *testing.T,
// openChannelStream blocks until an OpenChannel request for a channel funding // openChannelStream blocks until an OpenChannel request for a channel funding
// by alice succeeds. If it does, a stream client is returned to receive events // by alice succeeds. If it does, a stream client is returned to receive events
// about the opening channel. // about the opening channel.
func openChannelStream(ctx context.Context, t *harnessTest, func openChannelStream(t *harnessTest, net *lntest.NetworkHarness,
net *lntest.NetworkHarness, alice, bob *lntest.HarnessNode, alice, bob *lntest.HarnessNode,
p lntest.OpenChannelParams) lnrpc.Lightning_OpenChannelClient { p lntest.OpenChannelParams) lnrpc.Lightning_OpenChannelClient {
t.t.Helper() t.t.Helper()
@@ -49,7 +49,7 @@ func openChannelStream(ctx context.Context, t *harnessTest,
var chanOpenUpdate lnrpc.Lightning_OpenChannelClient var chanOpenUpdate lnrpc.Lightning_OpenChannelClient
err := wait.NoError(func() error { err := wait.NoError(func() error {
var err error var err error
chanOpenUpdate, err = net.OpenChannel(ctx, alice, bob, p) chanOpenUpdate, err = net.OpenChannel(alice, bob, p)
return err return err
}, defaultTimeout) }, defaultTimeout)
require.NoError(t.t, err, "unable to open channel") require.NoError(t.t, err, "unable to open channel")
@@ -62,13 +62,13 @@ func openChannelStream(ctx context.Context, t *harnessTest,
// after the channel is considered open: the funding transaction should be // after the channel is considered open: the funding transaction should be
// found within a block, and that Alice can report the status of the new // found within a block, and that Alice can report the status of the new
// channel. // channel.
func openChannelAndAssert(ctx context.Context, t *harnessTest, func openChannelAndAssert(t *harnessTest, net *lntest.NetworkHarness,
net *lntest.NetworkHarness, alice, bob *lntest.HarnessNode, alice, bob *lntest.HarnessNode,
p lntest.OpenChannelParams) *lnrpc.ChannelPoint { p lntest.OpenChannelParams) *lnrpc.ChannelPoint {
t.t.Helper() t.t.Helper()
chanOpenUpdate := openChannelStream(ctx, t, net, alice, bob, p) chanOpenUpdate := openChannelStream(t, net, alice, bob, p)
// Mine 6 blocks, then wait for Alice's node to notify us that the // Mine 6 blocks, then wait for Alice's node to notify us that the
// channel has been opened. The funding transaction should be found // channel has been opened. The funding transaction should be found
@@ -76,7 +76,7 @@ func openChannelAndAssert(ctx context.Context, t *harnessTest,
// case that the channel is public, it is announced to the network. // case that the channel is public, it is announced to the network.
block := mineBlocks(t, net, 6, 1)[0] block := mineBlocks(t, net, 6, 1)[0]
fundingChanPoint, err := net.WaitForChannelOpen(ctx, chanOpenUpdate) fundingChanPoint, err := net.WaitForChannelOpen(chanOpenUpdate)
require.NoError(t.t, err, "error while waiting for channel open") require.NoError(t.t, err, "error while waiting for channel open")
fundingTxID, err := lnrpc.GetChanPointFundingTxid(fundingChanPoint) fundingTxID, err := lnrpc.GetChanPointFundingTxid(fundingChanPoint)
@@ -91,11 +91,11 @@ func openChannelAndAssert(ctx context.Context, t *harnessTest,
Index: fundingChanPoint.OutputIndex, Index: fundingChanPoint.OutputIndex,
} }
require.NoError( require.NoError(
t.t, net.AssertChannelExists(ctx, alice, &chanPoint), t.t, net.AssertChannelExists(alice, &chanPoint),
"unable to assert channel existence", "unable to assert channel existence",
) )
require.NoError( require.NoError(
t.t, net.AssertChannelExists(ctx, bob, &chanPoint), t.t, net.AssertChannelExists(bob, &chanPoint),
"unable to assert channel existence", "unable to assert channel existence",
) )
@@ -230,9 +230,7 @@ func closeChannelAndAssertType(t *harnessTest,
defer close(graphSub.quit) defer close(graphSub.quit)
} }
closeUpdates, _, err := net.CloseChannel( closeUpdates, _, err := net.CloseChannel(node, fundingChanPoint, force)
ctxt, node, fundingChanPoint, force,
)
require.NoError(t.t, err, "unable to close channel") require.NoError(t.t, err, "unable to close channel")
// If the channel policy was enabled prior to the closure, wait until we // If the channel policy was enabled prior to the closure, wait until we
@@ -261,11 +259,15 @@ func closeChannelAndAssertType(t *harnessTest,
// //
// NOTE: This method does not verify that the node sends a disable update for // NOTE: This method does not verify that the node sends a disable update for
// the closed channel. // the closed channel.
func closeReorgedChannelAndAssert(ctx context.Context, t *harnessTest, func closeReorgedChannelAndAssert(t *harnessTest,
net *lntest.NetworkHarness, node *lntest.HarnessNode, net *lntest.NetworkHarness, node *lntest.HarnessNode,
fundingChanPoint *lnrpc.ChannelPoint, force bool) *chainhash.Hash { fundingChanPoint *lnrpc.ChannelPoint, force bool) *chainhash.Hash {
closeUpdates, _, err := net.CloseChannel(ctx, node, fundingChanPoint, force) ctxb := context.Background()
ctx, cancel := context.WithTimeout(ctxb, channelCloseTimeout)
defer cancel()
closeUpdates, _, err := net.CloseChannel(node, fundingChanPoint, force)
require.NoError(t.t, err, "unable to close channel") require.NoError(t.t, err, "unable to close channel")
return assertChannelClosed( return assertChannelClosed(
@@ -286,9 +288,8 @@ func assertChannelClosed(ctx context.Context, t *harnessTest,
// If the channel appears in list channels, ensure that its state // If the channel appears in list channels, ensure that its state
// contains ChanStatusCoopBroadcasted. // contains ChanStatusCoopBroadcasted.
ctxt, _ := context.WithTimeout(ctx, defaultTimeout)
listChansRequest := &lnrpc.ListChannelsRequest{} listChansRequest := &lnrpc.ListChannelsRequest{}
listChansResp, err := node.ListChannels(ctxt, listChansRequest) listChansResp, err := node.ListChannels(ctx, listChansRequest)
require.NoError(t.t, err, "unable to query for list channels") require.NoError(t.t, err, "unable to query for list channels")
for _, channel := range listChansResp.Channels { for _, channel := range listChansResp.Channels {
@@ -307,9 +308,8 @@ func assertChannelClosed(ctx context.Context, t *harnessTest,
// At this point, the channel should now be marked as being in the // At this point, the channel should now be marked as being in the
// state of "waiting close". // state of "waiting close".
ctxt, _ = context.WithTimeout(ctx, defaultTimeout)
pendingChansRequest := &lnrpc.PendingChannelsRequest{} pendingChansRequest := &lnrpc.PendingChannelsRequest{}
pendingChanResp, err := node.PendingChannels(ctxt, pendingChansRequest) pendingChanResp, err := node.PendingChannels(ctx, pendingChansRequest)
require.NoError(t.t, err, "unable to query for pending channels") require.NoError(t.t, err, "unable to query for pending channels")
var found bool var found bool
@@ -331,7 +331,7 @@ func assertChannelClosed(ctx context.Context, t *harnessTest,
block := mineBlocks(t, net, 1, expectedTxes)[0] block := mineBlocks(t, net, 1, expectedTxes)[0]
closingTxid, err := net.WaitForChannelClose(ctx, closeUpdates) closingTxid, err := net.WaitForChannelClose(closeUpdates)
require.NoError(t.t, err, "error while waiting for channel close") require.NoError(t.t, err, "error while waiting for channel close")
assertTxInBlock(t, block, closingTxid) assertTxInBlock(t, block, closingTxid)
@@ -395,8 +395,12 @@ func findWaitingCloseChannel(pendingChanResp *lnrpc.PendingChannelsResponse,
// waitForChannelPendingForceClose waits for the node to report that the // waitForChannelPendingForceClose waits for the node to report that the
// channel is pending force close, and that the UTXO nursery is aware of it. // channel is pending force close, and that the UTXO nursery is aware of it.
func waitForChannelPendingForceClose(ctx context.Context, func waitForChannelPendingForceClose(node *lntest.HarnessNode,
node *lntest.HarnessNode, fundingChanPoint *lnrpc.ChannelPoint) error { fundingChanPoint *lnrpc.ChannelPoint) error {
ctxb := context.Background()
ctx, cancel := context.WithTimeout(ctxb, defaultTimeout)
defer cancel()
txid, err := lnrpc.GetChanPointFundingTxid(fundingChanPoint) txid, err := lnrpc.GetChanPointFundingTxid(fundingChanPoint)
if err != nil { if err != nil {
@@ -439,10 +443,14 @@ type lnrpcForceCloseChannel = lnrpc.PendingChannelsResponse_ForceClosedChannel
// waitForNumChannelPendingForceClose waits for the node to report a certain // waitForNumChannelPendingForceClose waits for the node to report a certain
// number of channels in state pending force close. // number of channels in state pending force close.
func waitForNumChannelPendingForceClose(ctx context.Context, func waitForNumChannelPendingForceClose(node *lntest.HarnessNode,
node *lntest.HarnessNode, expectedNum int, expectedNum int,
perChanCheck func(channel *lnrpcForceCloseChannel) error) error { perChanCheck func(channel *lnrpcForceCloseChannel) error) error {
ctxb := context.Background()
ctx, cancel := context.WithTimeout(ctxb, defaultTimeout)
defer cancel()
return wait.NoError(func() error { return wait.NoError(func() error {
resp, err := node.PendingChannels( resp, err := node.PendingChannels(
ctx, &lnrpc.PendingChannelsRequest{}, ctx, &lnrpc.PendingChannelsRequest{},
@@ -477,11 +485,9 @@ func waitForNumChannelPendingForceClose(ctx context.Context,
// the following sweep transaction from the force closing node. // the following sweep transaction from the force closing node.
func cleanupForceClose(t *harnessTest, net *lntest.NetworkHarness, func cleanupForceClose(t *harnessTest, net *lntest.NetworkHarness,
node *lntest.HarnessNode, chanPoint *lnrpc.ChannelPoint) { node *lntest.HarnessNode, chanPoint *lnrpc.ChannelPoint) {
ctxb := context.Background()
// Wait for the channel to be marked pending force close. // Wait for the channel to be marked pending force close.
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) err := waitForChannelPendingForceClose(node, chanPoint)
err := waitForChannelPendingForceClose(ctxt, node, chanPoint)
require.NoError(t.t, err, "channel not pending force close") require.NoError(t.t, err, "channel not pending force close")
// Mine enough blocks for the node to sweep its funds from the force // Mine enough blocks for the node to sweep its funds from the force
@@ -513,9 +519,13 @@ func numOpenChannelsPending(ctxt context.Context,
// assertNumOpenChannelsPending asserts that a pair of nodes have the expected // assertNumOpenChannelsPending asserts that a pair of nodes have the expected
// number of pending channels between them. // number of pending channels between them.
func assertNumOpenChannelsPending(ctxt context.Context, t *harnessTest, func assertNumOpenChannelsPending(t *harnessTest,
alice, bob *lntest.HarnessNode, expected int) { alice, bob *lntest.HarnessNode, expected int) {
ctxb := context.Background()
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
defer cancel()
err := wait.NoError(func() error { err := wait.NoError(func() error {
aliceNumChans, err := numOpenChannelsPending(ctxt, alice) aliceNumChans, err := numOpenChannelsPending(ctxt, alice)
if err != nil { if err != nil {
@@ -972,11 +982,11 @@ func checkPendingHtlcStageAndMaturity(
// assertReports checks that the count of resolutions we have present per // assertReports checks that the count of resolutions we have present per
// type matches a set of expected resolutions. // type matches a set of expected resolutions.
func assertReports(ctxb context.Context, t *harnessTest, func assertReports(t *harnessTest, node *lntest.HarnessNode,
node *lntest.HarnessNode, channelPoint wire.OutPoint, channelPoint wire.OutPoint, expected map[string]*lnrpc.Resolution) {
expected map[string]*lnrpc.Resolution) {
// Get our node's closed channels. // Get our node's closed channels.
ctxb := context.Background()
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout) ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
defer cancel() defer cancel()
@@ -1007,11 +1017,13 @@ func assertReports(ctxb context.Context, t *harnessTest,
} }
// assertSweepFound looks up a sweep in a nodes list of broadcast sweeps. // assertSweepFound looks up a sweep in a nodes list of broadcast sweeps.
func assertSweepFound(ctx context.Context, t *testing.T, node *lntest.HarnessNode, func assertSweepFound(t *testing.T, node *lntest.HarnessNode,
sweep string, verbose bool) { sweep string, verbose bool) {
// List all sweeps that alice's node had broadcast. // List all sweeps that alice's node had broadcast.
ctx, _ = context.WithTimeout(ctx, defaultTimeout) ctxb := context.Background()
ctx, cancel := context.WithTimeout(ctxb, defaultTimeout)
defer cancel()
sweepResp, err := node.WalletKitClient.ListSweeps( sweepResp, err := node.WalletKitClient.ListSweeps(
ctx, &walletrpc.ListSweepsRequest{ ctx, &walletrpc.ListSweepsRequest{
Verbose: verbose, Verbose: verbose,
@@ -1275,7 +1287,7 @@ func assertDLPExecuted(net *lntest.NetworkHarness, t *harnessTest,
// To make sure the nodes are initiating DLP now, we have to manually // To make sure the nodes are initiating DLP now, we have to manually
// re-connect them. // re-connect them.
ctxb := context.Background() ctxb := context.Background()
net.EnsureConnected(ctxb, t.t, carol, dave) net.EnsureConnected(t.t, carol, dave)
// Upon reconnection, the nodes should detect that Dave is out of sync. // Upon reconnection, the nodes should detect that Dave is out of sync.
// Carol should force close the channel using her latest commitment. // Carol should force close the channel using her latest commitment.
@@ -1637,6 +1649,7 @@ func assertActiveHtlcs(nodes []*lntest.HarnessNode, payHashes ...[]byte) error {
func assertNumActiveHtlcsChanPoint(node *lntest.HarnessNode, func assertNumActiveHtlcsChanPoint(node *lntest.HarnessNode,
chanPoint wire.OutPoint, numHtlcs int) error { chanPoint wire.OutPoint, numHtlcs int) error {
ctxb := context.Background() ctxb := context.Background()
req := &lnrpc.ListChannelsRequest{} req := &lnrpc.ListChannelsRequest{}
@@ -1728,12 +1741,13 @@ func getSpendingTxInMempool(t *harnessTest, miner *rpcclient.Client,
// assertTxLabel is a helper function which finds a target tx in our set // assertTxLabel is a helper function which finds a target tx in our set
// of transactions and checks that it has the desired label. // of transactions and checks that it has the desired label.
func assertTxLabel(ctx context.Context, t *harnessTest, func assertTxLabel(t *harnessTest, node *lntest.HarnessNode,
node *lntest.HarnessNode, targetTx, label string) { targetTx, label string) {
// List all transactions relevant to our wallet, and find the tx so that // List all transactions relevant to our wallet, and find the tx so that
// we can check the correct label has been set. // we can check the correct label has been set.
ctxt, cancel := context.WithTimeout(ctx, defaultTimeout) ctxb := context.Background()
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
defer cancel() defer cancel()
txResp, err := node.GetTransactions( txResp, err := node.GetTransactions(
@@ -1752,9 +1766,13 @@ func assertTxLabel(ctx context.Context, t *harnessTest,
// sendAndAssertSuccess sends the given payment requests and asserts that the // sendAndAssertSuccess sends the given payment requests and asserts that the
// payment completes successfully. // payment completes successfully.
func sendAndAssertSuccess(ctx context.Context, t *harnessTest, node *lntest.HarnessNode, func sendAndAssertSuccess(t *harnessTest, node *lntest.HarnessNode,
req *routerrpc.SendPaymentRequest) *lnrpc.Payment { req *routerrpc.SendPaymentRequest) *lnrpc.Payment {
ctxb := context.Background()
ctx, cancel := context.WithTimeout(ctxb, defaultTimeout)
defer cancel()
var result *lnrpc.Payment var result *lnrpc.Payment
err := wait.NoError(func() error { err := wait.NoError(func() error {
stream, err := node.RouterClient.SendPaymentV2(ctx, req) stream, err := node.RouterClient.SendPaymentV2(ctx, req)

View File

@@ -117,10 +117,8 @@ func testSendPaymentAMPInvoiceCase(net *lntest.NetworkHarness, t *harnessTest,
require.NoError(t.t, err) require.NoError(t.t, err)
} }
ctxt, _ := context.WithTimeout(context.Background(), 4*defaultTimeout)
payment := sendAndAssertSuccess( payment := sendAndAssertSuccess(
ctxt, t, ctx.alice, t, ctx.alice, &routerrpc.SendPaymentRequest{
&routerrpc.SendPaymentRequest{
PaymentRequest: addInvoiceResp.PaymentRequest, PaymentRequest: addInvoiceResp.PaymentRequest,
PaymentAddr: externalPayAddr, PaymentAddr: externalPayAddr,
TimeoutSeconds: 60, TimeoutSeconds: 60,
@@ -249,10 +247,8 @@ func testSendPaymentAMP(net *lntest.NetworkHarness, t *harnessTest) {
t.Fatalf("dave policy update: %v", err) t.Fatalf("dave policy update: %v", err)
} }
ctxt, _ := context.WithTimeout(context.Background(), 4*defaultTimeout)
payment := sendAndAssertSuccess( payment := sendAndAssertSuccess(
ctxt, t, ctx.alice, t, ctx.alice, &routerrpc.SendPaymentRequest{
&routerrpc.SendPaymentRequest{
Dest: ctx.bob.PubKey[:], Dest: ctx.bob.PubKey[:],
Amt: int64(paymentAmt), Amt: int64(paymentAmt),
FinalCltvDelta: chainreg.DefaultBitcoinTimeLockDelta, FinalCltvDelta: chainreg.DefaultBitcoinTimeLockDelta,

View File

@@ -505,20 +505,16 @@ func testChannelBackupUpdates(net *lntest.NetworkHarness, t *harnessTest) {
// With Carol up, we'll now connect her to Alice, and open a channel // With Carol up, we'll now connect her to Alice, and open a channel
// between them. // between them.
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, carol, net.Alice)
net.ConnectNodes(ctxt, t.t, carol, net.Alice)
// Next, we'll open two channels between Alice and Carol back to back. // Next, we'll open two channels between Alice and Carol back to back.
var chanPoints []*lnrpc.ChannelPoint var chanPoints []*lnrpc.ChannelPoint
numChans := 2 numChans := 2
chanAmt := btcutil.Amount(1000000) chanAmt := btcutil.Amount(1000000)
for i := 0; i < numChans; i++ { for i := 0; i < numChans; i++ {
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
ctxt, t, net, net.Alice, carol, t, net, net.Alice, carol,
lntest.OpenChannelParams{ lntest.OpenChannelParams{Amt: chanAmt},
Amt: chanAmt,
},
) )
chanPoints = append(chanPoints, chanPoint) chanPoints = append(chanPoints, chanPoint)
@@ -644,20 +640,16 @@ func testExportChannelBackup(net *lntest.NetworkHarness, t *harnessTest) {
// With Carol up, we'll now connect her to Alice, and open a channel // With Carol up, we'll now connect her to Alice, and open a channel
// between them. // between them.
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, carol, net.Alice)
net.ConnectNodes(ctxt, t.t, carol, net.Alice)
// Next, we'll open two channels between Alice and Carol back to back. // Next, we'll open two channels between Alice and Carol back to back.
var chanPoints []*lnrpc.ChannelPoint var chanPoints []*lnrpc.ChannelPoint
numChans := 2 numChans := 2
chanAmt := btcutil.Amount(1000000) chanAmt := btcutil.Amount(1000000)
for i := 0; i < numChans; i++ { for i := 0; i < numChans; i++ {
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
ctxt, t, net, net.Alice, carol, t, net, net.Alice, carol,
lntest.OpenChannelParams{ lntest.OpenChannelParams{Amt: chanAmt},
Amt: chanAmt,
},
) )
chanPoints = append(chanPoints, chanPoint) chanPoints = append(chanPoints, chanPoint)
@@ -884,17 +876,15 @@ func testChanRestoreScenario(t *harnessTest, net *lntest.NetworkHarness,
// Now that our new nodes are created, we'll give them some coins for // Now that our new nodes are created, we'll give them some coins for
// channel opening and anchor sweeping. // channel opening and anchor sweeping.
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, carol)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol)
// For the anchor output case we need two UTXOs for Carol so she can // For the anchor output case we need two UTXOs for Carol so she can
// sweep both the local and remote anchor. // sweep both the local and remote anchor.
if testCase.anchorCommit { if testCase.anchorCommit {
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, carol)
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, dave)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, dave)
var from, to *lntest.HarnessNode var from, to *lntest.HarnessNode
if testCase.initiator { if testCase.initiator {
@@ -905,16 +895,15 @@ func testChanRestoreScenario(t *harnessTest, net *lntest.NetworkHarness,
// Next, we'll connect Dave to Carol, and open a new channel to her // Next, we'll connect Dave to Carol, and open a new channel to her
// with a portion pushed. // with a portion pushed.
net.ConnectNodes(ctxt, t.t, dave, carol) net.ConnectNodes(t.t, dave, carol)
// We will either open a confirmed or unconfirmed channel, depending on // We will either open a confirmed or unconfirmed channel, depending on
// the requirements of the test case. // the requirements of the test case.
var chanPoint *lnrpc.ChannelPoint var chanPoint *lnrpc.ChannelPoint
switch { switch {
case testCase.unconfirmed: case testCase.unconfirmed:
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
_, err := net.OpenPendingChannel( _, err := net.OpenPendingChannel(
ctxt, from, to, chanAmt, pushAmt, from, to, chanAmt, pushAmt,
) )
if err != nil { if err != nil {
t.Fatalf("couldn't open pending channel: %v", err) t.Fatalf("couldn't open pending channel: %v", err)
@@ -943,9 +932,8 @@ func testChanRestoreScenario(t *harnessTest, net *lntest.NetworkHarness,
) )
default: default:
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPoint = openChannelAndAssert( chanPoint = openChannelAndAssert(
ctxt, t, net, from, to, t, net, from, to,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
PushAmt: pushAmt, PushAmt: pushAmt,
@@ -954,7 +942,7 @@ func testChanRestoreScenario(t *harnessTest, net *lntest.NetworkHarness,
) )
// Wait for both sides to see the opened channel. // Wait for both sides to see the opened channel.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err = dave.WaitForNetworkChannelOpen(ctxt, chanPoint) err = dave.WaitForNetworkChannelOpen(ctxt, chanPoint)
if err != nil { if err != nil {
t.Fatalf("dave didn't report channel: %v", err) t.Fatalf("dave didn't report channel: %v", err)
@@ -968,6 +956,8 @@ func testChanRestoreScenario(t *harnessTest, net *lntest.NetworkHarness,
// If both parties should start with existing channel updates, then // If both parties should start with existing channel updates, then
// we'll send+settle an HTLC between 'from' and 'to' now. // we'll send+settle an HTLC between 'from' and 'to' now.
if testCase.channelsUpdated { if testCase.channelsUpdated {
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
invoice := &lnrpc.Invoice{ invoice := &lnrpc.Invoice{
Memo: "testing", Memo: "testing",
Value: 100000, Value: 100000,
@@ -977,9 +967,8 @@ func testChanRestoreScenario(t *harnessTest, net *lntest.NetworkHarness,
t.Fatalf("unable to add invoice: %v", err) t.Fatalf("unable to add invoice: %v", err)
} }
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err = completePaymentRequests( err = completePaymentRequests(
ctxt, from, from.RouterClient, from, from.RouterClient,
[]string{invoiceResp.PaymentRequest}, true, []string{invoiceResp.PaymentRequest}, true,
) )
if err != nil { if err != nil {
@@ -1016,7 +1005,7 @@ func testChanRestoreScenario(t *harnessTest, net *lntest.NetworkHarness,
// Before we start the recovery, we'll record the balances of both // Before we start the recovery, we'll record the balances of both
// Carol and Dave to ensure they both sweep their coins at the end. // Carol and Dave to ensure they both sweep their coins at the end.
balReq := &lnrpc.WalletBalanceRequest{} balReq := &lnrpc.WalletBalanceRequest{}
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
carolBalResp, err := carol.WalletBalance(ctxt, balReq) carolBalResp, err := carol.WalletBalance(ctxt, balReq)
if err != nil { if err != nil {
t.Fatalf("unable to get carol's balance: %v", err) t.Fatalf("unable to get carol's balance: %v", err)
@@ -1089,8 +1078,7 @@ func testChanRestoreScenario(t *harnessTest, net *lntest.NetworkHarness,
// Now that we have our new node up, we expect that it'll // Now that we have our new node up, we expect that it'll
// re-connect to Carol automatically based on the restored // re-connect to Carol automatically based on the restored
// backup. // backup.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.EnsureConnected(t.t, dave, carol)
net.EnsureConnected(ctxt, t.t, dave, carol)
assertTimeLockSwept( assertTimeLockSwept(
net, t, carol, carolStartingBalance, dave, net, t, carol, carolStartingBalance, dave,
@@ -1182,8 +1170,7 @@ func testChanRestoreScenario(t *harnessTest, net *lntest.NetworkHarness,
// Now that we have our new node up, we expect that it'll re-connect to // Now that we have our new node up, we expect that it'll re-connect to
// Carol automatically based on the restored backup. // Carol automatically based on the restored backup.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.EnsureConnected(t.t, dave, carol)
net.EnsureConnected(ctxt, t.t, dave, carol)
// TODO(roasbeef): move dave restarts? // TODO(roasbeef): move dave restarts?

View File

@@ -51,19 +51,17 @@ func testChannelBalance(net *lntest.NetworkHarness, t *harnessTest) {
} }
// Before beginning, make sure alice and bob are connected. // Before beginning, make sure alice and bob are connected.
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.EnsureConnected(t.t, net.Alice, net.Bob)
net.EnsureConnected(ctxt, t.t, net.Alice, net.Bob)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
ctxt, t, net, net.Alice, net.Bob, t, net, net.Alice, net.Bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: amount, Amt: amount,
}, },
) )
// Wait for both Alice and Bob to recognize this new channel. // Wait for both Alice and Bob to recognize this new channel.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err := net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint) err := net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint)
if err != nil { if err != nil {
t.Fatalf("alice didn't advertise channel before "+ t.Fatalf("alice didn't advertise channel before "+
@@ -145,13 +143,11 @@ func testChannelUnsettledBalance(net *lntest.NetworkHarness, t *harnessTest) {
defer shutdownAndAssert(net, t, carol) defer shutdownAndAssert(net, t, carol)
// Connect Alice to Carol. // Connect Alice to Carol.
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, net.Alice, carol)
net.ConnectNodes(ctxb, t.t, net.Alice, carol)
// Open a channel between Alice and Carol. // Open a channel between Alice and Carol.
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointAlice := openChannelAndAssert( chanPointAlice := openChannelAndAssert(
ctxt, t, net, net.Alice, carol, t, net, net.Alice, carol,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -159,7 +155,7 @@ func testChannelUnsettledBalance(net *lntest.NetworkHarness, t *harnessTest) {
// Wait for Alice and Carol to receive the channel edge from the // Wait for Alice and Carol to receive the channel edge from the
// funding manager. // funding manager.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err := net.Alice.WaitForNetworkChannelOpen(ctxt, chanPointAlice) err := net.Alice.WaitForNetworkChannelOpen(ctxt, chanPointAlice)
if err != nil { if err != nil {
t.Fatalf("alice didn't see the alice->carol channel before "+ t.Fatalf("alice didn't see the alice->carol channel before "+
@@ -231,8 +227,7 @@ func testChannelUnsettledBalance(net *lntest.NetworkHarness, t *harnessTest) {
// Check each nodes UnsettledBalance field. // Check each nodes UnsettledBalance field.
for _, node := range nodes { for _, node := range nodes {
// Get channel info for the node. // Get channel info for the node.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) chanInfo, err := getChanInfo(node)
chanInfo, err := getChanInfo(ctxt, node)
if err != nil { if err != nil {
unsettledErr = err unsettledErr = err
return false return false

View File

@@ -73,19 +73,19 @@ func testCommitmentTransactionDeadline(net *lntest.NetworkHarness,
net.SetFeeEstimate(feeRateDefault) net.SetFeeEstimate(feeRateDefault)
// setupNode creates a new node and sends 1 btc to the node. // setupNode creates a new node and sends 1 btc to the node.
setupNode := func(ctx context.Context, name string) *lntest.HarnessNode { setupNode := func(name string) *lntest.HarnessNode {
// Create the node. // Create the node.
args := []string{"--hodl.exit-settle"} args := []string{"--hodl.exit-settle"}
args = append(args, commitTypeAnchors.Args()...) args = append(args, commitTypeAnchors.Args()...)
node := net.NewNode(t.t, name, args) node := net.NewNode(t.t, name, args)
// Send some coins to the node. // Send some coins to the node.
net.SendCoins(ctx, t.t, btcutil.SatoshiPerBitcoin, node) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, node)
// For neutrino backend, we need one additional UTXO to create // For neutrino backend, we need one additional UTXO to create
// the sweeping tx for the remote anchor. // the sweeping tx for the remote anchor.
if net.BackendCfg.Name() == lntest.NeutrinoBackendName { if net.BackendCfg.Name() == lntest.NeutrinoBackendName {
net.SendCoins(ctx, t.t, btcutil.SatoshiPerBitcoin, node) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, node)
} }
return node return node
@@ -98,18 +98,18 @@ func testCommitmentTransactionDeadline(net *lntest.NetworkHarness,
defer cancel() defer cancel()
// Create two nodes, Alice and Bob. // Create two nodes, Alice and Bob.
alice := setupNode(ctxt, "Alice") alice := setupNode("Alice")
defer shutdownAndAssert(net, t, alice) defer shutdownAndAssert(net, t, alice)
bob := setupNode(ctxt, "Bob") bob := setupNode("Bob")
defer shutdownAndAssert(net, t, bob) defer shutdownAndAssert(net, t, bob)
// Connect Alice to Bob. // Connect Alice to Bob.
net.ConnectNodes(ctxt, t.t, alice, bob) net.ConnectNodes(t.t, alice, bob)
// Open a channel between Alice and Bob. // Open a channel between Alice and Bob.
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
ctxt, t, net, alice, bob, lntest.OpenChannelParams{ t, net, alice, bob, lntest.OpenChannelParams{
Amt: 10e6, Amt: 10e6,
PushAmt: 5e6, PushAmt: 5e6,
}, },
@@ -139,9 +139,7 @@ func testCommitmentTransactionDeadline(net *lntest.NetworkHarness,
require.NoError(t.t, err, "htlc mismatch") require.NoError(t.t, err, "htlc mismatch")
// Alice force closes the channel. // Alice force closes the channel.
ctxt, cancel = context.WithTimeout(ctxb, defaultTimeout) _, _, err = net.CloseChannel(alice, chanPoint, true)
defer cancel()
_, _, err = net.CloseChannel(ctxt, alice, chanPoint, true)
require.NoError(t.t, err, "unable to force close channel") require.NoError(t.t, err, "unable to force close channel")
// Now that the channel has been force closed, it should show // Now that the channel has been force closed, it should show
@@ -277,14 +275,11 @@ func testChannelForceClosure(net *lntest.NetworkHarness, t *harnessTest) {
// Each time, we'll send Alice new set of coins in // Each time, we'll send Alice new set of coins in
// order to fund the channel. // order to fund the channel.
ctxt, _ := context.WithTimeout( net.SendCoins(t, btcutil.SatoshiPerBitcoin, alice)
context.Background(), defaultTimeout,
)
net.SendCoins(ctxt, t, btcutil.SatoshiPerBitcoin, alice)
// Also give Carol some coins to allow her to sweep her // Also give Carol some coins to allow her to sweep her
// anchor. // anchor.
net.SendCoins(ctxt, t, btcutil.SatoshiPerBitcoin, carol) net.SendCoins(t, btcutil.SatoshiPerBitcoin, carol)
channelForceClosureTest( channelForceClosureTest(
net, ht, alice, carol, channelType, net, ht, alice, carol, channelType,
@@ -317,17 +312,16 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
// We must let Alice have an open channel before she can send a node // We must let Alice have an open channel before she can send a node
// announcement, so we open a channel with Carol, // announcement, so we open a channel with Carol,
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, alice, carol)
net.ConnectNodes(ctxt, t.t, alice, carol)
// We need one additional UTXO for sweeping the remote anchor. // We need one additional UTXO for sweeping the remote anchor.
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, alice) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, alice)
// Before we start, obtain Carol's current wallet balance, we'll check // Before we start, obtain Carol's current wallet balance, we'll check
// to ensure that at the end of the force closure by Alice, Carol // to ensure that at the end of the force closure by Alice, Carol
// recognizes his new on-chain output. // recognizes his new on-chain output.
carolBalReq := &lnrpc.WalletBalanceRequest{} carolBalReq := &lnrpc.WalletBalanceRequest{}
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
carolBalResp, err := carol.WalletBalance(ctxt, carolBalReq) carolBalResp, err := carol.WalletBalance(ctxt, carolBalReq)
if err != nil { if err != nil {
t.Fatalf("unable to get carol's balance: %v", err) t.Fatalf("unable to get carol's balance: %v", err)
@@ -335,9 +329,8 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
carolStartingBalance := carolBalResp.ConfirmedBalance carolStartingBalance := carolBalResp.ConfirmedBalance
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
ctxt, t, net, alice, carol, t, net, alice, carol,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
PushAmt: pushAmt, PushAmt: pushAmt,
@@ -420,8 +413,7 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
) )
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) aliceChan, err := getChanInfo(alice)
aliceChan, err := getChanInfo(ctxt, alice)
if err != nil { if err != nil {
t.Fatalf("unable to get alice's channel info: %v", err) t.Fatalf("unable to get alice's channel info: %v", err)
} }
@@ -436,8 +428,7 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
const actualFeeRate = 30000 const actualFeeRate = 30000
net.SetFeeEstimate(actualFeeRate) net.SetFeeEstimate(actualFeeRate)
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout) _, closingTxID, err := net.CloseChannel(alice, chanPoint, true)
_, closingTxID, err := net.CloseChannel(ctxt, alice, chanPoint, true)
if err != nil { if err != nil {
t.Fatalf("unable to execute force channel closure: %v", err) t.Fatalf("unable to execute force channel closure: %v", err)
} }
@@ -790,7 +781,7 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
// Check that we can find the commitment sweep in our set of known // Check that we can find the commitment sweep in our set of known
// sweeps, using the simple transaction id ListSweeps output. // sweeps, using the simple transaction id ListSweeps output.
assertSweepFound(ctxb, t.t, alice, sweepingTXID.String(), false) assertSweepFound(t.t, alice, sweepingTXID.String(), false)
// Restart Alice to ensure that she resumes watching the finalized // Restart Alice to ensure that she resumes watching the finalized
// commitment sweep txid. // commitment sweep txid.
@@ -1223,7 +1214,7 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
// Check that we can find the htlc sweep in our set of sweeps using // Check that we can find the htlc sweep in our set of sweeps using
// the verbose output of the listsweeps output. // the verbose output of the listsweeps output.
assertSweepFound(ctxb, t.t, alice, htlcSweepTx.Hash().String(), true) assertSweepFound(t.t, alice, htlcSweepTx.Hash().String(), true)
// The following restart checks to ensure that the nursery store is // The following restart checks to ensure that the nursery store is
// storing the txid of the previously broadcast htlc sweep txn, and that // storing the txid of the previously broadcast htlc sweep txn, and that
@@ -1341,8 +1332,8 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
// Finally, we check that alice and carol have the set of resolutions // Finally, we check that alice and carol have the set of resolutions
// we expect. // we expect.
assertReports(ctxb, t, alice, op, aliceReports) assertReports(t, alice, op, aliceReports)
assertReports(ctxb, t, carol, op, carolReports) assertReports(t, carol, op, carolReports)
} }
// padCLTV is a small helper function that pads a cltv value with a block // padCLTV is a small helper function that pads a cltv value with a block
@@ -1419,11 +1410,9 @@ func testFailingChannel(net *lntest.NetworkHarness, t *harnessTest) {
defer shutdownAndAssert(net, t, carol) defer shutdownAndAssert(net, t, carol)
// Let Alice connect and open a channel to Carol, // Let Alice connect and open a channel to Carol,
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, net.Alice, carol)
net.ConnectNodes(ctxt, t.t, net.Alice, carol)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
ctxt, t, net, net.Alice, carol, t, net, net.Alice, carol,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -1437,7 +1426,7 @@ func testFailingChannel(net *lntest.NetworkHarness, t *harnessTest) {
RPreimage: preimage, RPreimage: preimage,
Value: paymentAmt, Value: paymentAmt,
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
resp, err := carol.AddInvoice(ctxt, invoice) resp, err := carol.AddInvoice(ctxt, invoice)
if err != nil { if err != nil {
t.Fatalf("unable to add invoice: %v", err) t.Fatalf("unable to add invoice: %v", err)
@@ -1454,9 +1443,8 @@ func testFailingChannel(net *lntest.NetworkHarness, t *harnessTest) {
// Send the payment from Alice to Carol. We expect Carol to attempt to // Send the payment from Alice to Carol. We expect Carol to attempt to
// settle this payment with the wrong preimage. // settle this payment with the wrong preimage.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = completePaymentRequests( err = completePaymentRequests(
ctxt, net.Alice, net.Alice.RouterClient, carolPayReqs, false, net.Alice, net.Alice.RouterClient, carolPayReqs, false,
) )
if err != nil { if err != nil {
t.Fatalf("unable to send payments: %v", err) t.Fatalf("unable to send payments: %v", err)

View File

@@ -45,18 +45,16 @@ func testUpdateChanStatus(net *lntest.NetworkHarness, t *harnessTest) {
defer shutdownAndAssert(net, t, bob) defer shutdownAndAssert(net, t, bob)
// Connect Alice to Bob. // Connect Alice to Bob.
net.ConnectNodes(ctxb, t.t, alice, bob) net.ConnectNodes(t.t, alice, bob)
// Give Alice some coins so she can fund a channel. // Give Alice some coins so she can fund a channel.
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, alice)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, alice)
// Open a channel with 100k satoshis between Alice and Bob with Alice // Open a channel with 100k satoshis between Alice and Bob with Alice
// being the sole funder of the channel. // being the sole funder of the channel.
chanAmt := btcutil.Amount(100000) chanAmt := btcutil.Amount(100000)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
ctxt, t, net, alice, bob, t, net, alice, bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -64,7 +62,7 @@ func testUpdateChanStatus(net *lntest.NetworkHarness, t *harnessTest) {
// Wait for Alice and Bob to receive the channel edge from the // Wait for Alice and Bob to receive the channel edge from the
// funding manager. // funding manager.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err := alice.WaitForNetworkChannelOpen(ctxt, chanPoint) err := alice.WaitForNetworkChannelOpen(ctxt, chanPoint)
if err != nil { if err != nil {
t.Fatalf("alice didn't see the alice->bob channel before "+ t.Fatalf("alice didn't see the alice->bob channel before "+
@@ -84,11 +82,8 @@ func testUpdateChanStatus(net *lntest.NetworkHarness, t *harnessTest) {
carol := net.NewNode(t.t, "Carol", nil) carol := net.NewNode(t.t, "Carol", nil)
defer shutdownAndAssert(net, t, carol) defer shutdownAndAssert(net, t, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, alice, carol)
net.ConnectNodes(ctxt, t.t, alice, carol) net.ConnectNodes(t.t, bob, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.ConnectNodes(ctxt, t.t, bob, carol)
carolSub := subscribeGraphNotifications(ctxb, t, carol) carolSub := subscribeGraphNotifications(ctxb, t, carol)
defer close(carolSub.quit) defer close(carolSub.quit)
@@ -195,8 +190,7 @@ func testUpdateChanStatus(net *lntest.NetworkHarness, t *harnessTest) {
// disconnections from automatically disabling the channel again // disconnections from automatically disabling the channel again
// (we don't want to clutter the network with channels that are // (we don't want to clutter the network with channels that are
// falsely advertised as enabled when they don't work). // falsely advertised as enabled when they don't work).
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) if err := net.DisconnectNodes(alice, bob); err != nil {
if err := net.DisconnectNodes(ctxt, alice, bob); err != nil {
t.Fatalf("unable to disconnect Alice from Bob: %v", err) t.Fatalf("unable to disconnect Alice from Bob: %v", err)
} }
expectedPolicy.Disabled = true expectedPolicy.Disabled = true
@@ -209,8 +203,7 @@ func testUpdateChanStatus(net *lntest.NetworkHarness, t *harnessTest) {
) )
// Reconnecting the nodes should propagate a "Disabled = false" update. // Reconnecting the nodes should propagate a "Disabled = false" update.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.EnsureConnected(t.t, alice, bob)
net.EnsureConnected(ctxt, t.t, alice, bob)
expectedPolicy.Disabled = false expectedPolicy.Disabled = false
waitForChannelUpdate( waitForChannelUpdate(
t, carolSub, t, carolSub,
@@ -236,8 +229,7 @@ func testUpdateChanStatus(net *lntest.NetworkHarness, t *harnessTest) {
}, },
) )
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) if err := net.DisconnectNodes(alice, bob); err != nil {
if err := net.DisconnectNodes(ctxt, alice, bob); err != nil {
t.Fatalf("unable to disconnect Alice from Bob: %v", err) t.Fatalf("unable to disconnect Alice from Bob: %v", err)
} }
@@ -253,8 +245,7 @@ func testUpdateChanStatus(net *lntest.NetworkHarness, t *harnessTest) {
// Bob sends a "Disabled = false" update upon detecting the // Bob sends a "Disabled = false" update upon detecting the
// reconnect. // reconnect.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.EnsureConnected(t.t, alice, bob)
net.EnsureConnected(ctxt, t.t, alice, bob)
expectedPolicy.Disabled = false expectedPolicy.Disabled = false
waitForChannelUpdate( waitForChannelUpdate(
t, carolSub, t, carolSub,
@@ -268,8 +259,7 @@ func testUpdateChanStatus(net *lntest.NetworkHarness, t *harnessTest) {
// note the asymmetry between manual enable and manual disable! // note the asymmetry between manual enable and manual disable!
assertEdgeDisabled(alice, chanPoint, true) assertEdgeDisabled(alice, chanPoint, true)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) if err := net.DisconnectNodes(alice, bob); err != nil {
if err := net.DisconnectNodes(ctxt, alice, bob); err != nil {
t.Fatalf("unable to disconnect Alice from Bob: %v", err) t.Fatalf("unable to disconnect Alice from Bob: %v", err)
} }
@@ -287,7 +277,7 @@ func testUpdateChanStatus(net *lntest.NetworkHarness, t *harnessTest) {
// BOTH Alice and Bob should set the channel state back to "enabled" // BOTH Alice and Bob should set the channel state back to "enabled"
// on reconnect. // on reconnect.
sendReq(alice, chanPoint, routerrpc.ChanStatusAction_AUTO) sendReq(alice, chanPoint, routerrpc.ChanStatusAction_AUTO)
net.EnsureConnected(ctxt, t.t, alice, bob) net.EnsureConnected(t.t, alice, bob)
expectedPolicy.Disabled = false expectedPolicy.Disabled = false
waitForChannelUpdate( waitForChannelUpdate(
t, carolSub, t, carolSub,
@@ -308,9 +298,8 @@ func testUnannouncedChannels(net *lntest.NetworkHarness, t *harnessTest) {
// Open a channel between Alice and Bob, ensuring the // Open a channel between Alice and Bob, ensuring the
// channel has been opened properly. // channel has been opened properly.
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
chanOpenUpdate := openChannelStream( chanOpenUpdate := openChannelStream(
ctxt, t, net, net.Alice, net.Bob, t, net, net.Alice, net.Bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: amount, Amt: amount,
}, },
@@ -322,8 +311,7 @@ func testUnannouncedChannels(net *lntest.NetworkHarness, t *harnessTest) {
// One block is enough to make the channel ready for use, since the // One block is enough to make the channel ready for use, since the
// nodes have defaultNumConfs=1 set. // nodes have defaultNumConfs=1 set.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) fundingChanPoint, err := net.WaitForChannelOpen(chanOpenUpdate)
fundingChanPoint, err := net.WaitForChannelOpen(ctxt, chanOpenUpdate)
if err != nil { if err != nil {
t.Fatalf("error while waiting for channel open: %v", err) t.Fatalf("error while waiting for channel open: %v", err)
} }
@@ -332,7 +320,7 @@ func testUnannouncedChannels(net *lntest.NetworkHarness, t *harnessTest) {
req := &lnrpc.ChannelGraphRequest{ req := &lnrpc.ChannelGraphRequest{
IncludeUnannounced: true, IncludeUnannounced: true,
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
chanGraph, err := net.Alice.DescribeGraph(ctxt, req) chanGraph, err := net.Alice.DescribeGraph(ctxt, req)
if err != nil { if err != nil {
t.Fatalf("unable to query alice's graph: %v", err) t.Fatalf("unable to query alice's graph: %v", err)
@@ -445,16 +433,13 @@ func testGraphTopologyNtfns(net *lntest.NetworkHarness, t *harnessTest, pinned b
defer shutdownAndAssert(net, t, alice) defer shutdownAndAssert(net, t, alice)
// Connect Alice and Bob. // Connect Alice and Bob.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.EnsureConnected(t.t, alice, bob)
net.EnsureConnected(ctxt, t.t, alice, bob)
// Alice stimmy. // Alice stimmy.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, alice)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, alice)
// Bob stimmy. // Bob stimmy.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, bob)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, bob)
// Assert that Bob has the correct sync type before proceeeding. // Assert that Bob has the correct sync type before proceeeding.
if pinned { if pinned {
@@ -472,9 +457,8 @@ func testGraphTopologyNtfns(net *lntest.NetworkHarness, t *harnessTest, pinned b
defer close(graphSub.quit) defer close(graphSub.quit)
// Open a new channel between Alice and Bob. // Open a new channel between Alice and Bob.
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
ctxt, t, net, alice, bob, t, net, alice, bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -596,18 +580,15 @@ out:
// that a node that does not have any channels open is ignored, so first // that a node that does not have any channels open is ignored, so first
// we disconnect Alice and Bob, open a channel between Bob and Carol, // we disconnect Alice and Bob, open a channel between Bob and Carol,
// and finally connect Alice to Bob again. // and finally connect Alice to Bob again.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) if err := net.DisconnectNodes(alice, bob); err != nil {
if err := net.DisconnectNodes(ctxt, alice, bob); err != nil {
t.Fatalf("unable to disconnect alice and bob: %v", err) t.Fatalf("unable to disconnect alice and bob: %v", err)
} }
carol := net.NewNode(t.t, "Carol", nil) carol := net.NewNode(t.t, "Carol", nil)
defer shutdownAndAssert(net, t, carol) defer shutdownAndAssert(net, t, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, bob, carol)
net.ConnectNodes(ctxt, t.t, bob, carol)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPoint = openChannelAndAssert( chanPoint = openChannelAndAssert(
ctxt, t, net, bob, carol, t, net, bob, carol,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -619,8 +600,7 @@ out:
// and Carol. Note that we will also receive a node announcement from // and Carol. Note that we will also receive a node announcement from
// Bob, since a node will update its node announcement after a new // Bob, since a node will update its node announcement after a new
// channel is opened. // channel is opened.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.EnsureConnected(t.t, alice, bob)
net.EnsureConnected(ctxt, t.t, alice, bob)
// We should receive an update advertising the newly connected node, // We should receive an update advertising the newly connected node,
// Bob's new node announcement, and the channel between Bob and Carol. // Bob's new node announcement, and the channel between Bob and Carol.
@@ -702,8 +682,7 @@ func testNodeAnnouncement(net *lntest.NetworkHarness, t *harnessTest) {
// We must let Dave have an open channel before he can send a node // We must let Dave have an open channel before he can send a node
// announcement, so we open a channel with Bob, // announcement, so we open a channel with Bob,
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, net.Bob, dave)
net.ConnectNodes(ctxt, t.t, net.Bob, dave)
// Alice shouldn't receive any new updates yet since the channel has yet // Alice shouldn't receive any new updates yet since the channel has yet
// to be opened. // to be opened.
@@ -716,9 +695,8 @@ func testNodeAnnouncement(net *lntest.NetworkHarness, t *harnessTest) {
// We'll then go ahead and open a channel between Bob and Dave. This // We'll then go ahead and open a channel between Bob and Dave. This
// ensures that Alice receives the node announcement from Bob as part of // ensures that Alice receives the node announcement from Bob as part of
// the announcement broadcast. // the announcement broadcast.
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
ctxt, t, net, net.Bob, dave, t, net, net.Bob, dave,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: 1000000, Amt: 1000000,
}, },

View File

@@ -37,9 +37,8 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
pushAmt := chanAmt / 2 pushAmt := chanAmt / 2
// Create a channel Alice->Bob. // Create a channel Alice->Bob.
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
ctxt, t, net, net.Alice, net.Bob, t, net, net.Alice, net.Bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
PushAmt: pushAmt, PushAmt: pushAmt,
@@ -81,7 +80,7 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
) )
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err := net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint) err := net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint)
if err != nil { if err != nil {
t.Fatalf("alice didn't report channel: %v", err) t.Fatalf("alice didn't report channel: %v", err)
@@ -110,19 +109,17 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
nodes = append(nodes, carol) nodes = append(nodes, carol)
// Send some coins to Carol that can be used for channel funding. // Send some coins to Carol that can be used for channel funding.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, carol)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol)
net.ConnectNodes(ctxb, t.t, carol, net.Bob) net.ConnectNodes(t.t, carol, net.Bob)
// Open the channel Carol->Bob with a custom min_htlc value set. Since // Open the channel Carol->Bob with a custom min_htlc value set. Since
// Carol is opening the channel, she will require Bob to not forward // Carol is opening the channel, she will require Bob to not forward
// HTLCs smaller than this value, and hence he should advertise it as // HTLCs smaller than this value, and hence he should advertise it as
// part of his ChannelUpdate. // part of his ChannelUpdate.
const customMinHtlc = 5000 const customMinHtlc = 5000
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPoint2 := openChannelAndAssert( chanPoint2 := openChannelAndAssert(
ctxt, t, net, carol, net.Bob, t, net, carol, net.Bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
PushAmt: pushAmt, PushAmt: pushAmt,
@@ -197,9 +194,8 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
t.Fatalf("unable to add invoice: %v", err) t.Fatalf("unable to add invoice: %v", err)
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = completePaymentRequests( err = completePaymentRequests(
ctxt, net.Alice, net.Alice.RouterClient, net.Alice, net.Alice.RouterClient,
[]string{resp.PaymentRequest}, true, []string{resp.PaymentRequest}, true,
) )
@@ -380,9 +376,8 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
t.Fatalf("unable to add invoice: %v", err) t.Fatalf("unable to add invoice: %v", err)
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = completePaymentRequests( err = completePaymentRequests(
ctxt, net.Alice, net.Alice.RouterClient, net.Alice, net.Alice.RouterClient,
[]string{resp.PaymentRequest}, true, []string{resp.PaymentRequest}, true,
) )
if err != nil { if err != nil {
@@ -390,10 +385,9 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
} }
// We'll now open a channel from Alice directly to Carol. // We'll now open a channel from Alice directly to Carol.
net.ConnectNodes(ctxb, t.t, net.Alice, carol) net.ConnectNodes(t.t, net.Alice, carol)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPoint3 := openChannelAndAssert( chanPoint3 := openChannelAndAssert(
ctxt, t, net, net.Alice, carol, t, net, net.Alice, carol,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
PushAmt: pushAmt, PushAmt: pushAmt,

View File

@@ -100,15 +100,13 @@ func testEtcdFailoverCase(net *lntest.NetworkHarness, ht *harnessTest,
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
info1, err := carol1.GetInfo(ctxt, &lnrpc.GetInfoRequest{}) info1, err := carol1.GetInfo(ctxt, &lnrpc.GetInfoRequest{})
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(ht.t, carol1, net.Alice)
net.ConnectNodes(ctxt, ht.t, carol1, net.Alice)
// Open a channel with 100k satoshis between Carol and Alice with Alice // Open a channel with 100k satoshis between Carol and Alice with Alice
// being the sole funder of the channel. // being the sole funder of the channel.
chanAmt := btcutil.Amount(100000) chanAmt := btcutil.Amount(100000)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
_ = openChannelAndAssert( _ = openChannelAndAssert(
ctxt, ht, net, net.Alice, carol1, ht, net, net.Alice, carol1,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -131,11 +129,13 @@ func testEtcdFailoverCase(net *lntest.NetworkHarness, ht *harnessTest,
ht.Fatalf("Carol-2 is unable to create payment requests: %v", ht.Fatalf("Carol-2 is unable to create payment requests: %v",
err) err)
} }
sendAndAssertSuccess(ctxb, ht, net.Alice, &routerrpc.SendPaymentRequest{ sendAndAssertSuccess(
PaymentRequest: payReqs[0], ht, net.Alice, &routerrpc.SendPaymentRequest{
TimeoutSeconds: 60, PaymentRequest: payReqs[0],
FeeLimitSat: noFeeLimitMsat, TimeoutSeconds: 60,
}) FeeLimitSat: noFeeLimitMsat,
},
)
// Shut down or kill Carol-1 and wait for Carol-2 to become the leader. // Shut down or kill Carol-1 and wait for Carol-2 to become the leader.
var failoverTimeout time.Duration var failoverTimeout time.Duration
@@ -179,11 +179,13 @@ func testEtcdFailoverCase(net *lntest.NetworkHarness, ht *harnessTest,
// Now let Alice pay the second invoice but this time we expect Carol-2 // Now let Alice pay the second invoice but this time we expect Carol-2
// to receive the payment. // to receive the payment.
sendAndAssertSuccess(ctxb, ht, net.Alice, &routerrpc.SendPaymentRequest{ sendAndAssertSuccess(
PaymentRequest: payReqs[1], ht, net.Alice, &routerrpc.SendPaymentRequest{
TimeoutSeconds: 60, PaymentRequest: payReqs[1],
FeeLimitSat: noFeeLimitMsat, TimeoutSeconds: 60,
}) FeeLimitSat: noFeeLimitMsat,
},
)
shutdownAndAssert(net, ht, carol2) shutdownAndAssert(net, ht, carol2)
} }

View File

@@ -67,8 +67,8 @@ func testForwardInterceptor(net *lntest.NetworkHarness, t *harnessTest) {
testContext.waitForChannels() testContext.waitForChannels()
// Connect the interceptor. // Connect the interceptor.
ctx := context.Background() ctxb := context.Background()
ctxt, cancelInterceptor := context.WithTimeout(ctx, defaultTimeout) ctxt, cancelInterceptor := context.WithTimeout(ctxb, defaultTimeout)
interceptor, err := testContext.bob.RouterClient.HtlcInterceptor(ctxt) interceptor, err := testContext.bob.RouterClient.HtlcInterceptor(ctxt)
require.NoError(t.t, err, "failed to create HtlcInterceptor") require.NoError(t.t, err, "failed to create HtlcInterceptor")
@@ -230,8 +230,7 @@ func testForwardInterceptor(net *lntest.NetworkHarness, t *harnessTest) {
restartAlice, err := net.SuspendNode(alice) restartAlice, err := net.SuspendNode(alice)
require.NoError(t.t, err, "failed to suspend alice") require.NoError(t.t, err, "failed to suspend alice")
ctx = context.Background() ctxt, cancelInterceptor = context.WithTimeout(ctxb, defaultTimeout)
ctxt, cancelInterceptor = context.WithTimeout(ctx, defaultTimeout)
defer cancelInterceptor() defer cancelInterceptor()
interceptor, err = testContext.bob.RouterClient.HtlcInterceptor(ctxt) interceptor, err = testContext.bob.RouterClient.HtlcInterceptor(ctxt)
require.NoError(t.t, err, "failed to create HtlcInterceptor") require.NoError(t.t, err, "failed to create HtlcInterceptor")
@@ -259,7 +258,7 @@ func testForwardInterceptor(net *lntest.NetworkHarness, t *harnessTest) {
}() }()
err = wait.Predicate(func() bool { err = wait.Predicate(func() bool {
channels, err := bob.ListChannels(ctx, &lnrpc.ListChannelsRequest{ channels, err := bob.ListChannels(ctxt, &lnrpc.ListChannelsRequest{
ActiveOnly: true, Peer: alice.PubKey[:], ActiveOnly: true, Peer: alice.PubKey[:],
}) })
return err == nil && len(channels.Channels) > 0 return err == nil && len(channels.Channels) > 0
@@ -286,14 +285,11 @@ func newInterceptorTestContext(t *harnessTest,
net *lntest.NetworkHarness, net *lntest.NetworkHarness,
alice, bob, carol *lntest.HarnessNode) *interceptorTestContext { alice, bob, carol *lntest.HarnessNode) *interceptorTestContext {
ctxb := context.Background()
// Connect nodes // Connect nodes
nodes := []*lntest.HarnessNode{alice, bob, carol} nodes := []*lntest.HarnessNode{alice, bob, carol}
for i := 0; i < len(nodes); i++ { for i := 0; i < len(nodes); i++ {
for j := i + 1; j < len(nodes); j++ { for j := i + 1; j < len(nodes); j++ {
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.EnsureConnected(t.t, nodes[i], nodes[j])
net.EnsureConnected(ctxt, t.t, nodes[i], nodes[j])
} }
} }
@@ -354,14 +350,10 @@ func (c *interceptorTestContext) prepareTestCases() []*interceptorTestCase {
func (c *interceptorTestContext) openChannel(from, to *lntest.HarnessNode, func (c *interceptorTestContext) openChannel(from, to *lntest.HarnessNode,
chanSize btcutil.Amount) { chanSize btcutil.Amount) {
ctxb := context.Background() c.net.SendCoins(c.t.t, btcutil.SatoshiPerBitcoin, from)
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
c.net.SendCoins(ctxt, c.t.t, btcutil.SatoshiPerBitcoin, from)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
ctxt, c.t, c.net, from, to, c.t, c.net, from, to,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanSize, Amt: chanSize,
}, },

View File

@@ -27,8 +27,6 @@ import (
// transaction was mined. // transaction was mined.
func testBasicChannelFunding(net *lntest.NetworkHarness, t *harnessTest) { func testBasicChannelFunding(net *lntest.NetworkHarness, t *harnessTest) {
ctxb := context.Background()
// Run through the test with combinations of all the different // Run through the test with combinations of all the different
// commitment types. // commitment types.
allTypes := []commitType{ allTypes := []commitType{
@@ -49,8 +47,7 @@ func testBasicChannelFunding(net *lntest.NetworkHarness, t *harnessTest) {
// Each time, we'll send Carol a new set of coins in order to // Each time, we'll send Carol a new set of coins in order to
// fund the channel. // fund the channel.
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, carol)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol)
daveArgs := daveCommitType.Args() daveArgs := daveCommitType.Args()
dave := net.NewNode(t.t, "Dave", daveArgs) dave := net.NewNode(t.t, "Dave", daveArgs)
@@ -58,8 +55,7 @@ func testBasicChannelFunding(net *lntest.NetworkHarness, t *harnessTest) {
// Before we start the test, we'll ensure both sides are // Before we start the test, we'll ensure both sides are
// connected to the funding flow can properly be executed. // connected to the funding flow can properly be executed.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.EnsureConnected(t.t, carol, dave)
net.EnsureConnected(ctxt, t.t, carol, dave)
carolChan, daveChan, closeChan, err := basicChannelFundingTest( carolChan, daveChan, closeChan, err := basicChannelFundingTest(
t, net, carol, dave, nil, t, net, carol, dave, nil,
@@ -202,9 +198,8 @@ func basicChannelFundingTest(t *harnessTest, net *lntest.NetworkHarness,
// assertions will be executed to ensure the funding process completed // assertions will be executed to ensure the funding process completed
// successfully. // successfully.
ctxb := context.Background() ctxb := context.Background()
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
ctxt, t, net, alice, bob, t, net, alice, bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
PushAmt: pushAmt, PushAmt: pushAmt,
@@ -213,7 +208,7 @@ func basicChannelFundingTest(t *harnessTest, net *lntest.NetworkHarness,
}, },
) )
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err := alice.WaitForNetworkChannelOpen(ctxt, chanPoint) err := alice.WaitForNetworkChannelOpen(ctxt, chanPoint)
require.NoError(t.t, err, "alice didn't report channel") require.NoError(t.t, err, "alice didn't report channel")
@@ -266,15 +261,14 @@ func testUnconfirmedChannelFunding(net *lntest.NetworkHarness, t *harnessTest) {
defer shutdownAndAssert(net, t, carol) defer shutdownAndAssert(net, t, carol)
// We'll send her some confirmed funds. // We'll send her some confirmed funds.
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(t.t, 2*chanAmt, carol)
net.SendCoins(ctxt, t.t, 2*chanAmt, carol)
// Now let Carol send some funds to herself, making a unconfirmed // Now let Carol send some funds to herself, making a unconfirmed
// change output. // change output.
addrReq := &lnrpc.NewAddressRequest{ addrReq := &lnrpc.NewAddressRequest{
Type: lnrpc.AddressType_WITNESS_PUBKEY_HASH, Type: lnrpc.AddressType_WITNESS_PUBKEY_HASH,
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
resp, err := carol.NewAddress(ctxt, addrReq) resp, err := carol.NewAddress(ctxt, addrReq)
require.NoError(t.t, err, "unable to get new address") require.NoError(t.t, err, "unable to get new address")
@@ -293,12 +287,10 @@ func testUnconfirmedChannelFunding(net *lntest.NetworkHarness, t *harnessTest) {
// Now, we'll connect her to Alice so that they can open a channel // Now, we'll connect her to Alice so that they can open a channel
// together. The funding flow should select Carol's unconfirmed output // together. The funding flow should select Carol's unconfirmed output
// as she doesn't have any other funds since it's a new node. // as she doesn't have any other funds since it's a new node.
net.ConnectNodes(t.t, carol, net.Alice)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.ConnectNodes(ctxt, t.t, carol, net.Alice)
chanOpenUpdate := openChannelStream( chanOpenUpdate := openChannelStream(
ctxt, t, net, carol, net.Alice, t, net, carol, net.Alice,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
PushAmt: pushAmt, PushAmt: pushAmt,
@@ -362,8 +354,7 @@ func testUnconfirmedChannelFunding(net *lntest.NetworkHarness, t *harnessTest) {
// parties. Two transactions should be mined, the unconfirmed spend and // parties. Two transactions should be mined, the unconfirmed spend and
// the funding tx. // the funding tx.
mineBlocks(t, net, 6, 2) mineBlocks(t, net, 6, 2)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) chanPoint, err := net.WaitForChannelOpen(chanOpenUpdate)
chanPoint, err := net.WaitForChannelOpen(ctxt, chanOpenUpdate)
require.NoError(t.t, err, "error while waitinng for channel open") require.NoError(t.t, err, "error while waitinng for channel open")
// With the channel open, we'll check the balances on each side of the // With the channel open, we'll check the balances on each side of the
@@ -391,13 +382,11 @@ func testExternalFundingChanPoint(net *lntest.NetworkHarness, t *harnessTest) {
// Carol will be funding the channel, so we'll send some coins over to // Carol will be funding the channel, so we'll send some coins over to
// her and ensure they have enough confirmations before we proceed. // her and ensure they have enough confirmations before we proceed.
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, carol)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol)
// Before we start the test, we'll ensure both sides are connected to // Before we start the test, we'll ensure both sides are connected to
// the funding flow can properly be executed. // the funding flow can properly be executed.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.EnsureConnected(t.t, carol, dave)
net.EnsureConnected(ctxt, t.t, carol, dave)
// At this point, we're ready to simulate our external channel funding // At this point, we're ready to simulate our external channel funding
// flow. To start with, we'll create a pending channel with a shim for // flow. To start with, we'll create a pending channel with a shim for
@@ -408,13 +397,12 @@ func testExternalFundingChanPoint(net *lntest.NetworkHarness, t *harnessTest) {
net, t, carol, dave, chanSize, thawHeight, 1, false, net, t, carol, dave, chanSize, thawHeight, 1, false,
) )
_ = openChannelStream( _ = openChannelStream(
ctxb, t, net, carol, dave, lntest.OpenChannelParams{ t, net, carol, dave, lntest.OpenChannelParams{
Amt: chanSize, Amt: chanSize,
FundingShim: fundingShim1, FundingShim: fundingShim1,
}, },
) )
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) assertNumOpenChannelsPending(t, carol, dave, 1)
assertNumOpenChannelsPending(ctxt, t, carol, dave, 1)
// That channel is now pending forever and normally would saturate the // That channel is now pending forever and normally would saturate the
// max pending channel limit for both nodes. But because the channel is // max pending channel limit for both nodes. But because the channel is
@@ -449,13 +437,11 @@ func testExternalFundingChanPoint(net *lntest.NetworkHarness, t *harnessTest) {
Memo: "new chans", Memo: "new chans",
Value: int64(payAmt), Value: int64(payAmt),
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
resp, err := dave.AddInvoice(ctxt, invoice) resp, err := dave.AddInvoice(ctxt, invoice)
require.NoError(t.t, err) require.NoError(t.t, err)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = completePaymentRequests( err = completePaymentRequests(
ctxt, carol, carol.RouterClient, []string{resp.PaymentRequest}, carol, carol.RouterClient, []string{resp.PaymentRequest}, true,
true,
) )
require.NoError(t.t, err) require.NoError(t.t, err)
@@ -466,8 +452,7 @@ func testExternalFundingChanPoint(net *lntest.NetworkHarness, t *harnessTest) {
// First, we'll try to close the channel as Carol, the initiator. This // First, we'll try to close the channel as Carol, the initiator. This
// should fail as a frozen channel only allows the responder to // should fail as a frozen channel only allows the responder to
// initiate a channel close. // initiate a channel close.
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout) _, _, err = net.CloseChannel(carol, chanPoint2, false)
_, _, err = net.CloseChannel(ctxt, carol, chanPoint2, false)
require.Error(t.t, err, require.Error(t.t, err,
"carol wasn't denied a co-op close attempt "+ "carol wasn't denied a co-op close attempt "+
"for a frozen channel", "for a frozen channel",
@@ -479,8 +464,7 @@ func testExternalFundingChanPoint(net *lntest.NetworkHarness, t *harnessTest) {
// As a last step, we check if we still have the pending channel hanging // As a last step, we check if we still have the pending channel hanging
// around because we never published the funding TX. // around because we never published the funding TX.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) assertNumOpenChannelsPending(t, carol, dave, 1)
assertNumOpenChannelsPending(ctxt, t, carol, dave, 1)
// Let's make sure we can abandon it. // Let's make sure we can abandon it.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
@@ -497,7 +481,7 @@ func testExternalFundingChanPoint(net *lntest.NetworkHarness, t *harnessTest) {
require.NoError(t.t, err) require.NoError(t.t, err)
// It should now not appear in the pending channels anymore. // It should now not appear in the pending channels anymore.
assertNumOpenChannelsPending(ctxt, t, carol, dave, 0) assertNumOpenChannelsPending(t, carol, dave, 0)
} }
// testFundingPersistence is intended to ensure that the Funding Manager // testFundingPersistence is intended to ensure that the Funding Manager
@@ -507,8 +491,6 @@ func testExternalFundingChanPoint(net *lntest.NetworkHarness, t *harnessTest) {
// testFundingPersistence mirrors testBasicChannelFunding, but adds restarts // testFundingPersistence mirrors testBasicChannelFunding, but adds restarts
// and checks for the state of channels with unconfirmed funding transactions. // and checks for the state of channels with unconfirmed funding transactions.
func testChannelFundingPersistence(net *lntest.NetworkHarness, t *harnessTest) { func testChannelFundingPersistence(net *lntest.NetworkHarness, t *harnessTest) {
ctxb := context.Background()
chanAmt := funding.MaxBtcFundingAmount chanAmt := funding.MaxBtcFundingAmount
pushAmt := btcutil.Amount(0) pushAmt := btcutil.Amount(0)
@@ -522,14 +504,13 @@ func testChannelFundingPersistence(net *lntest.NetworkHarness, t *harnessTest) {
// Clean up carol's node when the test finishes. // Clean up carol's node when the test finishes.
defer shutdownAndAssert(net, t, carol) defer shutdownAndAssert(net, t, carol)
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, net.Alice, carol)
net.ConnectNodes(ctxt, t.t, net.Alice, carol)
// Create a new channel that requires 5 confs before it's considered // Create a new channel that requires 5 confs before it's considered
// open, then broadcast the funding transaction // open, then broadcast the funding transaction
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) pendingUpdate, err := net.OpenPendingChannel(
pendingUpdate, err := net.OpenPendingChannel(ctxt, net.Alice, carol, net.Alice, carol, chanAmt, pushAmt,
chanAmt, pushAmt) )
if err != nil { if err != nil {
t.Fatalf("unable to open channel: %v", err) t.Fatalf("unable to open channel: %v", err)
} }
@@ -537,8 +518,7 @@ func testChannelFundingPersistence(net *lntest.NetworkHarness, t *harnessTest) {
// At this point, the channel's funding transaction will have been // At this point, the channel's funding transaction will have been
// broadcast, but not confirmed. Alice and Bob's nodes should reflect // broadcast, but not confirmed. Alice and Bob's nodes should reflect
// this when queried via RPC. // this when queried via RPC.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) assertNumOpenChannelsPending(t, net.Alice, carol, 1)
assertNumOpenChannelsPending(ctxt, t, net.Alice, carol, 1)
// Restart both nodes to test that the appropriate state has been // Restart both nodes to test that the appropriate state has been
// persisted and that both nodes recover gracefully. // persisted and that both nodes recover gracefully.
@@ -577,8 +557,7 @@ func testChannelFundingPersistence(net *lntest.NetworkHarness, t *harnessTest) {
// The following block ensures that after both nodes have restarted, // The following block ensures that after both nodes have restarted,
// they have reconnected before the execution of the next test. // they have reconnected before the execution of the next test.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.EnsureConnected(t.t, net.Alice, carol)
net.EnsureConnected(ctxt, t.t, net.Alice, carol)
// Next, mine enough blocks s.t the channel will open with a single // Next, mine enough blocks s.t the channel will open with a single
// additional block mined. // additional block mined.
@@ -589,7 +568,7 @@ func testChannelFundingPersistence(net *lntest.NetworkHarness, t *harnessTest) {
// Assert that our wallet has our opening transaction with a label // Assert that our wallet has our opening transaction with a label
// that does not have a channel ID set yet, because we have not // that does not have a channel ID set yet, because we have not
// reached our required confirmations. // reached our required confirmations.
tx := findTxAtHeight(ctxt, t, height, fundingTxStr, net.Alice) tx := findTxAtHeight(t, height, fundingTxStr, net.Alice)
// At this stage, we expect the transaction to be labelled, but not with // At this stage, we expect the transaction to be labelled, but not with
// our channel ID because our transaction has not yet confirmed. // our channel ID because our transaction has not yet confirmed.
@@ -598,8 +577,7 @@ func testChannelFundingPersistence(net *lntest.NetworkHarness, t *harnessTest) {
// Both nodes should still show a single channel as pending. // Both nodes should still show a single channel as pending.
time.Sleep(time.Second * 1) time.Sleep(time.Second * 1)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) assertNumOpenChannelsPending(t, net.Alice, carol, 1)
assertNumOpenChannelsPending(ctxt, t, net.Alice, carol, 1)
// Finally, mine the last block which should mark the channel as open. // Finally, mine the last block which should mark the channel as open.
if _, err := net.Miner.Client.Generate(1); err != nil { if _, err := net.Miner.Client.Generate(1); err != nil {
@@ -609,8 +587,7 @@ func testChannelFundingPersistence(net *lntest.NetworkHarness, t *harnessTest) {
// At this point, the channel should be fully opened and there should // At this point, the channel should be fully opened and there should
// be no pending channels remaining for either node. // be no pending channels remaining for either node.
time.Sleep(time.Second * 1) time.Sleep(time.Second * 1)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) assertNumOpenChannelsPending(t, net.Alice, carol, 0)
assertNumOpenChannelsPending(ctxt, t, net.Alice, carol, 0)
// The channel should be listed in the peer information returned by // The channel should be listed in the peer information returned by
// both peers. // both peers.
@@ -620,7 +597,7 @@ func testChannelFundingPersistence(net *lntest.NetworkHarness, t *harnessTest) {
} }
// Re-lookup our transaction in the block that it confirmed in. // Re-lookup our transaction in the block that it confirmed in.
tx = findTxAtHeight(ctxt, t, height, fundingTxStr, net.Alice) tx = findTxAtHeight(t, height, fundingTxStr, net.Alice)
// Create an additional check for our channel assertion that will // Create an additional check for our channel assertion that will
// check that our label is as expected. // check that our label is as expected.
@@ -637,13 +614,11 @@ func testChannelFundingPersistence(net *lntest.NetworkHarness, t *harnessTest) {
} }
// Check both nodes to ensure that the channel is ready for operation. // Check both nodes to ensure that the channel is ready for operation.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) err = net.AssertChannelExists(net.Alice, &outPoint, check)
err = net.AssertChannelExists(ctxt, net.Alice, &outPoint, check)
if err != nil { if err != nil {
t.Fatalf("unable to assert channel existence: %v", err) t.Fatalf("unable to assert channel existence: %v", err)
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) if err := net.AssertChannelExists(carol, &outPoint); err != nil {
if err := net.AssertChannelExists(ctxt, carol, &outPoint); err != nil {
t.Fatalf("unable to assert channel existence: %v", err) t.Fatalf("unable to assert channel existence: %v", err)
} }

View File

@@ -25,10 +25,8 @@ func testHoldInvoiceForceClose(net *lntest.NetworkHarness, t *harnessTest) {
Amt: 300000, Amt: 300000,
} }
ctxt, cancel := context.WithTimeout(ctxb, channelOpenTimeout)
defer cancel()
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
ctxt, t, net, net.Alice, net.Bob, chanReq, t, net, net.Alice, net.Bob, chanReq,
) )
// Create a non-dust hold invoice for bob. // Create a non-dust hold invoice for bob.
@@ -42,7 +40,7 @@ func testHoldInvoiceForceClose(net *lntest.NetworkHarness, t *harnessTest) {
Hash: payHash[:], Hash: payHash[:],
} }
ctxt, cancel = context.WithTimeout(ctxb, defaultTimeout) ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
defer cancel() defer cancel()
bobInvoice, err := net.Bob.AddHoldInvoice(ctxt, invoiceReq) bobInvoice, err := net.Bob.AddHoldInvoice(ctxt, invoiceReq)
require.NoError(t.t, err) require.NoError(t.t, err)
@@ -107,8 +105,7 @@ func testHoldInvoiceForceClose(net *lntest.NetworkHarness, t *harnessTest) {
// Our channel should not have been force closed, instead we expect our // Our channel should not have been force closed, instead we expect our
// channel to still be open and our invoice to have been canceled before // channel to still be open and our invoice to have been canceled before
// expiry. // expiry.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) chanInfo, err := getChanInfo(net.Alice)
chanInfo, err := getChanInfo(ctxt, net.Alice)
require.NoError(t.t, err) require.NoError(t.t, err)
fundingTxID, err := lnrpc.GetChanPointFundingTxid(chanPoint) fundingTxID, err := lnrpc.GetChanPointFundingTxid(chanPoint)

View File

@@ -34,14 +34,12 @@ func testHoldInvoicePersistence(net *lntest.NetworkHarness, t *harnessTest) {
defer shutdownAndAssert(net, t, carol) defer shutdownAndAssert(net, t, carol)
// Connect Alice to Carol. // Connect Alice to Carol.
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, net.Alice, carol)
net.ConnectNodes(ctxb, t.t, net.Alice, carol)
// Open a channel between Alice and Carol which is private so that we // Open a channel between Alice and Carol which is private so that we
// cover the addition of hop hints for hold invoices. // cover the addition of hop hints for hold invoices.
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointAlice := openChannelAndAssert( chanPointAlice := openChannelAndAssert(
ctxt, t, net, net.Alice, carol, t, net, net.Alice, carol,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
Private: true, Private: true,
@@ -50,7 +48,7 @@ func testHoldInvoicePersistence(net *lntest.NetworkHarness, t *harnessTest) {
// Wait for Alice and Carol to receive the channel edge from the // Wait for Alice and Carol to receive the channel edge from the
// funding manager. // funding manager.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err := net.Alice.WaitForNetworkChannelOpen(ctxt, chanPointAlice) err := net.Alice.WaitForNetworkChannelOpen(ctxt, chanPointAlice)
if err != nil { if err != nil {
t.Fatalf("alice didn't see the alice->carol channel before "+ t.Fatalf("alice didn't see the alice->carol channel before "+
@@ -167,7 +165,7 @@ func testHoldInvoicePersistence(net *lntest.NetworkHarness, t *harnessTest) {
req := &lnrpc.ListPaymentsRequest{ req := &lnrpc.ListPaymentsRequest{
IncludeIncomplete: true, IncludeIncomplete: true,
} }
ctxt, _ = context.WithTimeout(ctxt, defaultTimeout) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
paymentsResp, err := net.Alice.ListPayments(ctxt, req) paymentsResp, err := net.Alice.ListPayments(ctxt, req)
if err != nil { if err != nil {
return fmt.Errorf("error when obtaining payments: %v", return fmt.Errorf("error when obtaining payments: %v",
@@ -370,7 +368,7 @@ func testHoldInvoicePersistence(net *lntest.NetworkHarness, t *harnessTest) {
req := &lnrpc.ListPaymentsRequest{ req := &lnrpc.ListPaymentsRequest{
IncludeIncomplete: true, IncludeIncomplete: true,
} }
ctxt, _ = context.WithTimeout(ctxt, defaultTimeout) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
paymentsResp, err := net.Alice.ListPayments(ctxt, req) paymentsResp, err := net.Alice.ListPayments(ctxt, req)
if err != nil { if err != nil {
t.Fatalf("error when obtaining Alice payments: %v", err) t.Fatalf("error when obtaining Alice payments: %v", err)

View File

@@ -3,7 +3,6 @@
package itest package itest
import ( import (
"context"
"fmt" "fmt"
"strings" "strings"
@@ -29,17 +28,16 @@ func testMaxChannelSize(net *lntest.NetworkHarness, t *harnessTest) {
defer shutdownAndAssert(net, t, wumboNode2) defer shutdownAndAssert(net, t, wumboNode2)
// We'll send 11 BTC to the wumbo node so it can test the wumbo soft limit. // We'll send 11 BTC to the wumbo node so it can test the wumbo soft limit.
ctxb := context.Background() net.SendCoins(t.t, 11*btcutil.SatoshiPerBitcoin, wumboNode)
net.SendCoins(ctxb, t.t, 11*btcutil.SatoshiPerBitcoin, wumboNode)
// Next we'll connect both nodes, then attempt to make a wumbo channel // Next we'll connect both nodes, then attempt to make a wumbo channel
// funding request, which should fail as it exceeds the default wumbo // funding request, which should fail as it exceeds the default wumbo
// soft limit of 10 BTC. // soft limit of 10 BTC.
net.EnsureConnected(ctxb, t.t, wumboNode, wumboNode2) net.EnsureConnected(t.t, wumboNode, wumboNode2)
chanAmt := funding.MaxBtcFundingAmountWumbo + 1 chanAmt := funding.MaxBtcFundingAmountWumbo + 1
_, err := net.OpenChannel( _, err := net.OpenChannel(
ctxb, wumboNode, wumboNode2, lntest.OpenChannelParams{ wumboNode, wumboNode2, lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
) )
@@ -58,10 +56,10 @@ func testMaxChannelSize(net *lntest.NetworkHarness, t *harnessTest) {
miniNode := net.NewNode(t.t, "mini", nil) miniNode := net.NewNode(t.t, "mini", nil)
defer shutdownAndAssert(net, t, miniNode) defer shutdownAndAssert(net, t, miniNode)
net.EnsureConnected(ctxb, t.t, wumboNode, miniNode) net.EnsureConnected(t.t, wumboNode, miniNode)
_, err = net.OpenChannel( _, err = net.OpenChannel(
ctxb, wumboNode, miniNode, lntest.OpenChannelParams{ wumboNode, miniNode, lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
) )
@@ -89,9 +87,9 @@ func testMaxChannelSize(net *lntest.NetworkHarness, t *harnessTest) {
defer shutdownAndAssert(net, t, wumboNode3) defer shutdownAndAssert(net, t, wumboNode3)
// Creating a wumbo channel between these two nodes should succeed. // Creating a wumbo channel between these two nodes should succeed.
net.EnsureConnected(ctxb, t.t, wumboNode, wumboNode3) net.EnsureConnected(t.t, wumboNode, wumboNode3)
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
ctxb, t, net, wumboNode, wumboNode3, t, net, wumboNode, wumboNode3,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },

View File

@@ -23,9 +23,8 @@ func testMaxHtlcPathfind(net *lntest.NetworkHarness, t *harnessTest) {
// Bob to add a maximum of 5 htlcs to her commitment. // Bob to add a maximum of 5 htlcs to her commitment.
maxHtlcs := 5 maxHtlcs := 5
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
ctxt, t, net, net.Alice, net.Bob, t, net, net.Alice, net.Bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: 1000000, Amt: 1000000,
PushAmt: 800000, PushAmt: 800000,
@@ -35,7 +34,7 @@ func testMaxHtlcPathfind(net *lntest.NetworkHarness, t *harnessTest) {
// Wait for Alice and Bob to receive the channel edge from the // Wait for Alice and Bob to receive the channel edge from the
// funding manager. // funding manager.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err := net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint) err := net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint)
require.NoError(t.t, err, "alice does not have open channel") require.NoError(t.t, err, "alice does not have open channel")

View File

@@ -31,8 +31,6 @@ import (
// Bob-peer and then re-connects them again. We expect Alice to be able to // Bob-peer and then re-connects them again. We expect Alice to be able to
// disconnect at any point. // disconnect at any point.
func testDisconnectingTargetPeer(net *lntest.NetworkHarness, t *harnessTest) { func testDisconnectingTargetPeer(net *lntest.NetworkHarness, t *harnessTest) {
ctxb := context.Background()
// We'll start both nodes with a high backoff so that they don't // We'll start both nodes with a high backoff so that they don't
// reconnect automatically during our test. // reconnect automatically during our test.
args := []string{ args := []string{
@@ -47,15 +45,13 @@ func testDisconnectingTargetPeer(net *lntest.NetworkHarness, t *harnessTest) {
defer shutdownAndAssert(net, t, bob) defer shutdownAndAssert(net, t, bob)
// Start by connecting Alice and Bob with no channels. // Start by connecting Alice and Bob with no channels.
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, alice, bob)
net.ConnectNodes(ctxt, t.t, alice, bob)
// Check existing connection. // Check existing connection.
assertNumConnections(t, alice, bob, 1) assertNumConnections(t, alice, bob, 1)
// Give Alice some coins so she can fund a channel. // Give Alice some coins so she can fund a channel.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, alice)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, alice)
chanAmt := funding.MaxBtcFundingAmount chanAmt := funding.MaxBtcFundingAmount
pushAmt := btcutil.Amount(0) pushAmt := btcutil.Amount(0)
@@ -63,9 +59,8 @@ func testDisconnectingTargetPeer(net *lntest.NetworkHarness, t *harnessTest) {
// Create a new channel that requires 1 confs before it's considered // Create a new channel that requires 1 confs before it's considered
// open, then broadcast the funding transaction // open, then broadcast the funding transaction
const numConfs = 1 const numConfs = 1
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
pendingUpdate, err := net.OpenPendingChannel( pendingUpdate, err := net.OpenPendingChannel(
ctxt, alice, bob, chanAmt, pushAmt, alice, bob, chanAmt, pushAmt,
) )
if err != nil { if err != nil {
t.Fatalf("unable to open channel: %v", err) t.Fatalf("unable to open channel: %v", err)
@@ -74,12 +69,11 @@ func testDisconnectingTargetPeer(net *lntest.NetworkHarness, t *harnessTest) {
// At this point, the channel's funding transaction will have been // At this point, the channel's funding transaction will have been
// broadcast, but not confirmed. Alice and Bob's nodes should reflect // broadcast, but not confirmed. Alice and Bob's nodes should reflect
// this when queried via RPC. // this when queried via RPC.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) assertNumOpenChannelsPending(t, alice, bob, 1)
assertNumOpenChannelsPending(ctxt, t, alice, bob, 1)
// Disconnect Alice-peer from Bob-peer and get error causes by one // Disconnect Alice-peer from Bob-peer and get error causes by one
// pending channel with detach node is existing. // pending channel with detach node is existing.
if err := net.DisconnectNodes(ctxt, alice, bob); err != nil { if err := net.DisconnectNodes(alice, bob); err != nil {
t.Fatalf("Bob's peer was disconnected from Alice's"+ t.Fatalf("Bob's peer was disconnected from Alice's"+
" while one pending channel is existing: err %v", err) " while one pending channel is existing: err %v", err)
} }
@@ -104,13 +98,11 @@ func testDisconnectingTargetPeer(net *lntest.NetworkHarness, t *harnessTest) {
// At this point, the channel should be fully opened and there should be // At this point, the channel should be fully opened and there should be
// no pending channels remaining for either node. // no pending channels remaining for either node.
time.Sleep(time.Millisecond * 300) time.Sleep(time.Millisecond * 300)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
assertNumOpenChannelsPending(ctxt, t, alice, bob, 0) assertNumOpenChannelsPending(t, alice, bob, 0)
// Reconnect the nodes so that the channel can become active. // Reconnect the nodes so that the channel can become active.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, alice, bob)
net.ConnectNodes(ctxt, t.t, alice, bob)
// The channel should be listed in the peer information returned by both // The channel should be listed in the peer information returned by both
// peers. // peers.
@@ -120,18 +112,16 @@ func testDisconnectingTargetPeer(net *lntest.NetworkHarness, t *harnessTest) {
} }
// Check both nodes to ensure that the channel is ready for operation. // Check both nodes to ensure that the channel is ready for operation.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) if err := net.AssertChannelExists(alice, &outPoint); err != nil {
if err := net.AssertChannelExists(ctxt, alice, &outPoint); err != nil {
t.Fatalf("unable to assert channel existence: %v", err) t.Fatalf("unable to assert channel existence: %v", err)
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) if err := net.AssertChannelExists(bob, &outPoint); err != nil {
if err := net.AssertChannelExists(ctxt, bob, &outPoint); err != nil {
t.Fatalf("unable to assert channel existence: %v", err) t.Fatalf("unable to assert channel existence: %v", err)
} }
// Disconnect Alice-peer from Bob-peer and get error causes by one // Disconnect Alice-peer from Bob-peer and get error causes by one
// active channel with detach node is existing. // active channel with detach node is existing.
if err := net.DisconnectNodes(ctxt, alice, bob); err != nil { if err := net.DisconnectNodes(alice, bob); err != nil {
t.Fatalf("Bob's peer was disconnected from Alice's"+ t.Fatalf("Bob's peer was disconnected from Alice's"+
" while one active channel is existing: err %v", err) " while one active channel is existing: err %v", err)
} }
@@ -140,8 +130,7 @@ func testDisconnectingTargetPeer(net *lntest.NetworkHarness, t *harnessTest) {
assertNumConnections(t, alice, bob, 0) assertNumConnections(t, alice, bob, 0)
// Reconnect both nodes before force closing the channel. // Reconnect both nodes before force closing the channel.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, alice, bob)
net.ConnectNodes(ctxt, t.t, alice, bob)
// Finally, immediately close the channel. This function will also block // Finally, immediately close the channel. This function will also block
// until the channel is closed and will additionally assert the relevant // until the channel is closed and will additionally assert the relevant
@@ -157,7 +146,7 @@ func testDisconnectingTargetPeer(net *lntest.NetworkHarness, t *harnessTest) {
// Disconnect Alice-peer from Bob-peer without getting error about // Disconnect Alice-peer from Bob-peer without getting error about
// existing channels. // existing channels.
if err := net.DisconnectNodes(ctxt, alice, bob); err != nil { if err := net.DisconnectNodes(alice, bob); err != nil {
t.Fatalf("unable to disconnect Bob's peer from Alice's: err %v", t.Fatalf("unable to disconnect Bob's peer from Alice's: err %v",
err) err)
} }
@@ -166,8 +155,7 @@ func testDisconnectingTargetPeer(net *lntest.NetworkHarness, t *harnessTest) {
assertNumConnections(t, alice, bob, 0) assertNumConnections(t, alice, bob, 0)
// Finally, re-connect both nodes. // Finally, re-connect both nodes.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, alice, bob)
net.ConnectNodes(ctxt, t.t, alice, bob)
// Check existing connection. // Check existing connection.
assertNumConnections(t, alice, net.Bob, 1) assertNumConnections(t, alice, net.Bob, 1)
@@ -202,14 +190,11 @@ func testSphinxReplayPersistence(net *lntest.NetworkHarness, t *harnessTest) {
carol := net.NewNode(t.t, "Carol", []string{"--unsafe-replay"}) carol := net.NewNode(t.t, "Carol", []string{"--unsafe-replay"})
defer shutdownAndAssert(net, t, carol) defer shutdownAndAssert(net, t, carol)
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, carol, dave)
net.ConnectNodes(ctxt, t.t, carol, dave) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
ctxt, t, net, carol, dave, t, net, carol, dave,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -223,14 +208,11 @@ func testSphinxReplayPersistence(net *lntest.NetworkHarness, t *harnessTest) {
fred := net.NewNode(t.t, "Fred", nil) fred := net.NewNode(t.t, "Fred", nil)
defer shutdownAndAssert(net, t, fred) defer shutdownAndAssert(net, t, fred)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, fred, carol)
net.ConnectNodes(ctxt, t.t, fred, carol) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, fred)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, fred)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointFC := openChannelAndAssert( chanPointFC := openChannelAndAssert(
ctxt, t, net, fred, carol, t, net, fred, carol,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -246,7 +228,7 @@ func testSphinxReplayPersistence(net *lntest.NetworkHarness, t *harnessTest) {
RPreimage: preimage, RPreimage: preimage,
Value: paymentAmt, Value: paymentAmt,
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
invoiceResp, err := dave.AddInvoice(ctxt, invoice) invoiceResp, err := dave.AddInvoice(ctxt, invoice)
if err != nil { if err != nil {
t.Fatalf("unable to add invoice: %v", err) t.Fatalf("unable to add invoice: %v", err)
@@ -381,11 +363,10 @@ func testListChannels(net *lntest.NetworkHarness, t *harnessTest) {
defer shutdownAndAssert(net, t, bob) defer shutdownAndAssert(net, t, bob)
// Connect Alice to Bob. // Connect Alice to Bob.
net.ConnectNodes(ctxb, t.t, alice, bob) net.ConnectNodes(t.t, alice, bob)
// Give Alice some coins so she can fund a channel. // Give Alice some coins so she can fund a channel.
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, alice)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, alice)
// Open a channel with 100k satoshis between Alice and Bob with Alice // Open a channel with 100k satoshis between Alice and Bob with Alice
// being the sole funder of the channel. The minial HTLC amount is set to // being the sole funder of the channel. The minial HTLC amount is set to
@@ -393,9 +374,8 @@ func testListChannels(net *lntest.NetworkHarness, t *harnessTest) {
const customizedMinHtlc = 4200 const customizedMinHtlc = 4200
chanAmt := btcutil.Amount(100000) chanAmt := btcutil.Amount(100000)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
ctxt, t, net, alice, bob, t, net, alice, bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
MinHtlc: customizedMinHtlc, MinHtlc: customizedMinHtlc,
@@ -405,7 +385,7 @@ func testListChannels(net *lntest.NetworkHarness, t *harnessTest) {
// Wait for Alice and Bob to receive the channel edge from the // Wait for Alice and Bob to receive the channel edge from the
// funding manager. // funding manager.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err := alice.WaitForNetworkChannelOpen(ctxt, chanPoint) err := alice.WaitForNetworkChannelOpen(ctxt, chanPoint)
if err != nil { if err != nil {
t.Fatalf("alice didn't see the alice->bob channel before "+ t.Fatalf("alice didn't see the alice->bob channel before "+
@@ -513,21 +493,18 @@ func testMaxPendingChannels(net *lntest.NetworkHarness, t *harnessTest) {
carol := net.NewNode(t.t, "Carol", args) carol := net.NewNode(t.t, "Carol", args)
defer shutdownAndAssert(net, t, carol) defer shutdownAndAssert(net, t, carol)
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, net.Alice, carol)
net.ConnectNodes(ctxt, t.t, net.Alice, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
carolBalance := btcutil.Amount(maxPendingChannels) * amount carolBalance := btcutil.Amount(maxPendingChannels) * amount
net.SendCoins(ctxt, t.t, carolBalance, carol) net.SendCoins(t.t, carolBalance, carol)
// Send open channel requests without generating new blocks thereby // Send open channel requests without generating new blocks thereby
// increasing pool of pending channels. Then check that we can't open // increasing pool of pending channels. Then check that we can't open
// the channel if the number of pending channels exceed max value. // the channel if the number of pending channels exceed max value.
openStreams := make([]lnrpc.Lightning_OpenChannelClient, maxPendingChannels) openStreams := make([]lnrpc.Lightning_OpenChannelClient, maxPendingChannels)
for i := 0; i < maxPendingChannels; i++ { for i := 0; i < maxPendingChannels; i++ {
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
stream := openChannelStream( stream := openChannelStream(
ctxt, t, net, net.Alice, carol, t, net, net.Alice, carol,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: amount, Amt: amount,
}, },
@@ -537,10 +514,8 @@ func testMaxPendingChannels(net *lntest.NetworkHarness, t *harnessTest) {
// Carol exhausted available amount of pending channels, next open // Carol exhausted available amount of pending channels, next open
// channel request should cause ErrorGeneric to be sent back to Alice. // channel request should cause ErrorGeneric to be sent back to Alice.
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
_, err := net.OpenChannel( _, err := net.OpenChannel(
ctxt, net.Alice, carol, net.Alice, carol, lntest.OpenChannelParams{
lntest.OpenChannelParams{
Amt: amount, Amt: amount,
}, },
) )
@@ -565,8 +540,7 @@ func testMaxPendingChannels(net *lntest.NetworkHarness, t *harnessTest) {
chanPoints := make([]*lnrpc.ChannelPoint, maxPendingChannels) chanPoints := make([]*lnrpc.ChannelPoint, maxPendingChannels)
for i, stream := range openStreams { for i, stream := range openStreams {
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) fundingChanPoint, err := net.WaitForChannelOpen(stream)
fundingChanPoint, err := net.WaitForChannelOpen(ctxt, stream)
if err != nil { if err != nil {
t.Fatalf("error while waiting for channel open: %v", err) t.Fatalf("error while waiting for channel open: %v", err)
} }
@@ -579,7 +553,7 @@ func testMaxPendingChannels(net *lntest.NetworkHarness, t *harnessTest) {
// Ensure that the funding transaction enters a block, and is // Ensure that the funding transaction enters a block, and is
// properly advertised by Alice. // properly advertised by Alice.
assertTxInBlock(t, block, fundingTxID) assertTxInBlock(t, block, fundingTxID)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err = net.Alice.WaitForNetworkChannelOpen(ctxt, fundingChanPoint) err = net.Alice.WaitForNetworkChannelOpen(ctxt, fundingChanPoint)
if err != nil { if err != nil {
t.Fatalf("channel not seen on network before "+ t.Fatalf("channel not seen on network before "+
@@ -592,10 +566,8 @@ func testMaxPendingChannels(net *lntest.NetworkHarness, t *harnessTest) {
Hash: *fundingTxID, Hash: *fundingTxID,
Index: fundingChanPoint.OutputIndex, Index: fundingChanPoint.OutputIndex,
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) err = net.AssertChannelExists(net.Alice, &chanPoint)
if err := net.AssertChannelExists(ctxt, net.Alice, &chanPoint); err != nil { require.NoError(t.t, err, "unable to assert channel existence")
t.Fatalf("unable to assert channel existence: %v", err)
}
chanPoints[i] = fundingChanPoint chanPoints[i] = fundingChanPoint
} }
@@ -618,9 +590,8 @@ func testGarbageCollectLinkNodes(net *lntest.NetworkHarness, t *harnessTest) {
// Open a channel between Alice and Bob which will later be // Open a channel between Alice and Bob which will later be
// cooperatively closed. // cooperatively closed.
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
coopChanPoint := openChannelAndAssert( coopChanPoint := openChannelAndAssert(
ctxt, t, net, net.Alice, net.Bob, lntest.OpenChannelParams{ t, net, net.Alice, net.Bob, lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
) )
@@ -628,14 +599,12 @@ func testGarbageCollectLinkNodes(net *lntest.NetworkHarness, t *harnessTest) {
// Create Carol's node and connect Alice to her. // Create Carol's node and connect Alice to her.
carol := net.NewNode(t.t, "Carol", nil) carol := net.NewNode(t.t, "Carol", nil)
defer shutdownAndAssert(net, t, carol) defer shutdownAndAssert(net, t, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, net.Alice, carol)
net.ConnectNodes(ctxt, t.t, net.Alice, carol)
// Open a channel between Alice and Carol which will later be force // Open a channel between Alice and Carol which will later be force
// closed. // closed.
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
forceCloseChanPoint := openChannelAndAssert( forceCloseChanPoint := openChannelAndAssert(
ctxt, t, net, net.Alice, carol, lntest.OpenChannelParams{ t, net, net.Alice, carol, lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
) )
@@ -646,10 +615,9 @@ func testGarbageCollectLinkNodes(net *lntest.NetworkHarness, t *harnessTest) {
dave := net.NewNode(t.t, "Dave", nil) dave := net.NewNode(t.t, "Dave", nil)
defer shutdownAndAssert(net, t, dave) defer shutdownAndAssert(net, t, dave)
net.ConnectNodes(ctxt, t.t, net.Alice, dave) net.ConnectNodes(t.t, net.Alice, dave)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
persistentChanPoint := openChannelAndAssert( persistentChanPoint := openChannelAndAssert(
ctxt, t, net, net.Alice, dave, lntest.OpenChannelParams{ t, net, net.Alice, dave, lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
) )
@@ -658,7 +626,7 @@ func testGarbageCollectLinkNodes(net *lntest.NetworkHarness, t *harnessTest) {
// Alice. // Alice.
isConnected := func(pubKey string) bool { isConnected := func(pubKey string) bool {
req := &lnrpc.ListPeersRequest{} req := &lnrpc.ListPeersRequest{}
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
resp, err := net.Alice.ListPeers(ctxt, req) resp, err := net.Alice.ListPeers(ctxt, req)
if err != nil { if err != nil {
t.Fatalf("unable to retrieve alice's peers: %v", err) t.Fatalf("unable to retrieve alice's peers: %v", err)
@@ -780,7 +748,7 @@ func testGarbageCollectLinkNodes(net *lntest.NetworkHarness, t *harnessTest) {
var predErr error var predErr error
pendingChansRequest := &lnrpc.PendingChannelsRequest{} pendingChansRequest := &lnrpc.PendingChannelsRequest{}
err = wait.Predicate(func() bool { err = wait.Predicate(func() bool {
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
pendingChanResp, err := net.Alice.PendingChannels( pendingChanResp, err := net.Alice.PendingChannels(
ctxt, pendingChansRequest, ctxt, pendingChansRequest,
) )
@@ -821,7 +789,7 @@ func testGarbageCollectLinkNodes(net *lntest.NetworkHarness, t *harnessTest) {
describeGraphReq := &lnrpc.ChannelGraphRequest{ describeGraphReq := &lnrpc.ChannelGraphRequest{
IncludeUnannounced: true, IncludeUnannounced: true,
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
channelGraph, err := net.Alice.DescribeGraph(ctxt, describeGraphReq) channelGraph, err := net.Alice.DescribeGraph(ctxt, describeGraphReq)
if err != nil { if err != nil {
t.Fatalf("unable to query for alice's channel graph: %v", err) t.Fatalf("unable to query for alice's channel graph: %v", err)
@@ -869,8 +837,7 @@ func testDataLossProtection(net *lntest.NetworkHarness, t *harnessTest) {
// Before we make a channel, we'll load up Carol with some coins sent // Before we make a channel, we'll load up Carol with some coins sent
// directly from the miner. // directly from the miner.
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, carol)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol)
// timeTravel is a method that will make Carol open a channel to the // timeTravel is a method that will make Carol open a channel to the
// passed node, settle a series of payments, then reset the node back // passed node, settle a series of payments, then reset the node back
@@ -882,14 +849,12 @@ func testDataLossProtection(net *lntest.NetworkHarness, t *harnessTest) {
// We must let the node communicate with Carol before they are // We must let the node communicate with Carol before they are
// able to open channel, so we connect them. // able to open channel, so we connect them.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.EnsureConnected(t.t, carol, node)
net.EnsureConnected(ctxt, t.t, carol, node)
// We'll first open up a channel between them with a 0.5 BTC // We'll first open up a channel between them with a 0.5 BTC
// value. // value.
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
ctxt, t, net, carol, node, t, net, carol, node,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -909,7 +874,7 @@ func testDataLossProtection(net *lntest.NetworkHarness, t *harnessTest) {
// Wait for Carol to receive the channel edge from the funding // Wait for Carol to receive the channel edge from the funding
// manager. // manager.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err = carol.WaitForNetworkChannelOpen(ctxt, chanPoint) err = carol.WaitForNetworkChannelOpen(ctxt, chanPoint)
if err != nil { if err != nil {
t.Fatalf("carol didn't see the carol->%s channel "+ t.Fatalf("carol didn't see the carol->%s channel "+
@@ -918,9 +883,8 @@ func testDataLossProtection(net *lntest.NetworkHarness, t *harnessTest) {
// Send payments from Carol using 3 of the payment hashes // Send payments from Carol using 3 of the payment hashes
// generated above. // generated above.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = completePaymentRequests( err = completePaymentRequests(
ctxt, carol, carol.RouterClient, carol, carol.RouterClient,
payReqs[:numInvoices/2], true, payReqs[:numInvoices/2], true,
) )
if err != nil { if err != nil {
@@ -933,8 +897,7 @@ func testDataLossProtection(net *lntest.NetworkHarness, t *harnessTest) {
var nodeChan *lnrpc.Channel var nodeChan *lnrpc.Channel
var predErr error var predErr error
err = wait.Predicate(func() bool { err = wait.Predicate(func() bool {
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) bChan, err := getChanInfo(node)
bChan, err := getChanInfo(ctxt, node)
if err != nil { if err != nil {
t.Fatalf("unable to get channel info: %v", err) t.Fatalf("unable to get channel info: %v", err)
} }
@@ -966,17 +929,14 @@ func testDataLossProtection(net *lntest.NetworkHarness, t *harnessTest) {
// Finally, send more payments from , using the remaining // Finally, send more payments from , using the remaining
// payment hashes. // payment hashes.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = completePaymentRequests( err = completePaymentRequests(
ctxt, carol, carol.RouterClient, carol, carol.RouterClient, payReqs[numInvoices/2:], true,
payReqs[numInvoices/2:], true,
) )
if err != nil { if err != nil {
t.Fatalf("unable to send payments: %v", err) t.Fatalf("unable to send payments: %v", err)
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) nodeChan, err = getChanInfo(node)
nodeChan, err = getChanInfo(ctxt, node)
if err != nil { if err != nil {
t.Fatalf("unable to get dave chan info: %v", err) t.Fatalf("unable to get dave chan info: %v", err)
} }
@@ -998,8 +958,7 @@ func testDataLossProtection(net *lntest.NetworkHarness, t *harnessTest) {
// Now query for the channel state, it should show that it's at // Now query for the channel state, it should show that it's at
// a state number in the past, not the *latest* state. // a state number in the past, not the *latest* state.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) nodeChan, err = getChanInfo(node)
nodeChan, err = getChanInfo(ctxt, node)
if err != nil { if err != nil {
t.Fatalf("unable to get dave chan info: %v", err) t.Fatalf("unable to get dave chan info: %v", err)
} }
@@ -1031,7 +990,7 @@ func testDataLossProtection(net *lntest.NetworkHarness, t *harnessTest) {
// We make a note of the nodes' current on-chain balances, to make sure // We make a note of the nodes' current on-chain balances, to make sure
// they are able to retrieve the channel funds eventually, // they are able to retrieve the channel funds eventually,
balReq := &lnrpc.WalletBalanceRequest{} balReq := &lnrpc.WalletBalanceRequest{}
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
carolBalResp, err := carol.WalletBalance(ctxt, balReq) carolBalResp, err := carol.WalletBalance(ctxt, balReq)
if err != nil { if err != nil {
t.Fatalf("unable to get carol's balance: %v", err) t.Fatalf("unable to get carol's balance: %v", err)
@@ -1073,8 +1032,7 @@ func testDataLossProtection(net *lntest.NetworkHarness, t *harnessTest) {
closeChannelAndAssert(t, net, carol, chanPoint2, true) closeChannelAndAssert(t, net, carol, chanPoint2, true)
// Wait for the channel to be marked pending force close. // Wait for the channel to be marked pending force close.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) err = waitForChannelPendingForceClose(carol, chanPoint2)
err = waitForChannelPendingForceClose(ctxt, carol, chanPoint2)
if err != nil { if err != nil {
t.Fatalf("channel not pending force close: %v", err) t.Fatalf("channel not pending force close: %v", err)
} }
@@ -1162,30 +1120,28 @@ func testRejectHTLC(net *lntest.NetworkHarness, t *harnessTest) {
defer shutdownAndAssert(net, t, carol) defer shutdownAndAssert(net, t, carol)
// Connect Alice to Carol. // Connect Alice to Carol.
net.ConnectNodes(ctxb, t.t, net.Alice, carol) net.ConnectNodes(t.t, net.Alice, carol)
// Connect Carol to Bob. // Connect Carol to Bob.
net.ConnectNodes(ctxb, t.t, carol, net.Bob) net.ConnectNodes(t.t, carol, net.Bob)
// Send coins to Carol. // Send coins to Carol.
net.SendCoins(ctxb, t.t, btcutil.SatoshiPerBitcoin, carol) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, carol)
// Send coins to Alice. // Send coins to Alice.
net.SendCoins(ctxb, t.t, btcutil.SatoshiPerBitcent, net.Alice) net.SendCoins(t.t, btcutil.SatoshiPerBitcent, net.Alice)
// Open a channel between Alice and Carol. // Open a channel between Alice and Carol.
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
chanPointAlice := openChannelAndAssert( chanPointAlice := openChannelAndAssert(
ctxt, t, net, net.Alice, carol, t, net, net.Alice, carol,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
) )
// Open a channel between Carol and Bob. // Open a channel between Carol and Bob.
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointCarol := openChannelAndAssert( chanPointCarol := openChannelAndAssert(
ctxt, t, net, carol, net.Bob, t, net, carol, net.Bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -1223,9 +1179,8 @@ func testRejectHTLC(net *lntest.NetworkHarness, t *harnessTest) {
} }
// Alice pays Carols invoice. // Alice pays Carols invoice.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = completePaymentRequests( err = completePaymentRequests(
ctxt, net.Alice, net.Alice.RouterClient, net.Alice, net.Alice.RouterClient,
[]string{resp.PaymentRequest}, true, []string{resp.PaymentRequest}, true,
) )
if err != nil { if err != nil {
@@ -1249,9 +1204,8 @@ func testRejectHTLC(net *lntest.NetworkHarness, t *harnessTest) {
} }
// Carol pays Bobs invoice. // Carol pays Bobs invoice.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = completePaymentRequests( err = completePaymentRequests(
ctxt, carol, carol.RouterClient, carol, carol.RouterClient,
[]string{resp.PaymentRequest}, true, []string{resp.PaymentRequest}, true,
) )
if err != nil { if err != nil {
@@ -1278,9 +1232,8 @@ func testRejectHTLC(net *lntest.NetworkHarness, t *harnessTest) {
// Alice attempts to pay Bobs invoice. This payment should be rejected since // Alice attempts to pay Bobs invoice. This payment should be rejected since
// we are using Carol as an intermediary hop, Carol is running lnd with // we are using Carol as an intermediary hop, Carol is running lnd with
// --rejecthtlc. // --rejecthtlc.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = completePaymentRequests( err = completePaymentRequests(
ctxt, net.Alice, net.Alice.RouterClient, net.Alice, net.Alice.RouterClient,
[]string{resp.PaymentRequest}, true, []string{resp.PaymentRequest}, true,
) )
if err == nil { if err == nil {
@@ -1303,9 +1256,8 @@ func testNodeSignVerify(net *lntest.NetworkHarness, t *harnessTest) {
pushAmt := btcutil.Amount(100000) pushAmt := btcutil.Amount(100000)
// Create a channel between alice and bob. // Create a channel between alice and bob.
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
aliceBobCh := openChannelAndAssert( aliceBobCh := openChannelAndAssert(
ctxt, t, net, net.Alice, net.Bob, t, net, net.Alice, net.Bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
PushAmt: pushAmt, PushAmt: pushAmt,
@@ -1316,7 +1268,7 @@ func testNodeSignVerify(net *lntest.NetworkHarness, t *harnessTest) {
// alice signs "alice msg" and sends her signature to bob. // alice signs "alice msg" and sends her signature to bob.
sigReq := &lnrpc.SignMessageRequest{Msg: aliceMsg} sigReq := &lnrpc.SignMessageRequest{Msg: aliceMsg}
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
sigResp, err := net.Alice.SignMessage(ctxt, sigReq) sigResp, err := net.Alice.SignMessage(ctxt, sigReq)
if err != nil { if err != nil {
t.Fatalf("SignMessage rpc call failed: %v", err) t.Fatalf("SignMessage rpc call failed: %v", err)
@@ -1384,9 +1336,8 @@ func testSendUpdateDisableChannel(net *lntest.NetworkHarness, t *harnessTest) {
// Open a channel between Alice and Bob and Alice and Carol. These will // Open a channel between Alice and Bob and Alice and Carol. These will
// be closed later on in order to trigger channel update messages // be closed later on in order to trigger channel update messages
// marking the channels as disabled. // marking the channels as disabled.
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
chanPointAliceBob := openChannelAndAssert( chanPointAliceBob := openChannelAndAssert(
ctxt, t, net, net.Alice, net.Bob, t, net, net.Alice, net.Bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -1401,11 +1352,9 @@ func testSendUpdateDisableChannel(net *lntest.NetworkHarness, t *harnessTest) {
}) })
defer shutdownAndAssert(net, t, carol) defer shutdownAndAssert(net, t, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, net.Alice, carol)
net.ConnectNodes(ctxt, t.t, net.Alice, carol)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointAliceCarol := openChannelAndAssert( chanPointAliceCarol := openChannelAndAssert(
ctxt, t, net, net.Alice, carol, t, net, net.Alice, carol,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -1424,18 +1373,14 @@ func testSendUpdateDisableChannel(net *lntest.NetworkHarness, t *harnessTest) {
defer shutdownAndAssert(net, t, eve) defer shutdownAndAssert(net, t, eve)
// Give Eve some coins. // Give Eve some coins.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, eve)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, eve)
// Connect Eve to Carol and Bob, and open a channel to carol. // Connect Eve to Carol and Bob, and open a channel to carol.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, eve, carol)
net.ConnectNodes(ctxt, t.t, eve, carol) net.ConnectNodes(t.t, eve, net.Bob)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.ConnectNodes(ctxt, t.t, eve, net.Bob)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointEveCarol := openChannelAndAssert( chanPointEveCarol := openChannelAndAssert(
ctxt, t, net, eve, carol, t, net, eve, carol,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -1447,8 +1392,7 @@ func testSendUpdateDisableChannel(net *lntest.NetworkHarness, t *harnessTest) {
dave := net.NewNode(t.t, "Dave", nil) dave := net.NewNode(t.t, "Dave", nil)
defer shutdownAndAssert(net, t, dave) defer shutdownAndAssert(net, t, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, net.Bob, dave)
net.ConnectNodes(ctxt, t.t, net.Bob, dave)
daveSub := subscribeGraphNotifications(ctxb, t, dave) daveSub := subscribeGraphNotifications(ctxb, t, dave)
defer close(daveSub.quit) defer close(daveSub.quit)
@@ -1494,8 +1438,7 @@ func testSendUpdateDisableChannel(net *lntest.NetworkHarness, t *harnessTest) {
// Now we'll test a long disconnection. Disconnect Carol and Eve and // Now we'll test a long disconnection. Disconnect Carol and Eve and
// ensure they both detect each other as disabled. Their min backoffs // ensure they both detect each other as disabled. Their min backoffs
// are high enough to not interfere with disabling logic. // are high enough to not interfere with disabling logic.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) if err := net.DisconnectNodes(carol, eve); err != nil {
if err := net.DisconnectNodes(ctxt, carol, eve); err != nil {
t.Fatalf("unable to disconnect Carol from Eve: %v", err) t.Fatalf("unable to disconnect Carol from Eve: %v", err)
} }
@@ -1511,8 +1454,7 @@ func testSendUpdateDisableChannel(net *lntest.NetworkHarness, t *harnessTest) {
// Reconnect Carol and Eve, this should cause them to reenable the // Reconnect Carol and Eve, this should cause them to reenable the
// channel from both ends after a short delay. // channel from both ends after a short delay.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.EnsureConnected(t.t, carol, eve)
net.EnsureConnected(ctxt, t.t, carol, eve)
expectedPolicy.Disabled = false expectedPolicy.Disabled = false
waitForChannelUpdate( waitForChannelUpdate(
@@ -1529,13 +1471,11 @@ func testSendUpdateDisableChannel(net *lntest.NetworkHarness, t *harnessTest) {
// should allow for the disconnect to be detected, but still leave time // should allow for the disconnect to be detected, but still leave time
// to cancel the announcement before the 3 second inactive timeout is // to cancel the announcement before the 3 second inactive timeout is
// hit. // hit.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) if err := net.DisconnectNodes(carol, eve); err != nil {
if err := net.DisconnectNodes(ctxt, carol, eve); err != nil {
t.Fatalf("unable to disconnect Carol from Eve: %v", err) t.Fatalf("unable to disconnect Carol from Eve: %v", err)
} }
time.Sleep(time.Second) time.Sleep(time.Second)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.EnsureConnected(t.t, eve, carol)
net.EnsureConnected(ctxt, t.t, eve, carol)
// Since the disable should have been canceled by both Carol and Eve, we // Since the disable should have been canceled by both Carol and Eve, we
// expect no channel updates to appear on the network. // expect no channel updates to appear on the network.
@@ -1543,14 +1483,12 @@ func testSendUpdateDisableChannel(net *lntest.NetworkHarness, t *harnessTest) {
// Close Alice's channels with Bob and Carol cooperatively and // Close Alice's channels with Bob and Carol cooperatively and
// unilaterally respectively. // unilaterally respectively.
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout) _, _, err = net.CloseChannel(net.Alice, chanPointAliceBob, false)
_, _, err = net.CloseChannel(ctxt, net.Alice, chanPointAliceBob, false)
if err != nil { if err != nil {
t.Fatalf("unable to close channel: %v", err) t.Fatalf("unable to close channel: %v", err)
} }
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout) _, _, err = net.CloseChannel(net.Alice, chanPointAliceCarol, true)
_, _, err = net.CloseChannel(ctxt, net.Alice, chanPointAliceCarol, true)
if err != nil { if err != nil {
t.Fatalf("unable to close channel: %v", err) t.Fatalf("unable to close channel: %v", err)
} }
@@ -1570,8 +1508,7 @@ func testSendUpdateDisableChannel(net *lntest.NetworkHarness, t *harnessTest) {
mineBlocks(t, net, 1, 2) mineBlocks(t, net, 1, 2)
// Also do this check for Eve's channel with Carol. // Also do this check for Eve's channel with Carol.
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout) _, _, err = net.CloseChannel(eve, chanPointEveCarol, false)
_, _, err = net.CloseChannel(ctxt, eve, chanPointEveCarol, false)
if err != nil { if err != nil {
t.Fatalf("unable to close channel: %v", err) t.Fatalf("unable to close channel: %v", err)
} }
@@ -1602,16 +1539,15 @@ func testAbandonChannel(net *lntest.NetworkHarness, t *harnessTest) {
PushAmt: btcutil.Amount(100000), PushAmt: btcutil.Amount(100000),
} }
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
ctxt, t, net, net.Alice, net.Bob, channelParam, t, net, net.Alice, net.Bob, channelParam,
) )
txid, err := lnrpc.GetChanPointFundingTxid(chanPoint) txid, err := lnrpc.GetChanPointFundingTxid(chanPoint)
require.NoError(t.t, err, "alice bob get channel funding txid") require.NoError(t.t, err, "alice bob get channel funding txid")
chanPointStr := fmt.Sprintf("%v:%v", txid, chanPoint.OutputIndex) chanPointStr := fmt.Sprintf("%v:%v", txid, chanPoint.OutputIndex)
// Wait for channel to be confirmed open. // Wait for channel to be confirmed open.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err = net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint) err = net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint)
require.NoError(t.t, err, "alice wait for network channel open") require.NoError(t.t, err, "alice wait for network channel open")
err = net.Bob.WaitForNetworkChannelOpen(ctxt, chanPoint) err = net.Bob.WaitForNetworkChannelOpen(ctxt, chanPoint)
@@ -1742,13 +1678,12 @@ func testSweepAllCoins(net *lntest.NetworkHarness, t *harnessTest) {
// Next, we'll give Ainz exactly 2 utxos of 1 BTC each, with one of // Next, we'll give Ainz exactly 2 utxos of 1 BTC each, with one of
// them being p2wkh and the other being a n2wpkh address. // them being p2wkh and the other being a n2wpkh address.
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, ainz)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, ainz)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.SendCoinsNP2WKH(t.t, btcutil.SatoshiPerBitcoin, ainz)
net.SendCoinsNP2WKH(ctxt, t.t, btcutil.SatoshiPerBitcoin, ainz)
// Ensure that we can't send coins to our own Pubkey. // Ensure that we can't send coins to our own Pubkey.
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
info, err := ainz.GetInfo(ctxt, &lnrpc.GetInfoRequest{}) info, err := ainz.GetInfo(ctxt, &lnrpc.GetInfoRequest{})
if err != nil { if err != nil {
t.Fatalf("unable to get node info: %v", err) t.Fatalf("unable to get node info: %v", err)
@@ -1843,7 +1778,7 @@ func testSweepAllCoins(net *lntest.NetworkHarness, t *harnessTest) {
} }
sweepTxStr := sweepTx.TxHash().String() sweepTxStr := sweepTx.TxHash().String()
assertTxLabel(ctxb, t, ainz, sweepTxStr, sendCoinsLabel) assertTxLabel(t, ainz, sweepTxStr, sendCoinsLabel)
// While we are looking at labels, we test our label transaction command // While we are looking at labels, we test our label transaction command
// to make sure it is behaving as expected. First, we try to label our // to make sure it is behaving as expected. First, we try to label our
@@ -1902,7 +1837,7 @@ func testSweepAllCoins(net *lntest.NetworkHarness, t *harnessTest) {
t.Fatalf("could not label tx: %v", err) t.Fatalf("could not label tx: %v", err)
} }
assertTxLabel(ctxb, t, ainz, sweepTxStr, newLabel) assertTxLabel(t, ainz, sweepTxStr, newLabel)
// Finally, Ainz should now have no coins at all within his wallet. // Finally, Ainz should now have no coins at all within his wallet.
balReq := &lnrpc.WalletBalanceRequest{} balReq := &lnrpc.WalletBalanceRequest{}

View File

@@ -255,8 +255,6 @@ type mppTestContext struct {
func newMppTestContext(t *harnessTest, func newMppTestContext(t *harnessTest,
net *lntest.NetworkHarness) *mppTestContext { net *lntest.NetworkHarness) *mppTestContext {
ctxb := context.Background()
alice := net.NewNode(t.t, "alice", nil) alice := net.NewNode(t.t, "alice", nil)
bob := net.NewNode(t.t, "bob", []string{"--accept-amp"}) bob := net.NewNode(t.t, "bob", []string{"--accept-amp"})
@@ -270,8 +268,7 @@ func newMppTestContext(t *harnessTest,
nodes := []*lntest.HarnessNode{alice, bob, carol, dave, eve} nodes := []*lntest.HarnessNode{alice, bob, carol, dave, eve}
for i := 0; i < len(nodes); i++ { for i := 0; i < len(nodes); i++ {
for j := i + 1; j < len(nodes); j++ { for j := i + 1; j < len(nodes); j++ {
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.EnsureConnected(t.t, nodes[i], nodes[j])
net.EnsureConnected(ctxt, t.t, nodes[i], nodes[j])
} }
} }
@@ -290,18 +287,14 @@ func newMppTestContext(t *harnessTest,
} }
// openChannel is a helper to open a channel from->to. // openChannel is a helper to open a channel from->to.
func (c *mppTestContext) openChannel(from, to *lntest.HarnessNode, chanSize btcutil.Amount) { func (c *mppTestContext) openChannel(from, to *lntest.HarnessNode,
ctxb := context.Background() chanSize btcutil.Amount) {
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) c.net.SendCoins(c.t.t, btcutil.SatoshiPerBitcoin, from)
c.net.SendCoins(ctxt, c.t.t, btcutil.SatoshiPerBitcoin, from)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
ctxt, c.t, c.net, from, to, c.t, c.net, from, to,
lntest.OpenChannelParams{ lntest.OpenChannelParams{Amt: chanSize},
Amt: chanSize,
},
) )
c.closeChannelFuncs = append(c.closeChannelFuncs, func() { c.closeChannelFuncs = append(c.closeChannelFuncs, func() {

View File

@@ -23,14 +23,13 @@ func testHtlcErrorPropagation(net *lntest.NetworkHarness, t *harnessTest) {
// First establish a channel with a capacity of 0.5 BTC between Alice // First establish a channel with a capacity of 0.5 BTC between Alice
// and Bob. // and Bob.
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
chanPointAlice := openChannelAndAssert( chanPointAlice := openChannelAndAssert(
ctxt, t, net, net.Alice, net.Bob, t, net, net.Alice, net.Bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
) )
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
if err := net.Alice.WaitForNetworkChannelOpen(ctxt, chanPointAlice); err != nil { if err := net.Alice.WaitForNetworkChannelOpen(ctxt, chanPointAlice); err != nil {
t.Fatalf("channel not seen by alice before timeout: %v", err) t.Fatalf("channel not seen by alice before timeout: %v", err)
} }
@@ -94,12 +93,10 @@ func testHtlcErrorPropagation(net *lntest.NetworkHarness, t *harnessTest) {
// channel between them so we have the topology: Alice -> Bob -> Carol. // channel between them so we have the topology: Alice -> Bob -> Carol.
// The channel created will be of lower capacity that the one created // The channel created will be of lower capacity that the one created
// above. // above.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, net.Bob, carol)
net.ConnectNodes(ctxt, t.t, net.Bob, carol)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
const bobChanAmt = funding.MaxBtcFundingAmount const bobChanAmt = funding.MaxBtcFundingAmount
chanPointBob := openChannelAndAssert( chanPointBob := openChannelAndAssert(
ctxt, t, net, net.Bob, carol, t, net, net.Bob, carol,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -292,10 +289,8 @@ out:
t.Fatalf("unable to generate carol invoice: %v", err) t.Fatalf("unable to generate carol invoice: %v", err)
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
sendAndAssertSuccess( sendAndAssertSuccess(
ctxt, t, net.Bob, t, net.Bob, &routerrpc.SendPaymentRequest{
&routerrpc.SendPaymentRequest{
PaymentRequest: carolInvoice2.PaymentRequest, PaymentRequest: carolInvoice2.PaymentRequest,
TimeoutSeconds: 60, TimeoutSeconds: 60,
FeeLimitMsat: noFeeLimitMsat, FeeLimitMsat: noFeeLimitMsat,

View File

@@ -20,9 +20,8 @@ func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) {
// Open a channel with 100k satoshis between Alice and Bob with Alice // Open a channel with 100k satoshis between Alice and Bob with Alice
// being the sole funder of the channel. // being the sole funder of the channel.
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
chanPointAlice := openChannelAndAssert( chanPointAlice := openChannelAndAssert(
ctxt, t, net, net.Alice, net.Bob, t, net, net.Alice, net.Bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -50,14 +49,11 @@ func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) {
dave := net.NewNode(t.t, "Dave", daveArgs) dave := net.NewNode(t.t, "Dave", daveArgs)
defer shutdownAndAssert(net, t, dave) defer shutdownAndAssert(net, t, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, dave, net.Alice)
net.ConnectNodes(ctxt, t.t, dave, net.Alice) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, dave)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointDave := openChannelAndAssert( chanPointDave := openChannelAndAssert(
ctxt, t, net, dave, net.Alice, t, net, dave, net.Alice,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -77,14 +73,11 @@ func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) {
carol := net.NewNode(t.t, "Carol", nil) carol := net.NewNode(t.t, "Carol", nil)
defer shutdownAndAssert(net, t, carol) defer shutdownAndAssert(net, t, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, carol, dave)
net.ConnectNodes(ctxt, t.t, carol, dave) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointCarol := openChannelAndAssert( chanPointCarol := openChannelAndAssert(
ctxt, t, net, carol, dave, t, net, carol, dave,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -114,7 +107,7 @@ func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) {
Index: chanPoint.OutputIndex, Index: chanPoint.OutputIndex,
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err = node.WaitForNetworkChannelOpen(ctxt, chanPoint) err = node.WaitForNetworkChannelOpen(ctxt, chanPoint)
if err != nil { if err != nil {
t.Fatalf("%s(%d): timeout waiting for "+ t.Fatalf("%s(%d): timeout waiting for "+
@@ -137,7 +130,7 @@ func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) {
// We'll wait for all parties to recognize the new channels within the // We'll wait for all parties to recognize the new channels within the
// network. // network.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err = dave.WaitForNetworkChannelOpen(ctxt, chanPointDave) err = dave.WaitForNetworkChannelOpen(ctxt, chanPointDave)
if err != nil { if err != nil {
t.Fatalf("dave didn't advertise his channel: %v", err) t.Fatalf("dave didn't advertise his channel: %v", err)
@@ -205,10 +198,7 @@ func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) {
// Using Carol as the source, pay to the 5 invoices from Bob created // Using Carol as the source, pay to the 5 invoices from Bob created
// above. // above.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) err = completePaymentRequests(carol, carol.RouterClient, payReqs, true)
err = completePaymentRequests(
ctxt, carol, carol.RouterClient, payReqs, true,
)
if err != nil { if err != nil {
t.Fatalf("unable to send payments: %v", err) t.Fatalf("unable to send payments: %v", err)
} }

View File

@@ -318,9 +318,8 @@ func testMultiHopHtlcAggregation(net *lntest.NetworkHarness, t *harnessTest,
// At this point, Bob should have broadcast his second layer success // At this point, Bob should have broadcast his second layer success
// transaction, and should have sent it to the nursery for incubation, // transaction, and should have sent it to the nursery for incubation,
// or to the sweeper for sweeping. // or to the sweeper for sweeping.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = waitForNumChannelPendingForceClose( err = waitForNumChannelPendingForceClose(
ctxt, bob, 1, func(c *lnrpcForceCloseChannel) error { bob, 1, func(c *lnrpcForceCloseChannel) error {
if c.Channel.LocalBalance != 0 { if c.Channel.LocalBalance != 0 {
return nil return nil
} }
@@ -415,15 +414,14 @@ func testMultiHopHtlcAggregation(net *lntest.NetworkHarness, t *harnessTest,
block = mineBlocks(t, net, 1, 1)[0] block = mineBlocks(t, net, 1, 1)[0]
assertTxInBlock(t, block, bobSweep) assertTxInBlock(t, block, bobSweep)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) err = waitForNumChannelPendingForceClose(bob, 0, nil)
err = waitForNumChannelPendingForceClose(ctxt, bob, 0, nil)
require.NoError(t.t, err) require.NoError(t.t, err)
// THe channel with Alice is still open. // THe channel with Alice is still open.
assertNodeNumChannels(t, bob, 1) assertNodeNumChannels(t, bob, 1)
// Carol should have no channels left (open nor pending). // Carol should have no channels left (open nor pending).
err = waitForNumChannelPendingForceClose(ctxt, carol, 0, nil) err = waitForNumChannelPendingForceClose(carol, 0, nil)
require.NoError(t.t, err) require.NoError(t.t, err)
assertNodeNumChannels(t, carol, 0) assertNodeNumChannels(t, carol, 0)

View File

@@ -219,9 +219,8 @@ func testMultiHopHtlcLocalChainClaim(net *lntest.NetworkHarness, t *harnessTest,
// At this point, Bob should have broadcast his second layer success // At this point, Bob should have broadcast his second layer success
// transaction, and should have sent it to the nursery for incubation. // transaction, and should have sent it to the nursery for incubation.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = waitForNumChannelPendingForceClose( err = waitForNumChannelPendingForceClose(
ctxt, bob, 1, func(c *lnrpcForceCloseChannel) error { bob, 1, func(c *lnrpcForceCloseChannel) error {
if c.Channel.LocalBalance != 0 { if c.Channel.LocalBalance != 0 {
return nil return nil
} }
@@ -288,21 +287,17 @@ func testMultiHopHtlcLocalChainClaim(net *lntest.NetworkHarness, t *harnessTest,
block = mineBlocks(t, net, 1, 1)[0] block = mineBlocks(t, net, 1, 1)[0]
assertTxInBlock(t, block, bobSweep) assertTxInBlock(t, block, bobSweep)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) err = waitForNumChannelPendingForceClose(bob, 0, nil)
err = waitForNumChannelPendingForceClose(ctxt, bob, 0, nil)
require.NoError(t.t, err) require.NoError(t.t, err)
assertNodeNumChannels(t, bob, 0) assertNodeNumChannels(t, bob, 0)
// Also Carol should have no channels left (open nor pending). // Also Carol should have no channels left (open nor pending).
err = waitForNumChannelPendingForceClose(ctxt, carol, 0, nil) err = waitForNumChannelPendingForceClose(carol, 0, nil)
require.NoError(t.t, err) require.NoError(t.t, err)
assertNodeNumChannels(t, carol, 0) assertNodeNumChannels(t, carol, 0)
// Finally, check that the Alice's payment is correctly marked // Finally, check that the Alice's payment is correctly marked
// succeeded. // succeeded.
ctxt, _ = context.WithTimeout(ctxt, defaultTimeout) err = checkPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED)
err = checkPaymentStatus(
ctxt, alice, preimage, lnrpc.Payment_SUCCEEDED,
)
require.NoError(t.t, err) require.NoError(t.t, err)
} }

View File

@@ -223,8 +223,7 @@ func testMultiHopHtlcLocalTimeout(net *lntest.NetworkHarness, t *harnessTest,
// Once this transaction has been confirmed, Bob should detect that he // Once this transaction has been confirmed, Bob should detect that he
// no longer has any pending channels. // no longer has any pending channels.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) err = waitForNumChannelPendingForceClose(bob, 0, nil)
err = waitForNumChannelPendingForceClose(ctxt, bob, 0, nil)
require.NoError(t.t, err) require.NoError(t.t, err)
// Coop close channel, expect no anchors. // Coop close channel, expect no anchors.

View File

@@ -209,8 +209,7 @@ func testMultiHopReceiverChainClaim(net *lntest.NetworkHarness, t *harnessTest,
// afterwards. // afterwards.
_, err = net.Miner.Client.Generate(1) _, err = net.Miner.Client.Generate(1)
require.NoError(t.t, err) require.NoError(t.t, err)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) err = waitForNumChannelPendingForceClose(carol, 0, nil)
err = waitForNumChannelPendingForceClose(ctxt, carol, 0, nil)
require.NoError(t.t, err) require.NoError(t.t, err)
// The invoice should show as settled for Carol, indicating that it was // The invoice should show as settled for Carol, indicating that it was
@@ -225,10 +224,7 @@ func testMultiHopReceiverChainClaim(net *lntest.NetworkHarness, t *harnessTest,
// Finally, check that the Alice's payment is correctly marked // Finally, check that the Alice's payment is correctly marked
// succeeded. // succeeded.
ctxt, _ = context.WithTimeout(ctxt, defaultTimeout) err = checkPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED)
err = checkPaymentStatus(
ctxt, alice, preimage, lnrpc.Payment_SUCCEEDED,
)
require.NoError(t.t, err) require.NoError(t.t, err)
// We'll close out the channel between Alice and Bob, then shutdown // We'll close out the channel between Alice and Bob, then shutdown

View File

@@ -90,8 +90,7 @@ func testMultiHopHtlcRemoteChainClaim(net *lntest.NetworkHarness, t *harnessTest
) )
// Wait for the channel to be marked pending force close. // Wait for the channel to be marked pending force close.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) err = waitForChannelPendingForceClose(alice, aliceChanPoint)
err = waitForChannelPendingForceClose(ctxt, alice, aliceChanPoint)
require.NoError(t.t, err) require.NoError(t.t, err)
// After closeChannelAndAssertType returns, it has mined a block so now // After closeChannelAndAssertType returns, it has mined a block so now
@@ -230,8 +229,7 @@ func testMultiHopHtlcRemoteChainClaim(net *lntest.NetworkHarness, t *harnessTest
// Now that the sweeping transaction has been confirmed, Bob should now // Now that the sweeping transaction has been confirmed, Bob should now
// recognize that all contracts have been fully resolved, and show no // recognize that all contracts have been fully resolved, and show no
// pending close channels. // pending close channels.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) err = waitForNumChannelPendingForceClose(bob, 0, nil)
err = waitForNumChannelPendingForceClose(ctxt, bob, 0, nil)
require.NoError(t.t, err) require.NoError(t.t, err)
// If we then mine 3 additional blocks, Carol's second level tx will // If we then mine 3 additional blocks, Carol's second level tx will
@@ -249,8 +247,7 @@ func testMultiHopHtlcRemoteChainClaim(net *lntest.NetworkHarness, t *harnessTest
block = mineBlocks(t, net, 1, 1)[0] block = mineBlocks(t, net, 1, 1)[0]
assertTxInBlock(t, block, carolSweep) assertTxInBlock(t, block, carolSweep)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) err = waitForNumChannelPendingForceClose(carol, 0, nil)
err = waitForNumChannelPendingForceClose(ctxt, carol, 0, nil)
require.NoError(t.t, err) require.NoError(t.t, err)
// The invoice should show as settled for Carol, indicating that it was // The invoice should show as settled for Carol, indicating that it was
@@ -265,9 +262,6 @@ func testMultiHopHtlcRemoteChainClaim(net *lntest.NetworkHarness, t *harnessTest
// Finally, check that the Alice's payment is correctly marked // Finally, check that the Alice's payment is correctly marked
// succeeded. // succeeded.
ctxt, _ = context.WithTimeout(ctxt, defaultTimeout) err = checkPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED)
err = checkPaymentStatus(
ctxt, alice, preimage, lnrpc.Payment_SUCCEEDED,
)
require.NoError(t.t, err) require.NoError(t.t, err)
} }

View File

@@ -77,9 +77,8 @@ func testMultiHopLocalForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
// At this point, Bob should have a pending force close channel as he // At this point, Bob should have a pending force close channel as he
// just went to chain. // just went to chain.
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err = waitForNumChannelPendingForceClose( err = waitForNumChannelPendingForceClose(
ctxt, bob, 1, func(c *lnrpcForceCloseChannel) error { bob, 1, func(c *lnrpcForceCloseChannel) error {
if c.LimboBalance == 0 { if c.LimboBalance == 0 {
return fmt.Errorf("bob should have nonzero "+ return fmt.Errorf("bob should have nonzero "+
"limbo balance instead has: %v", "limbo balance instead has: %v",
@@ -117,9 +116,8 @@ func testMultiHopLocalForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
// Bob's pending channel report should show that he has a single HTLC // Bob's pending channel report should show that he has a single HTLC
// that's now in stage one. // that's now in stage one.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = waitForNumChannelPendingForceClose( err = waitForNumChannelPendingForceClose(
ctxt, bob, 1, func(c *lnrpcForceCloseChannel) error { bob, 1, func(c *lnrpcForceCloseChannel) error {
if len(c.PendingHtlcs) != 1 { if len(c.PendingHtlcs) != 1 {
return fmt.Errorf("bob should have pending " + return fmt.Errorf("bob should have pending " +
"htlc but doesn't") "htlc but doesn't")
@@ -155,9 +153,8 @@ func testMultiHopLocalForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
// Additionally, Bob should now show that HTLC as being advanced to the // Additionally, Bob should now show that HTLC as being advanced to the
// second stage. // second stage.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = waitForNumChannelPendingForceClose( err = waitForNumChannelPendingForceClose(
ctxt, bob, 1, func(c *lnrpcForceCloseChannel) error { bob, 1, func(c *lnrpcForceCloseChannel) error {
if len(c.PendingHtlcs) != 1 { if len(c.PendingHtlcs) != 1 {
return fmt.Errorf("bob should have pending " + return fmt.Errorf("bob should have pending " +
"htlc but doesn't") "htlc but doesn't")
@@ -189,8 +186,7 @@ func testMultiHopLocalForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
// At this point, Bob should no longer show any channels as pending // At this point, Bob should no longer show any channels as pending
// close. // close.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) err = waitForNumChannelPendingForceClose(bob, 0, nil)
err = waitForNumChannelPendingForceClose(ctxt, bob, 0, nil)
require.NoError(t.t, err) require.NoError(t.t, err)
// Coop close, no anchors. // Coop close, no anchors.

View File

@@ -89,8 +89,7 @@ func testMultiHopRemoteForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
// At this point, Bob should have a pending force close channel as // At this point, Bob should have a pending force close channel as
// Carol has gone directly to chain. // Carol has gone directly to chain.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) err = waitForNumChannelPendingForceClose(bob, 1, nil)
err = waitForNumChannelPendingForceClose(ctxt, bob, 1, nil)
require.NoError(t.t, err) require.NoError(t.t, err)
// Bob can sweep his output immediately. If there is an anchor, Bob will // Bob can sweep his output immediately. If there is an anchor, Bob will
@@ -115,9 +114,8 @@ func testMultiHopRemoteForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
// If we check Bob's pending channel report, it should show that he has // If we check Bob's pending channel report, it should show that he has
// a single HTLC that's now in the second stage, as skip the initial // a single HTLC that's now in the second stage, as skip the initial
// first stage since this is a direct HTLC. // first stage since this is a direct HTLC.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = waitForNumChannelPendingForceClose( err = waitForNumChannelPendingForceClose(
ctxt, bob, 1, func(c *lnrpcForceCloseChannel) error { bob, 1, func(c *lnrpcForceCloseChannel) error {
if len(c.PendingHtlcs) != 1 { if len(c.PendingHtlcs) != 1 {
return fmt.Errorf("bob should have pending " + return fmt.Errorf("bob should have pending " +
"htlc but doesn't") "htlc but doesn't")
@@ -172,8 +170,7 @@ func testMultiHopRemoteForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
// Now we'll check Bob's pending channel report. Since this was Carol's // Now we'll check Bob's pending channel report. Since this was Carol's
// commitment, he doesn't have to wait for any CSV delays. As a result, // commitment, he doesn't have to wait for any CSV delays. As a result,
// he should show no additional pending transactions. // he should show no additional pending transactions.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) err = waitForNumChannelPendingForceClose(bob, 0, nil)
err = waitForNumChannelPendingForceClose(ctxt, bob, 0, nil)
require.NoError(t.t, err) require.NoError(t.t, err)
// While we're here, we assert that our expired invoice's state is // While we're here, we assert that our expired invoice's state is

View File

@@ -87,9 +87,7 @@ func testMultiHopHtlcClaims(net *lntest.NetworkHarness, t *harnessTest) {
bob := net.NewNode(t, "Bob", args) bob := net.NewNode(t, "Bob", args)
defer shutdownAndAssert(net, ht, bob) defer shutdownAndAssert(net, ht, bob)
ctxb := context.Background() net.ConnectNodes(t, alice, bob)
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
net.ConnectNodes(ctxt, t, alice, bob)
for _, subTest := range subTests { for _, subTest := range subTests {
subTest := subTest subTest := subTest
@@ -150,8 +148,12 @@ func waitForInvoiceAccepted(t *harnessTest, node *lntest.HarnessNode,
// checkPaymentStatus asserts that the given node list a payment with the given // checkPaymentStatus asserts that the given node list a payment with the given
// preimage has the expected status. // preimage has the expected status.
func checkPaymentStatus(ctxt context.Context, node *lntest.HarnessNode, func checkPaymentStatus(node *lntest.HarnessNode, preimage lntypes.Preimage,
preimage lntypes.Preimage, status lnrpc.Payment_PaymentStatus) error { status lnrpc.Payment_PaymentStatus) error {
ctxb := context.Background()
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
defer cancel()
req := &lnrpc.ListPaymentsRequest{ req := &lnrpc.ListPaymentsRequest{
IncludeIncomplete: true, IncludeIncomplete: true,
@@ -208,30 +210,25 @@ func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness,
ctxb := context.Background() ctxb := context.Background()
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.EnsureConnected(t.t, alice, bob)
net.EnsureConnected(ctxt, t.t, alice, bob)
// Make sure there are enough utxos for anchoring. // Make sure there are enough utxos for anchoring.
for i := 0; i < 2; i++ { for i := 0; i < 2; i++ {
ctxt, _ = context.WithTimeout(context.Background(), defaultTimeout) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, alice)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, alice) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, bob)
ctxt, _ = context.WithTimeout(context.Background(), defaultTimeout)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, bob)
} }
// We'll start the test by creating a channel between Alice and Bob, // We'll start the test by creating a channel between Alice and Bob,
// which will act as the first leg for out multi-hop HTLC. // which will act as the first leg for out multi-hop HTLC.
const chanAmt = 1000000 const chanAmt = 1000000
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
aliceChanPoint := openChannelAndAssert( aliceChanPoint := openChannelAndAssert(
ctxt, t, net, alice, bob, t, net, alice, bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
) )
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err := alice.WaitForNetworkChannelOpen(ctxt, aliceChanPoint) err := alice.WaitForNetworkChannelOpen(ctxt, aliceChanPoint)
if err != nil { if err != nil {
t.Fatalf("alice didn't report channel: %v", err) t.Fatalf("alice didn't report channel: %v", err)
@@ -252,23 +249,20 @@ func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness,
} }
carol := net.NewNode(t.t, "Carol", carolFlags) carol := net.NewNode(t.t, "Carol", carolFlags)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, bob, carol)
net.ConnectNodes(ctxt, t.t, bob, carol)
// Make sure Carol has enough utxos for anchoring. Because the anchor by // Make sure Carol has enough utxos for anchoring. Because the anchor by
// itself often doesn't meet the dust limit, a utxo from the wallet // itself often doesn't meet the dust limit, a utxo from the wallet
// needs to be attached as an additional input. This can still lead to a // needs to be attached as an additional input. This can still lead to a
// positively-yielding transaction. // positively-yielding transaction.
for i := 0; i < 2; i++ { for i := 0; i < 2; i++ {
ctxt, _ = context.WithTimeout(context.Background(), defaultTimeout) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, carol)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol)
} }
// We'll then create a channel from Bob to Carol. After this channel is // We'll then create a channel from Bob to Carol. After this channel is
// open, our topology looks like: A -> B -> C. // open, our topology looks like: A -> B -> C.
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
bobChanPoint := openChannelAndAssert( bobChanPoint := openChannelAndAssert(
ctxt, t, net, bob, carol, t, net, bob, carol,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },

View File

@@ -69,10 +69,6 @@ func assertTimeoutError(ctxt context.Context, t *harnessTest,
t.t.Helper() t.t.Helper()
// Create a context with a timeout value.
ctxt, cancel := context.WithTimeout(ctxt, defaultTimeout)
defer cancel()
err := connect(ctxt, node, req) err := connect(ctxt, node, req)
// a DeadlineExceeded error will appear in the context if the above // a DeadlineExceeded error will appear in the context if the above

View File

@@ -31,14 +31,13 @@ func testCPFP(net *lntest.NetworkHarness, t *harnessTest) {
// We'll start the test by sending Alice some coins, which she'll use to // We'll start the test by sending Alice some coins, which she'll use to
// send to Bob. // send to Bob.
ctxb := context.Background() ctxb := context.Background()
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, net.Alice)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, net.Alice)
// Create an address for Bob to send the coins to. // Create an address for Bob to send the coins to.
addrReq := &lnrpc.NewAddressRequest{ addrReq := &lnrpc.NewAddressRequest{
Type: lnrpc.AddressType_WITNESS_PUBKEY_HASH, Type: lnrpc.AddressType_WITNESS_PUBKEY_HASH,
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
resp, err := net.Bob.NewAddress(ctxt, addrReq) resp, err := net.Bob.NewAddress(ctxt, addrReq)
if err != nil { if err != nil {
t.Fatalf("unable to get new address for bob: %v", err) t.Fatalf("unable to get new address for bob: %v", err)
@@ -176,8 +175,7 @@ func testAnchorReservedValue(net *lntest.NetworkHarness, t *harnessTest) {
defer shutdownAndAssert(net, t, bob) defer shutdownAndAssert(net, t, bob)
ctxb := context.Background() ctxb := context.Background()
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, alice, bob)
net.ConnectNodes(ctxt, t.t, alice, bob)
// Send just enough coins for Alice to open a channel without a change // Send just enough coins for Alice to open a channel without a change
// output. // output.
@@ -186,16 +184,13 @@ func testAnchorReservedValue(net *lntest.NetworkHarness, t *harnessTest) {
feeEst = 8000 feeEst = 8000
) )
ctxt, _ = context.WithTimeout(context.Background(), defaultTimeout) net.SendCoins(t.t, chanAmt+feeEst, alice)
net.SendCoins(ctxt, t.t, chanAmt+feeEst, alice)
// wallet, without a change output. This should not be allowed. // wallet, without a change output. This should not be allowed.
resErr := lnwallet.ErrReservedValueInvalidated.Error() resErr := lnwallet.ErrReservedValueInvalidated.Error()
ctxt, _ = context.WithTimeout(context.Background(), defaultTimeout)
_, err := net.OpenChannel( _, err := net.OpenChannel(
ctxt, alice, bob, alice, bob, lntest.OpenChannelParams{
lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
) )
@@ -205,9 +200,8 @@ func testAnchorReservedValue(net *lntest.NetworkHarness, t *harnessTest) {
// Alice opens a smaller channel. This works since it will have a // Alice opens a smaller channel. This works since it will have a
// change output. // change output.
ctxt, _ = context.WithTimeout(context.Background(), defaultTimeout)
aliceChanPoint1 := openChannelAndAssert( aliceChanPoint1 := openChannelAndAssert(
ctxt, t, net, alice, bob, t, net, alice, bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt / 4, Amt: chanAmt / 4,
}, },
@@ -216,7 +210,7 @@ func testAnchorReservedValue(net *lntest.NetworkHarness, t *harnessTest) {
// If Alice tries to open another anchor channel to Bob, Bob should not // If Alice tries to open another anchor channel to Bob, Bob should not
// reject it as he is not contributing any funds. // reject it as he is not contributing any funds.
aliceChanPoint2 := openChannelAndAssert( aliceChanPoint2 := openChannelAndAssert(
ctxt, t, net, alice, bob, lntest.OpenChannelParams{ t, net, alice, bob, lntest.OpenChannelParams{
Amt: chanAmt / 4, Amt: chanAmt / 4,
}, },
) )
@@ -226,9 +220,8 @@ func testAnchorReservedValue(net *lntest.NetworkHarness, t *harnessTest) {
// to remove his support for anchors. // to remove his support for anchors.
err = net.RestartNode(bob, nil) err = net.RestartNode(bob, nil)
require.NoError(t.t, err) require.NoError(t.t, err)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
aliceChanPoint3 := openChannelAndAssert( aliceChanPoint3 := openChannelAndAssert(
ctxt, t, net, alice, bob, lntest.OpenChannelParams{ t, net, alice, bob, lntest.OpenChannelParams{
Amt: chanAmt / 4, Amt: chanAmt / 4,
}, },
) )
@@ -237,7 +230,7 @@ func testAnchorReservedValue(net *lntest.NetworkHarness, t *harnessTest) {
aliceChanPoint1, aliceChanPoint2, aliceChanPoint3, aliceChanPoint1, aliceChanPoint2, aliceChanPoint3,
} }
for _, chanPoint := range chanPoints { for _, chanPoint := range chanPoints {
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err = alice.WaitForNetworkChannelOpen(ctxt, chanPoint) err = alice.WaitForNetworkChannelOpen(ctxt, chanPoint)
require.NoError(t.t, err) require.NoError(t.t, err)
@@ -252,7 +245,7 @@ func testAnchorReservedValue(net *lntest.NetworkHarness, t *harnessTest) {
addrReq := &lnrpc.NewAddressRequest{ addrReq := &lnrpc.NewAddressRequest{
Type: lnrpc.AddressType_WITNESS_PUBKEY_HASH, Type: lnrpc.AddressType_WITNESS_PUBKEY_HASH,
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
resp, err := alice.NewAddress(ctxt, addrReq) resp, err := alice.NewAddress(ctxt, addrReq)
require.NoError(t.t, err) require.NoError(t.t, err)

View File

@@ -82,9 +82,9 @@ func testOpenChannelAfterReorg(net *lntest.NetworkHarness, t *harnessTest) {
// open, then broadcast the funding transaction // open, then broadcast the funding transaction
chanAmt := funding.MaxBtcFundingAmount chanAmt := funding.MaxBtcFundingAmount
pushAmt := btcutil.Amount(0) pushAmt := btcutil.Amount(0)
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) pendingUpdate, err := net.OpenPendingChannel(
pendingUpdate, err := net.OpenPendingChannel(ctxt, net.Alice, net.Bob, net.Alice, net.Bob, chanAmt, pushAmt,
chanAmt, pushAmt) )
if err != nil { if err != nil {
t.Fatalf("unable to open channel: %v", err) t.Fatalf("unable to open channel: %v", err)
} }
@@ -98,8 +98,7 @@ func testOpenChannelAfterReorg(net *lntest.NetworkHarness, t *harnessTest) {
// At this point, the channel's funding transaction will have been // At this point, the channel's funding transaction will have been
// broadcast, but not confirmed, and the channel should be pending. // broadcast, but not confirmed, and the channel should be pending.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) assertNumOpenChannelsPending(t, net.Alice, net.Bob, 1)
assertNumOpenChannelsPending(ctxt, t, net.Alice, net.Bob, 1)
fundingTxID, err := chainhash.NewHash(pendingUpdate.Txid) fundingTxID, err := chainhash.NewHash(pendingUpdate.Txid)
if err != nil { if err != nil {
@@ -126,8 +125,7 @@ func testOpenChannelAfterReorg(net *lntest.NetworkHarness, t *harnessTest) {
if err != nil { if err != nil {
t.Fatalf("unable to get current blockheight %v", err) t.Fatalf("unable to get current blockheight %v", err)
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) err = waitForNodeBlockHeight(net.Alice, minerHeight)
err = waitForNodeBlockHeight(ctxt, net.Alice, minerHeight)
if err != nil { if err != nil {
t.Fatalf("unable to sync to chain: %v", err) t.Fatalf("unable to sync to chain: %v", err)
} }
@@ -140,11 +138,11 @@ func testOpenChannelAfterReorg(net *lntest.NetworkHarness, t *harnessTest) {
} }
// Ensure channel is no longer pending. // Ensure channel is no longer pending.
assertNumOpenChannelsPending(ctxt, t, net.Alice, net.Bob, 0) assertNumOpenChannelsPending(t, net.Alice, net.Bob, 0)
// Wait for Alice and Bob to recognize and advertise the new channel // Wait for Alice and Bob to recognize and advertise the new channel
// generated above. // generated above.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err = net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint) err = net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint)
if err != nil { if err != nil {
t.Fatalf("alice didn't advertise channel before "+ t.Fatalf("alice didn't advertise channel before "+
@@ -218,8 +216,7 @@ func testOpenChannelAfterReorg(net *lntest.NetworkHarness, t *harnessTest) {
if err != nil { if err != nil {
t.Fatalf("unable to get current blockheight %v", err) t.Fatalf("unable to get current blockheight %v", err)
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) err = waitForNodeBlockHeight(net.Alice, tempMinerHeight)
err = waitForNodeBlockHeight(ctxt, net.Alice, tempMinerHeight)
if err != nil { if err != nil {
t.Fatalf("unable to sync to chain: %v", err) t.Fatalf("unable to sync to chain: %v", err)
} }
@@ -255,8 +252,7 @@ func testOpenChannelAfterReorg(net *lntest.NetworkHarness, t *harnessTest) {
block = mineBlocks(t, net, 1, 1)[0] block = mineBlocks(t, net, 1, 1)[0]
assertTxInBlock(t, block, fundingTxID) assertTxInBlock(t, block, fundingTxID)
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout) closeReorgedChannelAndAssert(t, net, net.Alice, chanPoint, false)
closeReorgedChannelAndAssert(ctxt, t, net, net.Alice, chanPoint, false)
} }
// testBasicChannelCreationAndUpdates tests multiple channel opening and closing, // testBasicChannelCreationAndUpdates tests multiple channel opening and closing,
@@ -280,9 +276,8 @@ func testBasicChannelCreationAndUpdates(net *lntest.NetworkHarness, t *harnessTe
// have been properly opened on-chain. // have been properly opened on-chain.
chanPoints := make([]*lnrpc.ChannelPoint, numChannels) chanPoints := make([]*lnrpc.ChannelPoint, numChannels)
for i := 0; i < numChannels; i++ { for i := 0; i < numChannels; i++ {
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
chanPoints[i] = openChannelAndAssert( chanPoints[i] = openChannelAndAssert(
ctxt, t, net, net.Alice, net.Bob, t, net, net.Alice, net.Bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: amount, Amt: amount,
}, },

View File

@@ -31,7 +31,7 @@ func testListPayments(net *lntest.NetworkHarness, t *harnessTest) {
// Check that there are no payments before test. // Check that there are no payments before test.
reqInit := &lnrpc.ListPaymentsRequest{} reqInit := &lnrpc.ListPaymentsRequest{}
ctxt, _ = context.WithTimeout(ctxt, defaultTimeout) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
paymentsRespInit, err := net.Alice.ListPayments(ctxt, reqInit) paymentsRespInit, err := net.Alice.ListPayments(ctxt, reqInit)
if err != nil { if err != nil {
t.Fatalf("error when obtaining Alice payments: %v", err) t.Fatalf("error when obtaining Alice payments: %v", err)
@@ -44,9 +44,8 @@ func testListPayments(net *lntest.NetworkHarness, t *harnessTest) {
// Open a channel with 100k satoshis between Alice and Bob with Alice // Open a channel with 100k satoshis between Alice and Bob with Alice
// being the sole funder of the channel. // being the sole funder of the channel.
chanAmt := btcutil.Amount(100000) chanAmt := btcutil.Amount(100000)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
ctxt, t, net, net.Alice, net.Bob, t, net, net.Alice, net.Bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -82,10 +81,8 @@ func testListPayments(net *lntest.NetworkHarness, t *harnessTest) {
// With the invoice for Bob added, send a payment towards Alice paying // With the invoice for Bob added, send a payment towards Alice paying
// to the above generated invoice. // to the above generated invoice.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
sendAndAssertSuccess( sendAndAssertSuccess(
ctxt, t, net.Alice, t, net.Alice, &routerrpc.SendPaymentRequest{
&routerrpc.SendPaymentRequest{
PaymentRequest: invoiceResp.PaymentRequest, PaymentRequest: invoiceResp.PaymentRequest,
TimeoutSeconds: 60, TimeoutSeconds: 60,
FeeLimitSat: 1000000, FeeLimitSat: 1000000,
@@ -95,7 +92,7 @@ func testListPayments(net *lntest.NetworkHarness, t *harnessTest) {
// Grab Alice's list of payments, she should show the existence of // Grab Alice's list of payments, she should show the existence of
// exactly one payment. // exactly one payment.
req := &lnrpc.ListPaymentsRequest{} req := &lnrpc.ListPaymentsRequest{}
ctxt, _ = context.WithTimeout(ctxt, defaultTimeout) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
paymentsResp, err := net.Alice.ListPayments(ctxt, req) paymentsResp, err := net.Alice.ListPayments(ctxt, req)
if err != nil { if err != nil {
t.Fatalf("error when obtaining Alice payments: %v", err) t.Fatalf("error when obtaining Alice payments: %v", err)
@@ -141,7 +138,7 @@ func testListPayments(net *lntest.NetworkHarness, t *harnessTest) {
// Delete all payments from Alice. DB should have no payments. // Delete all payments from Alice. DB should have no payments.
delReq := &lnrpc.DeleteAllPaymentsRequest{} delReq := &lnrpc.DeleteAllPaymentsRequest{}
ctxt, _ = context.WithTimeout(ctxt, defaultTimeout) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
_, err = net.Alice.DeleteAllPayments(ctxt, delReq) _, err = net.Alice.DeleteAllPayments(ctxt, delReq)
if err != nil { if err != nil {
t.Fatalf("Can't delete payments at the end: %v", err) t.Fatalf("Can't delete payments at the end: %v", err)
@@ -149,7 +146,7 @@ func testListPayments(net *lntest.NetworkHarness, t *harnessTest) {
// Check that there are no payments after test. // Check that there are no payments after test.
listReq := &lnrpc.ListPaymentsRequest{} listReq := &lnrpc.ListPaymentsRequest{}
ctxt, _ = context.WithTimeout(ctxt, defaultTimeout) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
paymentsResp, err = net.Alice.ListPayments(ctxt, listReq) paymentsResp, err = net.Alice.ListPayments(ctxt, listReq)
if err != nil { if err != nil {
t.Fatalf("error when obtaining Alice payments: %v", err) t.Fatalf("error when obtaining Alice payments: %v", err)
@@ -174,10 +171,8 @@ func testPaymentFollowingChannelOpen(net *lntest.NetworkHarness, t *harnessTest)
channelCapacity := paymentAmt * 1000 channelCapacity := paymentAmt * 1000
// We first establish a channel between Alice and Bob. // We first establish a channel between Alice and Bob.
ctxt, cancel := context.WithTimeout(ctxb, channelOpenTimeout)
defer cancel()
pendingUpdate, err := net.OpenPendingChannel( pendingUpdate, err := net.OpenPendingChannel(
ctxt, net.Alice, net.Bob, channelCapacity, 0, net.Alice, net.Bob, channelCapacity, 0,
) )
if err != nil { if err != nil {
t.Fatalf("unable to open channel: %v", err) t.Fatalf("unable to open channel: %v", err)
@@ -186,9 +181,7 @@ func testPaymentFollowingChannelOpen(net *lntest.NetworkHarness, t *harnessTest)
// At this point, the channel's funding transaction will have been // At this point, the channel's funding transaction will have been
// broadcast, but not confirmed. Alice and Bob's nodes // broadcast, but not confirmed. Alice and Bob's nodes
// should reflect this when queried via RPC. // should reflect this when queried via RPC.
ctxt, cancel = context.WithTimeout(ctxb, defaultTimeout) assertNumOpenChannelsPending(t, net.Alice, net.Bob, 1)
defer cancel()
assertNumOpenChannelsPending(ctxt, t, net.Alice, net.Bob, 1)
// We are restarting Bob's node to let the link be created for the // We are restarting Bob's node to let the link be created for the
// pending channel. // pending channel.
@@ -197,16 +190,13 @@ func testPaymentFollowingChannelOpen(net *lntest.NetworkHarness, t *harnessTest)
} }
// We ensure that Bob reconnects to Alice. // We ensure that Bob reconnects to Alice.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.EnsureConnected(t.t, net.Bob, net.Alice)
net.EnsureConnected(ctxt, t.t, net.Bob, net.Alice)
// We mine one block for the channel to be confirmed. // We mine one block for the channel to be confirmed.
_ = mineBlocks(t, net, 6, 1)[0] _ = mineBlocks(t, net, 6, 1)[0]
// We verify that the channel is open from both nodes point of view. // We verify that the channel is open from both nodes point of view.
ctxt, cancel = context.WithTimeout(ctxb, defaultTimeout) assertNumOpenChannelsPending(t, net.Alice, net.Bob, 0)
defer cancel()
assertNumOpenChannelsPending(ctxt, t, net.Alice, net.Bob, 0)
// With the channel open, we'll create invoices for Bob that Alice will // With the channel open, we'll create invoices for Bob that Alice will
// pay to in order to advance the state of the channel. // pay to in order to advance the state of the channel.
@@ -219,9 +209,8 @@ func testPaymentFollowingChannelOpen(net *lntest.NetworkHarness, t *harnessTest)
// Send payment to Bob so that a channel update to disk will be // Send payment to Bob so that a channel update to disk will be
// executed. // executed.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
sendAndAssertSuccess( sendAndAssertSuccess(
ctxt, t, net.Alice, &routerrpc.SendPaymentRequest{ t, net.Alice, &routerrpc.SendPaymentRequest{
PaymentRequest: bobPayReqs[0], PaymentRequest: bobPayReqs[0],
TimeoutSeconds: 60, TimeoutSeconds: 60,
FeeLimitSat: 1000000, FeeLimitSat: 1000000,
@@ -230,7 +219,7 @@ func testPaymentFollowingChannelOpen(net *lntest.NetworkHarness, t *harnessTest)
// At this point we want to make sure the channel is opened and not // At this point we want to make sure the channel is opened and not
// pending. // pending.
ctxt, cancel = context.WithTimeout(ctxb, defaultTimeout) ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
defer cancel() defer cancel()
res, err := net.Bob.ListChannels(ctxt, &lnrpc.ListChannelsRequest{}) res, err := net.Bob.ListChannels(ctxt, &lnrpc.ListChannelsRequest{})
if err != nil { if err != nil {
@@ -263,17 +252,15 @@ func testAsyncPayments(net *lntest.NetworkHarness, t *harnessTest) {
// First establish a channel with a capacity equals to the overall // First establish a channel with a capacity equals to the overall
// amount of payments, between Alice and Bob, at the end of the test // amount of payments, between Alice and Bob, at the end of the test
// Alice should send all money from her side to Bob. // Alice should send all money from her side to Bob.
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
channelCapacity := btcutil.Amount(paymentAmt * 2000) channelCapacity := btcutil.Amount(paymentAmt * 2000)
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
ctxt, t, net, net.Alice, net.Bob, t, net, net.Alice, net.Bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: channelCapacity, Amt: channelCapacity,
}, },
) )
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) info, err := getChanInfo(net.Alice)
info, err := getChanInfo(ctxt, net.Alice)
if err != nil { if err != nil {
t.Fatalf("unable to get alice channel info: %v", err) t.Fatalf("unable to get alice channel info: %v", err)
} }
@@ -298,7 +285,7 @@ func testAsyncPayments(net *lntest.NetworkHarness, t *harnessTest) {
} }
// Wait for Alice to receive the channel edge from the funding manager. // Wait for Alice to receive the channel edge from the funding manager.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err = net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint) err = net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint)
if err != nil { if err != nil {
t.Fatalf("alice didn't see the alice->bob channel before "+ t.Fatalf("alice didn't see the alice->bob channel before "+
@@ -357,8 +344,7 @@ func testAsyncPayments(net *lntest.NetworkHarness, t *harnessTest) {
// htlcs listed and has correct balances. This is needed due to the fact // htlcs listed and has correct balances. This is needed due to the fact
// that we now pipeline the settles. // that we now pipeline the settles.
err = wait.Predicate(func() bool { err = wait.Predicate(func() bool {
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) aliceChan, err := getChanInfo(net.Alice)
aliceChan, err := getChanInfo(ctxt, net.Alice)
if err != nil { if err != nil {
return false return false
} }
@@ -380,8 +366,7 @@ func testAsyncPayments(net *lntest.NetworkHarness, t *harnessTest) {
// Wait for Bob to receive revocation from Alice. // Wait for Bob to receive revocation from Alice.
err = wait.NoError(func() error { err = wait.NoError(func() error {
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) bobChan, err := getChanInfo(net.Bob)
bobChan, err := getChanInfo(ctxt, net.Bob)
if err != nil { if err != nil {
t.Fatalf("unable to get bob's channel info: %v", err) t.Fatalf("unable to get bob's channel info: %v", err)
} }
@@ -429,17 +414,15 @@ func testBidirectionalAsyncPayments(net *lntest.NetworkHarness, t *harnessTest)
// First establish a channel with a capacity equals to the overall // First establish a channel with a capacity equals to the overall
// amount of payments, between Alice and Bob, at the end of the test // amount of payments, between Alice and Bob, at the end of the test
// Alice should send all money from her side to Bob. // Alice should send all money from her side to Bob.
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
ctxt, t, net, net.Alice, net.Bob, t, net, net.Alice, net.Bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: paymentAmt * 2000, Amt: paymentAmt * 2000,
PushAmt: paymentAmt * 1000, PushAmt: paymentAmt * 1000,
}, },
) )
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) info, err := getChanInfo(net.Alice)
info, err := getChanInfo(ctxt, net.Alice)
if err != nil { if err != nil {
t.Fatalf("unable to get alice channel info: %v", err) t.Fatalf("unable to get alice channel info: %v", err)
} }
@@ -475,7 +458,7 @@ func testBidirectionalAsyncPayments(net *lntest.NetworkHarness, t *harnessTest)
} }
// Wait for Alice to receive the channel edge from the funding manager. // Wait for Alice to receive the channel edge from the funding manager.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
if err = net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint); err != nil { if err = net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint); err != nil {
t.Fatalf("alice didn't see the alice->bob channel before "+ t.Fatalf("alice didn't see the alice->bob channel before "+
"timeout: %v", err) "timeout: %v", err)
@@ -547,8 +530,7 @@ func testBidirectionalAsyncPayments(net *lntest.NetworkHarness, t *harnessTest)
// Wait for Alice and Bob to receive revocations messages, and update // Wait for Alice and Bob to receive revocations messages, and update
// states, i.e. balance info. // states, i.e. balance info.
err = wait.NoError(func() error { err = wait.NoError(func() error {
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) aliceInfo, err := getChanInfo(net.Alice)
aliceInfo, err := getChanInfo(ctxt, net.Alice)
if err != nil { if err != nil {
t.Fatalf("unable to get alice's channel info: %v", err) t.Fatalf("unable to get alice's channel info: %v", err)
} }
@@ -578,8 +560,7 @@ func testBidirectionalAsyncPayments(net *lntest.NetworkHarness, t *harnessTest)
// Next query for Bob's and Alice's channel states, in order to confirm // Next query for Bob's and Alice's channel states, in order to confirm
// that all payment have been successful transmitted. // that all payment have been successful transmitted.
err = wait.NoError(func() error { err = wait.NoError(func() error {
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) bobInfo, err := getChanInfo(net.Bob)
bobInfo, err := getChanInfo(ctxt, net.Bob)
if err != nil { if err != nil {
t.Fatalf("unable to get bob's channel info: %v", err) t.Fatalf("unable to get bob's channel info: %v", err)
} }
@@ -619,9 +600,8 @@ func testInvoiceSubscriptions(net *lntest.NetworkHarness, t *harnessTest) {
// Open a channel with 500k satoshis between Alice and Bob with Alice // Open a channel with 500k satoshis between Alice and Bob with Alice
// being the sole funder of the channel. // being the sole funder of the channel.
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
ctxt, t, net, net.Alice, net.Bob, t, net, net.Alice, net.Bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -636,7 +616,7 @@ func testInvoiceSubscriptions(net *lntest.NetworkHarness, t *harnessTest) {
RPreimage: makeFakePayHash(t), RPreimage: makeFakePayHash(t),
Value: paymentAmt, Value: paymentAmt,
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
invoiceResp, err := net.Bob.AddInvoice(ctxt, invoice) invoiceResp, err := net.Bob.AddInvoice(ctxt, invoice)
if err != nil { if err != nil {
t.Fatalf("unable to add invoice: %v", err) t.Fatalf("unable to add invoice: %v", err)
@@ -784,9 +764,8 @@ func testInvoiceSubscriptions(net *lntest.NetworkHarness, t *harnessTest) {
// We'll now have Bob settle out the remainder of these invoices so we // We'll now have Bob settle out the remainder of these invoices so we
// can test that all settled invoices are properly notified. // can test that all settled invoices are properly notified.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = completePaymentRequests( err = completePaymentRequests(
ctxt, net.Alice, net.Alice.RouterClient, payReqs, true, net.Alice, net.Alice.RouterClient, payReqs, true,
) )
if err != nil { if err != nil {
t.Fatalf("unable to send payment: %v", err) t.Fatalf("unable to send payment: %v", err)

View File

@@ -31,14 +31,12 @@ func testPsbtChanFunding(net *lntest.NetworkHarness, t *harnessTest) {
dave := net.NewNode(t.t, "dave", nil) dave := net.NewNode(t.t, "dave", nil)
defer shutdownAndAssert(net, t, dave) defer shutdownAndAssert(net, t, dave)
net.SendCoins(ctxb, t.t, btcutil.SatoshiPerBitcoin, dave) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, dave)
// Before we start the test, we'll ensure both sides are connected so // Before we start the test, we'll ensure both sides are connected so
// the funding flow can be properly executed. // the funding flow can be properly executed.
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout) net.EnsureConnected(t.t, carol, dave)
defer cancel() net.EnsureConnected(t.t, carol, net.Alice)
net.EnsureConnected(ctxt, t.t, carol, dave)
net.EnsureConnected(ctxt, t.t, carol, net.Alice)
// At this point, we can begin our PSBT channel funding workflow. We'll // At this point, we can begin our PSBT channel funding workflow. We'll
// start by generating a pending channel ID externally that will be used // start by generating a pending channel ID externally that will be used
@@ -55,7 +53,7 @@ func testPsbtChanFunding(net *lntest.NetworkHarness, t *harnessTest) {
// Now that we have the pending channel ID, Carol will open the channel // Now that we have the pending channel ID, Carol will open the channel
// by specifying a PSBT shim. We use the NoPublish flag here to avoid // by specifying a PSBT shim. We use the NoPublish flag here to avoid
// publishing the whole batch TX too early. // publishing the whole batch TX too early.
ctxt, cancel = context.WithTimeout(ctxb, defaultTimeout) ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
defer cancel() defer cancel()
chanUpdates, tempPsbt, err := openChannelPsbt( chanUpdates, tempPsbt, err := openChannelPsbt(
ctxt, carol, dave, lntest.OpenChannelParams{ ctxt, carol, dave, lntest.OpenChannelParams{
@@ -235,10 +233,8 @@ func testPsbtChanFunding(net *lntest.NetworkHarness, t *harnessTest) {
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
resp, err := dave.AddInvoice(ctxt, invoice) resp, err := dave.AddInvoice(ctxt, invoice)
require.NoError(t.t, err) require.NoError(t.t, err)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = completePaymentRequests( err = completePaymentRequests(
ctxt, carol, carol.RouterClient, []string{resp.PaymentRequest}, carol, carol.RouterClient, []string{resp.PaymentRequest}, true,
true,
) )
require.NoError(t.t, err) require.NoError(t.t, err)

View File

@@ -45,8 +45,7 @@ func testGetRecoveryInfo(net *lntest.NetworkHarness, t *harnessTest) {
if err != nil { if err != nil {
t.Fatalf("unable to get current blockheight %v", err) t.Fatalf("unable to get current blockheight %v", err)
} }
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) err = waitForNodeBlockHeight(node, minerHeight)
err = waitForNodeBlockHeight(ctxt, node, minerHeight)
if err != nil { if err != nil {
t.Fatalf("unable to sync to chain: %v", err) t.Fatalf("unable to sync to chain: %v", err)
} }
@@ -233,15 +232,11 @@ func testOnchainFundRecovery(net *lntest.NetworkHarness, t *harnessTest) {
} }
// Send one BTC to the next P2WKH address. // Send one BTC to the next P2WKH address.
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, node)
net.SendCoins(
ctxt, t.t, btcutil.SatoshiPerBitcoin, node,
)
// And another to the next NP2WKH address. // And another to the next NP2WKH address.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.SendCoinsNP2WKH( net.SendCoinsNP2WKH(
ctxt, t.t, btcutil.SatoshiPerBitcoin, node, t.t, btcutil.SatoshiPerBitcoin, node,
) )
} }
} }

View File

@@ -499,17 +499,15 @@ func wsTestCaseBiDirectionalSubscription(ht *harnessTest,
// Before we start opening channels, make sure the two nodes are // Before we start opening channels, make sure the two nodes are
// connected. // connected.
net.EnsureConnected(context.Background(), ht.t, net.Alice, net.Bob) net.EnsureConnected(ht.t, net.Alice, net.Bob)
// Open 3 channels to make sure multiple requests and responses can be // Open 3 channels to make sure multiple requests and responses can be
// sent over the web socket. // sent over the web socket.
const numChannels = 3 const numChannels = 3
for i := 0; i < numChannels; i++ { for i := 0; i < numChannels; i++ {
openChannelAndAssert( openChannelAndAssert(
context.Background(), ht, net, net.Bob, net.Alice, ht, net, net.Bob, net.Alice,
lntest.OpenChannelParams{ lntest.OpenChannelParams{Amt: 500000},
Amt: 500000,
},
) )
select { select {

View File

@@ -44,20 +44,17 @@ func testRevokedCloseRetribution(net *lntest.NetworkHarness, t *harnessTest) {
// We must let Bob communicate with Carol before they are able to open // We must let Bob communicate with Carol before they are able to open
// channel, so we connect Bob and Carol, // channel, so we connect Bob and Carol,
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, carol, net.Bob)
net.ConnectNodes(ctxt, t.t, carol, net.Bob)
// Before we make a channel, we'll load up Carol with some coins sent // Before we make a channel, we'll load up Carol with some coins sent
// directly from the miner. // directly from the miner.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, carol)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol)
// In order to test Carol's response to an uncooperative channel // In order to test Carol's response to an uncooperative channel
// closure by Bob, we'll first open up a channel between them with a // closure by Bob, we'll first open up a channel between them with a
// 0.5 BTC value. // 0.5 BTC value.
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
ctxt, t, net, carol, net.Bob, t, net, carol, net.Bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -73,7 +70,7 @@ func testRevokedCloseRetribution(net *lntest.NetworkHarness, t *harnessTest) {
} }
// Wait for Carol to receive the channel edge from the funding manager. // Wait for Carol to receive the channel edge from the funding manager.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err = carol.WaitForNetworkChannelOpen(ctxt, chanPoint) err = carol.WaitForNetworkChannelOpen(ctxt, chanPoint)
if err != nil { if err != nil {
t.Fatalf("carol didn't see the carol->bob channel before "+ t.Fatalf("carol didn't see the carol->bob channel before "+
@@ -82,10 +79,8 @@ func testRevokedCloseRetribution(net *lntest.NetworkHarness, t *harnessTest) {
// Send payments from Carol to Bob using 3 of Bob's payment hashes // Send payments from Carol to Bob using 3 of Bob's payment hashes
// generated above. // generated above.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = completePaymentRequests( err = completePaymentRequests(
ctxt, carol, carol.RouterClient, bobPayReqs[:numInvoices/2], carol, carol.RouterClient, bobPayReqs[:numInvoices/2], true,
true,
) )
if err != nil { if err != nil {
t.Fatalf("unable to send payments: %v", err) t.Fatalf("unable to send payments: %v", err)
@@ -96,8 +91,7 @@ func testRevokedCloseRetribution(net *lntest.NetworkHarness, t *harnessTest) {
var bobChan *lnrpc.Channel var bobChan *lnrpc.Channel
var predErr error var predErr error
err = wait.Predicate(func() bool { err = wait.Predicate(func() bool {
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) bChan, err := getChanInfo(net.Bob)
bChan, err := getChanInfo(ctxt, net.Bob)
if err != nil { if err != nil {
t.Fatalf("unable to get bob's channel info: %v", err) t.Fatalf("unable to get bob's channel info: %v", err)
} }
@@ -129,17 +123,14 @@ func testRevokedCloseRetribution(net *lntest.NetworkHarness, t *harnessTest) {
// Finally, send payments from Carol to Bob, consuming Bob's remaining // Finally, send payments from Carol to Bob, consuming Bob's remaining
// payment hashes. // payment hashes.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = completePaymentRequests( err = completePaymentRequests(
ctxt, carol, carol.RouterClient, bobPayReqs[numInvoices/2:], carol, carol.RouterClient, bobPayReqs[numInvoices/2:], true,
true,
) )
if err != nil { if err != nil {
t.Fatalf("unable to send payments: %v", err) t.Fatalf("unable to send payments: %v", err)
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) bobChan, err = getChanInfo(net.Bob)
bobChan, err = getChanInfo(ctxt, net.Bob)
if err != nil { if err != nil {
t.Fatalf("unable to get bob chan info: %v", err) t.Fatalf("unable to get bob chan info: %v", err)
} }
@@ -156,8 +147,7 @@ func testRevokedCloseRetribution(net *lntest.NetworkHarness, t *harnessTest) {
// Now query for Bob's channel state, it should show that he's at a // Now query for Bob's channel state, it should show that he's at a
// state number in the past, not the *latest* state. // state number in the past, not the *latest* state.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) bobChan, err = getChanInfo(net.Bob)
bobChan, err = getChanInfo(ctxt, net.Bob)
if err != nil { if err != nil {
t.Fatalf("unable to get bob chan info: %v", err) t.Fatalf("unable to get bob chan info: %v", err)
} }
@@ -172,8 +162,9 @@ func testRevokedCloseRetribution(net *lntest.NetworkHarness, t *harnessTest) {
var closeUpdates lnrpc.Lightning_CloseChannelClient var closeUpdates lnrpc.Lightning_CloseChannelClient
force := true force := true
err = wait.Predicate(func() bool { err = wait.Predicate(func() bool {
ctxt, _ := context.WithTimeout(ctxb, channelCloseTimeout) closeUpdates, _, err = net.CloseChannel(
closeUpdates, _, err = net.CloseChannel(ctxt, net.Bob, chanPoint, force) net.Bob, chanPoint, force,
)
if err != nil { if err != nil {
predErr = err predErr = err
return false return false
@@ -206,8 +197,7 @@ func testRevokedCloseRetribution(net *lntest.NetworkHarness, t *harnessTest) {
// block. // block.
block := mineBlocks(t, net, 1, 1)[0] block := mineBlocks(t, net, 1, 1)[0]
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout) breachTXID, err := net.WaitForChannelClose(closeUpdates)
breachTXID, err := net.WaitForChannelClose(ctxt, closeUpdates)
if err != nil { if err != nil {
t.Fatalf("error while waiting for channel close: %v", err) t.Fatalf("error while waiting for channel close: %v", err)
} }
@@ -302,20 +292,17 @@ func testRevokedCloseRetributionZeroValueRemoteOutput(net *lntest.NetworkHarness
// We must let Dave have an open channel before she can send a node // We must let Dave have an open channel before she can send a node
// announcement, so we open a channel with Carol, // announcement, so we open a channel with Carol,
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, dave, carol)
net.ConnectNodes(ctxt, t.t, dave, carol)
// Before we make a channel, we'll load up Dave with some coins sent // Before we make a channel, we'll load up Dave with some coins sent
// directly from the miner. // directly from the miner.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, dave)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, dave)
// In order to test Dave's response to an uncooperative channel // In order to test Dave's response to an uncooperative channel
// closure by Carol, we'll first open up a channel between them with a // closure by Carol, we'll first open up a channel between them with a
// 0.5 BTC value. // 0.5 BTC value.
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
ctxt, t, net, dave, carol, t, net, dave, carol,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -331,7 +318,7 @@ func testRevokedCloseRetributionZeroValueRemoteOutput(net *lntest.NetworkHarness
} }
// Wait for Dave to receive the channel edge from the funding manager. // Wait for Dave to receive the channel edge from the funding manager.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err = dave.WaitForNetworkChannelOpen(ctxt, chanPoint) err = dave.WaitForNetworkChannelOpen(ctxt, chanPoint)
if err != nil { if err != nil {
t.Fatalf("dave didn't see the dave->carol channel before "+ t.Fatalf("dave didn't see the dave->carol channel before "+
@@ -340,8 +327,7 @@ func testRevokedCloseRetributionZeroValueRemoteOutput(net *lntest.NetworkHarness
// Next query for Carol's channel state, as we sent 0 payments, Carol // Next query for Carol's channel state, as we sent 0 payments, Carol
// should now see her balance as being 0 satoshis. // should now see her balance as being 0 satoshis.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) carolChan, err := getChanInfo(carol)
carolChan, err := getChanInfo(ctxt, carol)
if err != nil { if err != nil {
t.Fatalf("unable to get carol's channel info: %v", err) t.Fatalf("unable to get carol's channel info: %v", err)
} }
@@ -364,16 +350,14 @@ func testRevokedCloseRetributionZeroValueRemoteOutput(net *lntest.NetworkHarness
// Finally, send payments from Dave to Carol, consuming Carol's remaining // Finally, send payments from Dave to Carol, consuming Carol's remaining
// payment hashes. // payment hashes.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = completePaymentRequests( err = completePaymentRequests(
ctxt, dave, dave.RouterClient, carolPayReqs, false, dave, dave.RouterClient, carolPayReqs, false,
) )
if err != nil { if err != nil {
t.Fatalf("unable to send payments: %v", err) t.Fatalf("unable to send payments: %v", err)
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) _, err = getChanInfo(carol)
_, err = getChanInfo(ctxt, carol)
if err != nil { if err != nil {
t.Fatalf("unable to get carol chan info: %v", err) t.Fatalf("unable to get carol chan info: %v", err)
} }
@@ -390,8 +374,7 @@ func testRevokedCloseRetributionZeroValueRemoteOutput(net *lntest.NetworkHarness
// Now query for Carol's channel state, it should show that he's at a // Now query for Carol's channel state, it should show that he's at a
// state number in the past, not the *latest* state. // state number in the past, not the *latest* state.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) carolChan, err = getChanInfo(carol)
carolChan, err = getChanInfo(ctxt, carol)
if err != nil { if err != nil {
t.Fatalf("unable to get carol chan info: %v", err) t.Fatalf("unable to get carol chan info: %v", err)
} }
@@ -411,9 +394,8 @@ func testRevokedCloseRetributionZeroValueRemoteOutput(net *lntest.NetworkHarness
force := true force := true
err = wait.Predicate(func() bool { err = wait.Predicate(func() bool {
ctxt, _ := context.WithTimeout(ctxb, channelCloseTimeout)
closeUpdates, closeTxID, closeErr = net.CloseChannel( closeUpdates, closeTxID, closeErr = net.CloseChannel(
ctxt, carol, chanPoint, force, carol, chanPoint, force,
) )
return closeErr == nil return closeErr == nil
}, defaultTimeout) }, defaultTimeout)
@@ -445,8 +427,7 @@ func testRevokedCloseRetributionZeroValueRemoteOutput(net *lntest.NetworkHarness
t.Fatalf("unable to stop Dave's node: %v", err) t.Fatalf("unable to stop Dave's node: %v", err)
} }
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout) breachTXID, err := net.WaitForChannelClose(closeUpdates)
breachTXID, err := net.WaitForChannelClose(ctxt, closeUpdates)
if err != nil { if err != nil {
t.Fatalf("error while waiting for channel close: %v", err) t.Fatalf("error while waiting for channel close: %v", err)
} }
@@ -535,20 +516,17 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness,
// We must let Dave communicate with Carol before they are able to open // We must let Dave communicate with Carol before they are able to open
// channel, so we connect Dave and Carol, // channel, so we connect Dave and Carol,
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, dave, carol)
net.ConnectNodes(ctxt, t.t, dave, carol)
// Before we make a channel, we'll load up Dave with some coins sent // Before we make a channel, we'll load up Dave with some coins sent
// directly from the miner. // directly from the miner.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, dave)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, dave)
// In order to test Dave's response to an uncooperative channel closure // In order to test Dave's response to an uncooperative channel closure
// by Carol, we'll first open up a channel between them with a // by Carol, we'll first open up a channel between them with a
// funding.MaxBtcFundingAmount (2^24) satoshis value. // funding.MaxBtcFundingAmount (2^24) satoshis value.
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
ctxt, t, net, dave, carol, t, net, dave, carol,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
PushAmt: pushAmt, PushAmt: pushAmt,
@@ -567,8 +545,7 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness,
// We'll introduce a closure to validate that Carol's current balance // We'll introduce a closure to validate that Carol's current balance
// matches the given expected amount. // matches the given expected amount.
checkCarolBalance := func(expectedAmt int64) { checkCarolBalance := func(expectedAmt int64) {
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) carolChan, err := getChanInfo(carol)
carolChan, err := getChanInfo(ctxt, carol)
if err != nil { if err != nil {
t.Fatalf("unable to get carol's channel info: %v", err) t.Fatalf("unable to get carol's channel info: %v", err)
} }
@@ -583,8 +560,7 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness,
// number of updates is at least as large as the provided minimum // number of updates is at least as large as the provided minimum
// number. // number.
checkCarolNumUpdatesAtLeast := func(minimum uint64) { checkCarolNumUpdatesAtLeast := func(minimum uint64) {
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) carolChan, err := getChanInfo(carol)
carolChan, err := getChanInfo(ctxt, carol)
if err != nil { if err != nil {
t.Fatalf("unable to get carol's channel info: %v", err) t.Fatalf("unable to get carol's channel info: %v", err)
} }
@@ -596,7 +572,7 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness,
} }
// Wait for Dave to receive the channel edge from the funding manager. // Wait for Dave to receive the channel edge from the funding manager.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err = dave.WaitForNetworkChannelOpen(ctxt, chanPoint) err = dave.WaitForNetworkChannelOpen(ctxt, chanPoint)
if err != nil { if err != nil {
t.Fatalf("dave didn't see the dave->carol channel before "+ t.Fatalf("dave didn't see the dave->carol channel before "+
@@ -608,10 +584,8 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness,
// Send payments from Dave to Carol using 3 of Carol's payment hashes // Send payments from Dave to Carol using 3 of Carol's payment hashes
// generated above. // generated above.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = completePaymentRequests( err = completePaymentRequests(
ctxt, dave, dave.RouterClient, carolPayReqs[:numInvoices/2], dave, dave.RouterClient, carolPayReqs[:numInvoices/2], false,
false,
) )
if err != nil { if err != nil {
t.Fatalf("unable to send payments: %v", err) t.Fatalf("unable to send payments: %v", err)
@@ -629,10 +603,8 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness,
// Send payments from Carol to Dave using 3 of Dave's payment hashes // Send payments from Carol to Dave using 3 of Dave's payment hashes
// generated above. // generated above.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = completePaymentRequests( err = completePaymentRequests(
ctxt, carol, carol.RouterClient, davePayReqs[:numInvoices/2], carol, carol.RouterClient, davePayReqs[:numInvoices/2], false,
false,
) )
if err != nil { if err != nil {
t.Fatalf("unable to send payments: %v", err) t.Fatalf("unable to send payments: %v", err)
@@ -641,8 +613,7 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness,
// Next query for Carol's channel state, as we sent 3 payments of 10k // Next query for Carol's channel state, as we sent 3 payments of 10k
// satoshis each, however Carol should now see her balance as being // satoshis each, however Carol should now see her balance as being
// equal to the push amount in satoshis since she has not settled. // equal to the push amount in satoshis since she has not settled.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) carolChan, err := getChanInfo(carol)
carolChan, err := getChanInfo(ctxt, carol)
if err != nil { if err != nil {
t.Fatalf("unable to get carol's channel info: %v", err) t.Fatalf("unable to get carol's channel info: %v", err)
} }
@@ -669,10 +640,8 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness,
// Finally, send payments from Dave to Carol, consuming Carol's // Finally, send payments from Dave to Carol, consuming Carol's
// remaining payment hashes. // remaining payment hashes.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = completePaymentRequests( err = completePaymentRequests(
ctxt, dave, dave.RouterClient, carolPayReqs[numInvoices/2:], dave, dave.RouterClient, carolPayReqs[numInvoices/2:], false,
false,
) )
if err != nil { if err != nil {
t.Fatalf("unable to send payments: %v", err) t.Fatalf("unable to send payments: %v", err)
@@ -711,8 +680,7 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness,
// Now query for Carol's channel state, it should show that she's at a // Now query for Carol's channel state, it should show that she's at a
// state number in the past, *not* the latest state. // state number in the past, *not* the latest state.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) carolChan, err = getChanInfo(carol)
carolChan, err = getChanInfo(ctxt, carol)
if err != nil { if err != nil {
t.Fatalf("unable to get carol chan info: %v", err) t.Fatalf("unable to get carol chan info: %v", err)
} }
@@ -725,9 +693,9 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness,
// commitment transaction of a prior *revoked* state, so she'll soon // commitment transaction of a prior *revoked* state, so she'll soon
// feel the wrath of Dave's retribution. // feel the wrath of Dave's retribution.
force := true force := true
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout) closeUpdates, closeTxID, err := net.CloseChannel(
closeUpdates, closeTxID, err := net.CloseChannel(ctxt, carol, carol, chanPoint, force,
chanPoint, force) )
if err != nil { if err != nil {
t.Fatalf("unable to close channel: %v", err) t.Fatalf("unable to close channel: %v", err)
} }
@@ -755,8 +723,7 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness,
// Finally, wait for the final close status update, then ensure that // Finally, wait for the final close status update, then ensure that
// the closing transaction was included in the block. // the closing transaction was included in the block.
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout) breachTXID, err := net.WaitForChannelClose(closeUpdates)
breachTXID, err := net.WaitForChannelClose(ctxt, closeUpdates)
if err != nil { if err != nil {
t.Fatalf("error while waiting for channel close: %v", err) t.Fatalf("error while waiting for channel close: %v", err)
} }
@@ -1032,18 +999,17 @@ func testRevokedCloseRetributionAltruistWatchtowerCase(
// We must let Dave have an open channel before she can send a node // We must let Dave have an open channel before she can send a node
// announcement, so we open a channel with Carol, // announcement, so we open a channel with Carol,
net.ConnectNodes(ctxb, t.t, dave, carol) net.ConnectNodes(t.t, dave, carol)
// Before we make a channel, we'll load up Dave with some coins sent // Before we make a channel, we'll load up Dave with some coins sent
// directly from the miner. // directly from the miner.
net.SendCoins(ctxb, t.t, btcutil.SatoshiPerBitcoin, dave) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, dave)
// In order to test Dave's response to an uncooperative channel // In order to test Dave's response to an uncooperative channel
// closure by Carol, we'll first open up a channel between them with a // closure by Carol, we'll first open up a channel between them with a
// 0.5 BTC value. // 0.5 BTC value.
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
ctxt, t, net, dave, carol, t, net, dave, carol,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: 3 * (chanAmt / 4), Amt: 3 * (chanAmt / 4),
PushAmt: chanAmt / 4, PushAmt: chanAmt / 4,
@@ -1070,8 +1036,7 @@ func testRevokedCloseRetributionAltruistWatchtowerCase(
// Next query for Carol's channel state, as we sent 0 payments, Carol // Next query for Carol's channel state, as we sent 0 payments, Carol
// should still see her balance as the push amount, which is 1/4 of the // should still see her balance as the push amount, which is 1/4 of the
// capacity. // capacity.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) carolChan, err := getChanInfo(carol)
carolChan, err := getChanInfo(ctxt, carol)
if err != nil { if err != nil {
t.Fatalf("unable to get carol's channel info: %v", err) t.Fatalf("unable to get carol's channel info: %v", err)
} }
@@ -1095,7 +1060,7 @@ func testRevokedCloseRetributionAltruistWatchtowerCase(
// Finally, send payments from Dave to Carol, consuming Carol's remaining // Finally, send payments from Dave to Carol, consuming Carol's remaining
// payment hashes. // payment hashes.
err = completePaymentRequests( err = completePaymentRequests(
ctxb, dave, dave.RouterClient, carolPayReqs, false, dave, dave.RouterClient, carolPayReqs, false,
) )
if err != nil { if err != nil {
t.Fatalf("unable to send payments: %v", err) t.Fatalf("unable to send payments: %v", err)
@@ -1154,8 +1119,7 @@ func testRevokedCloseRetributionAltruistWatchtowerCase(
// Now query for Carol's channel state, it should show that he's at a // Now query for Carol's channel state, it should show that he's at a
// state number in the past, not the *latest* state. // state number in the past, not the *latest* state.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) carolChan, err = getChanInfo(carol)
carolChan, err = getChanInfo(ctxt, carol)
if err != nil { if err != nil {
t.Fatalf("unable to get carol chan info: %v", err) t.Fatalf("unable to get carol chan info: %v", err)
} }
@@ -1167,9 +1131,7 @@ func testRevokedCloseRetributionAltruistWatchtowerCase(
// broadcasting his current channel state. This is actually the // broadcasting his current channel state. This is actually the
// commitment transaction of a prior *revoked* state, so he'll soon // commitment transaction of a prior *revoked* state, so he'll soon
// feel the wrath of Dave's retribution. // feel the wrath of Dave's retribution.
closeUpdates, closeTxID, err := net.CloseChannel( closeUpdates, closeTxID, err := net.CloseChannel(carol, chanPoint, true)
ctxb, carol, chanPoint, true,
)
if err != nil { if err != nil {
t.Fatalf("unable to close channel: %v", err) t.Fatalf("unable to close channel: %v", err)
} }
@@ -1191,8 +1153,7 @@ func testRevokedCloseRetributionAltruistWatchtowerCase(
// block. // block.
block := mineBlocks(t, net, 1, 1)[0] block := mineBlocks(t, net, 1, 1)[0]
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) breachTXID, err := net.WaitForChannelClose(closeUpdates)
breachTXID, err := net.WaitForChannelClose(ctxt, closeUpdates)
if err != nil { if err != nil {
t.Fatalf("error while waiting for channel close: %v", err) t.Fatalf("error while waiting for channel close: %v", err)
} }

View File

@@ -103,16 +103,13 @@ func testSingleHopSendToRouteCase(net *lntest.NetworkHarness, t *harnessTest,
dave := net.NewNode(t.t, "Dave", nil) dave := net.NewNode(t.t, "Dave", nil)
defer shutdownAndAssert(net, t, dave) defer shutdownAndAssert(net, t, dave)
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, carol, dave)
net.ConnectNodes(ctxt, t.t, carol, dave) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol)
// Open a channel with 100k satoshis between Carol and Dave with Carol // Open a channel with 100k satoshis between Carol and Dave with Carol
// being the sole funder of the channel. // being the sole funder of the channel.
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointCarol := openChannelAndAssert( chanPointCarol := openChannelAndAssert(
ctxt, t, net, carol, dave, t, net, carol, dave,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -141,7 +138,7 @@ func testSingleHopSendToRouteCase(net *lntest.NetworkHarness, t *harnessTest,
Index: chanPoint.OutputIndex, Index: chanPoint.OutputIndex,
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err = node.WaitForNetworkChannelOpen(ctxt, chanPoint) err = node.WaitForNetworkChannelOpen(ctxt, chanPoint)
if err != nil { if err != nil {
t.Fatalf("%s(%d): timeout waiting for "+ t.Fatalf("%s(%d): timeout waiting for "+
@@ -182,10 +179,8 @@ func testSingleHopSendToRouteCase(net *lntest.NetworkHarness, t *harnessTest,
if err != nil { if err != nil {
t.Fatalf("unable to get best height: %v", err) t.Fatalf("unable to get best height: %v", err)
} }
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout) require.NoError(t.t, waitForNodeBlockHeight(carol, minerHeight))
defer cancel() require.NoError(t.t, waitForNodeBlockHeight(dave, minerHeight))
require.NoError(t.t, waitForNodeBlockHeight(ctxt, carol, minerHeight))
require.NoError(t.t, waitForNodeBlockHeight(ctxt, dave, minerHeight))
// Query for routes to pay from Carol to Dave using the default CLTV // Query for routes to pay from Carol to Dave using the default CLTV
// config. // config.
@@ -193,7 +188,7 @@ func testSingleHopSendToRouteCase(net *lntest.NetworkHarness, t *harnessTest,
PubKey: dave.PubKeyStr, PubKey: dave.PubKeyStr,
Amt: paymentAmtSat, Amt: paymentAmtSat,
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
routes, err := carol.QueryRoutes(ctxt, routesReq) routes, err := carol.QueryRoutes(ctxt, routesReq)
if err != nil { if err != nil {
t.Fatalf("unable to get route from %s: %v", t.Fatalf("unable to get route from %s: %v",
@@ -310,7 +305,7 @@ func testSingleHopSendToRouteCase(net *lntest.NetworkHarness, t *harnessTest,
// Verify that the payment's from Carol's PoV have the correct payment // Verify that the payment's from Carol's PoV have the correct payment
// hash and amount. // hash and amount.
ctxt, _ = context.WithTimeout(ctxt, defaultTimeout) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
paymentsResp, err := carol.ListPayments( paymentsResp, err := carol.ListPayments(
ctxt, &lnrpc.ListPaymentsRequest{}, ctxt, &lnrpc.ListPaymentsRequest{},
) )
@@ -390,7 +385,7 @@ func testSingleHopSendToRouteCase(net *lntest.NetworkHarness, t *harnessTest,
// Verify that the invoices's from Dave's PoV have the correct payment // Verify that the invoices's from Dave's PoV have the correct payment
// hash and amount. // hash and amount.
ctxt, _ = context.WithTimeout(ctxt, defaultTimeout) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
invoicesResp, err := dave.ListInvoices( invoicesResp, err := dave.ListInvoices(
ctxt, &lnrpc.ListInvoiceRequest{}, ctxt, &lnrpc.ListInvoiceRequest{},
) )
@@ -445,9 +440,8 @@ func testMultiHopSendToRoute(net *lntest.NetworkHarness, t *harnessTest) {
// Open a channel with 100k satoshis between Alice and Bob with Alice // Open a channel with 100k satoshis between Alice and Bob with Alice
// being the sole funder of the channel. // being the sole funder of the channel.
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
chanPointAlice := openChannelAndAssert( chanPointAlice := openChannelAndAssert(
ctxt, t, net, net.Alice, net.Bob, t, net, net.Alice, net.Bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -469,14 +463,11 @@ func testMultiHopSendToRoute(net *lntest.NetworkHarness, t *harnessTest) {
carol := net.NewNode(t.t, "Carol", nil) carol := net.NewNode(t.t, "Carol", nil)
defer shutdownAndAssert(net, t, carol) defer shutdownAndAssert(net, t, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, carol, net.Bob)
net.ConnectNodes(ctxt, t.t, carol, net.Bob) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, net.Bob)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, net.Bob)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointBob := openChannelAndAssert( chanPointBob := openChannelAndAssert(
ctxt, t, net, net.Bob, carol, t, net, net.Bob, carol,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -505,7 +496,7 @@ func testMultiHopSendToRoute(net *lntest.NetworkHarness, t *harnessTest) {
Index: chanPoint.OutputIndex, Index: chanPoint.OutputIndex,
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err = node.WaitForNetworkChannelOpen(ctxt, chanPoint) err = node.WaitForNetworkChannelOpen(ctxt, chanPoint)
if err != nil { if err != nil {
t.Fatalf("%s(%d): timeout waiting for "+ t.Fatalf("%s(%d): timeout waiting for "+
@@ -537,7 +528,7 @@ func testMultiHopSendToRoute(net *lntest.NetworkHarness, t *harnessTest) {
Amt: paymentAmt, Amt: paymentAmt,
FinalCltvDelta: chainreg.DefaultBitcoinTimeLockDelta, FinalCltvDelta: chainreg.DefaultBitcoinTimeLockDelta,
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
routes, err := net.Alice.QueryRoutes(ctxt, routesReq) routes, err := net.Alice.QueryRoutes(ctxt, routesReq)
if err != nil { if err != nil {
t.Fatalf("unable to get route: %v", err) t.Fatalf("unable to get route: %v", err)
@@ -618,15 +609,14 @@ func testSendToRouteErrorPropagation(net *lntest.NetworkHarness, t *harnessTest)
// Open a channel with 100k satoshis between Alice and Bob with Alice // Open a channel with 100k satoshis between Alice and Bob with Alice
// being the sole funder of the channel. // being the sole funder of the channel.
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
chanPointAlice := openChannelAndAssert( chanPointAlice := openChannelAndAssert(
ctxt, t, net, net.Alice, net.Bob, t, net, net.Alice, net.Bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
) )
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err := net.Alice.WaitForNetworkChannelOpen(ctxt, chanPointAlice) err := net.Alice.WaitForNetworkChannelOpen(ctxt, chanPointAlice)
if err != nil { if err != nil {
t.Fatalf("alice didn't advertise her channel: %v", err) t.Fatalf("alice didn't advertise her channel: %v", err)
@@ -642,21 +632,17 @@ func testSendToRouteErrorPropagation(net *lntest.NetworkHarness, t *harnessTest)
carol := net.NewNode(t.t, "Carol", nil) carol := net.NewNode(t.t, "Carol", nil)
defer shutdownAndAssert(net, t, carol) defer shutdownAndAssert(net, t, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, carol)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol)
charlie := net.NewNode(t.t, "Charlie", nil) charlie := net.NewNode(t.t, "Charlie", nil)
defer shutdownAndAssert(net, t, charlie) defer shutdownAndAssert(net, t, charlie)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, charlie)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, charlie)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, carol, charlie)
net.ConnectNodes(ctxt, t.t, carol, charlie)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointCarol := openChannelAndAssert( chanPointCarol := openChannelAndAssert(
ctxt, t, net, carol, charlie, t, net, carol, charlie,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -745,9 +731,8 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) {
// where the 100k channel between Carol and Alice is private. // where the 100k channel between Carol and Alice is private.
// Open a channel with 200k satoshis between Alice and Bob. // Open a channel with 200k satoshis between Alice and Bob.
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
chanPointAlice := openChannelAndAssert( chanPointAlice := openChannelAndAssert(
ctxt, t, net, net.Alice, net.Bob, t, net, net.Alice, net.Bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt * 2, Amt: chanAmt * 2,
}, },
@@ -767,14 +752,11 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) {
dave := net.NewNode(t.t, "Dave", nil) dave := net.NewNode(t.t, "Dave", nil)
defer shutdownAndAssert(net, t, dave) defer shutdownAndAssert(net, t, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, dave, net.Alice)
net.ConnectNodes(ctxt, t.t, dave, net.Alice) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, dave)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointDave := openChannelAndAssert( chanPointDave := openChannelAndAssert(
ctxt, t, net, dave, net.Alice, t, net, dave, net.Alice,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -794,14 +776,11 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) {
carol := net.NewNode(t.t, "Carol", nil) carol := net.NewNode(t.t, "Carol", nil)
defer shutdownAndAssert(net, t, carol) defer shutdownAndAssert(net, t, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, carol, dave)
net.ConnectNodes(ctxt, t.t, carol, dave) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointCarol := openChannelAndAssert( chanPointCarol := openChannelAndAssert(
ctxt, t, net, carol, dave, t, net, carol, dave,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -832,7 +811,7 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) {
Index: chanPoint.OutputIndex, Index: chanPoint.OutputIndex,
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err = node.WaitForNetworkChannelOpen(ctxt, chanPoint) err = node.WaitForNetworkChannelOpen(ctxt, chanPoint)
if err != nil { if err != nil {
t.Fatalf("%s(%d): timeout waiting for "+ t.Fatalf("%s(%d): timeout waiting for "+
@@ -843,11 +822,9 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) {
} }
// Now create a _private_ channel directly between Carol and // Now create a _private_ channel directly between Carol and
// Alice of 100k. // Alice of 100k.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, carol, net.Alice)
net.ConnectNodes(ctxt, t.t, carol, net.Alice)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanOpenUpdate := openChannelStream( chanOpenUpdate := openChannelStream(
ctxt, t, net, carol, net.Alice, t, net, carol, net.Alice,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
Private: true, Private: true,
@@ -861,8 +838,7 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) {
// nodes have defaultNumConfs=1 set. // nodes have defaultNumConfs=1 set.
block := mineBlocks(t, net, 1, 1)[0] block := mineBlocks(t, net, 1, 1)[0]
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) chanPointPrivate, err := net.WaitForChannelOpen(chanOpenUpdate)
chanPointPrivate, err := net.WaitForChannelOpen(ctxt, chanOpenUpdate)
if err != nil { if err != nil {
t.Fatalf("error while waiting for channel open: %v", err) t.Fatalf("error while waiting for channel open: %v", err)
} }
@@ -878,13 +854,11 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) {
Hash: *fundingTxID, Hash: *fundingTxID,
Index: chanPointPrivate.OutputIndex, Index: chanPointPrivate.OutputIndex,
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) err = net.AssertChannelExists(carol, &privateFundPoint)
err = net.AssertChannelExists(ctxt, carol, &privateFundPoint)
if err != nil { if err != nil {
t.Fatalf("unable to assert channel existence: %v", err) t.Fatalf("unable to assert channel existence: %v", err)
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) err = net.AssertChannelExists(net.Alice, &privateFundPoint)
err = net.AssertChannelExists(ctxt, net.Alice, &privateFundPoint)
if err != nil { if err != nil {
t.Fatalf("unable to assert channel existence: %v", err) t.Fatalf("unable to assert channel existence: %v", err)
} }
@@ -908,10 +882,7 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) {
time.Sleep(time.Millisecond * 50) time.Sleep(time.Millisecond * 50)
// Let Carol pay the invoices. // Let Carol pay the invoices.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) err = completePaymentRequests(carol, carol.RouterClient, payReqs, true)
err = completePaymentRequests(
ctxt, carol, carol.RouterClient, payReqs, true,
)
if err != nil { if err != nil {
t.Fatalf("unable to send payments: %v", err) t.Fatalf("unable to send payments: %v", err)
} }
@@ -966,9 +937,8 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) {
time.Sleep(time.Millisecond * 50) time.Sleep(time.Millisecond * 50)
// Let Bob pay the invoices. // Let Bob pay the invoices.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = completePaymentRequests( err = completePaymentRequests(
ctxt, net.Alice, net.Alice.RouterClient, payReqs, true, net.Alice, net.Alice.RouterClient, payReqs, true,
) )
if err != nil { if err != nil {
t.Fatalf("unable to send payments: %v", err) t.Fatalf("unable to send payments: %v", err)
@@ -1066,9 +1036,8 @@ func testUpdateChannelPolicyForPrivateChannel(net *lntest.NetworkHarness,
const chanAmt = btcutil.Amount(100000) const chanAmt = btcutil.Amount(100000)
// Open a channel with 100k satoshis between Alice and Bob. // Open a channel with 100k satoshis between Alice and Bob.
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
chanPointAliceBob := openChannelAndAssert( chanPointAliceBob := openChannelAndAssert(
ctxt, t, net, net.Alice, net.Bob, t, net, net.Alice, net.Bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -1088,13 +1057,11 @@ func testUpdateChannelPolicyForPrivateChannel(net *lntest.NetworkHarness,
defer shutdownAndAssert(net, t, carol) defer shutdownAndAssert(net, t, carol)
// Connect Carol to Bob. // Connect Carol to Bob.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, carol, net.Bob)
net.ConnectNodes(ctxt, t.t, carol, net.Bob)
// Open a channel with 100k satoshis between Bob and Carol. // Open a channel with 100k satoshis between Bob and Carol.
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointBobCarol := openChannelAndAssert( chanPointBobCarol := openChannelAndAssert(
ctxt, t, net, net.Bob, carol, t, net, net.Bob, carol,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
Private: true, Private: true,
@@ -1120,7 +1087,7 @@ func testUpdateChannelPolicyForPrivateChannel(net *lntest.NetworkHarness,
Value: paymentAmt, Value: paymentAmt,
Private: true, Private: true,
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
resp, err := carol.AddInvoice(ctxt, invoice) resp, err := carol.AddInvoice(ctxt, invoice)
require.NoError(t.t, err, "unable to create invoice for carol") require.NoError(t.t, err, "unable to create invoice for carol")
@@ -1142,17 +1109,16 @@ func testUpdateChannelPolicyForPrivateChannel(net *lntest.NetworkHarness,
// Alice pays the invoices. She will use the updated baseFeeMSat in the // Alice pays the invoices. She will use the updated baseFeeMSat in the
// payment // payment
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
payReqs := []string{resp.PaymentRequest} payReqs := []string{resp.PaymentRequest}
require.NoError(t.t, require.NoError(t.t,
completePaymentRequests( completePaymentRequests(
ctxt, net.Alice, net.Alice.RouterClient, payReqs, true, net.Alice, net.Alice.RouterClient, payReqs, true,
), "unable to send payment", ), "unable to send payment",
) )
// Check that Alice did make the payment with two HTLCs, one failed and // Check that Alice did make the payment with two HTLCs, one failed and
// one succeeded. // one succeeded.
ctxt, _ = context.WithTimeout(ctxt, defaultTimeout) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
paymentsResp, err := net.Alice.ListPayments( paymentsResp, err := net.Alice.ListPayments(
ctxt, &lnrpc.ListPaymentsRequest{}, ctxt, &lnrpc.ListPaymentsRequest{},
) )
@@ -1205,9 +1171,8 @@ func testInvoiceRoutingHints(net *lntest.NetworkHarness, t *harnessTest) {
// throughout this test. We'll include a push amount since we currently // throughout this test. We'll include a push amount since we currently
// require channels to have enough remote balance to cover the invoice's // require channels to have enough remote balance to cover the invoice's
// payment. // payment.
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
chanPointBob := openChannelAndAssert( chanPointBob := openChannelAndAssert(
ctxt, t, net, net.Alice, net.Bob, t, net, net.Alice, net.Bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
PushAmt: chanAmt / 2, PushAmt: chanAmt / 2,
@@ -1221,11 +1186,9 @@ func testInvoiceRoutingHints(net *lntest.NetworkHarness, t *harnessTest) {
carol := net.NewNode(t.t, "Carol", nil) carol := net.NewNode(t.t, "Carol", nil)
defer shutdownAndAssert(net, t, carol) defer shutdownAndAssert(net, t, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, net.Alice, carol)
net.ConnectNodes(ctxt, t.t, net.Alice, carol)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointCarol := openChannelAndAssert( chanPointCarol := openChannelAndAssert(
ctxt, t, net, net.Alice, carol, t, net, net.Alice, carol,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
PushAmt: chanAmt / 2, PushAmt: chanAmt / 2,
@@ -1237,11 +1200,9 @@ func testInvoiceRoutingHints(net *lntest.NetworkHarness, t *harnessTest) {
// we should only include routing hints for nodes that are publicly // we should only include routing hints for nodes that are publicly
// advertised, otherwise we'd end up leaking information about nodes // advertised, otherwise we'd end up leaking information about nodes
// that wish to stay unadvertised. // that wish to stay unadvertised.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, net.Bob, carol)
net.ConnectNodes(ctxt, t.t, net.Bob, carol)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointBobCarol := openChannelAndAssert( chanPointBobCarol := openChannelAndAssert(
ctxt, t, net, net.Bob, carol, t, net, net.Bob, carol,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
PushAmt: chanAmt / 2, PushAmt: chanAmt / 2,
@@ -1255,11 +1216,9 @@ func testInvoiceRoutingHints(net *lntest.NetworkHarness, t *harnessTest) {
dave := net.NewNode(t.t, "Dave", nil) dave := net.NewNode(t.t, "Dave", nil)
defer shutdownAndAssert(net, t, dave) defer shutdownAndAssert(net, t, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, net.Alice, dave)
net.ConnectNodes(ctxt, t.t, net.Alice, dave)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointDave := openChannelAndAssert( chanPointDave := openChannelAndAssert(
ctxt, t, net, net.Alice, dave, t, net, net.Alice, dave,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
Private: true, Private: true,
@@ -1271,11 +1230,9 @@ func testInvoiceRoutingHints(net *lntest.NetworkHarness, t *harnessTest) {
// channel has been created to avoid populating routing hints for // channel has been created to avoid populating routing hints for
// inactive channels. // inactive channels.
eve := net.NewNode(t.t, "Eve", nil) eve := net.NewNode(t.t, "Eve", nil)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, net.Alice, eve)
net.ConnectNodes(ctxt, t.t, net.Alice, eve)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointEve := openChannelAndAssert( chanPointEve := openChannelAndAssert(
ctxt, t, net, net.Alice, eve, t, net, net.Alice, eve,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
PushAmt: chanAmt / 2, PushAmt: chanAmt / 2,
@@ -1316,7 +1273,7 @@ func testInvoiceRoutingHints(net *lntest.NetworkHarness, t *harnessTest) {
var predErr error var predErr error
var decoded *lnrpc.PayReq var decoded *lnrpc.PayReq
err := wait.Predicate(func() bool { err := wait.Predicate(func() bool {
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
resp, err := net.Alice.AddInvoice(ctxt, invoice) resp, err := net.Alice.AddInvoice(ctxt, invoice)
if err != nil { if err != nil {
predErr = fmt.Errorf("unable to add invoice: %v", err) predErr = fmt.Errorf("unable to add invoice: %v", err)
@@ -1356,7 +1313,7 @@ func testInvoiceRoutingHints(net *lntest.NetworkHarness, t *harnessTest) {
// We'll need the short channel ID of the channel between Alice and Bob // We'll need the short channel ID of the channel between Alice and Bob
// to make sure the routing hint is for this channel. // to make sure the routing hint is for this channel.
listReq := &lnrpc.ListChannelsRequest{} listReq := &lnrpc.ListChannelsRequest{}
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
listResp, err := net.Alice.ListChannels(ctxt, listReq) listResp, err := net.Alice.ListChannels(ctxt, listReq)
if err != nil { if err != nil {
t.Fatalf("unable to retrieve alice's channels: %v", err) t.Fatalf("unable to retrieve alice's channels: %v", err)
@@ -1406,16 +1363,15 @@ func testMultiHopOverPrivateChannels(net *lntest.NetworkHarness, t *harnessTest)
// First, we'll open a private channel between Alice and Bob with Alice // First, we'll open a private channel between Alice and Bob with Alice
// being the funder. // being the funder.
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
chanPointAlice := openChannelAndAssert( chanPointAlice := openChannelAndAssert(
ctxt, t, net, net.Alice, net.Bob, t, net, net.Alice, net.Bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
Private: true, Private: true,
}, },
) )
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err := net.Alice.WaitForNetworkChannelOpen(ctxt, chanPointAlice) err := net.Alice.WaitForNetworkChannelOpen(ctxt, chanPointAlice)
if err != nil { if err != nil {
t.Fatalf("alice didn't see the channel alice <-> bob before "+ t.Fatalf("alice didn't see the channel alice <-> bob before "+
@@ -1443,11 +1399,9 @@ func testMultiHopOverPrivateChannels(net *lntest.NetworkHarness, t *harnessTest)
carol := net.NewNode(t.t, "Carol", nil) carol := net.NewNode(t.t, "Carol", nil)
defer shutdownAndAssert(net, t, carol) defer shutdownAndAssert(net, t, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, net.Bob, carol)
net.ConnectNodes(ctxt, t.t, net.Bob, carol)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointBob := openChannelAndAssert( chanPointBob := openChannelAndAssert(
ctxt, t, net, net.Bob, carol, t, net, net.Bob, carol,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -1487,14 +1441,11 @@ func testMultiHopOverPrivateChannels(net *lntest.NetworkHarness, t *harnessTest)
dave := net.NewNode(t.t, "Dave", nil) dave := net.NewNode(t.t, "Dave", nil)
defer shutdownAndAssert(net, t, dave) defer shutdownAndAssert(net, t, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, carol, dave)
net.ConnectNodes(ctxt, t.t, carol, dave) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointCarol := openChannelAndAssert( chanPointCarol := openChannelAndAssert(
ctxt, t, net, carol, dave, t, net, carol, dave,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
Private: true, Private: true,
@@ -1552,9 +1503,8 @@ func testMultiHopOverPrivateChannels(net *lntest.NetworkHarness, t *harnessTest)
// Let Alice pay the invoice. // Let Alice pay the invoice.
payReqs := []string{resp.PaymentRequest} payReqs := []string{resp.PaymentRequest}
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = completePaymentRequests( err = completePaymentRequests(
ctxt, net.Alice, net.Alice.RouterClient, payReqs, true, net.Alice, net.Alice.RouterClient, payReqs, true,
) )
if err != nil { if err != nil {
t.Fatalf("unable to send payments from alice to dave: %v", err) t.Fatalf("unable to send payments from alice to dave: %v", err)
@@ -1612,9 +1562,8 @@ func testQueryRoutes(net *lntest.NetworkHarness, t *harnessTest) {
var networkChans []*lnrpc.ChannelPoint var networkChans []*lnrpc.ChannelPoint
// Open a channel between Alice and Bob. // Open a channel between Alice and Bob.
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
chanPointAlice := openChannelAndAssert( chanPointAlice := openChannelAndAssert(
ctxt, t, net, net.Alice, net.Bob, t, net, net.Alice, net.Bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -1625,14 +1574,11 @@ func testQueryRoutes(net *lntest.NetworkHarness, t *harnessTest) {
carol := net.NewNode(t.t, "Carol", nil) carol := net.NewNode(t.t, "Carol", nil)
defer shutdownAndAssert(net, t, carol) defer shutdownAndAssert(net, t, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, carol, net.Bob)
net.ConnectNodes(ctxt, t.t, carol, net.Bob) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, net.Bob)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, net.Bob)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointBob := openChannelAndAssert( chanPointBob := openChannelAndAssert(
ctxt, t, net, net.Bob, carol, t, net, net.Bob, carol,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -1643,14 +1589,11 @@ func testQueryRoutes(net *lntest.NetworkHarness, t *harnessTest) {
dave := net.NewNode(t.t, "Dave", nil) dave := net.NewNode(t.t, "Dave", nil)
defer shutdownAndAssert(net, t, dave) defer shutdownAndAssert(net, t, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, dave, carol)
net.ConnectNodes(ctxt, t.t, dave, carol) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointCarol := openChannelAndAssert( chanPointCarol := openChannelAndAssert(
ctxt, t, net, carol, dave, t, net, carol, dave,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -1671,7 +1614,7 @@ func testQueryRoutes(net *lntest.NetworkHarness, t *harnessTest) {
Index: chanPoint.OutputIndex, Index: chanPoint.OutputIndex,
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err = node.WaitForNetworkChannelOpen(ctxt, chanPoint) err = node.WaitForNetworkChannelOpen(ctxt, chanPoint)
if err != nil { if err != nil {
t.Fatalf("%s(%d): timeout waiting for "+ t.Fatalf("%s(%d): timeout waiting for "+
@@ -1687,7 +1630,7 @@ func testQueryRoutes(net *lntest.NetworkHarness, t *harnessTest) {
PubKey: dave.PubKeyStr, PubKey: dave.PubKeyStr,
Amt: paymentAmt, Amt: paymentAmt,
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
routesRes, err := net.Alice.QueryRoutes(ctxt, routesReq) routesRes, err := net.Alice.QueryRoutes(ctxt, routesReq)
if err != nil { if err != nil {
t.Fatalf("unable to get route: %v", err) t.Fatalf("unable to get route: %v", err)
@@ -1904,9 +1847,8 @@ func testRouteFeeCutoff(net *lntest.NetworkHarness, t *harnessTest) {
const chanAmt = btcutil.Amount(100000) const chanAmt = btcutil.Amount(100000)
// Open a channel between Alice and Bob. // Open a channel between Alice and Bob.
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
chanPointAliceBob := openChannelAndAssert( chanPointAliceBob := openChannelAndAssert(
ctxt, t, net, net.Alice, net.Bob, t, net, net.Alice, net.Bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -1917,14 +1859,11 @@ func testRouteFeeCutoff(net *lntest.NetworkHarness, t *harnessTest) {
carol := net.NewNode(t.t, "Carol", nil) carol := net.NewNode(t.t, "Carol", nil)
defer shutdownAndAssert(net, t, carol) defer shutdownAndAssert(net, t, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, carol, net.Alice)
net.ConnectNodes(ctxt, t.t, carol, net.Alice) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointAliceCarol := openChannelAndAssert( chanPointAliceCarol := openChannelAndAssert(
ctxt, t, net, net.Alice, carol, t, net, net.Alice, carol,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -1935,22 +1874,18 @@ func testRouteFeeCutoff(net *lntest.NetworkHarness, t *harnessTest) {
dave := net.NewNode(t.t, "Dave", nil) dave := net.NewNode(t.t, "Dave", nil)
defer shutdownAndAssert(net, t, dave) defer shutdownAndAssert(net, t, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, dave, net.Bob)
net.ConnectNodes(ctxt, t.t, dave, net.Bob)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointBobDave := openChannelAndAssert( chanPointBobDave := openChannelAndAssert(
ctxt, t, net, net.Bob, dave, t, net, net.Bob, dave,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
) )
// Open a channel between Carol and Dave. // Open a channel between Carol and Dave.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, carol, dave)
net.ConnectNodes(ctxt, t.t, carol, dave)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointCarolDave := openChannelAndAssert( chanPointCarolDave := openChannelAndAssert(
ctxt, t, net, carol, dave, t, net, carol, dave,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -2012,7 +1947,7 @@ func testRouteFeeCutoff(net *lntest.NetworkHarness, t *harnessTest) {
ChanPoint: chanPointCarolDave, ChanPoint: chanPointCarolDave,
}, },
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
if _, err := carol.UpdateChannelPolicy(ctxt, updateFeeReq); err != nil { if _, err := carol.UpdateChannelPolicy(ctxt, updateFeeReq); err != nil {
t.Fatalf("unable to update chan policy: %v", err) t.Fatalf("unable to update chan policy: %v", err)
} }
@@ -2113,8 +2048,7 @@ func testRouteFeeCutoff(net *lntest.NetworkHarness, t *harnessTest) {
sendReq.FeeLimitMsat = 1000 * paymentAmt * limit.Percent / 100 sendReq.FeeLimitMsat = 1000 * paymentAmt * limit.Percent / 100
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) result := sendAndAssertSuccess(t, net.Alice, sendReq)
result := sendAndAssertSuccess(ctxt, t, net.Alice, sendReq)
checkRoute(result.Htlcs[0].Route) checkRoute(result.Htlcs[0].Route)
} }

View File

@@ -68,10 +68,8 @@ func testSendMultiPathPayment(net *lntest.NetworkHarness, t *harnessTest) {
rHash := rHashes[0] rHash := rHashes[0]
payReq := payReqs[0] payReq := payReqs[0]
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
payment := sendAndAssertSuccess( payment := sendAndAssertSuccess(
ctxt, t, ctx.alice, t, ctx.alice, &routerrpc.SendPaymentRequest{
&routerrpc.SendPaymentRequest{
PaymentRequest: payReq, PaymentRequest: payReq,
MaxParts: 10, MaxParts: 10,
TimeoutSeconds: 60, TimeoutSeconds: 60,
@@ -106,7 +104,7 @@ func testSendMultiPathPayment(net *lntest.NetworkHarness, t *harnessTest) {
// Make sure Bob show the invoice as settled for the full // Make sure Bob show the invoice as settled for the full
// amount. // amount.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
inv, err := ctx.bob.LookupInvoice( inv, err := ctx.bob.LookupInvoice(
ctxt, &lnrpc.PaymentHash{ ctxt, &lnrpc.PaymentHash{
RHash: rHash, RHash: rHash,

View File

@@ -23,10 +23,9 @@ func testSingleHopInvoice(net *lntest.NetworkHarness, t *harnessTest) {
// Open a channel with 100k satoshis between Alice and Bob with Alice being // Open a channel with 100k satoshis between Alice and Bob with Alice being
// the sole funder of the channel. // the sole funder of the channel.
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
chanAmt := btcutil.Amount(100000) chanAmt := btcutil.Amount(100000)
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
ctxt, t, net, net.Alice, net.Bob, t, net, net.Alice, net.Bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@@ -49,7 +48,7 @@ func testSingleHopInvoice(net *lntest.NetworkHarness, t *harnessTest) {
// Wait for Alice to recognize and advertise the new channel generated // Wait for Alice to recognize and advertise the new channel generated
// above. // above.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err = net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint) err = net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint)
if err != nil { if err != nil {
t.Fatalf("alice didn't advertise channel before "+ t.Fatalf("alice didn't advertise channel before "+
@@ -63,10 +62,8 @@ func testSingleHopInvoice(net *lntest.NetworkHarness, t *harnessTest) {
// With the invoice for Bob added, send a payment towards Alice paying // With the invoice for Bob added, send a payment towards Alice paying
// to the above generated invoice. // to the above generated invoice.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
resp := sendAndAssertSuccess( resp := sendAndAssertSuccess(
ctxt, t, net.Alice, t, net.Alice, &routerrpc.SendPaymentRequest{
&routerrpc.SendPaymentRequest{
PaymentRequest: invoiceResp.PaymentRequest, PaymentRequest: invoiceResp.PaymentRequest,
TimeoutSeconds: 60, TimeoutSeconds: 60,
FeeLimitMsat: noFeeLimitMsat, FeeLimitMsat: noFeeLimitMsat,
@@ -81,7 +78,7 @@ func testSingleHopInvoice(net *lntest.NetworkHarness, t *harnessTest) {
payHash := &lnrpc.PaymentHash{ payHash := &lnrpc.PaymentHash{
RHash: invoiceResp.RHash, RHash: invoiceResp.RHash,
} }
ctxt, _ = context.WithTimeout(ctxt, defaultTimeout) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
dbInvoice, err := net.Bob.LookupInvoice(ctxt, payHash) dbInvoice, err := net.Bob.LookupInvoice(ctxt, payHash)
if err != nil { if err != nil {
t.Fatalf("unable to lookup invoice: %v", err) t.Fatalf("unable to lookup invoice: %v", err)
@@ -108,7 +105,7 @@ func testSingleHopInvoice(net *lntest.NetworkHarness, t *harnessTest) {
Memo: "test3", Memo: "test3",
Value: paymentAmt, Value: paymentAmt,
} }
ctxt, _ = context.WithTimeout(ctxt, defaultTimeout) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
invoiceResp, err = net.Bob.AddInvoice(ctxt, invoice) invoiceResp, err = net.Bob.AddInvoice(ctxt, invoice)
if err != nil { if err != nil {
t.Fatalf("unable to add invoice: %v", err) t.Fatalf("unable to add invoice: %v", err)
@@ -116,10 +113,8 @@ func testSingleHopInvoice(net *lntest.NetworkHarness, t *harnessTest) {
// Next send another payment, but this time using a zpay32 encoded // Next send another payment, but this time using a zpay32 encoded
// invoice rather than manually specifying the payment details. // invoice rather than manually specifying the payment details.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
sendAndAssertSuccess( sendAndAssertSuccess(
ctxt, t, net.Alice, t, net.Alice, &routerrpc.SendPaymentRequest{
&routerrpc.SendPaymentRequest{
PaymentRequest: invoiceResp.PaymentRequest, PaymentRequest: invoiceResp.PaymentRequest,
TimeoutSeconds: 60, TimeoutSeconds: 60,
FeeLimitMsat: noFeeLimitMsat, FeeLimitMsat: noFeeLimitMsat,
@@ -140,10 +135,8 @@ func testSingleHopInvoice(net *lntest.NetworkHarness, t *harnessTest) {
keySendPreimage := lntypes.Preimage{3, 4, 5, 11} keySendPreimage := lntypes.Preimage{3, 4, 5, 11}
keySendHash := keySendPreimage.Hash() keySendHash := keySendPreimage.Hash()
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
sendAndAssertSuccess( sendAndAssertSuccess(
ctxt, t, net.Alice, t, net.Alice, &routerrpc.SendPaymentRequest{
&routerrpc.SendPaymentRequest{
Dest: net.Bob.PubKey[:], Dest: net.Bob.PubKey[:],
Amt: paymentAmt, Amt: paymentAmt,
FinalCltvDelta: 40, FinalCltvDelta: 40,
@@ -205,7 +198,7 @@ func testSingleHopInvoice(net *lntest.NetworkHarness, t *harnessTest) {
RouteHints: hints, RouteHints: hints,
} }
ctxt, _ = context.WithTimeout(ctxt, defaultTimeout) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
invoiceResp, err = net.Bob.AddInvoice(ctxt, invoice) invoiceResp, err = net.Bob.AddInvoice(ctxt, invoice)
if err != nil { if err != nil {
t.Fatalf("unable to add invoice: %v", err) t.Fatalf("unable to add invoice: %v", err)

View File

@@ -29,9 +29,8 @@ func testSwitchCircuitPersistence(net *lntest.NetworkHarness, t *harnessTest) {
// Open a channel with 100k satoshis between Alice and Bob with Alice // Open a channel with 100k satoshis between Alice and Bob with Alice
// being the sole funder of the channel. // being the sole funder of the channel.
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
chanPointAlice := openChannelAndAssert( chanPointAlice := openChannelAndAssert(
ctxt, t, net, net.Alice, net.Bob, t, net, net.Alice, net.Bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
PushAmt: pushAmt, PushAmt: pushAmt,
@@ -58,14 +57,11 @@ func testSwitchCircuitPersistence(net *lntest.NetworkHarness, t *harnessTest) {
dave := net.NewNode(t.t, "Dave", nil) dave := net.NewNode(t.t, "Dave", nil)
defer shutdownAndAssert(net, t, dave) defer shutdownAndAssert(net, t, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, dave, net.Alice)
net.ConnectNodes(ctxt, t.t, dave, net.Alice) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, dave)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointDave := openChannelAndAssert( chanPointDave := openChannelAndAssert(
ctxt, t, net, dave, net.Alice, t, net, dave, net.Alice,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
PushAmt: pushAmt, PushAmt: pushAmt,
@@ -87,14 +83,11 @@ func testSwitchCircuitPersistence(net *lntest.NetworkHarness, t *harnessTest) {
carol := net.NewNode(t.t, "Carol", []string{"--hodl.exit-settle"}) carol := net.NewNode(t.t, "Carol", []string{"--hodl.exit-settle"})
defer shutdownAndAssert(net, t, carol) defer shutdownAndAssert(net, t, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, carol, dave)
net.ConnectNodes(ctxt, t.t, carol, dave) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointCarol := openChannelAndAssert( chanPointCarol := openChannelAndAssert(
ctxt, t, net, carol, dave, t, net, carol, dave,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
PushAmt: pushAmt, PushAmt: pushAmt,
@@ -125,7 +118,7 @@ func testSwitchCircuitPersistence(net *lntest.NetworkHarness, t *harnessTest) {
Index: chanPoint.OutputIndex, Index: chanPoint.OutputIndex,
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err = node.WaitForNetworkChannelOpen(ctxt, chanPoint) err = node.WaitForNetworkChannelOpen(ctxt, chanPoint)
if err != nil { if err != nil {
t.Fatalf("%s(%d): timeout waiting for "+ t.Fatalf("%s(%d): timeout waiting for "+
@@ -148,7 +141,7 @@ func testSwitchCircuitPersistence(net *lntest.NetworkHarness, t *harnessTest) {
// We'll wait for all parties to recognize the new channels within the // We'll wait for all parties to recognize the new channels within the
// network. // network.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err = dave.WaitForNetworkChannelOpen(ctxt, chanPointDave) err = dave.WaitForNetworkChannelOpen(ctxt, chanPointDave)
if err != nil { if err != nil {
t.Fatalf("dave didn't advertise his channel: %v", err) t.Fatalf("dave didn't advertise his channel: %v", err)
@@ -164,9 +157,8 @@ func testSwitchCircuitPersistence(net *lntest.NetworkHarness, t *harnessTest) {
// Using Carol as the source, pay to the 5 invoices from Bob created // Using Carol as the source, pay to the 5 invoices from Bob created
// above. // above.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = completePaymentRequests( err = completePaymentRequests(
ctxt, net.Bob, net.Bob.RouterClient, payReqs, false, net.Bob, net.Bob.RouterClient, payReqs, false,
) )
if err != nil { if err != nil {
t.Fatalf("unable to send payments: %v", err) t.Fatalf("unable to send payments: %v", err)
@@ -196,11 +188,8 @@ func testSwitchCircuitPersistence(net *lntest.NetworkHarness, t *harnessTest) {
} }
// Ensure all of the intermediate links are reconnected. // Ensure all of the intermediate links are reconnected.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.EnsureConnected(t.t, net.Alice, dave)
net.EnsureConnected(ctxt, t.t, net.Alice, dave) net.EnsureConnected(t.t, net.Bob, net.Alice)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.EnsureConnected(ctxt, t.t, net.Bob, net.Alice)
// Ensure all nodes in the network still have 5 outstanding htlcs. // Ensure all nodes in the network still have 5 outstanding htlcs.
err = wait.Predicate(func() bool { err = wait.Predicate(func() bool {
@@ -218,8 +207,7 @@ func testSwitchCircuitPersistence(net *lntest.NetworkHarness, t *harnessTest) {
t.Fatalf("Node restart failed: %v", err) t.Fatalf("Node restart failed: %v", err)
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.EnsureConnected(t.t, dave, carol)
net.EnsureConnected(ctxt, t.t, dave, carol)
// After the payments settle, there should be no active htlcs on any of // After the payments settle, there should be no active htlcs on any of
// the nodes in the network. // the nodes in the network.
@@ -273,9 +261,8 @@ func testSwitchCircuitPersistence(net *lntest.NetworkHarness, t *harnessTest) {
// Using Carol as the source, pay to the 5 invoices from Bob created // Using Carol as the source, pay to the 5 invoices from Bob created
// above. // above.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = completePaymentRequests( err = completePaymentRequests(
ctxt, net.Bob, net.Bob.RouterClient, payReqs, true, net.Bob, net.Bob.RouterClient, payReqs, true,
) )
if err != nil { if err != nil {
t.Fatalf("unable to send payments: %v", err) t.Fatalf("unable to send payments: %v", err)
@@ -320,9 +307,8 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) {
// Open a channel with 100k satoshis between Alice and Bob with Alice // Open a channel with 100k satoshis between Alice and Bob with Alice
// being the sole funder of the channel. // being the sole funder of the channel.
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
chanPointAlice := openChannelAndAssert( chanPointAlice := openChannelAndAssert(
ctxt, t, net, net.Alice, net.Bob, t, net, net.Alice, net.Bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
PushAmt: pushAmt, PushAmt: pushAmt,
@@ -349,14 +335,11 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) {
dave := net.NewNode(t.t, "Dave", nil) dave := net.NewNode(t.t, "Dave", nil)
defer shutdownAndAssert(net, t, dave) defer shutdownAndAssert(net, t, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, dave, net.Alice)
net.ConnectNodes(ctxt, t.t, dave, net.Alice) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, dave)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointDave := openChannelAndAssert( chanPointDave := openChannelAndAssert(
ctxt, t, net, dave, net.Alice, t, net, dave, net.Alice,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
PushAmt: pushAmt, PushAmt: pushAmt,
@@ -378,14 +361,11 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) {
carol := net.NewNode(t.t, "Carol", []string{"--hodl.exit-settle"}) carol := net.NewNode(t.t, "Carol", []string{"--hodl.exit-settle"})
defer shutdownAndAssert(net, t, carol) defer shutdownAndAssert(net, t, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, carol, dave)
net.ConnectNodes(ctxt, t.t, carol, dave) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointCarol := openChannelAndAssert( chanPointCarol := openChannelAndAssert(
ctxt, t, net, carol, dave, t, net, carol, dave,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
PushAmt: pushAmt, PushAmt: pushAmt,
@@ -416,7 +396,7 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) {
Index: chanPoint.OutputIndex, Index: chanPoint.OutputIndex,
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err = node.WaitForNetworkChannelOpen(ctxt, chanPoint) err = node.WaitForNetworkChannelOpen(ctxt, chanPoint)
if err != nil { if err != nil {
t.Fatalf("%s(%d): timeout waiting for "+ t.Fatalf("%s(%d): timeout waiting for "+
@@ -439,7 +419,7 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) {
// We'll wait for all parties to recognize the new channels within the // We'll wait for all parties to recognize the new channels within the
// network. // network.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err = dave.WaitForNetworkChannelOpen(ctxt, chanPointDave) err = dave.WaitForNetworkChannelOpen(ctxt, chanPointDave)
if err != nil { if err != nil {
t.Fatalf("dave didn't advertise his channel: %v", err) t.Fatalf("dave didn't advertise his channel: %v", err)
@@ -463,9 +443,8 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) {
// Using Carol as the source, pay to the 5 invoices from Bob created // Using Carol as the source, pay to the 5 invoices from Bob created
// above. // above.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = completePaymentRequests( err = completePaymentRequests(
ctxt, net.Bob, net.Bob.RouterClient, payReqs, false, net.Bob, net.Bob.RouterClient, payReqs, false,
) )
if err != nil { if err != nil {
t.Fatalf("unable to send payments: %v", err) t.Fatalf("unable to send payments: %v", err)
@@ -482,14 +461,12 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) {
} }
// First, disconnect Dave and Alice so that their link is broken. // First, disconnect Dave and Alice so that their link is broken.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) if err := net.DisconnectNodes(dave, net.Alice); err != nil {
if err := net.DisconnectNodes(ctxt, dave, net.Alice); err != nil {
t.Fatalf("unable to disconnect alice from dave: %v", err) t.Fatalf("unable to disconnect alice from dave: %v", err)
} }
// Then, reconnect them to ensure Dave doesn't just fail back the htlc. // Then, reconnect them to ensure Dave doesn't just fail back the htlc.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, dave, net.Alice)
net.ConnectNodes(ctxt, t.t, dave, net.Alice)
// Wait to ensure that the payment remain are not failed back after // Wait to ensure that the payment remain are not failed back after
// reconnecting. All node should report the number payments initiated // reconnecting. All node should report the number payments initiated
@@ -504,8 +481,7 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) {
// Now, disconnect Dave from Alice again before settling back the // Now, disconnect Dave from Alice again before settling back the
// payment. // payment.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) if err := net.DisconnectNodes(dave, net.Alice); err != nil {
if err := net.DisconnectNodes(ctxt, dave, net.Alice); err != nil {
t.Fatalf("unable to disconnect alice from dave: %v", err) t.Fatalf("unable to disconnect alice from dave: %v", err)
} }
@@ -538,8 +514,7 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) {
// Now that the settles have reached Dave, reconnect him with Alice, // Now that the settles have reached Dave, reconnect him with Alice,
// allowing the settles to return to the sender. // allowing the settles to return to the sender.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.EnsureConnected(t.t, dave, net.Alice)
net.EnsureConnected(ctxt, t.t, dave, net.Alice)
// Wait until all outstanding htlcs in the network have been settled. // Wait until all outstanding htlcs in the network have been settled.
err = wait.Predicate(func() bool { err = wait.Predicate(func() bool {
@@ -590,9 +565,8 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) {
// Using Carol as the source, pay to the 5 invoices from Bob created // Using Carol as the source, pay to the 5 invoices from Bob created
// above. // above.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = completePaymentRequests( err = completePaymentRequests(
ctxt, net.Bob, net.Bob.RouterClient, payReqs, true, net.Bob, net.Bob.RouterClient, payReqs, true,
) )
if err != nil { if err != nil {
t.Fatalf("unable to send payments: %v", err) t.Fatalf("unable to send payments: %v", err)
@@ -638,9 +612,8 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness
// Open a channel with 100k satoshis between Alice and Bob with Alice // Open a channel with 100k satoshis between Alice and Bob with Alice
// being the sole funder of the channel. // being the sole funder of the channel.
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
chanPointAlice := openChannelAndAssert( chanPointAlice := openChannelAndAssert(
ctxt, t, net, net.Alice, net.Bob, t, net, net.Alice, net.Bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
PushAmt: pushAmt, PushAmt: pushAmt,
@@ -667,14 +640,11 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness
dave := net.NewNode(t.t, "Dave", nil) dave := net.NewNode(t.t, "Dave", nil)
defer shutdownAndAssert(net, t, dave) defer shutdownAndAssert(net, t, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, dave, net.Alice)
net.ConnectNodes(ctxt, t.t, dave, net.Alice) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, dave)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointDave := openChannelAndAssert( chanPointDave := openChannelAndAssert(
ctxt, t, net, dave, net.Alice, t, net, dave, net.Alice,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
PushAmt: pushAmt, PushAmt: pushAmt,
@@ -697,14 +667,11 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness
carol := net.NewNode(t.t, "Carol", []string{"--hodl.exit-settle"}) carol := net.NewNode(t.t, "Carol", []string{"--hodl.exit-settle"})
defer shutdownAndAssert(net, t, carol) defer shutdownAndAssert(net, t, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, carol, dave)
net.ConnectNodes(ctxt, t.t, carol, dave) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointCarol := openChannelAndAssert( chanPointCarol := openChannelAndAssert(
ctxt, t, net, carol, dave, t, net, carol, dave,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
PushAmt: pushAmt, PushAmt: pushAmt,
@@ -735,7 +702,7 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness
Index: chanPoint.OutputIndex, Index: chanPoint.OutputIndex,
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err = node.WaitForNetworkChannelOpen(ctxt, chanPoint) err = node.WaitForNetworkChannelOpen(ctxt, chanPoint)
if err != nil { if err != nil {
t.Fatalf("%s(%d): timeout waiting for "+ t.Fatalf("%s(%d): timeout waiting for "+
@@ -758,7 +725,7 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness
// We'll wait for all parties to recognize the new channels within the // We'll wait for all parties to recognize the new channels within the
// network. // network.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err = dave.WaitForNetworkChannelOpen(ctxt, chanPointDave) err = dave.WaitForNetworkChannelOpen(ctxt, chanPointDave)
if err != nil { if err != nil {
t.Fatalf("dave didn't advertise his channel: %v", err) t.Fatalf("dave didn't advertise his channel: %v", err)
@@ -772,9 +739,8 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness
// Using Carol as the source, pay to the 5 invoices from Bob created // Using Carol as the source, pay to the 5 invoices from Bob created
// above. // above.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = completePaymentRequests( err = completePaymentRequests(
ctxt, net.Bob, net.Bob.RouterClient, payReqs, false, net.Bob, net.Bob.RouterClient, payReqs, false,
) )
if err != nil { if err != nil {
t.Fatalf("unable to send payments: %v", err) t.Fatalf("unable to send payments: %v", err)
@@ -805,8 +771,7 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness
// Make Carol and Dave are reconnected before waiting for the htlcs to // Make Carol and Dave are reconnected before waiting for the htlcs to
// clear. // clear.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.EnsureConnected(t.t, dave, carol)
net.EnsureConnected(ctxt, t.t, dave, carol)
// Wait for Carol to report no outstanding htlcs, and also for Dav to // Wait for Carol to report no outstanding htlcs, and also for Dav to
// receive all the settles from Carol. // receive all the settles from Carol.
@@ -835,8 +800,7 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness
// Force Dave and Alice to reconnect before waiting for the htlcs to // Force Dave and Alice to reconnect before waiting for the htlcs to
// clear. // clear.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.EnsureConnected(t.t, dave, net.Alice)
net.EnsureConnected(ctxt, t.t, dave, net.Alice)
// After reconnection succeeds, the settles should be propagated all // After reconnection succeeds, the settles should be propagated all
// the way back to the sender. All nodes should report no active htlcs. // the way back to the sender. All nodes should report no active htlcs.
@@ -888,14 +852,12 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness
// Before completing the final payment request, ensure that the // Before completing the final payment request, ensure that the
// connection between Dave and Carol has been healed. // connection between Dave and Carol has been healed.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.EnsureConnected(t.t, dave, carol)
net.EnsureConnected(ctxt, t.t, dave, carol)
// Using Carol as the source, pay to the 5 invoices from Bob created // Using Carol as the source, pay to the 5 invoices from Bob created
// above. // above.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = completePaymentRequests( err = completePaymentRequests(
ctxt, net.Bob, net.Bob.RouterClient, payReqs, true, net.Bob, net.Bob.RouterClient, payReqs, true,
) )
if err != nil { if err != nil {
t.Fatalf("unable to send payments: %v", err) t.Fatalf("unable to send payments: %v", err)
@@ -942,9 +904,8 @@ func testSwitchOfflineDeliveryOutgoingOffline(
// Open a channel with 100k satoshis between Alice and Bob with Alice // Open a channel with 100k satoshis between Alice and Bob with Alice
// being the sole funder of the channel. // being the sole funder of the channel.
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
chanPointAlice := openChannelAndAssert( chanPointAlice := openChannelAndAssert(
ctxt, t, net, net.Alice, net.Bob, t, net, net.Alice, net.Bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
PushAmt: pushAmt, PushAmt: pushAmt,
@@ -971,14 +932,11 @@ func testSwitchOfflineDeliveryOutgoingOffline(
dave := net.NewNode(t.t, "Dave", nil) dave := net.NewNode(t.t, "Dave", nil)
defer shutdownAndAssert(net, t, dave) defer shutdownAndAssert(net, t, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, dave, net.Alice)
net.ConnectNodes(ctxt, t.t, dave, net.Alice) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, dave)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointDave := openChannelAndAssert( chanPointDave := openChannelAndAssert(
ctxt, t, net, dave, net.Alice, t, net, dave, net.Alice,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
PushAmt: pushAmt, PushAmt: pushAmt,
@@ -998,14 +956,11 @@ func testSwitchOfflineDeliveryOutgoingOffline(
// Dave. Carol is started in htlchodl mode so that we can disconnect the // Dave. Carol is started in htlchodl mode so that we can disconnect the
// intermediary hops before starting the settle. // intermediary hops before starting the settle.
carol := net.NewNode(t.t, "Carol", []string{"--hodl.exit-settle"}) carol := net.NewNode(t.t, "Carol", []string{"--hodl.exit-settle"})
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.ConnectNodes(t.t, carol, dave)
net.ConnectNodes(ctxt, t.t, carol, dave) net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointCarol := openChannelAndAssert( chanPointCarol := openChannelAndAssert(
ctxt, t, net, carol, dave, t, net, carol, dave,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
PushAmt: pushAmt, PushAmt: pushAmt,
@@ -1036,7 +991,7 @@ func testSwitchOfflineDeliveryOutgoingOffline(
Index: chanPoint.OutputIndex, Index: chanPoint.OutputIndex,
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err = node.WaitForNetworkChannelOpen(ctxt, chanPoint) err = node.WaitForNetworkChannelOpen(ctxt, chanPoint)
if err != nil { if err != nil {
t.Fatalf("%s(%d): timeout waiting for "+ t.Fatalf("%s(%d): timeout waiting for "+
@@ -1059,7 +1014,7 @@ func testSwitchOfflineDeliveryOutgoingOffline(
// We'll wait for all parties to recognize the new channels within the // We'll wait for all parties to recognize the new channels within the
// network. // network.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err = dave.WaitForNetworkChannelOpen(ctxt, chanPointDave) err = dave.WaitForNetworkChannelOpen(ctxt, chanPointDave)
if err != nil { if err != nil {
t.Fatalf("dave didn't advertise his channel: %v", err) t.Fatalf("dave didn't advertise his channel: %v", err)
@@ -1073,9 +1028,8 @@ func testSwitchOfflineDeliveryOutgoingOffline(
// Using Carol as the source, pay to the 5 invoices from Bob created // Using Carol as the source, pay to the 5 invoices from Bob created
// above. // above.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = completePaymentRequests( err = completePaymentRequests(
ctxt, net.Bob, net.Bob.RouterClient, payReqs, false, net.Bob, net.Bob.RouterClient, payReqs, false,
) )
if err != nil { if err != nil {
t.Fatalf("unable to send payments: %v", err) t.Fatalf("unable to send payments: %v", err)
@@ -1143,8 +1097,7 @@ func testSwitchOfflineDeliveryOutgoingOffline(
// Ensure that Dave is reconnected to Alice before waiting for the // Ensure that Dave is reconnected to Alice before waiting for the
// htlcs to clear. // htlcs to clear.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) net.EnsureConnected(t.t, dave, net.Alice)
net.EnsureConnected(ctxt, t.t, dave, net.Alice)
// Since Carol has been shutdown permanently, we will wait until all // Since Carol has been shutdown permanently, we will wait until all
// other nodes in the network report no active htlcs. // other nodes in the network report no active htlcs.

View File

@@ -1,7 +1,6 @@
package itest package itest
import ( import (
"context"
"flag" "flag"
"fmt" "fmt"
"os" "os"
@@ -225,8 +224,7 @@ func TestLightningNetworkDaemon(t *testing.T) {
}() }()
lndHarness.EnsureConnected( lndHarness.EnsureConnected(
context.Background(), t1, t1, lndHarness.Alice, lndHarness.Bob,
lndHarness.Alice, lndHarness.Bob,
) )
logLine := fmt.Sprintf( logLine := fmt.Sprintf(

View File

@@ -332,9 +332,7 @@ func fundChanAndCloseFromImportedAccount(t *harnessTest, srcNode, destNode,
// Now, start the channel funding process. We'll need to connect both // Now, start the channel funding process. We'll need to connect both
// nodes first. // nodes first.
ctxt, cancel = context.WithTimeout(ctxb, defaultTimeout) t.lndHarness.EnsureConnected(t.t, srcNode, destNode)
defer cancel()
t.lndHarness.EnsureConnected(ctxt, t.t, srcNode, destNode)
// The source node will then fund the channel through a PSBT shim. // The source node will then fund the channel through a PSBT shim.
var pendingChanID [32]byte var pendingChanID [32]byte
@@ -515,10 +513,8 @@ func fundChanAndCloseFromImportedAccount(t *harnessTest, srcNode, destNode,
}) })
require.NoError(t.t, err) require.NoError(t.t, err)
ctxt, cancel = context.WithTimeout(ctxb, defaultTimeout)
defer cancel()
err = completePaymentRequests( err = completePaymentRequests(
ctxt, srcNode, srcNode.RouterClient, srcNode, srcNode.RouterClient,
[]string{resp.PaymentRequest}, true, []string{resp.PaymentRequest}, true,
) )
require.NoError(t.t, err) require.NoError(t.t, err)

View File

@@ -1,7 +1,6 @@
package itest package itest
import ( import (
"context"
"strings" "strings"
"github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil"
@@ -28,17 +27,16 @@ func testWumboChannels(net *lntest.NetworkHarness, t *harnessTest) {
// We'll send coins to the wumbo node, as it'll be the one imitating // We'll send coins to the wumbo node, as it'll be the one imitating
// the channel funding. // the channel funding.
ctxb := context.Background() net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, wumboNode)
net.SendCoins(ctxb, t.t, btcutil.SatoshiPerBitcoin, wumboNode)
// Next we'll connect both nodes, then attempt to make a wumbo channel // Next we'll connect both nodes, then attempt to make a wumbo channel
// funding request to the mini node we created above. The wumbo request // funding request to the mini node we created above. The wumbo request
// should fail as the node isn't advertising wumbo channels. // should fail as the node isn't advertising wumbo channels.
net.EnsureConnected(ctxb, t.t, wumboNode, miniNode) net.EnsureConnected(t.t, wumboNode, miniNode)
chanAmt := funding.MaxBtcFundingAmount + 1 chanAmt := funding.MaxBtcFundingAmount + 1
_, err := net.OpenChannel( _, err := net.OpenChannel(
ctxb, wumboNode, miniNode, lntest.OpenChannelParams{ wumboNode, miniNode, lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
) )
@@ -61,9 +59,9 @@ func testWumboChannels(net *lntest.NetworkHarness, t *harnessTest) {
defer shutdownAndAssert(net, t, wumboNode2) defer shutdownAndAssert(net, t, wumboNode2)
// Creating a wumbo channel between these two nodes should succeed. // Creating a wumbo channel between these two nodes should succeed.
net.EnsureConnected(ctxb, t.t, wumboNode, wumboNode2) net.EnsureConnected(t.t, wumboNode, wumboNode2)
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
ctxb, t, net, wumboNode, wumboNode2, t, net, wumboNode, wumboNode2,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },

View File

@@ -39,7 +39,6 @@ const (
defaultCSV = lntest.DefaultCSV defaultCSV = lntest.DefaultCSV
defaultTimeout = lntest.DefaultTimeout defaultTimeout = lntest.DefaultTimeout
minerMempoolTimeout = lntest.MinerMempoolTimeout minerMempoolTimeout = lntest.MinerMempoolTimeout
channelOpenTimeout = lntest.ChannelOpenTimeout
channelCloseTimeout = lntest.ChannelCloseTimeout channelCloseTimeout = lntest.ChannelCloseTimeout
itestLndBinary = "../../lnd-itest" itestLndBinary = "../../lnd-itest"
anchorSize = 330 anchorSize = 330

View File

@@ -25,16 +25,19 @@ import (
// completePaymentRequests sends payments from a lightning node to complete all // completePaymentRequests sends payments from a lightning node to complete all
// payment requests. If the awaitResponse parameter is true, this function // payment requests. If the awaitResponse parameter is true, this function
// does not return until all payments successfully complete without errors. // does not return until all payments successfully complete without errors.
func completePaymentRequests(ctx context.Context, client lnrpc.LightningClient, func completePaymentRequests(client lnrpc.LightningClient,
routerClient routerrpc.RouterClient, paymentRequests []string, routerClient routerrpc.RouterClient, paymentRequests []string,
awaitResponse bool) error { awaitResponse bool) error {
ctxb := context.Background()
ctx, cancel := context.WithTimeout(ctxb, defaultTimeout)
defer cancel()
// We start by getting the current state of the client's channels. This // We start by getting the current state of the client's channels. This
// is needed to ensure the payments actually have been committed before // is needed to ensure the payments actually have been committed before
// we return. // we return.
ctxt, _ := context.WithTimeout(ctx, defaultTimeout)
req := &lnrpc.ListChannelsRequest{} req := &lnrpc.ListChannelsRequest{}
listResp, err := client.ListChannels(ctxt, req) listResp, err := client.ListChannels(ctx, req)
if err != nil { if err != nil {
return err return err
} }
@@ -95,8 +98,7 @@ func completePaymentRequests(ctx context.Context, client lnrpc.LightningClient,
// the send before cancelling the request. We wait for the number of // the send before cancelling the request. We wait for the number of
// updates to one of our channels has increased before we return. // updates to one of our channels has increased before we return.
err = wait.Predicate(func() bool { err = wait.Predicate(func() bool {
ctxt, _ = context.WithTimeout(ctx, defaultTimeout) newListResp, err := client.ListChannels(ctx, req)
newListResp, err := client.ListChannels(ctxt, req)
if err != nil { if err != nil {
return false return false
} }
@@ -187,8 +189,11 @@ func createPayReqs(node *lntest.HarnessNode, paymentAmt btcutil.Amount,
// getChanInfo is a helper method for getting channel info for a node's sole // getChanInfo is a helper method for getting channel info for a node's sole
// channel. // channel.
func getChanInfo(ctx context.Context, node *lntest.HarnessNode) ( func getChanInfo(node *lntest.HarnessNode) (*lnrpc.Channel, error) {
*lnrpc.Channel, error) {
ctxb := context.Background()
ctx, cancel := context.WithTimeout(ctxb, defaultTimeout)
defer cancel()
req := &lnrpc.ListChannelsRequest{} req := &lnrpc.ListChannelsRequest{}
channelInfo, err := node.ListChannels(ctx, req) channelInfo, err := node.ListChannels(ctx, req)
@@ -323,12 +328,15 @@ func calculateMaxHtlc(chanCap btcutil.Amount) uint64 {
// waitForNodeBlockHeight queries the node for its current block height until // waitForNodeBlockHeight queries the node for its current block height until
// it reaches the passed height. // it reaches the passed height.
func waitForNodeBlockHeight(ctx context.Context, node *lntest.HarnessNode, func waitForNodeBlockHeight(node *lntest.HarnessNode, height int32) error {
height int32) error {
ctxb := context.Background()
ctx, cancel := context.WithTimeout(ctxb, defaultTimeout)
defer cancel()
var predErr error var predErr error
err := wait.Predicate(func() bool { err := wait.Predicate(func() bool {
ctxt, _ := context.WithTimeout(ctx, defaultTimeout) info, err := node.GetInfo(ctx, &lnrpc.GetInfoRequest{})
info, err := node.GetInfo(ctxt, &lnrpc.GetInfoRequest{})
if err != nil { if err != nil {
predErr = err predErr = err
return false return false
@@ -462,9 +470,13 @@ func subscribeChannelNotifications(ctxb context.Context, t *harnessTest,
// findTxAtHeight gets all of the transactions that a node's wallet has a record // findTxAtHeight gets all of the transactions that a node's wallet has a record
// of at the target height, and finds and returns the tx with the target txid, // of at the target height, and finds and returns the tx with the target txid,
// failing if it is not found. // failing if it is not found.
func findTxAtHeight(ctx context.Context, t *harnessTest, height int32, func findTxAtHeight(t *harnessTest, height int32,
target string, node *lntest.HarnessNode) *lnrpc.Transaction { target string, node *lntest.HarnessNode) *lnrpc.Transaction {
ctxb := context.Background()
ctx, cancel := context.WithTimeout(ctxb, defaultTimeout)
defer cancel()
txns, err := node.LightningClient.GetTransactions( txns, err := node.LightningClient.GetTransactions(
ctx, &lnrpc.GetTransactionsRequest{ ctx, &lnrpc.GetTransactionsRequest{
StartHeight: height, StartHeight: height,