2021-06-28 22:10:33 +02:00
|
|
|
package itest
|
|
|
|
|
|
|
|
import (
|
2022-08-03 23:37:43 +02:00
|
|
|
"fmt"
|
2022-01-25 17:48:07 +01:00
|
|
|
"math"
|
2021-08-07 22:50:45 +02:00
|
|
|
"time"
|
2021-06-28 22:10:33 +02:00
|
|
|
|
2022-02-23 14:48:00 +01:00
|
|
|
"github.com/btcsuite/btcd/btcutil"
|
2021-06-28 22:10:33 +02:00
|
|
|
"github.com/lightningnetwork/lnd/chainreg"
|
|
|
|
"github.com/lightningnetwork/lnd/funding"
|
|
|
|
"github.com/lightningnetwork/lnd/lnrpc"
|
2022-08-03 21:38:09 +02:00
|
|
|
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
|
2022-08-12 11:03:44 +02:00
|
|
|
"github.com/lightningnetwork/lnd/lntest"
|
|
|
|
"github.com/lightningnetwork/lnd/lntest/node"
|
2021-06-28 22:10:33 +02:00
|
|
|
"github.com/lightningnetwork/lnd/lnwire"
|
2021-08-07 22:50:45 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
2021-06-28 22:10:33 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// testUpdateChannelPolicy tests that policy updates made to a channel
|
2022-08-03 21:38:09 +02:00
|
|
|
// gets propagated to other nodes in the network.
|
2022-08-12 11:03:44 +02:00
|
|
|
func testUpdateChannelPolicy(ht *lntest.HarnessTest) {
|
2021-06-28 22:10:33 +02:00
|
|
|
const (
|
|
|
|
defaultFeeBase = 1000
|
|
|
|
defaultFeeRate = 1
|
|
|
|
defaultTimeLockDelta = chainreg.DefaultBitcoinTimeLockDelta
|
|
|
|
defaultMinHtlc = 1000
|
|
|
|
)
|
2022-08-12 11:03:44 +02:00
|
|
|
defaultMaxHtlc := lntest.CalculateMaxHtlc(funding.MaxBtcFundingAmount)
|
2021-06-28 22:10:33 +02:00
|
|
|
|
|
|
|
chanAmt := funding.MaxBtcFundingAmount
|
|
|
|
pushAmt := chanAmt / 2
|
|
|
|
|
2022-08-03 21:38:09 +02:00
|
|
|
alice, bob := ht.Alice, ht.Bob
|
|
|
|
|
2021-06-28 22:10:33 +02:00
|
|
|
// Create a channel Alice->Bob.
|
2022-08-03 21:38:09 +02:00
|
|
|
chanPoint := ht.OpenChannel(
|
2022-08-12 11:03:44 +02:00
|
|
|
alice, bob, lntest.OpenChannelParams{
|
2021-06-28 22:10:33 +02:00
|
|
|
Amt: chanAmt,
|
|
|
|
PushAmt: pushAmt,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
// We add all the nodes' update channels to a slice, such that we can
|
|
|
|
// make sure they all receive the expected updates.
|
2022-08-03 21:38:09 +02:00
|
|
|
nodes := []*node.HarnessNode{alice, bob}
|
2021-06-28 22:10:33 +02:00
|
|
|
|
|
|
|
// Alice and Bob should see each other's ChannelUpdates, advertising the
|
2024-05-20 21:17:53 +02:00
|
|
|
// default routing policies. We do not currently set any inbound fees.
|
|
|
|
// The inbound base and inbound fee rate are advertised with a default
|
|
|
|
// of 0.
|
2021-06-28 22:10:33 +02:00
|
|
|
expectedPolicy := &lnrpc.RoutingPolicy{
|
|
|
|
FeeBaseMsat: defaultFeeBase,
|
|
|
|
FeeRateMilliMsat: defaultFeeRate,
|
|
|
|
TimeLockDelta: defaultTimeLockDelta,
|
|
|
|
MinHtlc: defaultMinHtlc,
|
|
|
|
MaxHtlcMsat: defaultMaxHtlc,
|
|
|
|
}
|
|
|
|
|
2022-08-03 21:38:09 +02:00
|
|
|
assertNodesPolicyUpdate(ht, nodes, alice, expectedPolicy, chanPoint)
|
|
|
|
assertNodesPolicyUpdate(ht, nodes, bob, expectedPolicy, chanPoint)
|
2021-06-28 22:10:33 +02:00
|
|
|
|
|
|
|
// They should now know about the default policies.
|
|
|
|
for _, node := range nodes {
|
2022-08-03 21:38:09 +02:00
|
|
|
ht.AssertChannelPolicy(
|
|
|
|
node, alice.PubKeyStr, expectedPolicy, chanPoint,
|
2021-06-28 22:10:33 +02:00
|
|
|
)
|
2022-08-03 21:38:09 +02:00
|
|
|
ht.AssertChannelPolicy(
|
|
|
|
node, bob.PubKeyStr, expectedPolicy, chanPoint,
|
2021-06-28 22:10:33 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create Carol with options to rate limit channel updates up to 2 per
|
|
|
|
// day, and create a new channel Bob->Carol.
|
2022-08-03 21:38:09 +02:00
|
|
|
carol := ht.NewNode(
|
|
|
|
"Carol", []string{
|
2021-06-28 22:10:33 +02:00
|
|
|
"--gossip.max-channel-update-burst=2",
|
|
|
|
"--gossip.channel-update-interval=24h",
|
|
|
|
},
|
|
|
|
)
|
2022-08-03 21:38:09 +02:00
|
|
|
ht.ConnectNodes(carol, bob)
|
2021-06-28 22:10:33 +02:00
|
|
|
nodes = append(nodes, carol)
|
|
|
|
|
|
|
|
// Send some coins to Carol that can be used for channel funding.
|
2022-08-03 21:38:09 +02:00
|
|
|
ht.FundCoins(btcutil.SatoshiPerBitcoin, carol)
|
2021-06-28 22:10:33 +02:00
|
|
|
|
|
|
|
// Open the channel Carol->Bob with a custom min_htlc value set. Since
|
|
|
|
// Carol is opening the channel, she will require Bob to not forward
|
|
|
|
// HTLCs smaller than this value, and hence he should advertise it as
|
|
|
|
// part of his ChannelUpdate.
|
|
|
|
const customMinHtlc = 5000
|
2022-08-03 21:38:09 +02:00
|
|
|
chanPoint2 := ht.OpenChannel(
|
2022-08-12 11:03:44 +02:00
|
|
|
carol, bob, lntest.OpenChannelParams{
|
2021-06-28 22:10:33 +02:00
|
|
|
Amt: chanAmt,
|
|
|
|
PushAmt: pushAmt,
|
|
|
|
MinHtlc: customMinHtlc,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
expectedPolicyBob := &lnrpc.RoutingPolicy{
|
|
|
|
FeeBaseMsat: defaultFeeBase,
|
|
|
|
FeeRateMilliMsat: defaultFeeRate,
|
|
|
|
TimeLockDelta: defaultTimeLockDelta,
|
|
|
|
MinHtlc: customMinHtlc,
|
|
|
|
MaxHtlcMsat: defaultMaxHtlc,
|
|
|
|
}
|
|
|
|
expectedPolicyCarol := &lnrpc.RoutingPolicy{
|
|
|
|
FeeBaseMsat: defaultFeeBase,
|
|
|
|
FeeRateMilliMsat: defaultFeeRate,
|
|
|
|
TimeLockDelta: defaultTimeLockDelta,
|
|
|
|
MinHtlc: defaultMinHtlc,
|
|
|
|
MaxHtlcMsat: defaultMaxHtlc,
|
|
|
|
}
|
|
|
|
|
2022-08-03 21:38:09 +02:00
|
|
|
assertNodesPolicyUpdate(ht, nodes, bob, expectedPolicyBob, chanPoint2)
|
|
|
|
assertNodesPolicyUpdate(
|
|
|
|
ht, nodes, carol, expectedPolicyCarol, chanPoint2,
|
2021-08-08 11:12:37 +02:00
|
|
|
)
|
2021-06-28 22:10:33 +02:00
|
|
|
|
|
|
|
// Check that all nodes now know about the updated policies.
|
|
|
|
for _, node := range nodes {
|
2022-08-03 21:38:09 +02:00
|
|
|
ht.AssertChannelPolicy(
|
|
|
|
node, bob.PubKeyStr, expectedPolicyBob, chanPoint2,
|
2021-06-28 22:10:33 +02:00
|
|
|
)
|
2022-08-03 21:38:09 +02:00
|
|
|
ht.AssertChannelPolicy(
|
|
|
|
node, carol.PubKeyStr, expectedPolicyCarol, chanPoint2,
|
2021-06-28 22:10:33 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-08-03 21:38:09 +02:00
|
|
|
// Make sure Alice and Carol have seen each other's channels.
|
|
|
|
ht.AssertTopologyChannelOpen(alice, chanPoint2)
|
|
|
|
ht.AssertTopologyChannelOpen(carol, chanPoint)
|
2021-06-28 22:10:33 +02:00
|
|
|
|
|
|
|
// First we'll try to send a payment from Alice to Carol with an amount
|
|
|
|
// less than the min_htlc value required by Carol. This payment should
|
|
|
|
// fail, as the channel Bob->Carol cannot carry HTLCs this small.
|
|
|
|
payAmt := btcutil.Amount(4)
|
|
|
|
invoice := &lnrpc.Invoice{
|
|
|
|
Memo: "testing",
|
|
|
|
Value: int64(payAmt),
|
|
|
|
}
|
2022-08-03 21:38:09 +02:00
|
|
|
resp := carol.RPC.AddInvoice(invoice)
|
2021-06-28 22:10:33 +02:00
|
|
|
|
|
|
|
// Alice knows about the channel policy of Carol and should therefore
|
|
|
|
// not be able to find a path during routing.
|
2022-08-03 21:38:09 +02:00
|
|
|
payReq := &routerrpc.SendPaymentRequest{
|
|
|
|
PaymentRequest: resp.PaymentRequest,
|
|
|
|
TimeoutSeconds: 60,
|
|
|
|
FeeLimitMsat: noFeeLimitMsat,
|
|
|
|
}
|
|
|
|
ht.SendPaymentAssertFail(
|
|
|
|
alice, payReq,
|
|
|
|
lnrpc.PaymentFailureReason_FAILURE_REASON_NO_ROUTE,
|
|
|
|
)
|
2021-06-28 22:10:33 +02:00
|
|
|
|
|
|
|
// Now we try to send a payment over the channel with a value too low
|
|
|
|
// to be accepted. First we query for a route to route a payment of
|
|
|
|
// 5000 mSAT, as this is accepted.
|
|
|
|
payAmt = btcutil.Amount(5)
|
|
|
|
routesReq := &lnrpc.QueryRoutesRequest{
|
|
|
|
PubKey: carol.PubKeyStr,
|
|
|
|
Amt: int64(payAmt),
|
|
|
|
FinalCltvDelta: defaultTimeLockDelta,
|
|
|
|
}
|
2022-08-03 21:38:09 +02:00
|
|
|
routes := alice.RPC.QueryRoutes(routesReq)
|
|
|
|
require.Len(ht, routes.Routes, 1)
|
2021-06-28 22:10:33 +02:00
|
|
|
|
|
|
|
// We change the route to carry a payment of 4000 mSAT instead of 5000
|
|
|
|
// mSAT.
|
|
|
|
payAmt = btcutil.Amount(4)
|
|
|
|
amtSat := int64(payAmt)
|
|
|
|
amtMSat := int64(lnwire.NewMSatFromSatoshis(payAmt))
|
2022-08-12 09:49:54 +02:00
|
|
|
routes.Routes[0].Hops[0].AmtToForward = amtSat
|
2021-06-28 22:10:33 +02:00
|
|
|
routes.Routes[0].Hops[0].AmtToForwardMsat = amtMSat
|
2022-08-12 09:49:54 +02:00
|
|
|
routes.Routes[0].Hops[1].AmtToForward = amtSat
|
2021-06-28 22:10:33 +02:00
|
|
|
routes.Routes[0].Hops[1].AmtToForwardMsat = amtMSat
|
|
|
|
|
|
|
|
// Send the payment with the modified value.
|
2022-08-03 21:38:09 +02:00
|
|
|
alicePayStream := alice.RPC.SendToRoute()
|
|
|
|
|
2021-06-28 22:10:33 +02:00
|
|
|
sendReq := &lnrpc.SendToRouteRequest{
|
|
|
|
PaymentHash: resp.RHash,
|
|
|
|
Route: routes.Routes[0],
|
|
|
|
}
|
2022-08-03 21:38:09 +02:00
|
|
|
err := alicePayStream.Send(sendReq)
|
|
|
|
require.NoError(ht, err, "unable to send payment")
|
2021-06-28 22:10:33 +02:00
|
|
|
|
|
|
|
// We expect this payment to fail, and that the min_htlc value is
|
|
|
|
// communicated back to us, since the attempted HTLC value was too low.
|
2023-01-17 00:34:07 +01:00
|
|
|
sendResp, err := ht.ReceiveSendToRouteUpdate(alicePayStream)
|
2022-08-03 21:38:09 +02:00
|
|
|
require.NoError(ht, err, "unable to receive payment stream")
|
2021-06-28 22:10:33 +02:00
|
|
|
|
|
|
|
// Expected as part of the error message.
|
|
|
|
substrs := []string{
|
|
|
|
"AmountBelowMinimum",
|
|
|
|
"HtlcMinimumMsat: (lnwire.MilliSatoshi) 5000 mSAT",
|
|
|
|
}
|
|
|
|
for _, s := range substrs {
|
2022-08-03 21:38:09 +02:00
|
|
|
require.Contains(ht, sendResp.PaymentError, s)
|
2021-06-28 22:10:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure sending using the original value succeeds.
|
|
|
|
payAmt = btcutil.Amount(5)
|
|
|
|
amtSat = int64(payAmt)
|
|
|
|
amtMSat = int64(lnwire.NewMSatFromSatoshis(payAmt))
|
2022-08-12 09:49:54 +02:00
|
|
|
routes.Routes[0].Hops[0].AmtToForward = amtSat
|
2021-06-28 22:10:33 +02:00
|
|
|
routes.Routes[0].Hops[0].AmtToForwardMsat = amtMSat
|
2022-08-12 09:49:54 +02:00
|
|
|
routes.Routes[0].Hops[1].AmtToForward = amtSat
|
2021-06-28 22:10:33 +02:00
|
|
|
routes.Routes[0].Hops[1].AmtToForwardMsat = amtMSat
|
|
|
|
|
|
|
|
// Manually set the MPP payload a new for each payment since
|
|
|
|
// the payment addr will change with each invoice, although we
|
|
|
|
// can re-use the route itself.
|
|
|
|
route := routes.Routes[0]
|
|
|
|
route.Hops[len(route.Hops)-1].TlvPayload = true
|
|
|
|
route.Hops[len(route.Hops)-1].MppRecord = &lnrpc.MPPRecord{
|
|
|
|
PaymentAddr: resp.PaymentAddr,
|
|
|
|
TotalAmtMsat: amtMSat,
|
|
|
|
}
|
|
|
|
|
|
|
|
sendReq = &lnrpc.SendToRouteRequest{
|
|
|
|
PaymentHash: resp.RHash,
|
|
|
|
Route: route,
|
|
|
|
}
|
|
|
|
|
|
|
|
err = alicePayStream.Send(sendReq)
|
2022-08-03 21:38:09 +02:00
|
|
|
require.NoError(ht, err, "unable to send payment")
|
2021-06-28 22:10:33 +02:00
|
|
|
|
2023-01-17 00:34:07 +01:00
|
|
|
sendResp, err = ht.ReceiveSendToRouteUpdate(alicePayStream)
|
2022-08-03 21:38:09 +02:00
|
|
|
require.NoError(ht, err, "unable to receive payment stream")
|
|
|
|
require.Empty(ht, sendResp.PaymentError, "expected payment to succeed")
|
2021-06-28 22:10:33 +02:00
|
|
|
|
2024-05-20 21:17:53 +02:00
|
|
|
// With our little cluster set up, we'll update the outbound fees and
|
|
|
|
// the max htlc size for the Bob side of the Alice->Bob channel, and
|
|
|
|
// make sure all nodes learn about it. Inbound fees remain at 0.
|
2021-06-28 22:10:33 +02:00
|
|
|
baseFee := int64(1500)
|
|
|
|
feeRate := int64(12)
|
|
|
|
timeLockDelta := uint32(66)
|
|
|
|
maxHtlc := uint64(500000)
|
|
|
|
|
|
|
|
expectedPolicy = &lnrpc.RoutingPolicy{
|
|
|
|
FeeBaseMsat: baseFee,
|
|
|
|
FeeRateMilliMsat: testFeeBase * feeRate,
|
|
|
|
TimeLockDelta: timeLockDelta,
|
|
|
|
MinHtlc: defaultMinHtlc,
|
|
|
|
MaxHtlcMsat: maxHtlc,
|
|
|
|
}
|
|
|
|
|
|
|
|
req := &lnrpc.PolicyUpdateRequest{
|
|
|
|
BaseFeeMsat: baseFee,
|
|
|
|
FeeRate: float64(feeRate),
|
|
|
|
TimeLockDelta: timeLockDelta,
|
|
|
|
MaxHtlcMsat: maxHtlc,
|
|
|
|
Scope: &lnrpc.PolicyUpdateRequest_ChanPoint{
|
|
|
|
ChanPoint: chanPoint,
|
|
|
|
},
|
|
|
|
}
|
2022-08-03 21:38:09 +02:00
|
|
|
bob.RPC.UpdateChannelPolicy(req)
|
2021-06-28 22:10:33 +02:00
|
|
|
|
|
|
|
// Wait for all nodes to have seen the policy update done by Bob.
|
2022-08-03 21:38:09 +02:00
|
|
|
assertNodesPolicyUpdate(ht, nodes, bob, expectedPolicy, chanPoint)
|
2021-06-28 22:10:33 +02:00
|
|
|
|
|
|
|
// Check that all nodes now know about Bob's updated policy.
|
|
|
|
for _, node := range nodes {
|
2022-08-03 21:38:09 +02:00
|
|
|
ht.AssertChannelPolicy(
|
|
|
|
node, bob.PubKeyStr, expectedPolicy, chanPoint,
|
2021-06-28 22:10:33 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
// Note that the payment amount is >= the min_htlc value for the
|
|
|
|
// channel Bob->Carol, so it should successfully be forwarded.
|
|
|
|
payAmt = btcutil.Amount(5)
|
|
|
|
invoice = &lnrpc.Invoice{
|
|
|
|
Memo: "testing",
|
|
|
|
Value: int64(payAmt),
|
|
|
|
}
|
2022-08-03 21:38:09 +02:00
|
|
|
resp = carol.RPC.AddInvoice(invoice)
|
2021-06-28 22:10:33 +02:00
|
|
|
|
2022-08-03 21:38:09 +02:00
|
|
|
ht.CompletePaymentRequests(alice, []string{resp.PaymentRequest})
|
2021-06-28 22:10:33 +02:00
|
|
|
|
|
|
|
// We'll now open a channel from Alice directly to Carol.
|
2022-08-03 21:38:09 +02:00
|
|
|
ht.ConnectNodes(alice, carol)
|
|
|
|
chanPoint3 := ht.OpenChannel(
|
2022-08-12 11:03:44 +02:00
|
|
|
alice, carol, lntest.OpenChannelParams{
|
2021-06-28 22:10:33 +02:00
|
|
|
Amt: chanAmt,
|
|
|
|
PushAmt: pushAmt,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2022-08-03 21:38:09 +02:00
|
|
|
// Make sure Bob knows this channel.
|
|
|
|
ht.AssertTopologyChannelOpen(bob, chanPoint3)
|
2021-06-28 22:10:33 +02:00
|
|
|
|
|
|
|
// Make a global update, and check that both channels' new policies get
|
|
|
|
// propagated.
|
|
|
|
baseFee = int64(800)
|
|
|
|
feeRate = int64(123)
|
|
|
|
timeLockDelta = uint32(22)
|
|
|
|
maxHtlc *= 2
|
2024-05-20 21:17:53 +02:00
|
|
|
inboundBaseFee := int32(-400)
|
|
|
|
inboundFeeRatePpm := int32(-60)
|
2021-06-28 22:10:33 +02:00
|
|
|
|
|
|
|
expectedPolicy.FeeBaseMsat = baseFee
|
|
|
|
expectedPolicy.FeeRateMilliMsat = testFeeBase * feeRate
|
|
|
|
expectedPolicy.TimeLockDelta = timeLockDelta
|
|
|
|
expectedPolicy.MaxHtlcMsat = maxHtlc
|
2024-05-20 21:17:53 +02:00
|
|
|
expectedPolicy.InboundFeeBaseMsat = inboundBaseFee
|
|
|
|
expectedPolicy.InboundFeeRateMilliMsat = inboundFeeRatePpm
|
2021-06-28 22:10:33 +02:00
|
|
|
|
|
|
|
req = &lnrpc.PolicyUpdateRequest{
|
|
|
|
BaseFeeMsat: baseFee,
|
|
|
|
FeeRate: float64(feeRate),
|
|
|
|
TimeLockDelta: timeLockDelta,
|
|
|
|
MaxHtlcMsat: maxHtlc,
|
2024-05-20 21:17:53 +02:00
|
|
|
InboundFee: &lnrpc.InboundFee{
|
|
|
|
BaseFeeMsat: inboundBaseFee,
|
|
|
|
FeeRatePpm: inboundFeeRatePpm,
|
|
|
|
},
|
2021-06-28 22:10:33 +02:00
|
|
|
}
|
|
|
|
req.Scope = &lnrpc.PolicyUpdateRequest_Global{}
|
2022-08-03 21:38:09 +02:00
|
|
|
alice.RPC.UpdateChannelPolicy(req)
|
2021-06-28 22:10:33 +02:00
|
|
|
|
|
|
|
// Wait for all nodes to have seen the policy updates for both of
|
|
|
|
// Alice's channels.
|
2022-08-03 21:38:09 +02:00
|
|
|
assertNodesPolicyUpdate(ht, nodes, alice, expectedPolicy, chanPoint)
|
|
|
|
assertNodesPolicyUpdate(ht, nodes, alice, expectedPolicy, chanPoint3)
|
2021-06-28 22:10:33 +02:00
|
|
|
|
|
|
|
// And finally check that all nodes remembers the policy update they
|
|
|
|
// received.
|
|
|
|
for _, node := range nodes {
|
2022-08-03 21:38:09 +02:00
|
|
|
ht.AssertChannelPolicy(
|
|
|
|
node, alice.PubKeyStr, expectedPolicy, chanPoint,
|
|
|
|
)
|
|
|
|
ht.AssertChannelPolicy(
|
|
|
|
node, alice.PubKeyStr, expectedPolicy, chanPoint3,
|
2021-06-28 22:10:33 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2022-08-03 21:38:09 +02:00
|
|
|
|
|
|
|
// assertAliceAndBob is a helper closure which updates Alice's policy
|
|
|
|
// and asserts that both Alice and Bob have heard and updated the
|
|
|
|
// policy in their graph.
|
|
|
|
assertAliceAndBob := func(req *lnrpc.PolicyUpdateRequest,
|
|
|
|
expectedPolicy *lnrpc.RoutingPolicy) {
|
|
|
|
|
|
|
|
alice.RPC.UpdateChannelPolicy(req)
|
2021-06-28 22:10:33 +02:00
|
|
|
|
|
|
|
// 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.
|
2022-08-03 21:38:09 +02:00
|
|
|
assertNodesPolicyUpdate(
|
|
|
|
ht, []*node.HarnessNode{alice, bob},
|
|
|
|
alice, expectedPolicy, chanPoint,
|
2021-08-08 11:12:37 +02:00
|
|
|
)
|
2022-08-03 21:38:09 +02:00
|
|
|
assertNodesPolicyUpdate(
|
|
|
|
ht, []*node.HarnessNode{alice, bob},
|
|
|
|
alice, expectedPolicy, chanPoint3,
|
2021-08-08 11:12:37 +02:00
|
|
|
)
|
2022-09-10 18:04:56 +02:00
|
|
|
|
|
|
|
// Check that all nodes remember the policy update
|
2021-08-08 11:12:37 +02:00
|
|
|
// they received.
|
2022-08-03 21:38:09 +02:00
|
|
|
ht.AssertChannelPolicy(
|
|
|
|
alice, alice.PubKeyStr, expectedPolicy, chanPoint,
|
2021-08-08 11:12:37 +02:00
|
|
|
)
|
2022-08-03 21:38:09 +02:00
|
|
|
ht.AssertChannelPolicy(
|
|
|
|
alice, alice.PubKeyStr, expectedPolicy, chanPoint3,
|
2021-08-08 11:12:37 +02:00
|
|
|
)
|
2022-08-03 21:38:09 +02:00
|
|
|
ht.AssertChannelPolicy(
|
|
|
|
bob, alice.PubKeyStr, expectedPolicy, chanPoint,
|
2021-08-08 11:12:37 +02:00
|
|
|
)
|
2022-08-03 21:38:09 +02:00
|
|
|
ht.AssertChannelPolicy(
|
|
|
|
bob, alice.PubKeyStr, expectedPolicy, chanPoint3,
|
2021-08-08 11:12:37 +02:00
|
|
|
)
|
2021-06-28 22:10:33 +02:00
|
|
|
}
|
2022-08-03 21:38:09 +02:00
|
|
|
|
2024-05-20 21:17:53 +02:00
|
|
|
// Double the base fee and attach to the policy. Moreover, we set the
|
|
|
|
// inbound fee to nil and test that it does not change the propagated
|
|
|
|
// inbound fee.
|
2022-08-03 21:38:09 +02:00
|
|
|
baseFee1 := baseFee * 2
|
|
|
|
expectedPolicy.FeeBaseMsat = baseFee1
|
|
|
|
req.BaseFeeMsat = baseFee1
|
2024-05-20 21:17:53 +02:00
|
|
|
req.InboundFee = nil
|
2022-08-03 21:38:09 +02:00
|
|
|
assertAliceAndBob(req, expectedPolicy)
|
|
|
|
|
|
|
|
// Check that Carol has both heard the policy and updated it in her
|
|
|
|
// graph.
|
|
|
|
assertNodesPolicyUpdate(
|
|
|
|
ht, []*node.HarnessNode{carol},
|
|
|
|
alice, expectedPolicy, chanPoint,
|
|
|
|
)
|
|
|
|
assertNodesPolicyUpdate(
|
|
|
|
ht, []*node.HarnessNode{carol},
|
|
|
|
alice, expectedPolicy, chanPoint3,
|
|
|
|
)
|
|
|
|
ht.AssertChannelPolicy(
|
|
|
|
carol, alice.PubKeyStr, expectedPolicy, chanPoint,
|
|
|
|
)
|
|
|
|
ht.AssertChannelPolicy(
|
|
|
|
carol, alice.PubKeyStr, expectedPolicy, chanPoint3,
|
|
|
|
)
|
|
|
|
|
|
|
|
// Double the base fee and attach to the policy.
|
|
|
|
baseFee2 := baseFee1 * 2
|
|
|
|
expectedPolicy.FeeBaseMsat = baseFee2
|
|
|
|
req.BaseFeeMsat = baseFee2
|
|
|
|
assertAliceAndBob(req, expectedPolicy)
|
|
|
|
|
|
|
|
// Since Carol didn't receive the last update, she still has Alice's
|
|
|
|
// old policy. We validate this by checking the base fee is the older
|
|
|
|
// one.
|
|
|
|
expectedPolicy.FeeBaseMsat = baseFee1
|
|
|
|
ht.AssertChannelPolicy(
|
|
|
|
carol, alice.PubKeyStr, expectedPolicy, chanPoint,
|
|
|
|
)
|
|
|
|
ht.AssertChannelPolicy(
|
|
|
|
carol, alice.PubKeyStr, expectedPolicy, chanPoint3,
|
|
|
|
)
|
|
|
|
|
|
|
|
// Close all channels.
|
|
|
|
ht.CloseChannel(alice, chanPoint)
|
|
|
|
ht.CloseChannel(bob, chanPoint2)
|
|
|
|
ht.CloseChannel(alice, chanPoint3)
|
2021-06-28 22:10:33 +02:00
|
|
|
}
|
|
|
|
|
2021-08-07 22:50:45 +02:00
|
|
|
// testSendUpdateDisableChannel ensures that a channel update with the disable
|
|
|
|
// flag set is sent once a channel has been either unilaterally or cooperatively
|
|
|
|
// closed.
|
2022-08-03 23:37:43 +02:00
|
|
|
//
|
|
|
|
// NOTE: this test can be flaky as we are testing the chan-enable-timeout and
|
|
|
|
// chan-disable-timeout flags here. For instance, if some operations take more
|
|
|
|
// than 6 seconds to finish, the channel will be marked as disabled, thus a
|
|
|
|
// following operation will fail if it relies on the channel being enabled.
|
2022-08-12 11:03:44 +02:00
|
|
|
func testSendUpdateDisableChannel(ht *lntest.HarnessTest) {
|
2022-08-03 23:37:43 +02:00
|
|
|
const chanAmt = 100000
|
2021-08-07 22:50:45 +02:00
|
|
|
|
2022-08-03 23:37:43 +02:00
|
|
|
alice, bob := ht.Alice, ht.Bob
|
2021-08-07 22:50:45 +02:00
|
|
|
|
2022-08-03 23:37:43 +02:00
|
|
|
// Create a new node Eve, which will be restarted later with a config
|
|
|
|
// that has an inactive channel timeout of just 6 seconds (down from
|
|
|
|
// the default 20m). It will be used to test channel updates for
|
|
|
|
// channels going inactive.
|
|
|
|
//
|
|
|
|
// NOTE: we don't create Eve with the chan-disable-timeout here because
|
|
|
|
// the following channel openings might take longer than that timeout
|
|
|
|
// value, which will cause the channel Eve=>Carol being marked as
|
|
|
|
// disabled.
|
|
|
|
eve := ht.NewNode("Eve", nil)
|
|
|
|
|
|
|
|
// Create a new node Carol, which will later be restarted with the same
|
|
|
|
// config as Eve's.
|
|
|
|
carol := ht.NewNode("Carol", nil)
|
2021-08-07 22:50:45 +02:00
|
|
|
|
2022-08-03 23:37:43 +02:00
|
|
|
// Launch a node for Dave which will connect to Bob in order to receive
|
|
|
|
// graph updates from. This will ensure that the channel updates are
|
|
|
|
// propagated throughout the network.
|
|
|
|
dave := ht.NewNode("Dave", nil)
|
|
|
|
|
|
|
|
// We will start our test by creating the following topology,
|
|
|
|
// Alice --- Bob --- Dave
|
|
|
|
// | |
|
|
|
|
// Carol --- Eve
|
|
|
|
ht.EnsureConnected(alice, bob)
|
|
|
|
ht.ConnectNodes(alice, carol)
|
|
|
|
ht.ConnectNodes(bob, dave)
|
|
|
|
ht.ConnectNodes(eve, carol)
|
|
|
|
|
|
|
|
// Connect Eve and Bob using a persistent connection. Later after Eve
|
|
|
|
// is restarted, they will connect again automatically.
|
|
|
|
ht.ConnectNodesPerm(bob, eve)
|
2021-08-07 22:50:45 +02:00
|
|
|
|
|
|
|
// Give Eve some coins.
|
2022-08-03 23:37:43 +02:00
|
|
|
ht.FundCoins(btcutil.SatoshiPerBitcoin, eve)
|
|
|
|
|
|
|
|
// We now proceed to open channels: Alice=>Bob, Alice=>Carol and
|
|
|
|
// Eve=>Carol.
|
2022-08-12 11:03:44 +02:00
|
|
|
p := lntest.OpenChannelParams{Amt: chanAmt}
|
|
|
|
reqs := []*lntest.OpenChannelRequest{
|
2022-08-03 23:37:43 +02:00
|
|
|
{Local: alice, Remote: bob, Param: p},
|
|
|
|
{Local: alice, Remote: carol, Param: p},
|
|
|
|
{Local: eve, Remote: carol, Param: p},
|
|
|
|
}
|
|
|
|
resp := ht.OpenMultiChannelsAsync(reqs)
|
2021-08-07 22:50:45 +02:00
|
|
|
|
2022-08-03 23:37:43 +02:00
|
|
|
// Extract channel points from the response.
|
|
|
|
chanPointAliceBob := resp[0]
|
|
|
|
chanPointAliceCarol := resp[1]
|
|
|
|
chanPointEveCarol := resp[2]
|
2021-08-07 22:50:45 +02:00
|
|
|
|
2022-08-03 23:37:43 +02:00
|
|
|
// We will use 10 seconds as the disable timeout.
|
|
|
|
chanDisableTimeout := 10
|
|
|
|
chanEnableTimeout := 5
|
2021-08-07 22:50:45 +02:00
|
|
|
|
2022-08-03 23:37:43 +02:00
|
|
|
// waitChanDisabled is a helper closure to wait the chanDisableTimeout
|
|
|
|
// seconds such that the channel disable logic is taking effect.
|
|
|
|
waitChanDisabled := func() {
|
|
|
|
time.Sleep(time.Duration(chanDisableTimeout) * time.Second)
|
|
|
|
}
|
|
|
|
|
|
|
|
// With the channels open, we now restart Carol and Eve to use
|
|
|
|
// customized timeout values.
|
|
|
|
nodeCfg := []string{
|
|
|
|
"--minbackoff=60s",
|
|
|
|
fmt.Sprintf("--chan-enable-timeout=%ds", chanEnableTimeout),
|
|
|
|
fmt.Sprintf("--chan-disable-timeout=%ds", chanDisableTimeout),
|
|
|
|
"--chan-status-sample-interval=.5s",
|
|
|
|
}
|
|
|
|
ht.RestartNodeWithExtraArgs(carol, nodeCfg)
|
|
|
|
ht.RestartNodeWithExtraArgs(eve, nodeCfg)
|
2021-08-07 22:50:45 +02:00
|
|
|
|
2022-08-03 23:37:43 +02:00
|
|
|
// Dave should know all the channels.
|
|
|
|
ht.AssertTopologyChannelOpen(dave, chanPointAliceBob)
|
|
|
|
ht.AssertTopologyChannelOpen(dave, chanPointAliceCarol)
|
|
|
|
ht.AssertTopologyChannelOpen(dave, chanPointEveCarol)
|
2021-08-07 22:50:45 +02:00
|
|
|
|
|
|
|
// We should expect to see a channel update with the default routing
|
|
|
|
// policy, except that it should indicate the channel is disabled.
|
2021-06-28 22:10:33 +02:00
|
|
|
expectedPolicy := &lnrpc.RoutingPolicy{
|
2021-08-07 22:50:45 +02:00
|
|
|
FeeBaseMsat: int64(chainreg.DefaultBitcoinBaseFeeMSat),
|
|
|
|
FeeRateMilliMsat: int64(chainreg.DefaultBitcoinFeeRate),
|
|
|
|
TimeLockDelta: chainreg.DefaultBitcoinTimeLockDelta,
|
2021-06-28 22:10:33 +02:00
|
|
|
MinHtlc: 1000, // default value
|
2022-08-12 11:03:44 +02:00
|
|
|
MaxHtlcMsat: lntest.CalculateMaxHtlc(chanAmt),
|
2021-08-07 22:50:45 +02:00
|
|
|
Disabled: true,
|
2021-06-28 22:10:33 +02:00
|
|
|
}
|
|
|
|
|
2021-08-08 11:12:37 +02:00
|
|
|
// assertPolicyUpdate checks that the required policy update has
|
|
|
|
// happened on the given node.
|
2022-08-03 23:37:43 +02:00
|
|
|
assertPolicyUpdate := func(node *node.HarnessNode,
|
|
|
|
policy *lnrpc.RoutingPolicy, chanPoint *lnrpc.ChannelPoint,
|
|
|
|
numUpdates int) {
|
2021-08-08 11:12:37 +02:00
|
|
|
|
2022-08-03 23:37:43 +02:00
|
|
|
ht.AssertNumPolicyUpdates(dave, chanPoint, node, numUpdates)
|
|
|
|
ht.AssertChannelPolicyUpdate(
|
|
|
|
dave, node, policy, chanPoint, false,
|
2021-08-08 11:12:37 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-08-03 23:37:43 +02:00
|
|
|
// Let Carol go offline. Since Eve has an inactive timeout of 6s, we
|
2021-08-07 22:50:45 +02:00
|
|
|
// expect her to send an update disabling the channel.
|
2022-08-03 23:37:43 +02:00
|
|
|
restartCarol := ht.SuspendNode(carol)
|
2021-08-08 11:12:37 +02:00
|
|
|
|
2022-08-03 23:37:43 +02:00
|
|
|
// We expect to see a total of 2 channel policy updates from the
|
|
|
|
// channel Carol <-> Eve and advertised by Eve using the route
|
|
|
|
// Eve->Bob->Dave.
|
|
|
|
waitChanDisabled()
|
|
|
|
assertPolicyUpdate(eve, expectedPolicy, chanPointEveCarol, 2)
|
2021-08-07 22:50:45 +02:00
|
|
|
|
|
|
|
// We restart Carol. Since the channel now becomes active again, Eve
|
|
|
|
// should send a ChannelUpdate setting the channel no longer disabled.
|
2022-08-03 23:37:43 +02:00
|
|
|
require.NoError(ht, restartCarol(), "unable to restart carol")
|
2021-06-28 22:10:33 +02:00
|
|
|
|
2021-08-07 22:50:45 +02:00
|
|
|
expectedPolicy.Disabled = false
|
2022-08-03 23:37:43 +02:00
|
|
|
// We expect to see a total of 3 channel policy updates from the
|
|
|
|
// channel Carol <-> Eve and advertised by Eve using the route
|
|
|
|
// Eve->Bob->Dave.
|
|
|
|
assertPolicyUpdate(eve, expectedPolicy, chanPointEveCarol, 3)
|
2021-08-07 22:50:45 +02:00
|
|
|
|
2022-01-25 13:22:55 +01:00
|
|
|
// Wait until Carol and Eve are reconnected before we disconnect them
|
|
|
|
// again.
|
2022-08-03 23:37:43 +02:00
|
|
|
ht.EnsureConnected(eve, carol)
|
2022-01-25 13:22:55 +01:00
|
|
|
|
2021-08-07 22:50:45 +02:00
|
|
|
// Now we'll test a long disconnection. Disconnect Carol and Eve and
|
|
|
|
// ensure they both detect each other as disabled. Their min backoffs
|
|
|
|
// are high enough to not interfere with disabling logic.
|
2022-08-03 23:37:43 +02:00
|
|
|
ht.DisconnectNodes(carol, eve)
|
2021-06-28 22:10:33 +02:00
|
|
|
|
2021-08-07 22:50:45 +02:00
|
|
|
// Wait for a disable from both Carol and Eve to come through.
|
|
|
|
expectedPolicy.Disabled = true
|
2022-08-03 23:37:43 +02:00
|
|
|
// We expect to see a total of 4 channel policy updates from the
|
|
|
|
// channel Carol <-> Eve and advertised by Eve using the route
|
|
|
|
// Eve->Bob->Dave.
|
|
|
|
waitChanDisabled()
|
|
|
|
assertPolicyUpdate(eve, expectedPolicy, chanPointEveCarol, 4)
|
|
|
|
|
|
|
|
// Because Carol has restarted twice before, depending on how much time
|
|
|
|
// it has taken, she might mark the channel disabled and enable it
|
|
|
|
// multiple times. Thus we could see a total of 2 or 4 or 6 channel
|
|
|
|
// policy updates from the channel Carol <-> Eve and advertised by
|
|
|
|
// Carol using the route Carol->Alice->Bob->Dave.
|
|
|
|
//
|
|
|
|
// Assume there are 2 channel policy updates from Carol, and update it
|
|
|
|
// if more has found
|
|
|
|
numCarol := 2
|
|
|
|
op := ht.OutPointFromChannelPoint(chanPointEveCarol)
|
|
|
|
policyMap := dave.Watcher.GetPolicyUpdates(op)
|
|
|
|
nodePolicy, ok := policyMap[carol.PubKeyStr]
|
|
|
|
switch {
|
|
|
|
case !ok:
|
|
|
|
break
|
|
|
|
case len(nodePolicy) > 2:
|
|
|
|
numCarol = 4
|
|
|
|
case len(nodePolicy) > 4:
|
|
|
|
numCarol = 6
|
|
|
|
}
|
|
|
|
assertPolicyUpdate(carol, expectedPolicy, chanPointEveCarol, numCarol)
|
2021-08-07 22:50:45 +02:00
|
|
|
|
|
|
|
// Reconnect Carol and Eve, this should cause them to reenable the
|
|
|
|
// channel from both ends after a short delay.
|
2022-08-03 23:37:43 +02:00
|
|
|
ht.EnsureConnected(carol, eve)
|
2021-08-07 22:50:45 +02:00
|
|
|
|
|
|
|
expectedPolicy.Disabled = false
|
2022-08-03 23:37:43 +02:00
|
|
|
// We expect to see a total of 5 channel policy updates from the
|
|
|
|
// channel Carol <-> Eve and advertised by Eve using the route
|
|
|
|
// Eve->Bob->Dave.
|
|
|
|
assertPolicyUpdate(eve, expectedPolicy, chanPointEveCarol, 5)
|
|
|
|
// We expect to see a total of 3 or 5 channel policy updates from the
|
|
|
|
// channel Carol <-> Eve and advertised by Carol using the route
|
|
|
|
// Carol->Alice->Bob->Dave.
|
|
|
|
numCarol++
|
|
|
|
assertPolicyUpdate(carol, expectedPolicy, chanPointEveCarol, numCarol)
|
2021-08-07 22:50:45 +02:00
|
|
|
|
|
|
|
// Now we'll test a short disconnection. Disconnect Carol and Eve, then
|
|
|
|
// reconnect them after one second so that their scheduled disables are
|
|
|
|
// aborted. One second is twice the status sample interval, so this
|
|
|
|
// should allow for the disconnect to be detected, but still leave time
|
2022-08-03 23:37:43 +02:00
|
|
|
// to cancel the announcement before the 6 second inactive timeout is
|
2021-08-07 22:50:45 +02:00
|
|
|
// hit.
|
2022-08-03 23:37:43 +02:00
|
|
|
ht.DisconnectNodes(carol, eve)
|
2021-08-07 22:50:45 +02:00
|
|
|
time.Sleep(time.Second)
|
2022-08-03 23:37:43 +02:00
|
|
|
ht.EnsureConnected(eve, carol)
|
2021-08-07 22:50:45 +02:00
|
|
|
|
2022-08-03 23:37:43 +02:00
|
|
|
// Since the disable should have been canceled by both Carol and Eve,
|
|
|
|
// we expect no channel updates to appear on the network, which means
|
|
|
|
// we expect the polices stay unchanged(Disable == false).
|
|
|
|
assertPolicyUpdate(eve, expectedPolicy, chanPointEveCarol, 5)
|
|
|
|
assertPolicyUpdate(carol, expectedPolicy, chanPointEveCarol, numCarol)
|
2021-08-07 22:50:45 +02:00
|
|
|
|
|
|
|
// Close Alice's channels with Bob and Carol cooperatively and
|
2022-08-03 23:37:43 +02:00
|
|
|
// unilaterally respectively. Note that the CloseChannel will mine a
|
|
|
|
// block and check that the closing transaction can be found in both
|
|
|
|
// the mempool and the block.
|
|
|
|
ht.CloseChannel(alice, chanPointAliceBob)
|
|
|
|
ht.ForceCloseChannel(alice, chanPointAliceCarol)
|
2021-08-07 22:50:45 +02:00
|
|
|
|
|
|
|
// Now that the channel close processes have been started, we should
|
|
|
|
// receive an update marking each as disabled.
|
|
|
|
expectedPolicy.Disabled = true
|
2022-08-03 23:37:43 +02:00
|
|
|
// We expect to see a total of 2 channel policy updates from the
|
|
|
|
// channel Alice <-> Bob and advertised by Alice using the route
|
|
|
|
// Alice->Bob->Dave.
|
|
|
|
assertPolicyUpdate(alice, expectedPolicy, chanPointAliceBob, 2)
|
|
|
|
// We expect to see a total of 2 channel policy updates from the
|
|
|
|
// channel Alice <-> Carol and advertised by Alice using the route
|
|
|
|
// Alice->Bob->Dave.
|
|
|
|
assertPolicyUpdate(alice, expectedPolicy, chanPointAliceCarol, 2)
|
2021-08-07 22:50:45 +02:00
|
|
|
|
|
|
|
// Also do this check for Eve's channel with Carol.
|
2022-08-03 23:37:43 +02:00
|
|
|
ht.CloseChannel(eve, chanPointEveCarol)
|
2021-08-07 22:50:45 +02:00
|
|
|
|
2022-08-03 23:37:43 +02:00
|
|
|
// We expect to see a total of 5 channel policy updates from the
|
|
|
|
// channel Carol <-> Eve and advertised by Eve using the route
|
|
|
|
// Eve->Bob->Dave.
|
|
|
|
assertPolicyUpdate(eve, expectedPolicy, chanPointEveCarol, 6)
|
2021-08-07 22:50:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// testUpdateChannelPolicyForPrivateChannel tests when a private channel
|
|
|
|
// updates its channel edge policy, we will use the updated policy to send our
|
|
|
|
// payment.
|
|
|
|
// The topology is created as: Alice -> Bob -> Carol, where Alice -> Bob is
|
|
|
|
// public and Bob -> Carol is private. After an invoice is created by Carol,
|
|
|
|
// Bob will update the base fee via UpdateChannelPolicy, we will test that
|
|
|
|
// Alice will not fail the payment and send it using the updated channel
|
|
|
|
// policy.
|
2022-08-12 11:03:44 +02:00
|
|
|
func testUpdateChannelPolicyForPrivateChannel(ht *lntest.HarnessTest) {
|
2022-08-04 00:10:44 +02:00
|
|
|
const (
|
|
|
|
chanAmt = btcutil.Amount(100000)
|
|
|
|
paymentAmt = 20000
|
|
|
|
baseFeeMSat = 33000
|
|
|
|
)
|
2021-08-07 22:50:45 +02:00
|
|
|
|
|
|
|
// We'll create the following topology first,
|
|
|
|
// Alice <--public:100k--> Bob <--private:100k--> Carol
|
2022-08-04 00:10:44 +02:00
|
|
|
alice, bob := ht.Alice, ht.Bob
|
2021-08-07 22:50:45 +02:00
|
|
|
|
|
|
|
// Open a channel with 100k satoshis between Alice and Bob.
|
2022-08-04 00:10:44 +02:00
|
|
|
chanPointAliceBob := ht.OpenChannel(
|
2022-08-12 11:03:44 +02:00
|
|
|
alice, bob, lntest.OpenChannelParams{
|
2021-08-07 22:50:45 +02:00
|
|
|
Amt: chanAmt,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
// Create a new node Carol.
|
2022-08-04 00:10:44 +02:00
|
|
|
carol := ht.NewNode("Carol", nil)
|
2021-08-07 22:50:45 +02:00
|
|
|
|
|
|
|
// Connect Carol to Bob.
|
2022-08-04 00:10:44 +02:00
|
|
|
ht.ConnectNodes(carol, bob)
|
2021-08-07 22:50:45 +02:00
|
|
|
|
|
|
|
// Open a channel with 100k satoshis between Bob and Carol.
|
2022-08-04 00:10:44 +02:00
|
|
|
chanPointBobCarol := ht.OpenChannel(
|
2022-08-12 11:03:44 +02:00
|
|
|
bob, carol, lntest.OpenChannelParams{
|
2021-08-07 22:50:45 +02:00
|
|
|
Amt: chanAmt,
|
|
|
|
Private: true,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2022-11-08 07:15:38 +01:00
|
|
|
// Carol should be aware of the channel between Alice and Bob.
|
2022-08-04 00:10:44 +02:00
|
|
|
ht.AssertTopologyChannelOpen(carol, chanPointAliceBob)
|
2021-08-07 22:50:45 +02:00
|
|
|
|
|
|
|
// We should have the following topology now,
|
|
|
|
// Alice <--public:100k--> Bob <--private:100k--> Carol
|
|
|
|
//
|
|
|
|
// Now we will create an invoice for Carol.
|
|
|
|
invoice := &lnrpc.Invoice{
|
|
|
|
Memo: "routing hints",
|
|
|
|
Value: paymentAmt,
|
|
|
|
Private: true,
|
|
|
|
}
|
2022-08-04 00:10:44 +02:00
|
|
|
resp := carol.RPC.AddInvoice(invoice)
|
2021-08-07 22:50:45 +02:00
|
|
|
|
|
|
|
// Bob now updates the channel edge policy for the private channel.
|
|
|
|
timeLockDelta := uint32(chainreg.DefaultBitcoinTimeLockDelta)
|
|
|
|
updateFeeReq := &lnrpc.PolicyUpdateRequest{
|
|
|
|
BaseFeeMsat: baseFeeMSat,
|
|
|
|
TimeLockDelta: timeLockDelta,
|
|
|
|
Scope: &lnrpc.PolicyUpdateRequest_ChanPoint{
|
|
|
|
ChanPoint: chanPointBobCarol,
|
|
|
|
},
|
|
|
|
}
|
2022-08-04 00:10:44 +02:00
|
|
|
bob.RPC.UpdateChannelPolicy(updateFeeReq)
|
2021-08-07 22:50:45 +02:00
|
|
|
|
|
|
|
// Alice pays the invoices. She will use the updated baseFeeMSat in the
|
|
|
|
// payment
|
2022-11-14 10:27:49 +01:00
|
|
|
//
|
|
|
|
// TODO(yy): we may get a flake saying the timeout checking the
|
|
|
|
// payment's state, which is due to slow round of HTLC settlement. An
|
|
|
|
// example log is shown below, where Alice sent RevokeAndAck to Bob,
|
|
|
|
// but it took Bob 7 seconds to reply back the final UpdateFulfillHTLC.
|
|
|
|
//
|
|
|
|
// 2022-11-14 06:23:59.774 PEER: Peer(Bob): Sending UpdateAddHTLC
|
|
|
|
// 2022-11-14 06:24:00.635 PEER: Peer(Bob): Sending CommitSig
|
|
|
|
// 2022-11-14 06:24:01.784 PEER: Peer(Bob): Sending RevokeAndAck
|
|
|
|
// 2022-11-14 06:24:08.464 PEER: Peer(Bob): Received UpdateFulfillHTLC
|
|
|
|
//
|
|
|
|
// 7 seconds is too long for a local test and this needs more
|
|
|
|
// investigation.
|
2021-08-07 22:50:45 +02:00
|
|
|
payReqs := []string{resp.PaymentRequest}
|
2022-08-04 00:10:44 +02:00
|
|
|
ht.CompletePaymentRequests(alice, payReqs)
|
2021-08-07 22:50:45 +02:00
|
|
|
|
|
|
|
// Check that Alice did make the payment with two HTLCs, one failed and
|
|
|
|
// one succeeded.
|
2022-08-04 00:10:44 +02:00
|
|
|
payment := ht.AssertNumPayments(alice, 1)[0]
|
|
|
|
|
|
|
|
htlcs := payment.Htlcs
|
|
|
|
require.Equal(ht, 2, len(htlcs), "expected to have 2 HTLCs")
|
|
|
|
require.Equal(ht, lnrpc.HTLCAttempt_FAILED, htlcs[0].Status,
|
|
|
|
"the first HTLC attempt should fail")
|
|
|
|
require.Equal(ht, lnrpc.HTLCAttempt_SUCCEEDED, htlcs[1].Status,
|
|
|
|
"the second HTLC attempt should succeed")
|
2021-08-07 22:50:45 +02:00
|
|
|
|
|
|
|
// Carol should have received 20k satoshis from Bob.
|
2022-08-04 00:10:44 +02:00
|
|
|
ht.AssertAmountPaid("Carol(remote) [<=private] Bob(local)",
|
|
|
|
carol, chanPointBobCarol, 0, paymentAmt)
|
2021-08-07 22:50:45 +02:00
|
|
|
|
|
|
|
// Bob should have sent 20k satoshis to Carol.
|
2022-08-04 00:10:44 +02:00
|
|
|
ht.AssertAmountPaid("Bob(local) [private=>] Carol(remote)",
|
|
|
|
bob, chanPointBobCarol, paymentAmt, 0)
|
2021-08-07 22:50:45 +02:00
|
|
|
|
2022-01-13 17:29:43 +01:00
|
|
|
// Calculate the amount in satoshis.
|
2021-08-07 22:50:45 +02:00
|
|
|
amtExpected := int64(paymentAmt + baseFeeMSat/1000)
|
|
|
|
|
|
|
|
// Bob should have received 20k satoshis + fee from Alice.
|
2022-08-04 00:10:44 +02:00
|
|
|
ht.AssertAmountPaid("Bob(remote) <= Alice(local)",
|
|
|
|
bob, chanPointAliceBob, 0, amtExpected)
|
2021-08-07 22:50:45 +02:00
|
|
|
|
|
|
|
// Alice should have sent 20k satoshis + fee to Bob.
|
2022-08-04 00:10:44 +02:00
|
|
|
ht.AssertAmountPaid("Alice(local) => Bob(remote)",
|
|
|
|
alice, chanPointAliceBob, amtExpected, 0)
|
|
|
|
|
|
|
|
// Finally, close the channels.
|
|
|
|
ht.CloseChannel(alice, chanPointAliceBob)
|
|
|
|
ht.CloseChannel(bob, chanPointBobCarol)
|
2021-06-28 22:10:33 +02:00
|
|
|
}
|
2022-01-25 17:48:07 +01:00
|
|
|
|
|
|
|
// testUpdateChannelPolicyFeeRateAccuracy tests that updating the channel policy
|
|
|
|
// rounds fee rate values correctly as well as setting fee rate with ppm works
|
|
|
|
// as expected.
|
2022-08-12 11:03:44 +02:00
|
|
|
func testUpdateChannelPolicyFeeRateAccuracy(ht *lntest.HarnessTest) {
|
2022-01-25 17:48:07 +01:00
|
|
|
chanAmt := funding.MaxBtcFundingAmount
|
|
|
|
pushAmt := chanAmt / 2
|
|
|
|
|
|
|
|
// Create a channel Alice -> Bob.
|
2022-08-04 00:14:06 +02:00
|
|
|
alice, bob := ht.Alice, ht.Bob
|
|
|
|
chanPoint := ht.OpenChannel(
|
2022-08-12 11:03:44 +02:00
|
|
|
alice, bob, lntest.OpenChannelParams{
|
2022-01-25 17:48:07 +01:00
|
|
|
Amt: chanAmt,
|
|
|
|
PushAmt: pushAmt,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
// Nodes that we need to make sure receive the channel updates.
|
2022-08-04 00:14:06 +02:00
|
|
|
nodes := []*node.HarnessNode{alice, bob}
|
2022-01-25 17:48:07 +01:00
|
|
|
|
|
|
|
baseFee := int64(1500)
|
|
|
|
timeLockDelta := uint32(66)
|
|
|
|
maxHtlc := uint64(500000)
|
|
|
|
defaultMinHtlc := int64(1000)
|
|
|
|
|
|
|
|
// Originally LND did not properly round up fee rates which caused
|
|
|
|
// inaccuracy where fee rates were simply rounded down due to the
|
|
|
|
// integer conversion.
|
|
|
|
//
|
|
|
|
// We'll use a fee rate of 0.031337 which without rounding up would
|
|
|
|
// have resulted in a fee rate ppm of 31336.
|
|
|
|
feeRate := 0.031337
|
|
|
|
|
|
|
|
// Expected fee rate will be rounded up.
|
|
|
|
expectedFeeRateMilliMsat := int64(math.Round(testFeeBase * feeRate))
|
|
|
|
|
|
|
|
expectedPolicy := &lnrpc.RoutingPolicy{
|
|
|
|
FeeBaseMsat: baseFee,
|
|
|
|
FeeRateMilliMsat: expectedFeeRateMilliMsat,
|
|
|
|
TimeLockDelta: timeLockDelta,
|
|
|
|
MinHtlc: defaultMinHtlc,
|
|
|
|
MaxHtlcMsat: maxHtlc,
|
|
|
|
}
|
|
|
|
|
|
|
|
req := &lnrpc.PolicyUpdateRequest{
|
|
|
|
BaseFeeMsat: baseFee,
|
|
|
|
FeeRate: feeRate,
|
|
|
|
TimeLockDelta: timeLockDelta,
|
|
|
|
MaxHtlcMsat: maxHtlc,
|
|
|
|
Scope: &lnrpc.PolicyUpdateRequest_ChanPoint{
|
|
|
|
ChanPoint: chanPoint,
|
|
|
|
},
|
|
|
|
}
|
2022-08-04 00:14:06 +02:00
|
|
|
alice.RPC.UpdateChannelPolicy(req)
|
2022-01-25 17:48:07 +01:00
|
|
|
|
|
|
|
// Make sure that both Alice and Bob sees the same policy after update.
|
2022-08-04 00:14:06 +02:00
|
|
|
assertNodesPolicyUpdate(ht, nodes, alice, expectedPolicy, chanPoint)
|
2022-01-25 17:48:07 +01:00
|
|
|
|
|
|
|
// Now use the new PPM feerate field and make sure that the feerate is
|
|
|
|
// correctly set.
|
|
|
|
feeRatePPM := uint32(32337)
|
|
|
|
req.FeeRate = 0 // Can't set both at the same time.
|
|
|
|
req.FeeRatePpm = feeRatePPM
|
|
|
|
expectedPolicy.FeeRateMilliMsat = int64(feeRatePPM)
|
|
|
|
|
2022-08-04 00:14:06 +02:00
|
|
|
alice.RPC.UpdateChannelPolicy(req)
|
2022-01-25 17:48:07 +01:00
|
|
|
|
|
|
|
// Make sure that both Alice and Bob sees the same policy after update.
|
2022-08-04 00:14:06 +02:00
|
|
|
assertNodesPolicyUpdate(ht, nodes, alice, expectedPolicy, chanPoint)
|
|
|
|
|
|
|
|
ht.CloseChannel(alice, chanPoint)
|
2022-01-25 17:48:07 +01:00
|
|
|
}
|
2022-08-03 21:38:09 +02:00
|
|
|
|
|
|
|
// assertNodesPolicyUpdate checks that a given policy update has been received
|
|
|
|
// by a list of given nodes.
|
2022-08-12 11:03:44 +02:00
|
|
|
func assertNodesPolicyUpdate(ht *lntest.HarnessTest, nodes []*node.HarnessNode,
|
2022-08-03 21:38:09 +02:00
|
|
|
advertisingNode *node.HarnessNode, policy *lnrpc.RoutingPolicy,
|
|
|
|
chanPoint *lnrpc.ChannelPoint) {
|
|
|
|
|
|
|
|
for _, node := range nodes {
|
|
|
|
ht.AssertChannelPolicyUpdate(
|
|
|
|
node, advertisingNode, policy, chanPoint, false,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|