mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-31 08:02:25 +02:00
itest: add more tests related to inbound fees
Add tests for setting inbound fees in channel policies, including tests where no inbound fees are set in the PolicyUpdateRequest.
This commit is contained in:
@@ -45,7 +45,9 @@ func testUpdateChannelPolicy(ht *lntest.HarnessTest) {
|
|||||||
nodes := []*node.HarnessNode{alice, bob}
|
nodes := []*node.HarnessNode{alice, bob}
|
||||||
|
|
||||||
// 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. We do not currently set any inbound fees.
|
||||||
|
// The inbound base and inbound fee rate are advertised with a default
|
||||||
|
// of 0.
|
||||||
expectedPolicy := &lnrpc.RoutingPolicy{
|
expectedPolicy := &lnrpc.RoutingPolicy{
|
||||||
FeeBaseMsat: defaultFeeBase,
|
FeeBaseMsat: defaultFeeBase,
|
||||||
FeeRateMilliMsat: defaultFeeRate,
|
FeeRateMilliMsat: defaultFeeRate,
|
||||||
@@ -227,9 +229,9 @@ func testUpdateChannelPolicy(ht *lntest.HarnessTest) {
|
|||||||
require.NoError(ht, err, "unable to receive payment stream")
|
require.NoError(ht, err, "unable to receive payment stream")
|
||||||
require.Empty(ht, sendResp.PaymentError, "expected payment to succeed")
|
require.Empty(ht, sendResp.PaymentError, "expected payment to succeed")
|
||||||
|
|
||||||
// With our little cluster set up, we'll update the fees and the max
|
// With our little cluster set up, we'll update the outbound fees and
|
||||||
// htlc size for the Bob side of the Alice->Bob channel, and make sure
|
// the max htlc size for the Bob side of the Alice->Bob channel, and
|
||||||
// all nodes learn about it.
|
// make sure all nodes learn about it. Inbound fees remain at 0.
|
||||||
baseFee := int64(1500)
|
baseFee := int64(1500)
|
||||||
feeRate := int64(12)
|
feeRate := int64(12)
|
||||||
timeLockDelta := uint32(66)
|
timeLockDelta := uint32(66)
|
||||||
@@ -298,17 +300,25 @@ func testUpdateChannelPolicy(ht *lntest.HarnessTest) {
|
|||||||
feeRate = int64(123)
|
feeRate = int64(123)
|
||||||
timeLockDelta = uint32(22)
|
timeLockDelta = uint32(22)
|
||||||
maxHtlc *= 2
|
maxHtlc *= 2
|
||||||
|
inboundBaseFee := int32(-400)
|
||||||
|
inboundFeeRatePpm := int32(-60)
|
||||||
|
|
||||||
expectedPolicy.FeeBaseMsat = baseFee
|
expectedPolicy.FeeBaseMsat = baseFee
|
||||||
expectedPolicy.FeeRateMilliMsat = testFeeBase * feeRate
|
expectedPolicy.FeeRateMilliMsat = testFeeBase * feeRate
|
||||||
expectedPolicy.TimeLockDelta = timeLockDelta
|
expectedPolicy.TimeLockDelta = timeLockDelta
|
||||||
expectedPolicy.MaxHtlcMsat = maxHtlc
|
expectedPolicy.MaxHtlcMsat = maxHtlc
|
||||||
|
expectedPolicy.InboundFeeBaseMsat = inboundBaseFee
|
||||||
|
expectedPolicy.InboundFeeRateMilliMsat = inboundFeeRatePpm
|
||||||
|
|
||||||
req = &lnrpc.PolicyUpdateRequest{
|
req = &lnrpc.PolicyUpdateRequest{
|
||||||
BaseFeeMsat: baseFee,
|
BaseFeeMsat: baseFee,
|
||||||
FeeRate: float64(feeRate),
|
FeeRate: float64(feeRate),
|
||||||
TimeLockDelta: timeLockDelta,
|
TimeLockDelta: timeLockDelta,
|
||||||
MaxHtlcMsat: maxHtlc,
|
MaxHtlcMsat: maxHtlc,
|
||||||
|
InboundFee: &lnrpc.InboundFee{
|
||||||
|
BaseFeeMsat: inboundBaseFee,
|
||||||
|
FeeRatePpm: inboundFeeRatePpm,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
req.Scope = &lnrpc.PolicyUpdateRequest_Global{}
|
req.Scope = &lnrpc.PolicyUpdateRequest_Global{}
|
||||||
alice.RPC.UpdateChannelPolicy(req)
|
alice.RPC.UpdateChannelPolicy(req)
|
||||||
@@ -370,10 +380,13 @@ func testUpdateChannelPolicy(ht *lntest.HarnessTest) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Double the base fee and attach to the policy.
|
// 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.
|
||||||
baseFee1 := baseFee * 2
|
baseFee1 := baseFee * 2
|
||||||
expectedPolicy.FeeBaseMsat = baseFee1
|
expectedPolicy.FeeBaseMsat = baseFee1
|
||||||
req.BaseFeeMsat = baseFee1
|
req.BaseFeeMsat = baseFee1
|
||||||
|
req.InboundFee = nil
|
||||||
assertAliceAndBob(req, expectedPolicy)
|
assertAliceAndBob(req, expectedPolicy)
|
||||||
|
|
||||||
// Check that Carol has both heard the policy and updated it in her
|
// Check that Carol has both heard the policy and updated it in her
|
||||||
|
@@ -74,8 +74,8 @@ func testMultiHopPayments(ht *lntest.HarnessTest) {
|
|||||||
const aliceFeeRatePPM = 100000
|
const aliceFeeRatePPM = 100000
|
||||||
updateChannelPolicy(
|
updateChannelPolicy(
|
||||||
ht, alice, chanPointAlice, aliceBaseFeeSat*1000,
|
ht, alice, chanPointAlice, aliceBaseFeeSat*1000,
|
||||||
aliceFeeRatePPM, 0, 0, chainreg.DefaultBitcoinTimeLockDelta,
|
aliceFeeRatePPM, 0, 0, false,
|
||||||
maxHtlc, carol,
|
chainreg.DefaultBitcoinTimeLockDelta, maxHtlc, carol,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Define a negative inbound fee for Alice, to verify that this is
|
// Define a negative inbound fee for Alice, to verify that this is
|
||||||
@@ -85,9 +85,19 @@ func testMultiHopPayments(ht *lntest.HarnessTest) {
|
|||||||
aliceInboundFeeRate = -50000 // 5%
|
aliceInboundFeeRate = -50000 // 5%
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// We update the channel twice. The first time we set the inbound fee,
|
||||||
|
// the second time we don't. This is done to test whether the switch is
|
||||||
|
// still aware of the inbound fees.
|
||||||
updateChannelPolicy(
|
updateChannelPolicy(
|
||||||
ht, alice, chanPointDave, 0, 0,
|
ht, alice, chanPointDave, 0, 0,
|
||||||
aliceInboundBaseFeeMsat, aliceInboundFeeRate,
|
aliceInboundBaseFeeMsat, aliceInboundFeeRate, true,
|
||||||
|
chainreg.DefaultBitcoinTimeLockDelta, maxHtlc,
|
||||||
|
dave,
|
||||||
|
)
|
||||||
|
|
||||||
|
updateChannelPolicy(
|
||||||
|
ht, alice, chanPointDave, 0, 0,
|
||||||
|
aliceInboundBaseFeeMsat, aliceInboundFeeRate, false,
|
||||||
chainreg.DefaultBitcoinTimeLockDelta, maxHtlc,
|
chainreg.DefaultBitcoinTimeLockDelta, maxHtlc,
|
||||||
dave,
|
dave,
|
||||||
)
|
)
|
||||||
@@ -96,7 +106,7 @@ func testMultiHopPayments(ht *lntest.HarnessTest) {
|
|||||||
const daveFeeRatePPM = 150000
|
const daveFeeRatePPM = 150000
|
||||||
updateChannelPolicy(
|
updateChannelPolicy(
|
||||||
ht, dave, chanPointDave, daveBaseFeeSat*1000, daveFeeRatePPM,
|
ht, dave, chanPointDave, daveBaseFeeSat*1000, daveFeeRatePPM,
|
||||||
0, 0,
|
0, 0, true,
|
||||||
chainreg.DefaultBitcoinTimeLockDelta, maxHtlc, carol,
|
chainreg.DefaultBitcoinTimeLockDelta, maxHtlc, carol,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -236,8 +246,8 @@ func testMultiHopPayments(ht *lntest.HarnessTest) {
|
|||||||
//
|
//
|
||||||
// NOTE: only used in current test.
|
// NOTE: only used in current test.
|
||||||
func updateChannelPolicy(ht *lntest.HarnessTest, hn *node.HarnessNode,
|
func updateChannelPolicy(ht *lntest.HarnessTest, hn *node.HarnessNode,
|
||||||
chanPoint *lnrpc.ChannelPoint, baseFee int64,
|
chanPoint *lnrpc.ChannelPoint, baseFee int64, feeRate int64,
|
||||||
feeRate int64, inboundBaseFee, inboundFeeRate int32,
|
inboundBaseFee, inboundFeeRate int32, updateInboundFee bool,
|
||||||
timeLockDelta uint32, maxHtlc uint64, listenerNode *node.HarnessNode) {
|
timeLockDelta uint32, maxHtlc uint64, listenerNode *node.HarnessNode) {
|
||||||
|
|
||||||
expectedPolicy := &lnrpc.RoutingPolicy{
|
expectedPolicy := &lnrpc.RoutingPolicy{
|
||||||
@@ -250,6 +260,14 @@ func updateChannelPolicy(ht *lntest.HarnessTest, hn *node.HarnessNode,
|
|||||||
InboundFeeRateMilliMsat: inboundFeeRate,
|
InboundFeeRateMilliMsat: inboundFeeRate,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var inboundFee *lnrpc.InboundFee
|
||||||
|
if updateInboundFee {
|
||||||
|
inboundFee = &lnrpc.InboundFee{
|
||||||
|
BaseFeeMsat: inboundBaseFee,
|
||||||
|
FeeRatePpm: inboundFeeRate,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
updateFeeReq := &lnrpc.PolicyUpdateRequest{
|
updateFeeReq := &lnrpc.PolicyUpdateRequest{
|
||||||
BaseFeeMsat: baseFee,
|
BaseFeeMsat: baseFee,
|
||||||
FeeRate: float64(feeRate) / testFeeBase,
|
FeeRate: float64(feeRate) / testFeeBase,
|
||||||
@@ -258,10 +276,7 @@ func updateChannelPolicy(ht *lntest.HarnessTest, hn *node.HarnessNode,
|
|||||||
ChanPoint: chanPoint,
|
ChanPoint: chanPoint,
|
||||||
},
|
},
|
||||||
MaxHtlcMsat: maxHtlc,
|
MaxHtlcMsat: maxHtlc,
|
||||||
InboundFee: &lnrpc.InboundFee{
|
InboundFee: inboundFee,
|
||||||
BaseFeeMsat: inboundBaseFee,
|
|
||||||
FeeRatePpm: inboundFeeRate,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hn.RPC.UpdateChannelPolicy(updateFeeReq)
|
hn.RPC.UpdateChannelPolicy(updateFeeReq)
|
||||||
|
@@ -681,6 +681,18 @@ func CheckChannelPolicy(policy, expectedPolicy *lnrpc.RoutingPolicy) error {
|
|||||||
return fmt.Errorf("expected max htlc %v, got %v",
|
return fmt.Errorf("expected max htlc %v, got %v",
|
||||||
expectedPolicy.MaxHtlcMsat, policy.MaxHtlcMsat)
|
expectedPolicy.MaxHtlcMsat, policy.MaxHtlcMsat)
|
||||||
}
|
}
|
||||||
|
if policy.InboundFeeBaseMsat != expectedPolicy.InboundFeeBaseMsat {
|
||||||
|
return fmt.Errorf("expected inbound base fee %v, got %v",
|
||||||
|
expectedPolicy.InboundFeeBaseMsat,
|
||||||
|
policy.InboundFeeBaseMsat)
|
||||||
|
}
|
||||||
|
if policy.InboundFeeRateMilliMsat !=
|
||||||
|
expectedPolicy.InboundFeeRateMilliMsat {
|
||||||
|
|
||||||
|
return fmt.Errorf("expected inbound fee rate %v, got %v",
|
||||||
|
expectedPolicy.InboundFeeRateMilliMsat,
|
||||||
|
policy.InboundFeeRateMilliMsat)
|
||||||
|
}
|
||||||
if policy.Disabled != expectedPolicy.Disabled {
|
if policy.Disabled != expectedPolicy.Disabled {
|
||||||
return errors.New("edge should be disabled but isn't")
|
return errors.New("edge should be disabled but isn't")
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user