Skip to content

Commit 855c762

Browse files
GeorgeTsagkguggero
authored andcommitted
itest: custom channels flakes fixes
1 parent 9d3f02e commit 855c762

File tree

2 files changed

+125
-61
lines changed

2 files changed

+125
-61
lines changed

itest/litd_custom_channels_test.go

Lines changed: 77 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,16 @@ func testCustomChannels(_ context.Context, net *NetworkHarness,
380380
assertAssetChan(t.t, dave, yara, daveFundingAmount, assetID)
381381
assertAssetChan(t.t, erin, fabia, erinFundingAmount, assetID)
382382

383+
// Before we start sending out payments, let's make sure each node can
384+
// see the other one in the graph and has all required features.
385+
require.NoError(t.t, t.lndHarness.AssertNodeKnown(charlie, dave))
386+
require.NoError(t.t, t.lndHarness.AssertNodeKnown(dave, charlie))
387+
require.NoError(t.t, t.lndHarness.AssertNodeKnown(dave, yara))
388+
require.NoError(t.t, t.lndHarness.AssertNodeKnown(yara, dave))
389+
require.NoError(t.t, t.lndHarness.AssertNodeKnown(erin, fabia))
390+
require.NoError(t.t, t.lndHarness.AssertNodeKnown(fabia, erin))
391+
require.NoError(t.t, t.lndHarness.AssertNodeKnown(charlie, erin))
392+
383393
// Print initial channel balances.
384394
logBalance(t.t, nodes, assetID, "initial")
385395

@@ -723,18 +733,16 @@ func testCustomChannelsGroupedAsset(_ context.Context, net *NetworkHarness,
723733
fabiaTap := newTapClient(t.t, fabia)
724734
yaraTap := newTapClient(t.t, yara)
725735

726-
groupAsset := itestAsset
727-
groupAsset.NewGroupedAsset = true
736+
groupAssetReq := itest.CopyRequest(&mintrpc.MintAssetRequest{
737+
Asset: itestAsset,
738+
})
739+
groupAssetReq.Asset.NewGroupedAsset = true
728740

729741
// Mint an asset on Charlie and sync all nodes to Charlie as the
730742
// universe.
731743
mintedAssets := itest.MintAssetsConfirmBatch(
732744
t.t, t.lndHarness.Miner.Client, charlieTap,
733-
[]*mintrpc.MintAssetRequest{
734-
{
735-
Asset: groupAsset,
736-
},
737-
},
745+
[]*mintrpc.MintAssetRequest{groupAssetReq},
738746
)
739747

740748
cents := mintedAssets[0]
@@ -924,6 +932,16 @@ func testCustomChannelsGroupedAsset(_ context.Context, net *NetworkHarness,
924932
assertAssetChan(t.t, dave, yara, daveFundingAmount, assetID)
925933
assertAssetChan(t.t, erin, fabia, erinFundingAmount, assetID)
926934

935+
// Before we start sending out payments, let's make sure each node can
936+
// see the other one in the graph and has all required features.
937+
require.NoError(t.t, t.lndHarness.AssertNodeKnown(charlie, dave))
938+
require.NoError(t.t, t.lndHarness.AssertNodeKnown(dave, charlie))
939+
require.NoError(t.t, t.lndHarness.AssertNodeKnown(dave, yara))
940+
require.NoError(t.t, t.lndHarness.AssertNodeKnown(yara, dave))
941+
require.NoError(t.t, t.lndHarness.AssertNodeKnown(erin, fabia))
942+
require.NoError(t.t, t.lndHarness.AssertNodeKnown(fabia, erin))
943+
require.NoError(t.t, t.lndHarness.AssertNodeKnown(charlie, erin))
944+
927945
// Print initial channel balances.
928946
logBalance(t.t, nodes, assetID, "initial")
929947

@@ -1276,9 +1294,7 @@ func testCustomChannelsForceClose(_ context.Context, net *NetworkHarness,
12761294

12771295
// Charlie's balance should reflect that the funding asset was added to
12781296
// the DB.
1279-
assertAssetBalance(
1280-
t.t, charlieTap, assetID, uint64(itestAsset.Amount),
1281-
)
1297+
assertAssetBalance(t.t, charlieTap, assetID, itestAsset.Amount)
12821298

12831299
// Make sure that Charlie properly uploaded funding proof to the
12841300
// Universe server.
@@ -1291,6 +1307,14 @@ func testCustomChannelsForceClose(_ context.Context, net *NetworkHarness,
12911307
),
12921308
)
12931309

1310+
// Make sure the channel shows the correct asset information.
1311+
assertAssetChan(t.t, charlie, dave, fundingAmount, assetID)
1312+
1313+
// Before we start sending out payments, let's make sure each node can
1314+
// see the other one in the graph and has all required features.
1315+
require.NoError(t.t, t.lndHarness.AssertNodeKnown(charlie, dave))
1316+
require.NoError(t.t, t.lndHarness.AssertNodeKnown(dave, charlie))
1317+
12941318
// We'll also have dave sync with Charlie+Zane to ensure he has the
12951319
// proof for the funding output. We sync the transfers as well so he
12961320
// has all the proofs needed.
@@ -1441,22 +1465,6 @@ func testCustomChannelsForceClose(_ context.Context, net *NetworkHarness,
14411465
t.t, charlieSweepTransfer,
14421466
))
14431467

1444-
charlieUTXOs, err := charlieTap.ListUtxos(
1445-
ctxb, &taprpc.ListUtxosRequest{},
1446-
)
1447-
require.NoError(t.t, err)
1448-
1449-
t.Logf("Charlie UTXOs: %v", toProtoJSON(t.t, charlieUTXOs))
1450-
1451-
daveUTXOs, err := daveTap.ListUtxos(
1452-
ctxb, &taprpc.ListUtxosRequest{},
1453-
)
1454-
require.NoError(t.t, err)
1455-
1456-
t.Logf("Dave UTXOs: %v", toProtoJSON(t.t, daveUTXOs))
1457-
1458-
// TODO(roasbeef): assert 2 charlie UTXOs
1459-
14601468
// Both sides should now reflect their updated asset balances.
14611469
daveBalance := uint64(numPayments * keySendAmount)
14621470
charlieBalance := itestAsset.Amount - daveBalance
@@ -1465,26 +1473,12 @@ func testCustomChannelsForceClose(_ context.Context, net *NetworkHarness,
14651473

14661474
// Dave should have a single managed UTXO that shows he has a new asset
14671475
// UTXO he can use.
1468-
err = wait.NoError(func() error {
1469-
daveUTXOs, err = daveTap.ListUtxos(
1470-
ctxb, &taprpc.ListUtxosRequest{},
1471-
)
1472-
if err != nil {
1473-
return err
1474-
}
1475-
1476-
if len(daveUTXOs.ManagedUtxos) != 1 {
1477-
return fmt.Errorf("expected 1 UTXO, got %d",
1478-
len(daveUTXOs.ManagedUtxos))
1479-
}
1480-
1481-
return nil
1482-
}, defaultTimeout)
1483-
require.NoError(t.t, err)
1484-
1485-
t.Logf("Dave UTXOs: %v", toProtoJSON(t.t, daveUTXOs))
1476+
assertNumAssetUTXOs(t.t, daveTap, 1)
1477+
assertNumAssetUTXOs(t.t, charlieTap, 2)
14861478
}
14871479

1480+
// testCustomChannelsBreach tests a force close scenario that breaches an old
1481+
// state, after both parties have an active asset balance.
14881482
func testCustomChannelsBreach(_ context.Context, net *NetworkHarness,
14891483
t *harnessTest) {
14901484

@@ -1528,6 +1522,7 @@ func testCustomChannelsBreach(_ context.Context, net *NetworkHarness,
15281522
connectAllNodes(t.t, net, nodes)
15291523
fundAllNodes(t.t, net, nodes)
15301524

1525+
universeTap := newTapClient(t.t, zane)
15311526
charlieTap := newTapClient(t.t, charlie)
15321527
daveTap := newTapClient(t.t, dave)
15331528

@@ -1569,7 +1564,39 @@ func testCustomChannelsBreach(_ context.Context, net *NetworkHarness,
15691564
// With the channel open, mine a block to confirm it.
15701565
mineBlocks(t, net, 6, 1)
15711566

1572-
time.Sleep(time.Second * 1)
1567+
// A transfer for the funding transaction should be found in Charlie's
1568+
// DB.
1569+
fundingTxid, err := chainhash.NewHashFromStr(assetFundResp.Txid)
1570+
require.NoError(t.t, err)
1571+
assetFundingTransfer := locateAssetTransfers(
1572+
t.t, charlieTap, *fundingTxid,
1573+
)
1574+
1575+
t.Logf("Channel funding transfer: %v",
1576+
toProtoJSON(t.t, assetFundingTransfer))
1577+
1578+
// Charlie's balance should reflect that the funding asset was added to
1579+
// the DB.
1580+
assertAssetBalance(t.t, charlieTap, assetID, itestAsset.Amount)
1581+
1582+
// Make sure that Charlie properly uploaded funding proof to the
1583+
// Universe server.
1584+
fundingScriptTree := tapchannel.NewFundingScriptTree()
1585+
fundingScriptKey := fundingScriptTree.TaprootKey
1586+
fundingScriptTreeBytes := fundingScriptKey.SerializeCompressed()
1587+
assertUniverseProofExists(
1588+
t.t, universeTap, assetID, fundingScriptTreeBytes, fmt.Sprintf(
1589+
"%v:%v", assetFundResp.Txid, assetFundResp.OutputIndex,
1590+
),
1591+
)
1592+
1593+
// Make sure the channel shows the correct asset information.
1594+
assertAssetChan(t.t, charlie, dave, fundingAmount, assetID)
1595+
1596+
// Before we start sending out payments, let's make sure each node can
1597+
// see the other one in the graph and has all required features.
1598+
require.NoError(t.t, t.lndHarness.AssertNodeKnown(charlie, dave))
1599+
require.NoError(t.t, t.lndHarness.AssertNodeKnown(dave, charlie))
15731600

15741601
// Next, we'll make keysend payments from Charlie to Dave. we'll use
15751602
// this to reach a state where both parties have funds in the channel.
@@ -1672,8 +1699,10 @@ func assertNumAssetUTXOs(t *testing.T, tapdClient *tapClient,
16721699

16731700
ctxb := context.Background()
16741701

1702+
var clientUTXOs *taprpc.ListUtxosResponse
16751703
err := wait.NoError(func() error {
1676-
clientUTXOs, err := tapdClient.ListUtxos(
1704+
var err error
1705+
clientUTXOs, err = tapdClient.ListUtxos(
16771706
ctxb, &taprpc.ListUtxosRequest{},
16781707
)
16791708
if err != nil {
@@ -1687,21 +1716,8 @@ func assertNumAssetUTXOs(t *testing.T, tapdClient *tapClient,
16871716

16881717
return nil
16891718
}, defaultTimeout)
1690-
1691-
clientUTXOs, err2 := tapdClient.ListUtxos(
1692-
ctxb, &taprpc.ListUtxosRequest{},
1693-
)
1694-
require.NoError(t, err2)
1695-
1696-
if err != nil {
1697-
t.Logf("wrong amount of UTXOs, got %d, expected %d: %v",
1698-
len(clientUTXOs.ManagedUtxos), numUTXOs,
1699-
toProtoJSON(t, clientUTXOs))
1700-
1701-
t.Fatalf("failed to assert UTXOs: %v", err)
1702-
1703-
return nil
1704-
}
1719+
require.NoErrorf(t, err, "failed to assert UTXOs: %v, last state: %v",
1720+
err, clientUTXOs)
17051721

17061722
return clientUTXOs
17071723
}

itest/network_harness.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,54 @@ func (n *NetworkHarness) AssertChannelExists(node *HarnessNode,
11801180
}, lntest.DefaultTimeout)
11811181
}
11821182

1183+
// AssertNodeKnown makes sure the given node knows about the target node in the
1184+
// network graph.
1185+
func (n *NetworkHarness) AssertNodeKnown(node, target *HarnessNode) error {
1186+
ctxb := context.Background()
1187+
ctxt, cancel := context.WithTimeout(ctxb, wait.DefaultTimeout)
1188+
defer cancel()
1189+
1190+
req := &lnrpc.NodeInfoRequest{
1191+
PubKey: hex.EncodeToString(
1192+
target.PubKey[:],
1193+
),
1194+
}
1195+
return wait.NoError(func() error {
1196+
info, err := node.GetNodeInfo(ctxt, req)
1197+
if err != nil {
1198+
return err
1199+
}
1200+
1201+
if info.Node == nil {
1202+
return fmt.Errorf("node %x has no info about %x",
1203+
node.PubKey[:], target.PubKey[:])
1204+
}
1205+
1206+
// TODO(guggero): Uncomment this once the lnd bug of the node
1207+
// announcement timing is fixed:
1208+
// https://github.com/lightningnetwork/lnd/issues/8870
1209+
//
1210+
// if len(info.Node.Features) == 0 {
1211+
// return fmt.Errorf("node %x has no features for %x",
1212+
// node.PubKey[:], target.PubKey[:])
1213+
// }
1214+
//
1215+
// _, optional := info.Node.Features[uint32(
1216+
// lnwire.TLVOnionPayloadOptional,
1217+
// )]
1218+
// _, required := info.Node.Features[uint32(
1219+
// lnwire.TLVOnionPayloadRequired,
1220+
// )]
1221+
// if !optional && !required {
1222+
// return fmt.Errorf("node %x has no onion payload "+
1223+
// "features for %x", node.PubKey[:],
1224+
// target.PubKey[:])
1225+
// }
1226+
1227+
return nil
1228+
}, lntest.DefaultTimeout)
1229+
}
1230+
11831231
// DumpLogs reads the current logs generated by the passed node, and returns
11841232
// the logs as a single string. This function is useful for examining the logs
11851233
// of a particular node in the case of a test failure.

0 commit comments

Comments
 (0)