mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-05-20 16:50:54 +02:00
itest: remove the method waitForChannelUpdate
This commit removes the method waitForChannelUpdate, and uses node.WaitForChannelPolicyUpdate instead.
This commit is contained in:
parent
06fa17513c
commit
cdec34c5f7
@ -146,15 +146,6 @@ func closeChannelAndAssertType(t *harnessTest,
|
|||||||
)[0]
|
)[0]
|
||||||
expectDisable := !curPolicy.Disabled
|
expectDisable := !curPolicy.Disabled
|
||||||
|
|
||||||
// If the current channel policy is enabled, begin subscribing the graph
|
|
||||||
// updates before initiating the channel closure.
|
|
||||||
var graphSub *graphSubscription
|
|
||||||
if expectDisable {
|
|
||||||
sub := subscribeGraphNotifications(ctxt, t, node)
|
|
||||||
graphSub = &sub
|
|
||||||
defer close(graphSub.quit)
|
|
||||||
}
|
|
||||||
|
|
||||||
closeUpdates, _, err := net.CloseChannel(node, fundingChanPoint, force)
|
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")
|
||||||
|
|
||||||
@ -162,11 +153,9 @@ func closeChannelAndAssertType(t *harnessTest,
|
|||||||
// received the disabled update.
|
// received the disabled update.
|
||||||
if expectDisable {
|
if expectDisable {
|
||||||
curPolicy.Disabled = true
|
curPolicy.Disabled = true
|
||||||
waitForChannelUpdate(
|
assertChannelPolicyUpdate(
|
||||||
t, *graphSub,
|
t.t, node, node.PubKeyStr,
|
||||||
[]expectedChanUpdate{
|
curPolicy, fundingChanPoint, false,
|
||||||
{node.PubKeyStr, curPolicy, fundingChanPoint},
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -565,13 +554,6 @@ func getChannelBalance(t *harnessTest,
|
|||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
|
||||||
// expectedChanUpdate houses params we expect a ChannelUpdate to advertise.
|
|
||||||
type expectedChanUpdate struct {
|
|
||||||
advertisingNode string
|
|
||||||
expectedPolicy *lnrpc.RoutingPolicy
|
|
||||||
chanPoint *lnrpc.ChannelPoint
|
|
||||||
}
|
|
||||||
|
|
||||||
// txStr returns the string representation of the channel's funding transaction.
|
// txStr returns the string representation of the channel's funding transaction.
|
||||||
func txStr(chanPoint *lnrpc.ChannelPoint) string {
|
func txStr(chanPoint *lnrpc.ChannelPoint) string {
|
||||||
fundingTxID, err := lnrpc.GetChanPointFundingTxid(chanPoint)
|
fundingTxID, err := lnrpc.GetChanPointFundingTxid(chanPoint)
|
||||||
@ -585,109 +567,6 @@ func txStr(chanPoint *lnrpc.ChannelPoint) string {
|
|||||||
return cp.String()
|
return cp.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// waitForChannelUpdate waits for a node to receive the expected channel
|
|
||||||
// updates.
|
|
||||||
func waitForChannelUpdate(t *harnessTest, subscription graphSubscription,
|
|
||||||
expUpdates []expectedChanUpdate) {
|
|
||||||
|
|
||||||
// Create an array indicating which expected channel updates we have
|
|
||||||
// received.
|
|
||||||
found := make([]bool, len(expUpdates))
|
|
||||||
out:
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case graphUpdate := <-subscription.updateChan:
|
|
||||||
for _, update := range graphUpdate.ChannelUpdates {
|
|
||||||
require.NotZerof(
|
|
||||||
t.t, len(expUpdates),
|
|
||||||
"received unexpected channel "+
|
|
||||||
"update from %v for channel %v",
|
|
||||||
update.AdvertisingNode,
|
|
||||||
update.ChanId,
|
|
||||||
)
|
|
||||||
|
|
||||||
// For each expected update, check if it matches
|
|
||||||
// the update we just received.
|
|
||||||
for i, exp := range expUpdates {
|
|
||||||
fundingTxStr := txStr(update.ChanPoint)
|
|
||||||
if fundingTxStr != txStr(exp.chanPoint) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if update.AdvertisingNode !=
|
|
||||||
exp.advertisingNode {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
err := lntest.CheckChannelPolicy(
|
|
||||||
update.RoutingPolicy,
|
|
||||||
exp.expectedPolicy,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// We got a policy update that matched
|
|
||||||
// the values and channel point of what
|
|
||||||
// we expected, mark it as found.
|
|
||||||
found[i] = true
|
|
||||||
|
|
||||||
// If we have no more channel updates
|
|
||||||
// we are waiting for, break out of the
|
|
||||||
// loop.
|
|
||||||
rem := 0
|
|
||||||
for _, f := range found {
|
|
||||||
if !f {
|
|
||||||
rem++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if rem == 0 {
|
|
||||||
break out
|
|
||||||
}
|
|
||||||
|
|
||||||
// Since we found a match among the
|
|
||||||
// expected updates, break out of the
|
|
||||||
// inner loop.
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case err := <-subscription.errChan:
|
|
||||||
t.Fatalf("unable to recv graph update: %v", err)
|
|
||||||
case <-time.After(defaultTimeout):
|
|
||||||
if len(expUpdates) == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
t.Fatalf("did not receive channel update")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// assertNoChannelUpdates ensures that no ChannelUpdates are sent via the
|
|
||||||
// graphSubscription. This method will block for the provided duration before
|
|
||||||
// returning to the caller if successful.
|
|
||||||
func assertNoChannelUpdates(t *harnessTest, subscription graphSubscription,
|
|
||||||
duration time.Duration) {
|
|
||||||
|
|
||||||
timeout := time.After(duration)
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case graphUpdate := <-subscription.updateChan:
|
|
||||||
require.Zero(
|
|
||||||
t.t, len(graphUpdate.ChannelUpdates),
|
|
||||||
"no channel updates were expected",
|
|
||||||
)
|
|
||||||
|
|
||||||
case err := <-subscription.errChan:
|
|
||||||
t.Fatalf("graph subscription failure: %v", err)
|
|
||||||
|
|
||||||
case <-timeout:
|
|
||||||
// No updates received, success.
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// getChannelPolicies queries the channel graph and retrieves the current edge
|
// getChannelPolicies queries the channel graph and retrieves the current edge
|
||||||
// policies for the provided channel points.
|
// policies for the provided channel points.
|
||||||
func getChannelPolicies(t *harnessTest, node *lntest.HarnessNode,
|
func getChannelPolicies(t *harnessTest, node *lntest.HarnessNode,
|
||||||
@ -745,7 +624,7 @@ func assertChannelPolicy(t *harnessTest, node *lntest.HarnessNode,
|
|||||||
for _, policy := range policies {
|
for _, policy := range policies {
|
||||||
err := lntest.CheckChannelPolicy(policy, expectedPolicy)
|
err := lntest.CheckChannelPolicy(policy, expectedPolicy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf(err.Error())
|
t.Fatalf(fmt.Sprintf("%v: %s", err.Error(), node))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1761,3 +1640,21 @@ func assertNumUTXOs(t *testing.T, node *lntest.HarnessNode, expectedUtxos int) {
|
|||||||
}, defaultTimeout)
|
}, defaultTimeout)
|
||||||
require.NoError(t, err, "wait for listunspent")
|
require.NoError(t, err, "wait for listunspent")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// assertChannelPolicyUpdate checks that the required policy update has
|
||||||
|
// happened on the given node.
|
||||||
|
func assertChannelPolicyUpdate(t *testing.T, node *lntest.HarnessNode,
|
||||||
|
advertisingNode string, policy *lnrpc.RoutingPolicy,
|
||||||
|
chanPoint *lnrpc.ChannelPoint, includeUnannounced bool) {
|
||||||
|
|
||||||
|
ctxb := context.Background()
|
||||||
|
ctxt, cancel := context.WithTimeout(ctxb, lntest.DefaultTimeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
require.NoError(
|
||||||
|
t, node.WaitForChannelPolicyUpdate(
|
||||||
|
ctxt, advertisingNode, policy,
|
||||||
|
chanPoint, includeUnannounced,
|
||||||
|
), "error while waiting for channel update",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
@ -86,8 +86,20 @@ func testUpdateChanStatus(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
net.ConnectNodes(t.t, alice, carol)
|
net.ConnectNodes(t.t, alice, carol)
|
||||||
net.ConnectNodes(t.t, bob, carol)
|
net.ConnectNodes(t.t, bob, carol)
|
||||||
|
|
||||||
carolSub := subscribeGraphNotifications(ctxb, t, carol)
|
// assertChannelUpdate checks that the required policy update has
|
||||||
defer close(carolSub.quit)
|
// happened on the given node.
|
||||||
|
assertChannelUpdate := func(node *lntest.HarnessNode,
|
||||||
|
policy *lnrpc.RoutingPolicy) {
|
||||||
|
|
||||||
|
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
require.NoError(
|
||||||
|
t.t, carol.WaitForChannelPolicyUpdate(
|
||||||
|
ctxt, node.PubKeyStr, policy, chanPoint, false,
|
||||||
|
), "error while waiting for channel update",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// sendReq sends an UpdateChanStatus request to the given node.
|
// sendReq sends an UpdateChanStatus request to the given node.
|
||||||
sendReq := func(node *lntest.HarnessNode, chanPoint *lnrpc.ChannelPoint,
|
sendReq := func(node *lntest.HarnessNode, chanPoint *lnrpc.ChannelPoint,
|
||||||
@ -169,23 +181,13 @@ func testUpdateChanStatus(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// update is propagated.
|
// update is propagated.
|
||||||
sendReq(alice, chanPoint, routerrpc.ChanStatusAction_DISABLE)
|
sendReq(alice, chanPoint, routerrpc.ChanStatusAction_DISABLE)
|
||||||
expectedPolicy.Disabled = true
|
expectedPolicy.Disabled = true
|
||||||
waitForChannelUpdate(
|
assertChannelUpdate(alice, expectedPolicy)
|
||||||
t, carolSub,
|
|
||||||
[]expectedChanUpdate{
|
|
||||||
{alice.PubKeyStr, expectedPolicy, chanPoint},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
// Re-enable the channel and ensure that a "Disabled = false" update
|
// Re-enable the channel and ensure that a "Disabled = false" update
|
||||||
// is propagated.
|
// is propagated.
|
||||||
sendReq(alice, chanPoint, routerrpc.ChanStatusAction_ENABLE)
|
sendReq(alice, chanPoint, routerrpc.ChanStatusAction_ENABLE)
|
||||||
expectedPolicy.Disabled = false
|
expectedPolicy.Disabled = false
|
||||||
waitForChannelUpdate(
|
assertChannelUpdate(alice, expectedPolicy)
|
||||||
t, carolSub,
|
|
||||||
[]expectedChanUpdate{
|
|
||||||
{alice.PubKeyStr, expectedPolicy, chanPoint},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
// Manually enabling a channel should NOT prevent subsequent
|
// Manually enabling a channel should NOT prevent subsequent
|
||||||
// disconnections from automatically disabling the channel again
|
// disconnections from automatically disabling the channel again
|
||||||
@ -195,24 +197,14 @@ func testUpdateChanStatus(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
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
|
||||||
waitForChannelUpdate(
|
assertChannelUpdate(alice, expectedPolicy)
|
||||||
t, carolSub,
|
assertChannelUpdate(bob, expectedPolicy)
|
||||||
[]expectedChanUpdate{
|
|
||||||
{alice.PubKeyStr, expectedPolicy, chanPoint},
|
|
||||||
{bob.PubKeyStr, expectedPolicy, chanPoint},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
// Reconnecting the nodes should propagate a "Disabled = false" update.
|
// Reconnecting the nodes should propagate a "Disabled = false" update.
|
||||||
net.EnsureConnected(t.t, alice, bob)
|
net.EnsureConnected(t.t, alice, bob)
|
||||||
expectedPolicy.Disabled = false
|
expectedPolicy.Disabled = false
|
||||||
waitForChannelUpdate(
|
assertChannelUpdate(alice, expectedPolicy)
|
||||||
t, carolSub,
|
assertChannelUpdate(bob, expectedPolicy)
|
||||||
[]expectedChanUpdate{
|
|
||||||
{alice.PubKeyStr, expectedPolicy, chanPoint},
|
|
||||||
{bob.PubKeyStr, expectedPolicy, chanPoint},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
// Manually disabling the channel should prevent a subsequent
|
// Manually disabling the channel should prevent a subsequent
|
||||||
// disconnect / reconnect from re-enabling the channel on
|
// disconnect / reconnect from re-enabling the channel on
|
||||||
@ -223,12 +215,7 @@ func testUpdateChanStatus(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// Alice sends out the "Disabled = true" update in response to
|
// Alice sends out the "Disabled = true" update in response to
|
||||||
// the ChanStatusAction_DISABLE request.
|
// the ChanStatusAction_DISABLE request.
|
||||||
expectedPolicy.Disabled = true
|
expectedPolicy.Disabled = true
|
||||||
waitForChannelUpdate(
|
assertChannelUpdate(alice, expectedPolicy)
|
||||||
t, carolSub,
|
|
||||||
[]expectedChanUpdate{
|
|
||||||
{alice.PubKeyStr, expectedPolicy, chanPoint},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
if err := net.DisconnectNodes(alice, bob); err != nil {
|
if err := net.DisconnectNodes(alice, bob); err != nil {
|
||||||
t.Fatalf("unable to disconnect Alice from Bob: %v", err)
|
t.Fatalf("unable to disconnect Alice from Bob: %v", err)
|
||||||
@ -237,23 +224,13 @@ func testUpdateChanStatus(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// Bob sends a "Disabled = true" update upon detecting the
|
// Bob sends a "Disabled = true" update upon detecting the
|
||||||
// disconnect.
|
// disconnect.
|
||||||
expectedPolicy.Disabled = true
|
expectedPolicy.Disabled = true
|
||||||
waitForChannelUpdate(
|
assertChannelUpdate(bob, expectedPolicy)
|
||||||
t, carolSub,
|
|
||||||
[]expectedChanUpdate{
|
|
||||||
{bob.PubKeyStr, expectedPolicy, chanPoint},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
// Bob sends a "Disabled = false" update upon detecting the
|
// Bob sends a "Disabled = false" update upon detecting the
|
||||||
// reconnect.
|
// reconnect.
|
||||||
net.EnsureConnected(t.t, alice, bob)
|
net.EnsureConnected(t.t, alice, bob)
|
||||||
expectedPolicy.Disabled = false
|
expectedPolicy.Disabled = false
|
||||||
waitForChannelUpdate(
|
assertChannelUpdate(bob, expectedPolicy)
|
||||||
t, carolSub,
|
|
||||||
[]expectedChanUpdate{
|
|
||||||
{bob.PubKeyStr, expectedPolicy, chanPoint},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
// However, since we manually disabled the channel on Alice's end,
|
// However, since we manually disabled the channel on Alice's end,
|
||||||
// the policy on Alice's end should still be "Disabled = true". Again,
|
// the policy on Alice's end should still be "Disabled = true". Again,
|
||||||
@ -267,26 +244,17 @@ func testUpdateChanStatus(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// Bob sends a "Disabled = true" update upon detecting the
|
// Bob sends a "Disabled = true" update upon detecting the
|
||||||
// disconnect.
|
// disconnect.
|
||||||
expectedPolicy.Disabled = true
|
expectedPolicy.Disabled = true
|
||||||
waitForChannelUpdate(
|
assertChannelUpdate(bob, expectedPolicy)
|
||||||
t, carolSub,
|
|
||||||
[]expectedChanUpdate{
|
|
||||||
{bob.PubKeyStr, expectedPolicy, chanPoint},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
// After restoring automatic channel state management on Alice's end,
|
// After restoring automatic channel state management on Alice's end,
|
||||||
// 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(t.t, alice, bob)
|
net.EnsureConnected(t.t, alice, bob)
|
||||||
|
|
||||||
expectedPolicy.Disabled = false
|
expectedPolicy.Disabled = false
|
||||||
waitForChannelUpdate(
|
assertChannelUpdate(alice, expectedPolicy)
|
||||||
t, carolSub,
|
assertChannelUpdate(bob, expectedPolicy)
|
||||||
[]expectedChanUpdate{
|
|
||||||
{alice.PubKeyStr, expectedPolicy, chanPoint},
|
|
||||||
{bob.PubKeyStr, expectedPolicy, chanPoint},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
assertEdgeDisabled(alice, chanPoint, false)
|
assertEdgeDisabled(alice, chanPoint, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,14 +28,6 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
)
|
)
|
||||||
defaultMaxHtlc := calculateMaxHtlc(funding.MaxBtcFundingAmount)
|
defaultMaxHtlc := calculateMaxHtlc(funding.MaxBtcFundingAmount)
|
||||||
|
|
||||||
// Launch notification clients for all nodes, such that we can
|
|
||||||
// get notified when they discover new channels and updates in the
|
|
||||||
// graph.
|
|
||||||
aliceSub := subscribeGraphNotifications(ctxb, t, net.Alice)
|
|
||||||
defer close(aliceSub.quit)
|
|
||||||
bobSub := subscribeGraphNotifications(ctxb, t, net.Bob)
|
|
||||||
defer close(bobSub.quit)
|
|
||||||
|
|
||||||
chanAmt := funding.MaxBtcFundingAmount
|
chanAmt := funding.MaxBtcFundingAmount
|
||||||
pushAmt := chanAmt / 2
|
pushAmt := chanAmt / 2
|
||||||
|
|
||||||
@ -47,12 +39,27 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
PushAmt: pushAmt,
|
PushAmt: pushAmt,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
defer closeChannelAndAssert(t, net, net.Alice, chanPoint, false)
|
||||||
|
|
||||||
// We add all the nodes' update channels to a slice, such that we can
|
// We add all the nodes' update channels to a slice, such that we can
|
||||||
// make sure they all receive the expected updates.
|
// make sure they all receive the expected updates.
|
||||||
graphSubs := []graphSubscription{aliceSub, bobSub}
|
|
||||||
nodes := []*lntest.HarnessNode{net.Alice, net.Bob}
|
nodes := []*lntest.HarnessNode{net.Alice, net.Bob}
|
||||||
|
|
||||||
|
// assertPolicyUpdate checks that a given policy update has been
|
||||||
|
// received by a list of given nodes.
|
||||||
|
assertPolicyUpdate := func(nodes []*lntest.HarnessNode,
|
||||||
|
advertisingNode string, policy *lnrpc.RoutingPolicy,
|
||||||
|
chanPoint *lnrpc.ChannelPoint) {
|
||||||
|
|
||||||
|
for _, node := range nodes {
|
||||||
|
assertChannelPolicyUpdate(
|
||||||
|
t.t, node, advertisingNode,
|
||||||
|
policy, chanPoint, false,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Alice and Bob should see each other's ChannelUpdates, advertising the
|
// Alice and Bob should see each other's ChannelUpdates, advertising the
|
||||||
// default routing policies.
|
// default routing policies.
|
||||||
expectedPolicy := &lnrpc.RoutingPolicy{
|
expectedPolicy := &lnrpc.RoutingPolicy{
|
||||||
@ -63,15 +70,10 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
MaxHtlcMsat: defaultMaxHtlc,
|
MaxHtlcMsat: defaultMaxHtlc,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, graphSub := range graphSubs {
|
assertPolicyUpdate(
|
||||||
waitForChannelUpdate(
|
nodes, net.Alice.PubKeyStr, expectedPolicy, chanPoint,
|
||||||
t, graphSub,
|
)
|
||||||
[]expectedChanUpdate{
|
assertPolicyUpdate(nodes, net.Bob.PubKeyStr, expectedPolicy, chanPoint)
|
||||||
{net.Alice.PubKeyStr, expectedPolicy, chanPoint},
|
|
||||||
{net.Bob.PubKeyStr, expectedPolicy, chanPoint},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// They should now know about the default policies.
|
// They should now know about the default policies.
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
@ -105,10 +107,6 @@ func testUpdateChannelPolicy(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)
|
||||||
|
|
||||||
carolSub := subscribeGraphNotifications(ctxb, t, carol)
|
|
||||||
defer close(carolSub.quit)
|
|
||||||
|
|
||||||
graphSubs = append(graphSubs, carolSub)
|
|
||||||
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.
|
||||||
@ -129,6 +127,7 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
MinHtlc: customMinHtlc,
|
MinHtlc: customMinHtlc,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
defer closeChannelAndAssert(t, net, net.Bob, chanPoint2, false)
|
||||||
|
|
||||||
expectedPolicyBob := &lnrpc.RoutingPolicy{
|
expectedPolicyBob := &lnrpc.RoutingPolicy{
|
||||||
FeeBaseMsat: defaultFeeBase,
|
FeeBaseMsat: defaultFeeBase,
|
||||||
@ -145,15 +144,12 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
MaxHtlcMsat: defaultMaxHtlc,
|
MaxHtlcMsat: defaultMaxHtlc,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, graphSub := range graphSubs {
|
assertPolicyUpdate(
|
||||||
waitForChannelUpdate(
|
nodes, net.Bob.PubKeyStr, expectedPolicyBob, chanPoint2,
|
||||||
t, graphSub,
|
)
|
||||||
[]expectedChanUpdate{
|
assertPolicyUpdate(
|
||||||
{net.Bob.PubKeyStr, expectedPolicyBob, chanPoint2},
|
nodes, carol.PubKeyStr, expectedPolicyCarol, chanPoint2,
|
||||||
{carol.PubKeyStr, expectedPolicyCarol, chanPoint2},
|
)
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check that all nodes now know about the updated policies.
|
// Check that all nodes now know about the updated policies.
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
@ -345,14 +341,7 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Wait for all nodes to have seen the policy update done by Bob.
|
// Wait for all nodes to have seen the policy update done by Bob.
|
||||||
for _, graphSub := range graphSubs {
|
assertPolicyUpdate(nodes, net.Bob.PubKeyStr, expectedPolicy, chanPoint)
|
||||||
waitForChannelUpdate(
|
|
||||||
t, graphSub,
|
|
||||||
[]expectedChanUpdate{
|
|
||||||
{net.Bob.PubKeyStr, expectedPolicy, chanPoint},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check that all nodes now know about Bob's updated policy.
|
// Check that all nodes now know about Bob's updated policy.
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
@ -396,6 +385,7 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
PushAmt: pushAmt,
|
PushAmt: pushAmt,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
defer closeChannelAndAssert(t, net, net.Alice, chanPoint3, false)
|
||||||
|
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||||
err = net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint3)
|
err = net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint3)
|
||||||
@ -436,15 +426,12 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
|
|
||||||
// Wait for all nodes to have seen the policy updates for both of
|
// Wait for all nodes to have seen the policy updates for both of
|
||||||
// Alice's channels.
|
// Alice's channels.
|
||||||
for _, graphSub := range graphSubs {
|
assertPolicyUpdate(
|
||||||
waitForChannelUpdate(
|
nodes, net.Alice.PubKeyStr, expectedPolicy, chanPoint,
|
||||||
t, graphSub,
|
)
|
||||||
[]expectedChanUpdate{
|
assertPolicyUpdate(
|
||||||
{net.Alice.PubKeyStr, expectedPolicy, chanPoint},
|
nodes, net.Alice.PubKeyStr, expectedPolicy, chanPoint3,
|
||||||
{net.Alice.PubKeyStr, expectedPolicy, chanPoint3},
|
)
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// And finally check that all nodes remembers the policy update they
|
// And finally check that all nodes remembers the policy update they
|
||||||
// received.
|
// received.
|
||||||
@ -469,47 +456,49 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
|
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
_, err = net.Alice.UpdateChannelPolicy(ctxt, req)
|
_, err = net.Alice.UpdateChannelPolicy(ctxt, req)
|
||||||
if err != nil {
|
require.NoError(t.t, err)
|
||||||
t.Fatalf("unable to update alice's channel policy: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for all nodes to have seen the policy updates for both
|
// Wait for all nodes to have seen the policy updates for both
|
||||||
// of Alice's channels. Carol will not see the last update as
|
// of Alice's channels. Carol will not see the last update as
|
||||||
// the limit has been reached.
|
// the limit has been reached.
|
||||||
for idx, graphSub := range graphSubs {
|
assertPolicyUpdate(
|
||||||
expUpdates := []expectedChanUpdate{
|
[]*lntest.HarnessNode{net.Alice, net.Bob},
|
||||||
{net.Alice.PubKeyStr, expectedPolicy, chanPoint},
|
net.Alice.PubKeyStr, expectedPolicy, chanPoint,
|
||||||
{net.Alice.PubKeyStr, expectedPolicy, chanPoint3},
|
)
|
||||||
}
|
assertPolicyUpdate(
|
||||||
// Carol was added last, which is why we check the last
|
[]*lntest.HarnessNode{net.Alice, net.Bob},
|
||||||
// index.
|
net.Alice.PubKeyStr, expectedPolicy, chanPoint3,
|
||||||
if i == numUpdatesTilRateLimit-1 && idx == len(graphSubs)-1 {
|
)
|
||||||
expUpdates = nil
|
// Check that all nodes remembers the policy update
|
||||||
}
|
// they received.
|
||||||
waitForChannelUpdate(t, graphSub, expUpdates)
|
assertChannelPolicy(
|
||||||
}
|
t, net.Alice, net.Alice.PubKeyStr,
|
||||||
|
expectedPolicy, chanPoint, chanPoint3,
|
||||||
|
)
|
||||||
|
assertChannelPolicy(
|
||||||
|
t, net.Bob, net.Alice.PubKeyStr,
|
||||||
|
expectedPolicy, chanPoint, chanPoint3,
|
||||||
|
)
|
||||||
|
|
||||||
// And finally check that all nodes remembers the policy update
|
// Carol was added last, which is why we check the last index.
|
||||||
// they received. Since Carol didn't receive the last update,
|
// Since Carol didn't receive the last update, she still has
|
||||||
// she still has Alice's old policy.
|
// Alice's old policy.
|
||||||
for idx, node := range nodes {
|
if i == numUpdatesTilRateLimit-1 {
|
||||||
policy := expectedPolicy
|
expectedPolicy = &prevAlicePolicy
|
||||||
// Carol was added last, which is why we check the last
|
|
||||||
// index.
|
|
||||||
if i == numUpdatesTilRateLimit-1 && idx == len(nodes)-1 {
|
|
||||||
policy = &prevAlicePolicy
|
|
||||||
}
|
|
||||||
assertChannelPolicy(
|
|
||||||
t, node, net.Alice.PubKeyStr, policy, chanPoint,
|
|
||||||
chanPoint3,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
assertPolicyUpdate(
|
||||||
|
[]*lntest.HarnessNode{carol},
|
||||||
|
net.Alice.PubKeyStr, expectedPolicy, chanPoint,
|
||||||
|
)
|
||||||
|
assertPolicyUpdate(
|
||||||
|
[]*lntest.HarnessNode{carol},
|
||||||
|
net.Alice.PubKeyStr, expectedPolicy, chanPoint3,
|
||||||
|
)
|
||||||
|
assertChannelPolicy(
|
||||||
|
t, carol, net.Alice.PubKeyStr,
|
||||||
|
expectedPolicy, chanPoint, chanPoint3,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close the channels.
|
|
||||||
closeChannelAndAssert(t, net, net.Alice, chanPoint, false)
|
|
||||||
closeChannelAndAssert(t, net, net.Bob, chanPoint2, false)
|
|
||||||
closeChannelAndAssert(t, net, net.Alice, chanPoint3, false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// testSendUpdateDisableChannel ensures that a channel update with the disable
|
// testSendUpdateDisableChannel ensures that a channel update with the disable
|
||||||
@ -583,9 +572,6 @@ func testSendUpdateDisableChannel(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
|
|
||||||
net.ConnectNodes(t.t, net.Bob, dave)
|
net.ConnectNodes(t.t, net.Bob, dave)
|
||||||
|
|
||||||
daveSub := subscribeGraphNotifications(ctxb, t, dave)
|
|
||||||
defer close(daveSub.quit)
|
|
||||||
|
|
||||||
// We should expect to see a channel update with the default routing
|
// We should expect to see a channel update with the default routing
|
||||||
// policy, except that it should indicate the channel is disabled.
|
// policy, except that it should indicate the channel is disabled.
|
||||||
expectedPolicy := &lnrpc.RoutingPolicy{
|
expectedPolicy := &lnrpc.RoutingPolicy{
|
||||||
@ -597,18 +583,29 @@ func testSendUpdateDisableChannel(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
Disabled: true,
|
Disabled: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// assertPolicyUpdate checks that the required policy update has
|
||||||
|
// happened on the given node.
|
||||||
|
assertPolicyUpdate := func(node *lntest.HarnessNode,
|
||||||
|
policy *lnrpc.RoutingPolicy, chanPoint *lnrpc.ChannelPoint) {
|
||||||
|
|
||||||
|
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
require.NoError(
|
||||||
|
t.t, dave.WaitForChannelPolicyUpdate(
|
||||||
|
ctxt, node.PubKeyStr, policy, chanPoint, false,
|
||||||
|
), "error while waiting for channel update",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// Let Carol go offline. Since Eve has an inactive timeout of 2s, we
|
// Let Carol go offline. Since Eve has an inactive timeout of 2s, we
|
||||||
// expect her to send an update disabling the channel.
|
// expect her to send an update disabling the channel.
|
||||||
restartCarol, err := net.SuspendNode(carol)
|
restartCarol, err := net.SuspendNode(carol)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to suspend carol: %v", err)
|
t.Fatalf("unable to suspend carol: %v", err)
|
||||||
}
|
}
|
||||||
waitForChannelUpdate(
|
|
||||||
t, daveSub,
|
assertPolicyUpdate(eve, expectedPolicy, chanPointEveCarol)
|
||||||
[]expectedChanUpdate{
|
|
||||||
{eve.PubKeyStr, expectedPolicy, chanPointEveCarol},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
// We restart Carol. Since the channel now becomes active again, Eve
|
// We restart Carol. Since the channel now becomes active again, Eve
|
||||||
// should send a ChannelUpdate setting the channel no longer disabled.
|
// should send a ChannelUpdate setting the channel no longer disabled.
|
||||||
@ -617,12 +614,7 @@ func testSendUpdateDisableChannel(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
expectedPolicy.Disabled = false
|
expectedPolicy.Disabled = false
|
||||||
waitForChannelUpdate(
|
assertPolicyUpdate(eve, expectedPolicy, chanPointEveCarol)
|
||||||
t, daveSub,
|
|
||||||
[]expectedChanUpdate{
|
|
||||||
{eve.PubKeyStr, expectedPolicy, chanPointEveCarol},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
// 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
|
||||||
@ -633,26 +625,16 @@ func testSendUpdateDisableChannel(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
|
|
||||||
// Wait for a disable from both Carol and Eve to come through.
|
// Wait for a disable from both Carol and Eve to come through.
|
||||||
expectedPolicy.Disabled = true
|
expectedPolicy.Disabled = true
|
||||||
waitForChannelUpdate(
|
assertPolicyUpdate(eve, expectedPolicy, chanPointEveCarol)
|
||||||
t, daveSub,
|
assertPolicyUpdate(carol, expectedPolicy, chanPointEveCarol)
|
||||||
[]expectedChanUpdate{
|
|
||||||
{eve.PubKeyStr, expectedPolicy, chanPointEveCarol},
|
|
||||||
{carol.PubKeyStr, expectedPolicy, chanPointEveCarol},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
// 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.
|
||||||
net.EnsureConnected(t.t, carol, eve)
|
net.EnsureConnected(t.t, carol, eve)
|
||||||
|
|
||||||
expectedPolicy.Disabled = false
|
expectedPolicy.Disabled = false
|
||||||
waitForChannelUpdate(
|
assertPolicyUpdate(eve, expectedPolicy, chanPointEveCarol)
|
||||||
t, daveSub,
|
assertPolicyUpdate(carol, expectedPolicy, chanPointEveCarol)
|
||||||
[]expectedChanUpdate{
|
|
||||||
{eve.PubKeyStr, expectedPolicy, chanPointEveCarol},
|
|
||||||
{carol.PubKeyStr, expectedPolicy, chanPointEveCarol},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
// Now we'll test a short disconnection. Disconnect Carol and Eve, then
|
// Now we'll test a short disconnection. Disconnect Carol and Eve, then
|
||||||
// reconnect them after one second so that their scheduled disables are
|
// reconnect them after one second so that their scheduled disables are
|
||||||
@ -667,8 +649,10 @@ func testSendUpdateDisableChannel(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
net.EnsureConnected(t.t, eve, carol)
|
net.EnsureConnected(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, which means we
|
||||||
assertNoChannelUpdates(t, daveSub, 4*time.Second)
|
// expect the polices stay unchanged(Disable == false).
|
||||||
|
assertPolicyUpdate(eve, expectedPolicy, chanPointEveCarol)
|
||||||
|
assertPolicyUpdate(carol, expectedPolicy, chanPointEveCarol)
|
||||||
|
|
||||||
// Close Alice's channels with Bob and Carol cooperatively and
|
// Close Alice's channels with Bob and Carol cooperatively and
|
||||||
// unilaterally respectively.
|
// unilaterally respectively.
|
||||||
@ -685,13 +669,8 @@ func testSendUpdateDisableChannel(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// Now that the channel close processes have been started, we should
|
// Now that the channel close processes have been started, we should
|
||||||
// receive an update marking each as disabled.
|
// receive an update marking each as disabled.
|
||||||
expectedPolicy.Disabled = true
|
expectedPolicy.Disabled = true
|
||||||
waitForChannelUpdate(
|
assertPolicyUpdate(net.Alice, expectedPolicy, chanPointAliceBob)
|
||||||
t, daveSub,
|
assertPolicyUpdate(net.Alice, expectedPolicy, chanPointAliceCarol)
|
||||||
[]expectedChanUpdate{
|
|
||||||
{net.Alice.PubKeyStr, expectedPolicy, chanPointAliceBob},
|
|
||||||
{net.Alice.PubKeyStr, expectedPolicy, chanPointAliceCarol},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
// Finally, close the channels by mining the closing transactions.
|
// Finally, close the channels by mining the closing transactions.
|
||||||
mineBlocks(t, net, 1, 2)
|
mineBlocks(t, net, 1, 2)
|
||||||
@ -702,12 +681,8 @@ func testSendUpdateDisableChannel(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
t.Fatalf("unable to close channel: %v", err)
|
t.Fatalf("unable to close channel: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
waitForChannelUpdate(
|
assertPolicyUpdate(eve, expectedPolicy, chanPointEveCarol)
|
||||||
t, daveSub,
|
|
||||||
[]expectedChanUpdate{
|
|
||||||
{eve.PubKeyStr, expectedPolicy, chanPointEveCarol},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
mineBlocks(t, net, 1, 1)
|
mineBlocks(t, net, 1, 1)
|
||||||
|
|
||||||
// And finally, clean up the force closed channel by mining the
|
// And finally, clean up the force closed channel by mining the
|
||||||
|
@ -418,14 +418,8 @@ func updateChannelPolicy(t *harnessTest, node *lntest.HarnessNode,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Wait for listener node to receive the channel update from node.
|
// Wait for listener node to receive the channel update from node.
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
assertChannelPolicyUpdate(
|
||||||
graphSub := subscribeGraphNotifications(ctxt, t, listenerNode)
|
t.t, listenerNode, node.PubKeyStr,
|
||||||
defer close(graphSub.quit)
|
expectedPolicy, chanPoint, false,
|
||||||
|
|
||||||
waitForChannelUpdate(
|
|
||||||
t, graphSub,
|
|
||||||
[]expectedChanUpdate{
|
|
||||||
{node.PubKeyStr, expectedPolicy, chanPoint},
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1814,15 +1814,9 @@ func testRouteFeeCutoff(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Wait for Alice to receive the channel update from Carol.
|
// Wait for Alice to receive the channel update from Carol.
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
assertChannelPolicyUpdate(
|
||||||
aliceSub := subscribeGraphNotifications(ctxt, t, net.Alice)
|
t.t, net.Alice, carol.PubKeyStr,
|
||||||
defer close(aliceSub.quit)
|
expectedPolicy, chanPointCarolDave, false,
|
||||||
|
|
||||||
waitForChannelUpdate(
|
|
||||||
t, aliceSub,
|
|
||||||
[]expectedChanUpdate{
|
|
||||||
{carol.PubKeyStr, expectedPolicy, chanPointCarolDave},
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// We'll also need the channel IDs for Bob's channels in order to
|
// We'll also need the channel IDs for Bob's channels in order to
|
||||||
|
Loading…
x
Reference in New Issue
Block a user