Merge pull request #4934 from cfromknecht/pinned-active-syncers
discovery: pinned syncers
This commit is contained in:
15 files changed
+1157
-840
No files matched your search
+119
-33
@@ -10330,21 +10330,119 @@ func subscribeGraphNotifications(t *harnessTest, ctxb context.Context,
|
||||
}
|
||||
}
|
||||
|
||||
func assertSyncType(t *harnessTest, node *lntest.HarnessNode,
|
||||
peer string, syncType lnrpc.Peer_SyncType) {
|
||||
|
||||
t.t.Helper()
|
||||
|
||||
ctxb := context.Background()
|
||||
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
||||
resp, err := node.ListPeers(ctxt, &lnrpc.ListPeersRequest{})
|
||||
require.NoError(t.t, err)
|
||||
|
||||
for _, rpcPeer := range resp.Peers {
|
||||
if rpcPeer.PubKey != peer {
|
||||
continue
|
||||
}
|
||||
|
||||
require.Equal(t.t, syncType, rpcPeer.SyncType)
|
||||
return
|
||||
}
|
||||
|
||||
t.t.Fatalf("unable to find peer: %s", peer)
|
||||
}
|
||||
|
||||
func waitForGraphSync(t *harnessTest, node *lntest.HarnessNode) {
|
||||
t.t.Helper()
|
||||
|
||||
err := wait.Predicate(func() bool {
|
||||
ctxb := context.Background()
|
||||
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
||||
resp, err := node.GetInfo(ctxt, &lnrpc.GetInfoRequest{})
|
||||
require.NoError(t.t, err)
|
||||
|
||||
return resp.SyncedToGraph
|
||||
}, defaultTimeout)
|
||||
require.NoError(t.t, err)
|
||||
}
|
||||
|
||||
func testGraphTopologyNotifications(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
t.t.Run("pinned", func(t *testing.T) {
|
||||
ht := newHarnessTest(t, net)
|
||||
testGraphTopologyNtfns(net, ht, true)
|
||||
})
|
||||
t.t.Run("unpinned", func(t *testing.T) {
|
||||
ht := newHarnessTest(t, net)
|
||||
testGraphTopologyNtfns(net, ht, false)
|
||||
})
|
||||
}
|
||||
|
||||
func testGraphTopologyNtfns(net *lntest.NetworkHarness, t *harnessTest, pinned bool) {
|
||||
ctxb := context.Background()
|
||||
|
||||
const chanAmt = funding.MaxBtcFundingAmount
|
||||
|
||||
// Spin up Bob first, since we will need to grab his pubkey when
|
||||
// starting Alice to test pinned syncing.
|
||||
bob, err := net.NewNode("bob", nil)
|
||||
require.NoError(t.t, err)
|
||||
defer shutdownAndAssert(net, t, bob)
|
||||
|
||||
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
||||
bobInfo, err := bob.GetInfo(ctxt, &lnrpc.GetInfoRequest{})
|
||||
require.NoError(t.t, err)
|
||||
bobPubkey := bobInfo.IdentityPubkey
|
||||
|
||||
// For unpinned syncing, start Alice as usual. Otherwise grab Bob's
|
||||
// pubkey to include in his pinned syncer set.
|
||||
var aliceArgs []string
|
||||
if pinned {
|
||||
aliceArgs = []string{
|
||||
"--numgraphsyncpeers=1",
|
||||
fmt.Sprintf("--gossip.pinned-syncers=%s", bobPubkey),
|
||||
}
|
||||
}
|
||||
|
||||
alice, err := net.NewNode("alice", aliceArgs)
|
||||
require.NoError(t.t, err)
|
||||
defer shutdownAndAssert(net, t, alice)
|
||||
|
||||
// Connect Alice and Bob.
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = net.EnsureConnected(ctxt, alice, bob)
|
||||
require.NoError(t.t, err)
|
||||
|
||||
// Alice stimmy.
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = net.SendCoins(ctxt, btcutil.SatoshiPerBitcoin, alice)
|
||||
require.NoError(t.t, err)
|
||||
|
||||
// Bob stimmy.
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = net.SendCoins(ctxt, btcutil.SatoshiPerBitcoin, bob)
|
||||
require.NoError(t.t, err)
|
||||
|
||||
// Assert that Bob has the correct sync type before proceeeding.
|
||||
if pinned {
|
||||
assertSyncType(t, alice, bobPubkey, lnrpc.Peer_PINNED_SYNC)
|
||||
} else {
|
||||
assertSyncType(t, alice, bobPubkey, lnrpc.Peer_ACTIVE_SYNC)
|
||||
}
|
||||
|
||||
// Regardless of syncer type, ensure that both peers report having
|
||||
// completed their initial sync before continuing to make a channel.
|
||||
waitForGraphSync(t, alice)
|
||||
|
||||
// Let Alice subscribe to graph notifications.
|
||||
graphSub := subscribeGraphNotifications(
|
||||
t, ctxb, net.Alice,
|
||||
t, ctxb, alice,
|
||||
)
|
||||
defer close(graphSub.quit)
|
||||
|
||||
// Open a new channel between Alice and Bob.
|
||||
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
|
||||
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
|
||||
chanPoint := openChannelAndAssert(
|
||||
ctxt, t, net, net.Alice, net.Bob,
|
||||
ctxt, t, net, alice, bob,
|
||||
lntest.OpenChannelParams{
|
||||
Amt: chanAmt,
|
||||
},
|
||||
@@ -10364,15 +10462,15 @@ func testGraphTopologyNotifications(net *lntest.NetworkHarness, t *harnessTest)
|
||||
// message.
|
||||
for _, chanUpdate := range graphUpdate.ChannelUpdates {
|
||||
switch chanUpdate.AdvertisingNode {
|
||||
case net.Alice.PubKeyStr:
|
||||
case net.Bob.PubKeyStr:
|
||||
case alice.PubKeyStr:
|
||||
case bob.PubKeyStr:
|
||||
default:
|
||||
t.Fatalf("unknown advertising node: %v",
|
||||
chanUpdate.AdvertisingNode)
|
||||
}
|
||||
switch chanUpdate.ConnectingNode {
|
||||
case net.Alice.PubKeyStr:
|
||||
case net.Bob.PubKeyStr:
|
||||
case alice.PubKeyStr:
|
||||
case bob.PubKeyStr:
|
||||
default:
|
||||
t.Fatalf("unknown connecting node: %v",
|
||||
chanUpdate.ConnectingNode)
|
||||
@@ -10388,8 +10486,8 @@ func testGraphTopologyNotifications(net *lntest.NetworkHarness, t *harnessTest)
|
||||
|
||||
for _, nodeUpdate := range graphUpdate.NodeUpdates {
|
||||
switch nodeUpdate.IdentityKey {
|
||||
case net.Alice.PubKeyStr:
|
||||
case net.Bob.PubKeyStr:
|
||||
case alice.PubKeyStr:
|
||||
case bob.PubKeyStr:
|
||||
default:
|
||||
t.Fatalf("unknown node: %v",
|
||||
nodeUpdate.IdentityKey)
|
||||
@@ -10413,7 +10511,7 @@ func testGraphTopologyNotifications(net *lntest.NetworkHarness, t *harnessTest)
|
||||
// Now we'll test that updates are properly sent after channels are closed
|
||||
// within the network.
|
||||
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout)
|
||||
closeChannelAndAssert(ctxt, t, net, net.Alice, chanPoint, false)
|
||||
closeChannelAndAssert(ctxt, t, net, alice, chanPoint, false)
|
||||
|
||||
// Now that the channel has been closed, we should receive a
|
||||
// notification indicating so.
|
||||
@@ -10468,7 +10566,7 @@ out:
|
||||
// we disconnect Alice and Bob, open a channel between Bob and Carol,
|
||||
// and finally connect Alice to Bob again.
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
if err := net.DisconnectNodes(ctxt, net.Alice, net.Bob); err != nil {
|
||||
if err := net.DisconnectNodes(ctxt, alice, bob); err != nil {
|
||||
t.Fatalf("unable to disconnect alice and bob: %v", err)
|
||||
}
|
||||
carol, err := net.NewNode("Carol", nil)
|
||||
@@ -10478,12 +10576,12 @@ out:
|
||||
defer shutdownAndAssert(net, t, carol)
|
||||
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
if err := net.ConnectNodes(ctxt, net.Bob, carol); err != nil {
|
||||
if err := net.ConnectNodes(ctxt, bob, carol); err != nil {
|
||||
t.Fatalf("unable to connect bob to carol: %v", err)
|
||||
}
|
||||
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
|
||||
chanPoint = openChannelAndAssert(
|
||||
ctxt, t, net, net.Bob, carol,
|
||||
ctxt, t, net, bob, carol,
|
||||
lntest.OpenChannelParams{
|
||||
Amt: chanAmt,
|
||||
},
|
||||
@@ -10496,7 +10594,7 @@ out:
|
||||
// Bob, since a node will update its node announcement after a new
|
||||
// channel is opened.
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
if err := net.EnsureConnected(ctxt, net.Alice, net.Bob); err != nil {
|
||||
if err := net.EnsureConnected(ctxt, alice, bob); err != nil {
|
||||
t.Fatalf("unable to connect alice to bob: %v", err)
|
||||
}
|
||||
|
||||
@@ -10510,7 +10608,7 @@ out:
|
||||
for _, nodeUpdate := range graphUpdate.NodeUpdates {
|
||||
switch nodeUpdate.IdentityKey {
|
||||
case carol.PubKeyStr:
|
||||
case net.Bob.PubKeyStr:
|
||||
case bob.PubKeyStr:
|
||||
default:
|
||||
t.Fatalf("unknown node update pubey: %v",
|
||||
nodeUpdate.IdentityKey)
|
||||
@@ -10521,14 +10619,14 @@ out:
|
||||
for _, chanUpdate := range graphUpdate.ChannelUpdates {
|
||||
switch chanUpdate.AdvertisingNode {
|
||||
case carol.PubKeyStr:
|
||||
case net.Bob.PubKeyStr:
|
||||
case bob.PubKeyStr:
|
||||
default:
|
||||
t.Fatalf("unknown advertising node: %v",
|
||||
chanUpdate.AdvertisingNode)
|
||||
}
|
||||
switch chanUpdate.ConnectingNode {
|
||||
case carol.PubKeyStr:
|
||||
case net.Bob.PubKeyStr:
|
||||
case bob.PubKeyStr:
|
||||
default:
|
||||
t.Fatalf("unknown connecting node: %v",
|
||||
chanUpdate.ConnectingNode)
|
||||
@@ -10552,7 +10650,7 @@ out:
|
||||
|
||||
// Close the channel between Bob and Carol.
|
||||
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout)
|
||||
closeChannelAndAssert(ctxt, t, net, net.Bob, chanPoint, false)
|
||||
closeChannelAndAssert(ctxt, t, net, bob, chanPoint, false)
|
||||
}
|
||||
|
||||
// testNodeAnnouncement ensures that when a node is started with one or more
|
||||
@@ -11774,11 +11872,7 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
|
||||
// Wait until all outstanding htlcs in the network have been settled.
|
||||
err = wait.Predicate(func() bool {
|
||||
predErr = assertNumActiveHtlcs(nodes, 0)
|
||||
if predErr != nil {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
return assertNumActiveHtlcs(nodes, 0) == nil
|
||||
}, defaultTimeout)
|
||||
if err != nil {
|
||||
t.Fatalf("htlc mismatch: %v", predErr)
|
||||
@@ -12102,11 +12196,7 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness
|
||||
// After reconnection succeeds, the settles should be propagated all
|
||||
// the way back to the sender. All nodes should report no active htlcs.
|
||||
err = wait.Predicate(func() bool {
|
||||
predErr = assertNumActiveHtlcs(nodes, 0)
|
||||
if predErr != nil {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
return assertNumActiveHtlcs(nodes, 0) == nil
|
||||
}, defaultTimeout)
|
||||
if err != nil {
|
||||
t.Fatalf("htlc mismatch: %v", predErr)
|
||||
@@ -12369,11 +12459,7 @@ func testSwitchOfflineDeliveryOutgoingOffline(
|
||||
// Wait for all payments to reach Carol.
|
||||
var predErr error
|
||||
err = wait.Predicate(func() bool {
|
||||
predErr = assertNumActiveHtlcs(nodes, numPayments)
|
||||
if predErr != nil {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
return assertNumActiveHtlcs(nodes, numPayments) == nil
|
||||
}, defaultTimeout)
|
||||
if err != nil {
|
||||
t.Fatalf("htlc mismatch: %v", predErr)
|
||||
|
||||
Reference in new issue
Block a user