test: update testUpdateChannelPolicy to ensure Bob's link uses the proper policies

In this commit, we update the testUpdateChannelPolicy to exercise the
recent set of changes within the switch. If one applies this test to a
fresh branch (without those new changes) it should fail. This is due to
the fact that before, Bob would attempt to apply the constraints of the
incoming link (which we updated) instead of the outgoing link. With the
recent set of changes, the test now properly passes.
This commit is contained in:
Olaoluwa Osuntokun 2018-04-03 20:18:42 -07:00
parent ffabb17ce6
commit 3fa2e08665
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
4 changed files with 74 additions and 41 deletions

@ -1147,6 +1147,12 @@ func (d *AuthenticatedGossiper) processChanPolicyUpdate(
} }
haveChanFilter := len(chansToUpdate) != 0 haveChanFilter := len(chansToUpdate) != 0
if haveChanFilter {
log.Infof("Updating routing policies for chan_points=%v",
spew.Sdump(chansToUpdate))
} else {
log.Infof("Updating routing policies for all chans")
}
type edgeWithInfo struct { type edgeWithInfo struct {
info *channeldb.ChannelEdgeInfo info *channeldb.ChannelEdgeInfo
@ -2145,8 +2151,8 @@ func (d *AuthenticatedGossiper) updateChannel(info *channeldb.ChannelEdgeInfo,
var err error var err error
// Make sure timestamp is always increased, such that our update // Make sure timestamp is always increased, such that our update gets
// gets propagated. // propagated.
timestamp := time.Now().Unix() timestamp := time.Now().Unix()
if timestamp <= edge.LastUpdate.Unix() { if timestamp <= edge.LastUpdate.Unix() {
timestamp = edge.LastUpdate.Unix() + 1 timestamp = edge.LastUpdate.Unix() + 1

@ -393,10 +393,10 @@ func (s *Switch) UpdateForwardingPolicies(newPolicy ForwardingPolicy,
return spew.Sdump(newPolicy) return spew.Sdump(newPolicy)
})) }))
s.indexMtx.RLock()
var linksToUpdate []ChannelLink var linksToUpdate []ChannelLink
s.indexMtx.RLock()
// If no channels have been targeted, then we'll collect all inks to // If no channels have been targeted, then we'll collect all inks to
// update their policies. // update their policies.
if len(targetChans) == 0 { if len(targetChans) == 0 {

@ -479,8 +479,8 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
ctxb := context.Background() ctxb := context.Background()
// Launch notification clients for all nodes, such that we can // Launch notification clients for all nodes, such that we can
// get notified when they discover new channels and updates // get notified when they discover new channels and updates in the
// in the graph. // graph.
aliceUpdates, aQuit := subscribeGraphNotifications(t, ctxb, net.Alice) aliceUpdates, aQuit := subscribeGraphNotifications(t, ctxb, net.Alice)
defer close(aQuit) defer close(aQuit)
bobUpdates, bQuit := subscribeGraphNotifications(t, ctxb, net.Bob) bobUpdates, bQuit := subscribeGraphNotifications(t, ctxb, net.Bob)
@ -530,8 +530,9 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
t.Fatalf("carol didn't report channel: %v", err) t.Fatalf("carol didn't report channel: %v", err)
} }
// Update the fees for the channel Alice->Bob, and make sure // With our little cluster set up, we'll update the fees for the
// all nodes learn about it. // channel Bob side of the Alice->Bob channel, and make sure all nodes
// learn about it.
const feeBase = 1000000 const feeBase = 1000000
baseFee := int64(1500) baseFee := int64(1500)
feeRate := int64(12) feeRate := int64(12)
@ -546,7 +547,7 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
ChanPoint: chanPoint, ChanPoint: chanPoint,
} }
_, err = net.Alice.UpdateChannelPolicy(ctxb, req) _, err = net.Bob.UpdateChannelPolicy(ctxb, req)
if err != nil { if err != nil {
t.Fatalf("unable to get alice's balance: %v", err) t.Fatalf("unable to get alice's balance: %v", err)
} }
@ -572,7 +573,8 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
// A closure that is used to wait for a channel updates that matches // A closure that is used to wait for a channel updates that matches
// the channel policy update done by Alice. // the channel policy update done by Alice.
waitForChannelUpdate := func(graphUpdates chan *lnrpc.GraphTopologyUpdate, waitForChannelUpdate := func(graphUpdates chan *lnrpc.GraphTopologyUpdate,
chanPoints ...*lnrpc.ChannelPoint) { advertisingNode string, chanPoints ...*lnrpc.ChannelPoint) {
// Create a map containing all the channel points we are // Create a map containing all the channel points we are
// waiting for updates for. // waiting for updates for.
cps := make(map[string]bool) cps := make(map[string]bool)
@ -592,7 +594,7 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
continue continue
} }
if chanUpdate.AdvertisingNode != net.Alice.PubKeyStr { if chanUpdate.AdvertisingNode != advertisingNode {
continue continue
} }
@ -623,16 +625,17 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
} }
} }
// Wait for all nodes to have seen the policy update done by Alice. // Wait for all nodes to have seen the policy update done by Bob.
waitForChannelUpdate(aliceUpdates, chanPoint) waitForChannelUpdate(aliceUpdates, net.Bob.PubKeyStr, chanPoint)
waitForChannelUpdate(bobUpdates, chanPoint) waitForChannelUpdate(bobUpdates, net.Bob.PubKeyStr, chanPoint)
waitForChannelUpdate(carolUpdates, chanPoint) waitForChannelUpdate(carolUpdates, net.Bob.PubKeyStr, chanPoint)
// assertChannelPolicy asserts that the passed node's known channel // assertChannelPolicy asserts that the passed node's known channel
// policy for the passed chanPoint is consistent with Alice's current // policy for the passed chanPoint is consistent with Bob's current
// expected policy values. // expected policy values.
assertChannelPolicy := func(node *lntest.HarnessNode, assertChannelPolicy := func(node *lntest.HarnessNode,
chanPoint *lnrpc.ChannelPoint) { advertisingNode string, chanPoint *lnrpc.ChannelPoint) {
// Get a DescribeGraph from the node. // Get a DescribeGraph from the node.
descReq := &lnrpc.ChannelGraphRequest{} descReq := &lnrpc.ChannelGraphRequest{}
chanGraph, err := node.DescribeGraph(ctxb, descReq) chanGraph, err := node.DescribeGraph(ctxb, descReq)
@ -645,7 +648,7 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
for _, e := range chanGraph.Edges { for _, e := range chanGraph.Edges {
if e.ChanPoint == txStr(chanPoint) { if e.ChanPoint == txStr(chanPoint) {
edgeFound = true edgeFound = true
if e.Node1Pub == net.Alice.PubKeyStr { if e.Node1Pub == advertisingNode {
if e.Node1Policy.FeeBaseMsat != baseFee { if e.Node1Policy.FeeBaseMsat != baseFee {
t.Fatalf("expected base fee "+ t.Fatalf("expected base fee "+
"%v, got %v", baseFee, "%v, got %v", baseFee,
@ -689,18 +692,42 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
} }
// Check that all nodes now know about Alice's updated policy. // Check that all nodes now know about Bob's updated policy.
assertChannelPolicy(net.Alice, chanPoint) assertChannelPolicy(net.Alice, net.Bob.PubKeyStr, chanPoint)
assertChannelPolicy(net.Bob, chanPoint) assertChannelPolicy(net.Bob, net.Bob.PubKeyStr, chanPoint)
assertChannelPolicy(carol, chanPoint) assertChannelPolicy(carol, net.Bob.PubKeyStr, chanPoint)
// Open channel to Carol. // Now that all nodes have received the new channel update, we'll try
// to send a payment from Alice to Carol to ensure that Alice has
// internalized this fee update. This shouldn't affect the route that
// Alice takes though: we updated the Alice -> Bob channel and she
// doesn't pay for transit over that channel as it's direct.
payAmt := lnwire.MilliSatoshi(2000)
invoice := &lnrpc.Invoice{
Memo: "testing",
Value: int64(payAmt),
}
resp, err := carol.AddInvoice(ctxb, invoice)
if err != nil {
t.Fatalf("unable to add invoice: %v", err)
}
ctxt, _ = context.WithTimeout(ctxb, timeout)
err = completePaymentRequests(
ctxt, net.Alice, []string{resp.PaymentRequest}, true,
)
if err != nil {
t.Fatalf("unable to send payment: %v", err)
}
// We'll now open a channel from Alice directly to Carol.
if err := net.ConnectNodes(ctxb, net.Alice, carol); err != nil { if err := net.ConnectNodes(ctxb, net.Alice, carol); err != nil {
t.Fatalf("unable to connect dave to alice: %v", err) t.Fatalf("unable to connect dave to alice: %v", err)
} }
ctxt, _ = context.WithTimeout(ctxb, timeout) ctxt, _ = context.WithTimeout(ctxb, timeout)
chanPoint3 := openChannelAndAssert(ctxt, t, net, net.Alice, carol, chanPoint3 := openChannelAndAssert(
chanAmt, pushAmt) ctxt, t, net, net.Alice, carol, chanAmt, pushAmt,
)
ctxt, _ = context.WithTimeout(ctxb, time.Second*15) ctxt, _ = context.WithTimeout(ctxb, time.Second*15)
err = net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint3) err = net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint3)
@ -712,8 +739,8 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
t.Fatalf("bob didn't report channel: %v", err) t.Fatalf("bob didn't report channel: %v", err)
} }
// Make a global update, and check that both channels' // Make a global update, and check that both channels' new policies get
// new policies get propagated. // propagated.
baseFee = int64(800) baseFee = int64(800)
feeRate = int64(123) feeRate = int64(123)
timeLockDelta = uint32(22) timeLockDelta = uint32(22)
@ -730,21 +757,21 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
t.Fatalf("unable to get alice's balance: %v", err) t.Fatalf("unable to get alice's balance: %v", err)
} }
// Wait for all nodes to have seen the policy updates // Wait for all nodes to have seen the policy updates for both of
// for both of Alice's channels. // Alice's channels.
waitForChannelUpdate(aliceUpdates, chanPoint, chanPoint3) waitForChannelUpdate(aliceUpdates, net.Alice.PubKeyStr, chanPoint3)
waitForChannelUpdate(bobUpdates, chanPoint, chanPoint3) waitForChannelUpdate(bobUpdates, net.Alice.PubKeyStr, chanPoint3)
waitForChannelUpdate(carolUpdates, chanPoint, chanPoint3) waitForChannelUpdate(carolUpdates, net.Alice.PubKeyStr, chanPoint3)
// And finally check that all nodes remembers the policy // And finally check that all nodes remembers the policy update they
// update they received. // received.
assertChannelPolicy(net.Alice, chanPoint) assertChannelPolicy(net.Alice, net.Alice.PubKeyStr, chanPoint)
assertChannelPolicy(net.Bob, chanPoint) assertChannelPolicy(net.Bob, net.Alice.PubKeyStr, chanPoint)
assertChannelPolicy(carol, chanPoint) assertChannelPolicy(carol, net.Alice.PubKeyStr, chanPoint)
assertChannelPolicy(net.Alice, chanPoint3) assertChannelPolicy(net.Alice, net.Alice.PubKeyStr, chanPoint3)
assertChannelPolicy(net.Bob, chanPoint3) assertChannelPolicy(net.Bob, net.Alice.PubKeyStr, chanPoint3)
assertChannelPolicy(carol, chanPoint3) assertChannelPolicy(carol, net.Alice.PubKeyStr, chanPoint3)
// Close the channels. // Close the channels.
ctxt, _ = context.WithTimeout(ctxb, timeout) ctxt, _ = context.WithTimeout(ctxb, timeout)

@ -3331,7 +3331,7 @@ func (r *rpcServer) UpdateChannelPolicy(ctx context.Context,
TimeLockDelta: req.TimeLockDelta, TimeLockDelta: req.TimeLockDelta,
} }
rpcsLog.Tracef("[updatechanpolicy] updating channel policy base_fee=%v, "+ rpcsLog.Debugf("[updatechanpolicy] updating channel policy base_fee=%v, "+
"rate_float=%v, rate_fixed=%v, time_lock_delta: %v, targets=%v", "rate_float=%v, rate_fixed=%v, time_lock_delta: %v, targets=%v",
req.BaseFeeMsat, req.FeeRate, feeRateFixed, req.TimeLockDelta, req.BaseFeeMsat, req.FeeRate, feeRateFixed, req.TimeLockDelta,
spew.Sdump(targetChans)) spew.Sdump(targetChans))