multi: move many t.Fatalf calls to require.NoError

This commit is contained in:
Tommy Volk committed 2022-06-17 04:26:55 +00:00
1 parent 9e6f0ef46b
commit 9a10c80bcb
92 files changed
+1905 -5565

No files matched your search

+55 -162
View File
@@ -30,6 +30,7 @@ import (
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/lntest/wait"
"github.com/stretchr/testify/require"
)
var (
@@ -200,34 +201,22 @@ func testFilterBlockNotifications(node *rpctest.Harness,
// To start the test, we'll create to fresh outputs paying to the
// private key that we generated above.
txid1, err := getTestTXID(node)
if err != nil {
t.Fatalf("unable to get test txid: %v", err)
}
require.NoError(t, err, "unable to get test txid")
err = waitForMempoolTx(node, txid1)
if err != nil {
t.Fatalf("unable to get test txid in mempool: %v", err)
}
require.NoError(t, err, "unable to get test txid in mempool")
txid2, err := getTestTXID(node)
if err != nil {
t.Fatalf("unable to get test txid: %v", err)
}
require.NoError(t, err, "unable to get test txid")
err = waitForMempoolTx(node, txid2)
if err != nil {
t.Fatalf("unable to get test txid in mempool: %v", err)
}
require.NoError(t, err, "unable to get test txid in mempool")
blockChan := chainView.FilteredBlocks()
// Next we'll mine a block confirming the output generated above.
newBlockHashes, err := node.Client.Generate(1)
if err != nil {
t.Fatalf("unable to generate block: %v", err)
}
require.NoError(t, err, "unable to generate block")
_, currentHeight, err := node.Client.GetBestBlock()
if err != nil {
t.Fatalf("unable to get current height: %v", err)
}
require.NoError(t, err, "unable to get current height")
// We should get an update, however it shouldn't yet contain any
// filtered transaction as the filter hasn't been update.
@@ -243,34 +232,22 @@ func testFilterBlockNotifications(node *rpctest.Harness,
// so we can add them to the filter, and also craft transaction
// spending the outputs we created.
tx1, err := node.Client.GetRawTransaction(txid1)
if err != nil {
t.Fatalf("unable to fetch transaction: %v", err)
}
require.NoError(t, err, "unable to fetch transaction")
tx2, err := node.Client.GetRawTransaction(txid2)
if err != nil {
t.Fatalf("unable to fetch transaction: %v", err)
}
require.NoError(t, err, "unable to fetch transaction")
targetScript, err := txscript.PayToAddrScript(testAddr)
if err != nil {
t.Fatalf("unable to create target output: %v", err)
}
require.NoError(t, err, "unable to create target output")
// Next, we'll locate the two outputs generated above that pay to use
// so we can properly add them to the filter.
outPoint1, _, err := locateOutput(tx1.MsgTx(), targetScript)
if err != nil {
t.Fatalf("unable to find output: %v", err)
}
require.NoError(t, err, "unable to find output")
outPoint2, _, err := locateOutput(tx2.MsgTx(), targetScript)
if err != nil {
t.Fatalf("unable to find output: %v", err)
}
require.NoError(t, err, "unable to find output")
_, currentHeight, err = node.Client.GetBestBlock()
if err != nil {
t.Fatalf("unable to get current height: %v", err)
}
require.NoError(t, err, "unable to get current height")
// Now we'll add both outpoints to the current filter.
filter := []channeldb.EdgePoint{
@@ -278,35 +255,23 @@ func testFilterBlockNotifications(node *rpctest.Harness,
{FundingPkScript: targetScript, OutPoint: *outPoint2},
}
err = chainView.UpdateFilter(filter, uint32(currentHeight))
if err != nil {
t.Fatalf("unable to update filter: %v", err)
}
require.NoError(t, err, "unable to update filter")
// With the filter updated, we'll now create two transaction spending
// the outputs we created.
spendingTx1, err := craftSpendTransaction(*outPoint1, targetScript)
if err != nil {
t.Fatalf("unable to create spending tx: %v", err)
}
require.NoError(t, err, "unable to create spending tx")
spendingTx2, err := craftSpendTransaction(*outPoint2, targetScript)
if err != nil {
t.Fatalf("unable to create spending tx: %v", err)
}
require.NoError(t, err, "unable to create spending tx")
// Now we'll broadcast the first spending transaction and also mine a
// block which should include it.
spendTxid1, err := node.Client.SendRawTransaction(spendingTx1, true)
if err != nil {
t.Fatalf("unable to broadcast transaction: %v", err)
}
require.NoError(t, err, "unable to broadcast transaction")
err = waitForMempoolTx(node, spendTxid1)
if err != nil {
t.Fatalf("unable to get spending txid in mempool: %v", err)
}
require.NoError(t, err, "unable to get spending txid in mempool")
newBlockHashes, err = node.Client.Generate(1)
if err != nil {
t.Fatalf("unable to generate block: %v", err)
}
require.NoError(t, err, "unable to generate block")
// We should receive a notification over the channel. The notification
// should correspond to the current block height and have that single
@@ -322,17 +287,11 @@ func testFilterBlockNotifications(node *rpctest.Harness,
// Next, mine the second transaction which spends the second output.
// This should also generate a notification.
spendTxid2, err := node.Client.SendRawTransaction(spendingTx2, true)
if err != nil {
t.Fatalf("unable to broadcast transaction: %v", err)
}
require.NoError(t, err, "unable to broadcast transaction")
err = waitForMempoolTx(node, spendTxid2)
if err != nil {
t.Fatalf("unable to get spending txid in mempool: %v", err)
}
require.NoError(t, err, "unable to get spending txid in mempool")
newBlockHashes, err = node.Client.Generate(1)
if err != nil {
t.Fatalf("unable to generate block: %v", err)
}
require.NoError(t, err, "unable to generate block")
select {
case filteredBlock := <-blockChan:
@@ -354,22 +313,16 @@ func testUpdateFilterBackTrack(node *rpctest.Harness,
t.Fatalf("unable to get test txid")
}
err = waitForMempoolTx(node, txid)
if err != nil {
t.Fatalf("unable to get test txid in mempool: %v", err)
}
require.NoError(t, err, "unable to get test txid in mempool")
// Next we'll mine a block confirming the output generated above.
initBlockHashes, err := node.Client.Generate(1)
if err != nil {
t.Fatalf("unable to generate block: %v", err)
}
require.NoError(t, err, "unable to generate block")
blockChan := chainView.FilteredBlocks()
_, currentHeight, err := node.Client.GetBestBlock()
if err != nil {
t.Fatalf("unable to get current height: %v", err)
}
require.NoError(t, err, "unable to get current height")
// Consume the notification sent which contains an empty filtered
// block.
@@ -384,29 +337,17 @@ func testUpdateFilterBackTrack(node *rpctest.Harness,
// Next, create a transaction which spends the output created above,
// mining the spend into a block.
tx, err := node.Client.GetRawTransaction(txid)
if err != nil {
t.Fatalf("unable to fetch transaction: %v", err)
}
require.NoError(t, err, "unable to fetch transaction")
outPoint, _, err := locateOutput(tx.MsgTx(), testScript)
if err != nil {
t.Fatalf("unable to find output: %v", err)
}
require.NoError(t, err, "unable to find output")
spendingTx, err := craftSpendTransaction(*outPoint, testScript)
if err != nil {
t.Fatalf("unable to create spending tx: %v", err)
}
require.NoError(t, err, "unable to create spending tx")
spendTxid, err := node.Client.SendRawTransaction(spendingTx, true)
if err != nil {
t.Fatalf("unable to broadcast transaction: %v", err)
}
require.NoError(t, err, "unable to broadcast transaction")
err = waitForMempoolTx(node, spendTxid)
if err != nil {
t.Fatalf("unable to get spending txid in mempool: %v", err)
}
require.NoError(t, err, "unable to get spending txid in mempool")
newBlockHashes, err := node.Client.Generate(1)
if err != nil {
t.Fatalf("unable to generate block: %v", err)
}
require.NoError(t, err, "unable to generate block")
// We should have received another empty filtered block notification.
select {
@@ -423,9 +364,7 @@ func testUpdateFilterBackTrack(node *rpctest.Harness,
{FundingPkScript: testScript, OutPoint: *outPoint},
}
err = chainView.UpdateFilter(filter, uint32(currentHeight))
if err != nil {
t.Fatalf("unable to update filter: %v", err)
}
require.NoError(t, err, "unable to update filter")
// We should now receive a fresh filtered block notification that
// includes the transaction spend we included above.
@@ -451,30 +390,22 @@ func testFilterSingleBlock(node *rpctest.Harness, chainView FilteredChainView,
t.Fatalf("unable to get test txid")
}
err = waitForMempoolTx(node, txid1)
if err != nil {
t.Fatalf("unable to get test txid in mempool: %v", err)
}
require.NoError(t, err, "unable to get test txid in mempool")
txid2, err := getTestTXID(node)
if err != nil {
t.Fatalf("unable to get test txid")
}
err = waitForMempoolTx(node, txid2)
if err != nil {
t.Fatalf("unable to get test txid in mempool: %v", err)
}
require.NoError(t, err, "unable to get test txid in mempool")
blockChan := chainView.FilteredBlocks()
// Next we'll mine a block confirming the output generated above.
newBlockHashes, err := node.Client.Generate(1)
if err != nil {
t.Fatalf("unable to generate block: %v", err)
}
require.NoError(t, err, "unable to generate block")
_, currentHeight, err := node.Client.GetBestBlock()
if err != nil {
t.Fatalf("unable to get current height: %v", err)
}
require.NoError(t, err, "unable to get current height")
// We should get an update, however it shouldn't yet contain any
// filtered transaction as the filter hasn't been updated.
@@ -487,37 +418,23 @@ func testFilterSingleBlock(node *rpctest.Harness, chainView FilteredChainView,
}
tx1, err := node.Client.GetRawTransaction(txid1)
if err != nil {
t.Fatalf("unable to fetch transaction: %v", err)
}
require.NoError(t, err, "unable to fetch transaction")
tx2, err := node.Client.GetRawTransaction(txid2)
if err != nil {
t.Fatalf("unable to fetch transaction: %v", err)
}
require.NoError(t, err, "unable to fetch transaction")
// Next, we'll create a block that includes two transactions, each
// which spend one of the outputs created.
outPoint1, _, err := locateOutput(tx1.MsgTx(), testScript)
if err != nil {
t.Fatalf("unable to find output: %v", err)
}
require.NoError(t, err, "unable to find output")
outPoint2, _, err := locateOutput(tx2.MsgTx(), testScript)
if err != nil {
t.Fatalf("unable to find output: %v", err)
}
require.NoError(t, err, "unable to find output")
spendingTx1, err := craftSpendTransaction(*outPoint1, testScript)
if err != nil {
t.Fatalf("unable to create spending tx: %v", err)
}
require.NoError(t, err, "unable to create spending tx")
spendingTx2, err := craftSpendTransaction(*outPoint2, testScript)
if err != nil {
t.Fatalf("unable to create spending tx: %v", err)
}
require.NoError(t, err, "unable to create spending tx")
txns := []*btcutil.Tx{btcutil.NewTx(spendingTx1), btcutil.NewTx(spendingTx2)}
block, err := node.GenerateAndSubmitBlock(txns, 11, time.Time{})
if err != nil {
t.Fatalf("unable to generate block: %v", err)
}
require.NoError(t, err, "unable to generate block")
select {
case filteredBlock := <-blockChan:
@@ -528,9 +445,7 @@ func testFilterSingleBlock(node *rpctest.Harness, chainView FilteredChainView,
}
_, currentHeight, err = node.Client.GetBestBlock()
if err != nil {
t.Fatalf("unable to get current height: %v", err)
}
require.NoError(t, err, "unable to get current height")
// Now we'll manually trigger filtering the block generated above.
// First, we'll add the two outpoints to our filter.
@@ -539,9 +454,7 @@ func testFilterSingleBlock(node *rpctest.Harness, chainView FilteredChainView,
{FundingPkScript: testScript, OutPoint: *outPoint2},
}
err = chainView.UpdateFilter(filter, uint32(currentHeight))
if err != nil {
t.Fatalf("unable to update filter: %v", err)
}
require.NoError(t, err, "unable to update filter")
// We set the filter with the current height, so we shouldn't get any
// notifications.
@@ -554,9 +467,7 @@ func testFilterSingleBlock(node *rpctest.Harness, chainView FilteredChainView,
// Now we'll manually rescan that past block. This should include two
// filtered transactions, the spending transactions we created above.
filteredBlock, err := chainView.FilterBlock(block.Hash())
if err != nil {
t.Fatalf("unable to filter block: %v", err)
}
require.NoError(t, err, "unable to filter block")
txn1, txn2 := spendingTx1.TxHash(), spendingTx2.TxHash()
expectedTxns := []*chainhash.Hash{&txn1, &txn2}
assertFilteredBlock(t, filteredBlock, currentHeight, block.Hash(),
@@ -573,9 +484,7 @@ func testFilterBlockDisconnected(node *rpctest.Harness,
// Create a node that has a shorter chain than the main chain, so we
// can trigger a reorg.
reorgNode, err := rpctest.New(netParams, nil, []string{"--txindex"}, "")
if err != nil {
t.Fatalf("unable to create mining node: %v", err)
}
require.NoError(t, err, "unable to create mining node")
defer reorgNode.TearDown()
// We want to overwrite some of the connection settings to make the
@@ -592,17 +501,13 @@ func testFilterBlockDisconnected(node *rpctest.Harness,
}
_, bestHeight, err := reorgNode.Client.GetBestBlock()
if err != nil {
t.Fatalf("error getting best block: %v", err)
}
require.NoError(t, err, "error getting best block")
// Init a chain view that has this node as its block source.
cleanUpFunc, reorgView, err := chainViewInit(
reorgNode.RPCConfig(), reorgNode.P2PAddress(), bestHeight,
)
if err != nil {
t.Fatalf("unable to create chain view: %v", err)
}
require.NoError(t, err, "unable to create chain view")
defer func() {
if cleanUpFunc != nil {
cleanUpFunc()
@@ -625,9 +530,7 @@ func testFilterBlockDisconnected(node *rpctest.Harness,
}
_, oldHeight, err := reorgNode.Client.GetBestBlock()
if err != nil {
t.Fatalf("unable to get current height: %v", err)
}
require.NoError(t, err, "unable to get current height")
// Now connect the node with the short chain to the main node, and wait
// for their chains to synchronize. The short chain will be reorged all
@@ -641,9 +544,7 @@ func testFilterBlockDisconnected(node *rpctest.Harness,
}
_, newHeight, err := reorgNode.Client.GetBestBlock()
if err != nil {
t.Fatalf("unable to get current height: %v", err)
}
require.NoError(t, err, "unable to get current height")
// We should be getting oldHeight number of blocks marked as
// stale/disconnected. We expect to first get all stale blocks,
@@ -681,16 +582,12 @@ func testFilterBlockDisconnected(node *rpctest.Harness,
// Now we trigger a small reorg, by disconnecting the nodes, mining
// a few blocks on each, then connecting them again.
peers, err := reorgNode.Client.GetPeerInfo()
if err != nil {
t.Fatalf("unable to get peer info: %v", err)
}
require.NoError(t, err, "unable to get peer info")
numPeers := len(peers)
// Disconnect the nodes.
err = reorgNode.Client.AddNode(node.P2PAddress(), rpcclient.ANRemove)
if err != nil {
t.Fatalf("unable to disconnect mining nodes: %v", err)
}
require.NoError(t, err, "unable to disconnect mining nodes")
// Wait for disconnection
for {
@@ -732,9 +629,7 @@ func testFilterBlockDisconnected(node *rpctest.Harness,
}
_, oldHeight, err = reorgNode.Client.GetBestBlock()
if err != nil {
t.Fatalf("unable to get current height: %v", err)
}
require.NoError(t, err, "unable to get current height")
// Now connect the two nodes, and wait for their chains to sync up.
if err := rpctest.ConnectNode(reorgNode, node); err != nil {
@@ -1135,9 +1030,7 @@ func TestFilteredChainView(t *testing.T) {
// this node with a chain length of 125, so we have plenty of BTC to
// play around with.
miner, err := rpctest.New(netParams, nil, []string{"--txindex"}, "")
if err != nil {
t.Fatalf("unable to create mining node: %v", err)
}
require.NoError(t, err, "unable to create mining node")
defer miner.TearDown()
if err := miner.SetUp(true, 25); err != nil {
t.Fatalf("unable to set up mining node: %v", err)
+9 -24
View File
@@ -15,6 +15,7 @@ import (
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/routing/route"
"github.com/stretchr/testify/require"
)
var (
@@ -48,9 +49,7 @@ func TestControlTowerSubscribeUnknown(t *testing.T) {
t.Parallel()
db, err := initDB()
if err != nil {
t.Fatalf("unable to init db: %v", err)
}
require.NoError(t, err, "unable to init db")
pControl := NewControlTower(channeldb.NewPaymentControl(db))
@@ -67,9 +66,7 @@ func TestControlTowerSubscribeSuccess(t *testing.T) {
t.Parallel()
db, err := initDB()
if err != nil {
t.Fatalf("unable to init db: %v", err)
}
require.NoError(t, err, "unable to init db")
pControl := NewControlTower(channeldb.NewPaymentControl(db))
@@ -87,9 +84,7 @@ func TestControlTowerSubscribeSuccess(t *testing.T) {
// Subscription should succeed and immediately report the InFlight
// status.
subscriber1, err := pControl.SubscribePayment(info.PaymentIdentifier)
if err != nil {
t.Fatalf("expected subscribe to succeed, but got: %v", err)
}
require.NoError(t, err, "expected subscribe to succeed, but got")
// Register an attempt.
err = pControl.RegisterAttempt(info.PaymentIdentifier, attempt)
@@ -99,9 +94,7 @@ func TestControlTowerSubscribeSuccess(t *testing.T) {
// Register a second subscriber after the first attempt has started.
subscriber2, err := pControl.SubscribePayment(info.PaymentIdentifier)
if err != nil {
t.Fatalf("expected subscribe to succeed, but got: %v", err)
}
require.NoError(t, err, "expected subscribe to succeed, but got")
// Mark the payment as successful.
settleInfo := channeldb.HTLCSettleInfo{
@@ -119,9 +112,7 @@ func TestControlTowerSubscribeSuccess(t *testing.T) {
// Register a third subscriber after the payment succeeded.
subscriber3, err := pControl.SubscribePayment(info.PaymentIdentifier)
if err != nil {
t.Fatalf("expected subscribe to succeed, but got: %v", err)
}
require.NoError(t, err, "expected subscribe to succeed, but got")
// We expect all subscribers to now report the final outcome followed by
// no other events.
@@ -184,9 +175,7 @@ func TestPaymentControlSubscribeFail(t *testing.T) {
func testPaymentControlSubscribeFail(t *testing.T, registerAttempt bool) {
db, err := initDB()
if err != nil {
t.Fatalf("unable to init db: %v", err)
}
require.NoError(t, err, "unable to init db")
pControl := NewControlTower(channeldb.NewPaymentControl(db))
@@ -203,9 +192,7 @@ func testPaymentControlSubscribeFail(t *testing.T, registerAttempt bool) {
// Subscription should succeed.
subscriber1, err := pControl.SubscribePayment(info.PaymentIdentifier)
if err != nil {
t.Fatalf("expected subscribe to succeed, but got: %v", err)
}
require.NoError(t, err, "expected subscribe to succeed, but got")
// Conditionally register the attempt based on the test type. This
// allows us to simulate failing after attempting with an htlc or before
@@ -239,9 +226,7 @@ func testPaymentControlSubscribeFail(t *testing.T, registerAttempt bool) {
// Register a second subscriber after the payment failed.
subscriber2, err := pControl.SubscribePayment(info.PaymentIdentifier)
if err != nil {
t.Fatalf("expected subscribe to succeed, but got: %v", err)
}
require.NoError(t, err, "expected subscribe to succeed, but got")
// We expect all subscribers to now report the final outcome followed by
// no other events.
+2 -6
View File
@@ -57,9 +57,7 @@ func TestProbabilityExtrapolation(t *testing.T) {
// modifications anywhere in the chain of components that is involved in
// this test.
attempts, err := ctx.testPayment(1)
if err != nil {
t.Fatalf("payment failed: %v", err)
}
require.NoError(t, err, "payment failed")
if len(attempts) != 5 {
t.Fatalf("expected 5 attempts, but needed %v", len(attempts))
}
@@ -69,9 +67,7 @@ func TestProbabilityExtrapolation(t *testing.T) {
// first before switching to the paid channel.
ctx.mcCfg.AprioriWeight = 1
attempts, err = ctx.testPayment(1)
if err != nil {
t.Fatalf("payment failed: %v", err)
}
require.NoError(t, err, "payment failed")
if len(attempts) != 11 {
t.Fatalf("expected 11 attempts, but needed %v", len(attempts))
}
+18 -54
View File
@@ -400,9 +400,7 @@ func TestEdgeUpdateNotification(t *testing.T) {
fundingTx, chanPoint, chanID, err := createChannelEdge(ctx,
bitcoinKey1.SerializeCompressed(), bitcoinKey2.SerializeCompressed(),
chanValue, 0)
if err != nil {
t.Fatalf("unable create channel edge: %v", err)
}
require.NoError(t, err, "unable create channel edge")
// We'll also add a record for the block that included our funding
// transaction.
@@ -414,13 +412,9 @@ func TestEdgeUpdateNotification(t *testing.T) {
// Next we'll create two test nodes that the fake channel will be open
// between.
node1, err := createTestNode()
if err != nil {
t.Fatalf("unable to create test node: %v", err)
}
require.NoError(t, err, "unable to create test node")
node2, err := createTestNode()
if err != nil {
t.Fatalf("unable to create test node: %v", err)
}
require.NoError(t, err, "unable to create test node")
// Finally, to conclude our test set up, we'll create a channel
// update to announce the created channel between the two nodes.
@@ -445,9 +439,7 @@ func TestEdgeUpdateNotification(t *testing.T) {
// With the channel edge now in place, we'll subscribe for topology
// notifications.
ntfnClient, err := ctx.router.SubscribeTopology()
if err != nil {
t.Fatalf("unable to subscribe for channel notifications: %v", err)
}
require.NoError(t, err, "unable to subscribe for channel notifications")
// Create random policy edges that are stemmed to the channel id
// created above.
@@ -514,13 +506,9 @@ func TestEdgeUpdateNotification(t *testing.T) {
}
node1Pub, err := node1.PubKey()
if err != nil {
t.Fatalf("unable to encode key: %v", err)
}
require.NoError(t, err, "unable to encode key")
node2Pub, err := node2.PubKey()
if err != nil {
t.Fatalf("unable to encode key: %v", err)
}
require.NoError(t, err, "unable to encode key")
const numEdgePolicies = 2
for i := 0; i < numEdgePolicies; i++ {
@@ -593,9 +581,7 @@ func TestNodeUpdateNotification(t *testing.T) {
bitcoinKey1.SerializeCompressed(),
bitcoinKey2.SerializeCompressed(),
chanValue, startingBlockHeight)
if err != nil {
t.Fatalf("unable create channel edge: %v", err)
}
require.NoError(t, err, "unable create channel edge")
// We'll also add a record for the block that included our funding
// transaction.
@@ -608,13 +594,9 @@ func TestNodeUpdateNotification(t *testing.T) {
// them to trigger notifications by sending updated node announcement
// messages.
node1, err := createTestNode()
if err != nil {
t.Fatalf("unable to create test node: %v", err)
}
require.NoError(t, err, "unable to create test node")
node2, err := createTestNode()
if err != nil {
t.Fatalf("unable to create test node: %v", err)
}
require.NoError(t, err, "unable to create test node")
testFeaturesBuf := new(bytes.Buffer)
require.NoError(t, testFeatures.Encode(testFeaturesBuf))
@@ -641,9 +623,7 @@ func TestNodeUpdateNotification(t *testing.T) {
// Create a new client to receive notifications.
ntfnClient, err := ctx.router.SubscribeTopology()
if err != nil {
t.Fatalf("unable to subscribe for channel notifications: %v", err)
}
require.NoError(t, err, "unable to subscribe for channel notifications")
// Change network topology by adding the updated info for the two nodes
// to the channel router.
@@ -778,9 +758,7 @@ func TestNotificationCancellation(t *testing.T) {
// Create a new client to receive notifications.
ntfnClient, err := ctx.router.SubscribeTopology()
if err != nil {
t.Fatalf("unable to subscribe for channel notifications: %v", err)
}
require.NoError(t, err, "unable to subscribe for channel notifications")
// We'll create the utxo for a new channel.
const chanValue = 10000
@@ -788,9 +766,7 @@ func TestNotificationCancellation(t *testing.T) {
bitcoinKey1.SerializeCompressed(),
bitcoinKey2.SerializeCompressed(),
chanValue, startingBlockHeight)
if err != nil {
t.Fatalf("unable create channel edge: %v", err)
}
require.NoError(t, err, "unable create channel edge")
// We'll also add a record for the block that included our funding
// transaction.
@@ -802,13 +778,9 @@ func TestNotificationCancellation(t *testing.T) {
// We'll create a fresh new node topology update to feed to the channel
// router.
node1, err := createTestNode()
if err != nil {
t.Fatalf("unable to create test node: %v", err)
}
require.NoError(t, err, "unable to create test node")
node2, err := createTestNode()
if err != nil {
t.Fatalf("unable to create test node: %v", err)
}
require.NoError(t, err, "unable to create test node")
// Before we send the message to the channel router, we'll cancel the
// notifications for this client. As a result, the notification
@@ -870,9 +842,7 @@ func TestChannelCloseNotification(t *testing.T) {
fundingTx, chanUtxo, chanID, err := createChannelEdge(ctx,
bitcoinKey1.SerializeCompressed(), bitcoinKey2.SerializeCompressed(),
chanValue, startingBlockHeight)
if err != nil {
t.Fatalf("unable create channel edge: %v", err)
}
require.NoError(t, err, "unable create channel edge")
// We'll also add a record for the block that included our funding
// transaction.
@@ -884,13 +854,9 @@ func TestChannelCloseNotification(t *testing.T) {
// Next we'll create two test nodes that the fake channel will be open
// between.
node1, err := createTestNode()
if err != nil {
t.Fatalf("unable to create test node: %v", err)
}
require.NoError(t, err, "unable to create test node")
node2, err := createTestNode()
if err != nil {
t.Fatalf("unable to create test node: %v", err)
}
require.NoError(t, err, "unable to create test node")
// Finally, to conclude our test set up, we'll create a channel
// announcement to announce the created channel between the two nodes.
@@ -914,9 +880,7 @@ func TestChannelCloseNotification(t *testing.T) {
// With the channel edge now in place, we'll subscribe for topology
// notifications.
ntfnClient, err := ctx.router.SubscribeTopology()
if err != nil {
t.Fatalf("unable to subscribe for channel notifications: %v", err)
}
require.NoError(t, err, "unable to subscribe for channel notifications")
// Next, we'll simulate the closure of our channel by generating a new
// block at height 102 which spends the original multi-sig output of
+57 -171
View File
@@ -962,9 +962,7 @@ func runFindLowestFeePath(t *testing.T, useCache bool) {
paymentAmt := lnwire.NewMSatFromSatoshis(100)
target := ctx.keyFromAlias("target")
path, err := ctx.findPath(target, paymentAmt)
if err != nil {
t.Fatalf("unable to find path: %v", err)
}
require.NoError(t, err, "unable to find path")
route, err := newRoute(
ctx.source, path, startingHeight,
finalHopParams{
@@ -973,9 +971,7 @@ func runFindLowestFeePath(t *testing.T, useCache bool) {
records: nil,
},
)
if err != nil {
t.Fatalf("unable to create path: %v", err)
}
require.NoError(t, err, "unable to create path")
// Assert that the lowest fee route is returned.
if route.Hops[1].PubKeyBytes != ctx.keyFromAlias("b") {
@@ -1058,9 +1054,7 @@ var basicGraphPathFindingTests = []basicGraphPathFindingTestCase{
func runBasicGraphPathFinding(t *testing.T, useCache bool) {
testGraphInstance, err := parseTestGraph(useCache, basicGraphFilePath)
if err != nil {
t.Fatalf("unable to create graph: %v", err)
}
require.NoError(t, err, "unable to create graph")
defer testGraphInstance.cleanUp()
// With the test graph loaded, we'll test some basic path finding using
@@ -1083,9 +1077,7 @@ func testBasicGraphPathFindingCase(t *testing.T, graphInstance *testGraphInstanc
expectedHopCount := len(expectedHops)
sourceNode, err := graphInstance.graph.SourceNode()
if err != nil {
t.Fatalf("unable to fetch source node: %v", err)
}
require.NoError(t, err, "unable to fetch source node")
sourceVertex := route.Vertex(sourceNode.PubKeyBytes)
const (
@@ -1112,9 +1104,7 @@ func testBasicGraphPathFindingCase(t *testing.T, graphInstance *testGraphInstanc
}
return
}
if err != nil {
t.Fatalf("unable to find path: %v", err)
}
require.NoError(t, err, "unable to find path")
route, err := newRoute(
sourceVertex, path, startingHeight,
@@ -1124,9 +1114,7 @@ func testBasicGraphPathFindingCase(t *testing.T, graphInstance *testGraphInstanc
records: nil,
},
)
if err != nil {
t.Fatalf("unable to create path: %v", err)
}
require.NoError(t, err, "unable to create path")
if len(route.Hops) != len(expectedHops) {
t.Fatalf("route is of incorrect length, expected %v got %v",
@@ -1148,9 +1136,7 @@ func testBasicGraphPathFindingCase(t *testing.T, graphInstance *testGraphInstanc
// properly points to the channel ID that the HTLC should be forwarded
// along.
sphinxPath, err := route.ToSphinxPath()
if err != nil {
t.Fatalf("unable to make sphinx path: %v", err)
}
require.NoError(t, err, "unable to make sphinx path")
if sphinxPath.TrueRouteLength() != expectedHopCount {
t.Fatalf("incorrect number of hop payloads: expected %v, got %v",
expectedHopCount, sphinxPath.TrueRouteLength())
@@ -1178,9 +1164,7 @@ func testBasicGraphPathFindingCase(t *testing.T, graphInstance *testGraphInstanc
lastHopIndex := len(expectedHops) - 1
hopData, err := sphinxPath[lastHopIndex].HopPayload.HopData()
if err != nil {
t.Fatalf("unable to create hop data: %v", err)
}
require.NoError(t, err, "unable to create hop data")
if !bytes.Equal(hopData.NextAddress[:], exitHop[:]) {
t.Fatalf("first hop has incorrect next hop: expected %x, got %x",
@@ -1235,15 +1219,11 @@ func testBasicGraphPathFindingCase(t *testing.T, graphInstance *testGraphInstanc
// appropriate circumstances.
func runPathFindingWithAdditionalEdges(t *testing.T, useCache bool) {
graph, err := parseTestGraph(useCache, basicGraphFilePath)
if err != nil {
t.Fatalf("unable to create graph: %v", err)
}
require.NoError(t, err, "unable to create graph")
defer graph.cleanUp()
sourceNode, err := graph.graph.SourceNode()
if err != nil {
t.Fatalf("unable to fetch source node: %v", err)
}
require.NoError(t, err, "unable to fetch source node")
paymentAmt := lnwire.NewMSatFromSatoshis(100)
@@ -1254,13 +1234,9 @@ func runPathFindingWithAdditionalEdges(t *testing.T, useCache bool) {
// to find a path from our source node, roasbeef, to doge.
dogePubKeyHex := "03dd46ff29a6941b4a2607525b043ec9b020b3f318a1bf281536fd7011ec59c882"
dogePubKeyBytes, err := hex.DecodeString(dogePubKeyHex)
if err != nil {
t.Fatalf("unable to decode public key: %v", err)
}
require.NoError(t, err, "unable to decode public key")
dogePubKey, err := btcec.ParsePubKey(dogePubKeyBytes)
if err != nil {
t.Fatalf("unable to parse public key from bytes: %v", err)
}
require.NoError(t, err, "unable to parse public key from bytes")
doge := &channeldb.LightningNode{}
doge.AddPubKey(dogePubKey)
@@ -1298,9 +1274,7 @@ func runPathFindingWithAdditionalEdges(t *testing.T, useCache bool) {
// We should now be able to find a path from roasbeef to doge.
path, err := find(noRestrictions)
if err != nil {
t.Fatalf("unable to find private path to doge: %v", err)
}
require.NoError(t, err, "unable to find private path to doge")
// The path should represent the following hops:
// roasbeef -> songoku -> doge
@@ -1330,9 +1304,7 @@ func runPathFindingWithAdditionalEdges(t *testing.T, useCache bool) {
restrictions.DestFeatures = tlvFeatures
path, err = find(&restrictions)
if err != nil {
t.Fatalf("path should have been found: %v", err)
}
require.NoError(t, err, "path should have been found")
assertExpectedPath(t, graph.aliasMap, path, "songoku", "doge")
}
@@ -1675,9 +1647,7 @@ func runNewRoutePathTooLong(t *testing.T, useCache bool) {
node20 := ctx.keyFromAlias("node-20")
payAmt := lnwire.MilliSatoshi(100001)
_, err := ctx.findPath(node20, payAmt)
if err != nil {
t.Fatalf("unexpected pathfinding failure: %v", err)
}
require.NoError(t, err, "unexpected pathfinding failure")
// Assert that finding a 21 hop route fails.
node21 := ctx.keyFromAlias("node-21")
@@ -1700,24 +1670,18 @@ func runNewRoutePathTooLong(t *testing.T, useCache bool) {
func runPathNotAvailable(t *testing.T, useCache bool) {
graph, err := parseTestGraph(useCache, basicGraphFilePath)
if err != nil {
t.Fatalf("unable to create graph: %v", err)
}
require.NoError(t, err, "unable to create graph")
defer graph.cleanUp()
sourceNode, err := graph.graph.SourceNode()
if err != nil {
t.Fatalf("unable to fetch source node: %v", err)
}
require.NoError(t, err, "unable to fetch source node")
// With the test graph loaded, we'll test that queries for target that
// are either unreachable within the graph, or unknown result in an
// error.
unknownNodeStr := "03dd46ff29a6941b4a2607525b043ec9b020b3f318a1bf281536fd7011ec59c882"
unknownNodeBytes, err := hex.DecodeString(unknownNodeStr)
if err != nil {
t.Fatalf("unable to parse bytes: %v", err)
}
require.NoError(t, err, "unable to parse bytes")
var unknownNode route.Vertex
copy(unknownNode[:], unknownNodeBytes)
@@ -1767,9 +1731,7 @@ func runDestTLVGraphFallback(t *testing.T, useCache bool) {
defer ctx.cleanup()
sourceNode, err := ctx.graph.SourceNode()
if err != nil {
t.Fatalf("unable to fetch source node: %v", err)
}
require.NoError(t, err, "unable to fetch source node")
find := func(r *RestrictParams,
target route.Vertex) ([]*channeldb.CachedEdgePolicy, error) {
@@ -1801,9 +1763,7 @@ func runDestTLVGraphFallback(t *testing.T, useCache bool) {
// However, path to satoshi should succeed via the fallback because his
// node ann features have the TLV bit.
path, err := find(&restrictions, satoshi)
if err != nil {
t.Fatalf("path should have been found: %v", err)
}
require.NoError(t, err, "path should have been found")
assertExpectedPath(t, ctx.testGraphInstance.aliasMap, path, "satoshi")
// Add empty destination features. This should cause both paths to fail,
@@ -1824,9 +1784,7 @@ func runDestTLVGraphFallback(t *testing.T, useCache bool) {
restrictions.DestFeatures = tlvFeatures
path, err = find(&restrictions, luoji)
if err != nil {
t.Fatalf("path should have been found: %v", err)
}
require.NoError(t, err, "path should have been found")
assertExpectedPath(t, ctx.testGraphInstance.aliasMap, path, "luoji")
}
@@ -1888,9 +1846,7 @@ func runMissingFeatureDep(t *testing.T, useCache bool) {
ctx.restrictParams.DestFeatures = tlvPayAddrFeatures
path, err := ctx.findPath(conner, 100)
if err != nil {
t.Fatalf("path should have been found: %v", err)
}
require.NoError(t, err, "path should have been found")
assertExpectedPath(t, ctx.testGraphInstance.aliasMap, path, "conner")
// Finally, try to find a route to joost through conner. The
@@ -2006,23 +1962,17 @@ func runDestPaymentAddr(t *testing.T, useCache bool) {
ctx.restrictParams.DestFeatures = tlvPayAddrFeatures
path, err := ctx.findPath(luoji, 100)
if err != nil {
t.Fatalf("path should have been found: %v", err)
}
require.NoError(t, err, "path should have been found")
assertExpectedPath(t, ctx.testGraphInstance.aliasMap, path, "luoji")
}
func runPathInsufficientCapacity(t *testing.T, useCache bool) {
graph, err := parseTestGraph(useCache, basicGraphFilePath)
if err != nil {
t.Fatalf("unable to create graph: %v", err)
}
require.NoError(t, err, "unable to create graph")
defer graph.cleanUp()
sourceNode, err := graph.graph.SourceNode()
if err != nil {
t.Fatalf("unable to fetch source node: %v", err)
}
require.NoError(t, err, "unable to fetch source node")
// Next, test that attempting to find a path in which the current
// channel graph cannot support due to insufficient capacity triggers
@@ -2049,15 +1999,11 @@ func runPathInsufficientCapacity(t *testing.T, useCache bool) {
// smaller than the advertised minHTLC of an edge, then path finding fails.
func runRouteFailMinHTLC(t *testing.T, useCache bool) {
graph, err := parseTestGraph(useCache, basicGraphFilePath)
if err != nil {
t.Fatalf("unable to create graph: %v", err)
}
require.NoError(t, err, "unable to create graph")
defer graph.cleanUp()
sourceNode, err := graph.graph.SourceNode()
if err != nil {
t.Fatalf("unable to fetch source node: %v", err)
}
require.NoError(t, err, "unable to fetch source node")
// We'll not attempt to route an HTLC of 10 SAT from roasbeef to Son
// Goku. However, the min HTLC of Son Goku is 1k SAT, as a result, this
@@ -2111,17 +2057,13 @@ func runRouteFailMaxHTLC(t *testing.T, useCache bool) {
target := ctx.keyFromAlias("target")
payAmt := lnwire.MilliSatoshi(100001)
_, err := ctx.findPath(target, payAmt)
if err != nil {
t.Fatalf("graph should've been able to support payment: %v", err)
}
require.NoError(t, err, "graph should've been able to support payment")
// Next, update the middle edge policy to only allow payments up to 100k
// msat.
graph := ctx.testGraphInstance.graph
_, midEdge, _, err := graph.FetchChannelEdgesByID(firstToSecondID)
if err != nil {
t.Fatalf("unable to fetch channel edges by ID: %v", err)
}
require.NoError(t, err, "unable to fetch channel edges by ID")
midEdge.MessageFlags = 1
midEdge.MaxHTLC = payAmt - 1
if err := graph.UpdateEdgePolicy(midEdge); err != nil {
@@ -2143,15 +2085,11 @@ func runRouteFailMaxHTLC(t *testing.T, useCache bool) {
// found among the bandwidth hints.
func runRouteFailDisabledEdge(t *testing.T, useCache bool) {
graph, err := parseTestGraph(useCache, basicGraphFilePath)
if err != nil {
t.Fatalf("unable to create graph: %v", err)
}
require.NoError(t, err, "unable to create graph")
defer graph.cleanUp()
sourceNode, err := graph.graph.SourceNode()
if err != nil {
t.Fatalf("unable to fetch source node: %v", err)
}
require.NoError(t, err, "unable to fetch source node")
// First, we'll try to route from roasbeef -> sophon. This should
// succeed without issue, and return a single path via phamnuwen
@@ -2162,18 +2100,14 @@ func runRouteFailDisabledEdge(t *testing.T, useCache bool) {
noRestrictions, testPathFindingConfig,
sourceNode.PubKeyBytes, target, payAmt, 0, 0,
)
if err != nil {
t.Fatalf("unable to find path: %v", err)
}
require.NoError(t, err, "unable to find path")
// Disable the edge roasbeef->phamnuwen. This should not impact the
// path finding, as we don't consider the disable flag for local
// channels (and roasbeef is the source).
roasToPham := uint64(999991)
_, e1, e2, err := graph.graph.FetchChannelEdgesByID(roasToPham)
if err != nil {
t.Fatalf("unable to fetch edge: %v", err)
}
require.NoError(t, err, "unable to fetch edge")
e1.ChannelFlags |= lnwire.ChanUpdateDisabled
if err := graph.graph.UpdateEdgePolicy(e1); err != nil {
t.Fatalf("unable to update edge: %v", err)
@@ -2188,17 +2122,13 @@ func runRouteFailDisabledEdge(t *testing.T, useCache bool) {
noRestrictions, testPathFindingConfig,
sourceNode.PubKeyBytes, target, payAmt, 0, 0,
)
if err != nil {
t.Fatalf("unable to find path: %v", err)
}
require.NoError(t, err, "unable to find path")
// Now, we'll modify the edge from phamnuwen -> sophon, to read that
// it's disabled.
phamToSophon := uint64(99999)
_, e, _, err := graph.graph.FetchChannelEdgesByID(phamToSophon)
if err != nil {
t.Fatalf("unable to fetch edge: %v", err)
}
require.NoError(t, err, "unable to fetch edge")
e.ChannelFlags |= lnwire.ChanUpdateDisabled
if err := graph.graph.UpdateEdgePolicy(e); err != nil {
t.Fatalf("unable to update edge: %v", err)
@@ -2221,15 +2151,11 @@ func runRouteFailDisabledEdge(t *testing.T, useCache bool) {
// use a local channel.
func runPathSourceEdgesBandwidth(t *testing.T, useCache bool) {
graph, err := parseTestGraph(useCache, basicGraphFilePath)
if err != nil {
t.Fatalf("unable to create graph: %v", err)
}
require.NoError(t, err, "unable to create graph")
defer graph.cleanUp()
sourceNode, err := graph.graph.SourceNode()
if err != nil {
t.Fatalf("unable to fetch source node: %v", err)
}
require.NoError(t, err, "unable to fetch source node")
// First, we'll try to route from roasbeef -> sophon. This should
// succeed without issue, and return a path via songoku, as that's the
@@ -2241,9 +2167,7 @@ func runPathSourceEdgesBandwidth(t *testing.T, useCache bool) {
noRestrictions, testPathFindingConfig,
sourceNode.PubKeyBytes, target, payAmt, 0, 0,
)
if err != nil {
t.Fatalf("unable to find path: %v", err)
}
require.NoError(t, err, "unable to find path")
assertExpectedPath(t, graph.aliasMap, path, "songoku", "sophon")
// Now we'll set the bandwidth of the edge roasbeef->songoku and
@@ -2279,18 +2203,14 @@ func runPathSourceEdgesBandwidth(t *testing.T, useCache bool) {
noRestrictions, testPathFindingConfig,
sourceNode.PubKeyBytes, target, payAmt, 0, 0,
)
if err != nil {
t.Fatalf("unable to find path: %v", err)
}
require.NoError(t, err, "unable to find path")
assertExpectedPath(t, graph.aliasMap, path, "phamnuwen", "sophon")
// Finally, set the roasbeef->songoku bandwidth, but also set its
// disable flag.
bandwidths.hints[roasToSongoku] = 2 * payAmt
_, e1, e2, err := graph.graph.FetchChannelEdgesByID(roasToSongoku)
if err != nil {
t.Fatalf("unable to fetch edge: %v", err)
}
require.NoError(t, err, "unable to fetch edge")
e1.ChannelFlags |= lnwire.ChanUpdateDisabled
if err := graph.graph.UpdateEdgePolicy(e1); err != nil {
t.Fatalf("unable to update edge: %v", err)
@@ -2307,9 +2227,7 @@ func runPathSourceEdgesBandwidth(t *testing.T, useCache bool) {
noRestrictions, testPathFindingConfig,
sourceNode.PubKeyBytes, target, payAmt, 0, 0,
)
if err != nil {
t.Fatalf("unable to find path: %v", err)
}
require.NoError(t, err, "unable to find path")
assertExpectedPath(t, graph.aliasMap, path, "songoku", "sophon")
}
@@ -2340,9 +2258,7 @@ func TestPathFindSpecExample(t *testing.T) {
// Bob.
bob := ctx.aliases["B"]
bobNode, err := ctx.graph.FetchLightningNode(bob)
if err != nil {
t.Fatalf("unable to find bob: %v", err)
}
require.NoError(t, err, "unable to find bob")
if err := ctx.graph.SetSourceNode(bobNode); err != nil {
t.Fatalf("unable to set source node: %v", err)
}
@@ -2354,9 +2270,7 @@ func TestPathFindSpecExample(t *testing.T) {
bobNode.PubKeyBytes, carol, amt, 0, noRestrictions, nil, nil,
MinCLTVDelta,
)
if err != nil {
t.Fatalf("unable to find route: %v", err)
}
require.NoError(t, err, "unable to find route")
// Now we'll examine the route returned for correctness.
//
@@ -2390,17 +2304,13 @@ func TestPathFindSpecExample(t *testing.T) {
// the proper route for any queries starting with Alice.
alice := ctx.aliases["A"]
aliceNode, err := ctx.graph.FetchLightningNode(alice)
if err != nil {
t.Fatalf("unable to find alice: %v", err)
}
require.NoError(t, err, "unable to find alice")
if err := ctx.graph.SetSourceNode(aliceNode); err != nil {
t.Fatalf("unable to set source node: %v", err)
}
ctx.router.selfNode = aliceNode
source, err := ctx.graph.SourceNode()
if err != nil {
t.Fatalf("unable to retrieve source node: %v", err)
}
require.NoError(t, err, "unable to retrieve source node")
if source.PubKeyBytes != alice {
t.Fatalf("source node not set")
}
@@ -2410,9 +2320,7 @@ func TestPathFindSpecExample(t *testing.T) {
source.PubKeyBytes, carol, amt, 0, noRestrictions, nil, nil,
MinCLTVDelta,
)
if err != nil {
t.Fatalf("unable to find routes: %v", err)
}
require.NoError(t, err, "unable to find routes")
// The route should be two hops.
if len(route.Hops) != 2 {
@@ -2569,9 +2477,7 @@ func runRestrictOutgoingChannel(t *testing.T, useCache bool) {
// outgoing channel.
ctx.restrictParams.OutgoingChannelIDs = []uint64{outgoingChannelID}
path, err := ctx.findPath(target, paymentAmt)
if err != nil {
t.Fatalf("unable to find path: %v", err)
}
require.NoError(t, err, "unable to find path")
// Assert that the route starts with channel chanSourceB1, in line with
// the specified restriction.
@@ -2587,9 +2493,7 @@ func runRestrictOutgoingChannel(t *testing.T, useCache bool) {
chanSourceB1, chanSourceTarget,
}
path, err = ctx.findPath(target, paymentAmt)
if err != nil {
t.Fatalf("unable to find path: %v", err)
}
require.NoError(t, err, "unable to find path")
if path[0].ChannelID != chanSourceTarget {
t.Fatalf("expected route to pass through channel %v",
chanSourceTarget)
@@ -2629,9 +2533,7 @@ func runRestrictLastHop(t *testing.T, useCache bool) {
// This should force pathfinding to not take the lowest cost option.
ctx.restrictParams.LastHop = &lastHop
path, err := ctx.findPath(target, paymentAmt)
if err != nil {
t.Fatalf("unable to find path: %v", err)
}
require.NoError(t, err, "unable to find path")
if path[0].ChannelID != 3 {
t.Fatalf("expected route to pass through channel 3, "+
"but channel %v was selected instead",
@@ -2704,9 +2606,7 @@ func testCltvLimit(t *testing.T, useCache bool, limit uint32,
}
t.Fatal("expected no path to be found")
}
if err != nil {
t.Fatalf("unable to find path: %v", err)
}
require.NoError(t, err, "unable to find path")
const (
startingHeight = 100
@@ -2720,9 +2620,7 @@ func testCltvLimit(t *testing.T, useCache bool, limit uint32,
records: nil,
},
)
if err != nil {
t.Fatalf("unable to create path: %v", err)
}
require.NoError(t, err, "unable to create path")
// Assert that the route starts with the expected channel.
if route.Hops[0].ChannelID != expectedChannel {
@@ -3037,9 +2935,7 @@ func runNoCycle(t *testing.T, useCache bool) {
// Find the best path given the restriction to only use channel 2 as the
// outgoing channel.
path, err := ctx.findPath(target, paymentAmt)
if err != nil {
t.Fatalf("unable to find path: %v", err)
}
require.NoError(t, err, "unable to find path")
route, err := newRoute(
ctx.source, path, startingHeight,
finalHopParams{
@@ -3048,9 +2944,7 @@ func runNoCycle(t *testing.T, useCache bool) {
records: nil,
},
)
if err != nil {
t.Fatalf("unable to create path: %v", err)
}
require.NoError(t, err, "unable to create path")
if len(route.Hops) != 2 {
t.Fatalf("unexpected route")
@@ -3089,9 +2983,7 @@ func runRouteToSelf(t *testing.T, useCache bool) {
// Find the best path to self. We expect this to be source->a->source,
// because a charges the lowest forwarding fee.
path, err := ctx.findPath(target, paymentAmt)
if err != nil {
t.Fatalf("unable to find path: %v", err)
}
require.NoError(t, err, "unable to find path")
ctx.assertPath(path, []uint64{1, 1})
outgoingChanID := uint64(1)
@@ -3102,9 +2994,7 @@ func runRouteToSelf(t *testing.T, useCache bool) {
// Find the best path to self given that we want to go out via channel 1
// and return through node b.
path, err = ctx.findPath(target, paymentAmt)
if err != nil {
t.Fatalf("unable to find path: %v", err)
}
require.NoError(t, err, "unable to find path")
ctx.assertPath(path, []uint64{1, 3, 2})
}
@@ -3125,14 +3015,10 @@ func newPathFindingTestContext(t *testing.T, useCache bool,
testGraphInstance, err := createTestGraphFromChannels(
useCache, testChannels, source,
)
if err != nil {
t.Fatalf("unable to create graph: %v", err)
}
require.NoError(t, err, "unable to create graph")
sourceNode, err := testGraphInstance.graph.SourceNode()
if err != nil {
t.Fatalf("unable to fetch source node: %v", err)
}
require.NoError(t, err, "unable to fetch source node")
ctx := &pathFindingTestContext{
t: t,
+2 -6
View File
@@ -181,9 +181,7 @@ func TestRouterPaymentStateMachine(t *testing.T) {
}
testGraph, err := createTestGraphFromChannels(true, testChannels, "a")
if err != nil {
t.Fatalf("unable to create graph: %v", err)
}
require.NoError(t, err, "unable to create graph")
defer testGraph.cleanUp()
paymentAmt := lnwire.NewMSatFromSatoshis(1000)
@@ -191,9 +189,7 @@ func TestRouterPaymentStateMachine(t *testing.T) {
// We create a simple route that we will supply every time the router
// requests one.
rt, err := createTestRoute(paymentAmt, testGraph.aliasMap)
if err != nil {
t.Fatalf("unable to create route: %v", err)
}
require.NoError(t, err, "unable to create route")
tests := []paymentLifecycleTestCase{
{
+40 -120
View File
@@ -1168,9 +1168,7 @@ func TestAddProof(t *testing.T) {
fundingTx, _, chanID, err := createChannelEdge(ctx,
bitcoinKey1.SerializeCompressed(), bitcoinKey2.SerializeCompressed(),
100, 0)
if err != nil {
t.Fatalf("unable create channel edge: %v", err)
}
require.NoError(t, err, "unable create channel edge")
fundingBlock := &wire.MsgBlock{
Transactions: []*wire.MsgTx{fundingTx},
}
@@ -1197,9 +1195,7 @@ func TestAddProof(t *testing.T) {
}
info, _, _, err := ctx.router.GetChannelByID(*chanID)
if err != nil {
t.Fatalf("unable to get channel: %v", err)
}
require.NoError(t, err, "unable to get channel")
if info.AuthProof == nil {
t.Fatal("proof have been updated")
}
@@ -1247,9 +1243,7 @@ func TestIgnoreChannelEdgePolicyForUnknownChannel(t *testing.T) {
testGraph, err := createTestGraphFromChannels(
true, testChannels, "roasbeef",
)
if err != nil {
t.Fatalf("unable to create graph: %v", err)
}
require.NoError(t, err, "unable to create graph")
defer testGraph.cleanUp()
ctx, cleanUp := createTestCtxFromGraphInstance(
@@ -1269,9 +1263,7 @@ func TestIgnoreChannelEdgePolicyForUnknownChannel(t *testing.T) {
ctx, bitcoinKey1.SerializeCompressed(),
bitcoinKey2.SerializeCompressed(), 10000, 500,
)
if err != nil {
t.Fatalf("unable to create channel edge: %v", err)
}
require.NoError(t, err, "unable to create channel edge")
fundingBlock := &wire.MsgBlock{
Transactions: []*wire.MsgTx{fundingTx},
}
@@ -1335,16 +1327,12 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
// The two nodes we are about to add should not exist yet.
_, exists1, err := ctx.graph.HasLightningNode(pub1)
if err != nil {
t.Fatalf("unable to query graph: %v", err)
}
require.NoError(t, err, "unable to query graph")
if exists1 {
t.Fatalf("node already existed")
}
_, exists2, err := ctx.graph.HasLightningNode(pub2)
if err != nil {
t.Fatalf("unable to query graph: %v", err)
}
require.NoError(t, err, "unable to query graph")
if exists2 {
t.Fatalf("node already existed")
}
@@ -1356,9 +1344,7 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
bitcoinKey2.SerializeCompressed(),
10000, 500,
)
if err != nil {
t.Fatalf("unable to create channel edge: %v", err)
}
require.NoError(t, err, "unable to create channel edge")
fundingBlock := &wire.MsgBlock{
Transactions: []*wire.MsgTx{fundingTx},
}
@@ -1419,16 +1405,12 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
// After adding the edge between the two previously unknown nodes, they
// should have been added to the graph.
_, exists1, err = ctx.graph.HasLightningNode(pub1)
if err != nil {
t.Fatalf("unable to query graph: %v", err)
}
require.NoError(t, err, "unable to query graph")
if !exists1 {
t.Fatalf("node1 was not added to the graph")
}
_, exists2, err = ctx.graph.HasLightningNode(pub2)
if err != nil {
t.Fatalf("unable to query graph: %v", err)
}
require.NoError(t, err, "unable to query graph")
if !exists2 {
t.Fatalf("node2 was not added to the graph")
}
@@ -1461,9 +1443,7 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
fundingTx, _, chanID, err = createChannelEdge(ctx,
pubKey1.SerializeCompressed(), pubKey2.SerializeCompressed(),
10000, 510)
if err != nil {
t.Fatalf("unable to create channel edge: %v", err)
}
require.NoError(t, err, "unable to create channel edge")
fundingBlock = &wire.MsgBlock{
Transactions: []*wire.MsgTx{fundingTx},
}
@@ -1528,9 +1508,7 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
targetPubKeyBytes, paymentAmt, 0, noRestrictions, nil, nil,
MinCLTVDelta,
)
if err != nil {
t.Fatalf("unable to find any routes: %v", err)
}
require.NoError(t, err, "unable to find any routes")
// Now check that we can update the node info for the partial node
// without messing up the channel graph.
@@ -1571,23 +1549,17 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
targetPubKeyBytes, paymentAmt, 0, noRestrictions, nil, nil,
MinCLTVDelta,
)
if err != nil {
t.Fatalf("unable to find any routes: %v", err)
}
require.NoError(t, err, "unable to find any routes")
copy1, err := ctx.graph.FetchLightningNode(pub1)
if err != nil {
t.Fatalf("unable to fetch node: %v", err)
}
require.NoError(t, err, "unable to fetch node")
if copy1.Alias != n1.Alias {
t.Fatalf("fetched node not equal to original")
}
copy2, err := ctx.graph.FetchLightningNode(pub2)
if err != nil {
t.Fatalf("unable to fetch node: %v", err)
}
require.NoError(t, err, "unable to fetch node")
if copy2.Alias != n2.Alias {
t.Fatalf("fetched node not equal to original")
@@ -1642,9 +1614,7 @@ func TestWakeUpOnStaleBranch(t *testing.T) {
time.Sleep(time.Millisecond * 500)
_, forkHeight, err := ctx.chain.GetBestBlock()
if err != nil {
t.Fatalf("unable to ge best block: %v", err)
}
require.NoError(t, err, "unable to ge best block")
// Create 10 blocks on the minority chain, confirming chanID2.
for i := uint32(1); i <= 10; i++ {
@@ -1675,13 +1645,9 @@ func TestWakeUpOnStaleBranch(t *testing.T) {
// Now add the two edges to the channel graph, and check that they
// correctly show up in the database.
node1, err := createTestNode()
if err != nil {
t.Fatalf("unable to create test node: %v", err)
}
require.NoError(t, err, "unable to create test node")
node2, err := createTestNode()
if err != nil {
t.Fatalf("unable to create test node: %v", err)
}
require.NoError(t, err, "unable to create test node")
edge1 := &channeldb.ChannelEdgeInfo{
ChannelID: chanID1,
@@ -1851,9 +1817,7 @@ func TestDisconnectedBlocks(t *testing.T) {
time.Sleep(time.Millisecond * 500)
_, forkHeight, err := ctx.chain.GetBestBlock()
if err != nil {
t.Fatalf("unable to get best block: %v", err)
}
require.NoError(t, err, "unable to get best block")
// Create 10 blocks on the minority chain, confirming chanID2.
var minorityChain []*wire.MsgBlock
@@ -1886,13 +1850,9 @@ func TestDisconnectedBlocks(t *testing.T) {
// Now add the two edges to the channel graph, and check that they
// correctly show up in the database.
node1, err := createTestNode()
if err != nil {
t.Fatalf("unable to create test node: %v", err)
}
require.NoError(t, err, "unable to create test node")
node2, err := createTestNode()
if err != nil {
t.Fatalf("unable to create test node: %v", err)
}
require.NoError(t, err, "unable to create test node")
edge1 := &channeldb.ChannelEdgeInfo{
ChannelID: chanID1,
@@ -2032,9 +1992,7 @@ func TestRouterChansClosedOfflinePruneGraph(t *testing.T) {
bitcoinKey1.SerializeCompressed(),
bitcoinKey2.SerializeCompressed(),
chanValue, uint32(nextHeight))
if err != nil {
t.Fatalf("unable create channel edge: %v", err)
}
require.NoError(t, err, "unable create channel edge")
block102.Transactions = append(block102.Transactions, fundingTx1)
ctx.chain.addBlock(block102, uint32(nextHeight), rand.Uint32())
ctx.chain.setBestBlock(int32(nextHeight))
@@ -2045,13 +2003,9 @@ func TestRouterChansClosedOfflinePruneGraph(t *testing.T) {
// for the ChannelRouter to properly recognize the channel we added
// above.
node1, err := createTestNode()
if err != nil {
t.Fatalf("unable to create test node: %v", err)
}
require.NoError(t, err, "unable to create test node")
node2, err := createTestNode()
if err != nil {
t.Fatalf("unable to create test node: %v", err)
}
require.NoError(t, err, "unable to create test node")
edge1 := &channeldb.ChannelEdgeInfo{
ChannelID: chanID1.ToUint64(),
NodeKey1Bytes: node1.PubKeyBytes,
@@ -2097,9 +2051,7 @@ func TestRouterChansClosedOfflinePruneGraph(t *testing.T) {
// At this point, our starting height should be 107.
_, chainHeight, err := ctx.chain.GetBestBlock()
if err != nil {
t.Fatalf("unable to get best block: %v", err)
}
require.NoError(t, err, "unable to get best block")
if chainHeight != 107 {
t.Fatalf("incorrect chain height: expected %v, got %v",
107, chainHeight)
@@ -2139,9 +2091,7 @@ func TestRouterChansClosedOfflinePruneGraph(t *testing.T) {
// At this point, our starting height should be 112.
_, chainHeight, err = ctx.chain.GetBestBlock()
if err != nil {
t.Fatalf("unable to get best block: %v", err)
}
require.NoError(t, err, "unable to get best block")
if chainHeight != 112 {
t.Fatalf("incorrect chain height: expected %v, got %v",
112, chainHeight)
@@ -2394,9 +2344,7 @@ func testPruneChannelGraphDoubleDisabled(t *testing.T, assumeValid bool) {
testGraph, err := createTestGraphFromChannels(
true, testChannels, "self",
)
if err != nil {
t.Fatalf("unable to create test graph: %v", err)
}
require.NoError(t, err, "unable to create test graph")
defer testGraph.cleanUp()
const startingHeight = 100
@@ -2450,9 +2398,7 @@ func TestFindPathFeeWeighting(t *testing.T) {
copy(preImage[:], bytes.Repeat([]byte{9}, 32))
sourceNode, err := ctx.graph.SourceNode()
if err != nil {
t.Fatalf("unable to fetch source node: %v", err)
}
require.NoError(t, err, "unable to fetch source node")
amt := lnwire.MilliSatoshi(100)
@@ -2467,9 +2413,7 @@ func TestFindPathFeeWeighting(t *testing.T) {
testPathFindingConfig,
sourceNode.PubKeyBytes, target, amt, 0, 0,
)
if err != nil {
t.Fatalf("unable to find path: %v", err)
}
require.NoError(t, err, "unable to find path")
// The route that was chosen should be exactly one hop, and should be
// directly to luoji.
@@ -2503,9 +2447,7 @@ func TestIsStaleNode(t *testing.T) {
bitcoinKey1.SerializeCompressed(),
bitcoinKey2.SerializeCompressed(),
10000, 500)
if err != nil {
t.Fatalf("unable to create channel edge: %v", err)
}
require.NoError(t, err, "unable to create channel edge")
fundingBlock := &wire.MsgBlock{
Transactions: []*wire.MsgTx{fundingTx},
}
@@ -2582,9 +2524,7 @@ func TestIsKnownEdge(t *testing.T) {
bitcoinKey1.SerializeCompressed(),
bitcoinKey2.SerializeCompressed(),
10000, 500)
if err != nil {
t.Fatalf("unable to create channel edge: %v", err)
}
require.NoError(t, err, "unable to create channel edge")
fundingBlock := &wire.MsgBlock{
Transactions: []*wire.MsgTx{fundingTx},
}
@@ -2633,9 +2573,7 @@ func TestIsStaleEdgePolicy(t *testing.T) {
bitcoinKey1.SerializeCompressed(),
bitcoinKey2.SerializeCompressed(),
10000, 500)
if err != nil {
t.Fatalf("unable to create channel edge: %v", err)
}
require.NoError(t, err, "unable to create channel edge")
fundingBlock := &wire.MsgBlock{
Transactions: []*wire.MsgTx{fundingTx},
}
@@ -2765,9 +2703,7 @@ func TestUnknownErrorSource(t *testing.T) {
testGraph, err := createTestGraphFromChannels(true, testChannels, "a")
defer testGraph.cleanUp()
if err != nil {
t.Fatalf("unable to create graph: %v", err)
}
require.NoError(t, err, "unable to create graph")
const startingBlockHeight = 101
ctx, cleanUp := createTestCtxFromGraphInstance(
@@ -2807,9 +2743,7 @@ func TestUnknownErrorSource(t *testing.T) {
// which should pruning the channel a->b. We expect the payment to
// succeed via a->d.
_, _, err = ctx.router.SendPayment(&payment)
if err != nil {
t.Fatalf("expected payment to succeed, but got: %v", err)
}
require.NoError(t, err, "expected payment to succeed, but got")
// Next we modify payment result to return an unknown failure.
ctx.router.cfg.Payer.(*mockPaymentAttemptDispatcherOld).setPaymentResult(
@@ -2900,9 +2834,7 @@ func TestSendToRouteStructuredError(t *testing.T) {
}
testGraph, err := createTestGraphFromChannels(true, testChannels, "a")
if err != nil {
t.Fatalf("unable to create graph: %v", err)
}
require.NoError(t, err, "unable to create graph")
defer testGraph.cleanUp()
const startingBlockHeight = 101
@@ -2938,9 +2870,7 @@ func TestSendToRouteStructuredError(t *testing.T) {
}
rt, err := route.NewRouteFromHops(payAmt, 100, ctx.aliases["a"], hops)
if err != nil {
t.Fatalf("unable to create route: %v", err)
}
require.NoError(t, err, "unable to create route")
finalHopIndex := len(hops)
testCases := map[int]lnwire.FailureMessage{
@@ -3036,9 +2966,7 @@ func TestSendToRouteMultiShardSend(t *testing.T) {
rt, err := route.NewRouteFromHops(
payAmt, 100, sourceNode.PubKeyBytes, hops,
)
if err != nil {
t.Fatalf("unable to create route: %v", err)
}
require.NoError(t, err, "unable to create route")
// The first shard we send we'll fail immediately, to check that we are
// still allowed to retry with other shards after a failed one.
@@ -3149,9 +3077,7 @@ func TestSendToRouteMaxHops(t *testing.T) {
}
testGraph, err := createTestGraphFromChannels(true, testChannels, "a")
if err != nil {
t.Fatalf("unable to create graph: %v", err)
}
require.NoError(t, err, "unable to create graph")
defer testGraph.cleanUp()
const startingBlockHeight = 101
@@ -3184,9 +3110,7 @@ func TestSendToRouteMaxHops(t *testing.T) {
}
rt, err := route.NewRouteFromHops(payAmt, 100, ctx.aliases["a"], hops)
if err != nil {
t.Fatalf("unable to create route: %v", err)
}
require.NoError(t, err, "unable to create route")
// Send off the payment request to the router. We expect an error back
// indicating that the route is too long.
@@ -3260,9 +3184,7 @@ func TestBuildRoute(t *testing.T) {
}
testGraph, err := createTestGraphFromChannels(true, testChannels, "a")
if err != nil {
t.Fatalf("unable to create graph: %v", err)
}
require.NoError(t, err, "unable to create graph")
defer testGraph.cleanUp()
const startingBlockHeight = 101
@@ -4358,7 +4280,5 @@ func TestBlockDifferenceFix(t *testing.T) {
return nil
}, testTimeout)
if err != nil {
t.Fatalf("block height wasn't updated: %v", err)
}
require.NoError(t, err, "block height wasn't updated")
}