itest: test new channel update rate limiting options
This commit is contained in:
parent
dcac5a87f4
commit
022d44f776
@ -1762,6 +1762,13 @@ out:
|
|||||||
select {
|
select {
|
||||||
case graphUpdate := <-subscription.updateChan:
|
case graphUpdate := <-subscription.updateChan:
|
||||||
for _, update := range graphUpdate.ChannelUpdates {
|
for _, update := range graphUpdate.ChannelUpdates {
|
||||||
|
if len(expUpdates) == 0 {
|
||||||
|
t.Fatalf("received unexpected channel "+
|
||||||
|
"update from %v for channel %v",
|
||||||
|
update.AdvertisingNode,
|
||||||
|
update.ChanId)
|
||||||
|
}
|
||||||
|
|
||||||
// For each expected update, check if it matches
|
// For each expected update, check if it matches
|
||||||
// the update we just received.
|
// the update we just received.
|
||||||
for i, exp := range expUpdates {
|
for i, exp := range expUpdates {
|
||||||
@ -1811,6 +1818,9 @@ out:
|
|||||||
case err := <-subscription.errChan:
|
case err := <-subscription.errChan:
|
||||||
t.Fatalf("unable to recv graph update: %v", err)
|
t.Fatalf("unable to recv graph update: %v", err)
|
||||||
case <-time.After(defaultTimeout):
|
case <-time.After(defaultTimeout):
|
||||||
|
if len(expUpdates) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
t.Fatalf("did not receive channel update")
|
t.Fatalf("did not receive channel update")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2014,8 +2024,14 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create Carol and a new channel Bob->Carol.
|
// Create Carol with options to rate limit channel updates up to 2 per
|
||||||
carol, err := net.NewNode("Carol", nil)
|
// day, and create a new channel Bob->Carol.
|
||||||
|
carol, err := net.NewNode(
|
||||||
|
"Carol", []string{
|
||||||
|
"--gossip.max-channel-update-burst=2",
|
||||||
|
"--gossip.channel-update-interval=24h",
|
||||||
|
},
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create new nodes: %v", err)
|
t.Fatalf("unable to create new nodes: %v", err)
|
||||||
}
|
}
|
||||||
@ -2062,7 +2078,6 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
MinHtlc: customMinHtlc,
|
MinHtlc: customMinHtlc,
|
||||||
MaxHtlcMsat: defaultMaxHtlc,
|
MaxHtlcMsat: defaultMaxHtlc,
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedPolicyCarol := &lnrpc.RoutingPolicy{
|
expectedPolicyCarol := &lnrpc.RoutingPolicy{
|
||||||
FeeBaseMsat: defaultFeeBase,
|
FeeBaseMsat: defaultFeeBase,
|
||||||
FeeRateMilliMsat: defaultFeeRate,
|
FeeRateMilliMsat: defaultFeeRate,
|
||||||
@ -2386,6 +2401,57 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Now, to test that Carol is properly rate limiting incoming updates,
|
||||||
|
// we'll send two more update from Alice. Carol should accept the first,
|
||||||
|
// but not the second, as she only allows two updates per day and a day
|
||||||
|
// has yet to elapse from the previous update.
|
||||||
|
const numUpdatesTilRateLimit = 2
|
||||||
|
for i := 0; i < numUpdatesTilRateLimit; i++ {
|
||||||
|
prevAlicePolicy := *expectedPolicy
|
||||||
|
baseFee *= 2
|
||||||
|
expectedPolicy.FeeBaseMsat = baseFee
|
||||||
|
req.BaseFeeMsat = baseFee
|
||||||
|
|
||||||
|
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
|
||||||
|
defer cancel()
|
||||||
|
_, err = net.Alice.UpdateChannelPolicy(ctxt, req)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unable to update alice's channel policy: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for all nodes to have seen the policy updates for both
|
||||||
|
// of Alice's channels. Carol will not see the last update as
|
||||||
|
// the limit has been reached.
|
||||||
|
for idx, graphSub := range graphSubs {
|
||||||
|
expUpdates := []expectedChanUpdate{
|
||||||
|
{net.Alice.PubKeyStr, expectedPolicy, chanPoint},
|
||||||
|
{net.Alice.PubKeyStr, expectedPolicy, chanPoint3},
|
||||||
|
}
|
||||||
|
// Carol was added last, which is why we check the last
|
||||||
|
// index.
|
||||||
|
if i == numUpdatesTilRateLimit-1 && idx == len(graphSubs)-1 {
|
||||||
|
expUpdates = nil
|
||||||
|
}
|
||||||
|
waitForChannelUpdate(t, graphSub, expUpdates)
|
||||||
|
}
|
||||||
|
|
||||||
|
// And finally check that all nodes remembers the policy update
|
||||||
|
// they received. Since Carol didn't receive the last update,
|
||||||
|
// she still has Alice's old policy.
|
||||||
|
for idx, node := range nodes {
|
||||||
|
policy := expectedPolicy
|
||||||
|
// 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,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Close the channels.
|
// Close the channels.
|
||||||
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout)
|
||||||
closeChannelAndAssert(ctxt, t, net, net.Alice, chanPoint, false)
|
closeChannelAndAssert(ctxt, t, net, net.Alice, chanPoint, false)
|
||||||
@ -12831,10 +12897,7 @@ func testSwitchOfflineDeliveryOutgoingOffline(
|
|||||||
nodesMinusCarol := []*lntest.HarnessNode{net.Bob, net.Alice, dave}
|
nodesMinusCarol := []*lntest.HarnessNode{net.Bob, net.Alice, dave}
|
||||||
err = wait.Predicate(func() bool {
|
err = wait.Predicate(func() bool {
|
||||||
predErr = assertNumActiveHtlcs(nodesMinusCarol, 0)
|
predErr = assertNumActiveHtlcs(nodesMinusCarol, 0)
|
||||||
if predErr != nil {
|
return predErr == nil
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}, defaultTimeout)
|
}, defaultTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("htlc mismatch: %v", predErr)
|
t.Fatalf("htlc mismatch: %v", predErr)
|
||||||
|
Loading…
Reference in New Issue
Block a user