mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-22 06:42:40 +02:00
itest: update channel open test to send payment
This commit enhances the custom fee policy channel open test by adding a second channel and testing forwarding payments through the channel with the custom forwarding policies. This was able to reproduce the bug reported in #5796 which was fixed in a previous commit of this PR.
This commit is contained in:
parent
ebf11bc2f1
commit
1eebbe3f42
@ -5,6 +5,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcjson"
|
"github.com/btcsuite/btcd/btcjson"
|
||||||
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
"github.com/btcsuite/btcd/integration/rpctest"
|
"github.com/btcsuite/btcd/integration/rpctest"
|
||||||
"github.com/lightningnetwork/lnd/chainreg"
|
"github.com/lightningnetwork/lnd/chainreg"
|
||||||
@ -159,19 +160,22 @@ func testOpenChannelAfterReorg(ht *lntest.HarnessTest) {
|
|||||||
ht.CloseChannel(alice, chanPoint)
|
ht.CloseChannel(alice, chanPoint)
|
||||||
}
|
}
|
||||||
|
|
||||||
// testOpenChannelFeePolicy checks if different channel fee scenarios
|
// testOpenChannelFeePolicy checks if different channel fee scenarios are
|
||||||
// are correctly handled when the optional channel fee parameters
|
// correctly handled when the optional channel fee parameters baseFee and
|
||||||
// baseFee and feeRate are provided. If the OpenChannelRequest is not
|
// feeRate are provided. If the OpenChannelRequest is not provided with a value
|
||||||
// provided with a value for baseFee/feeRate the expectation is that the
|
// for baseFee/feeRate the expectation is that the default baseFee/feeRate is
|
||||||
// default baseFee/feeRate is applied.
|
// applied.
|
||||||
// 1.) no params provided to OpenChannelRequest
|
//
|
||||||
// ChannelUpdate --> defaultBaseFee, defaultFeeRate
|
// 1. No params provided to OpenChannelRequest:
|
||||||
// 2.) only baseFee provided to OpenChannelRequest
|
// ChannelUpdate --> defaultBaseFee, defaultFeeRate
|
||||||
// ChannelUpdate --> provided baseFee, defaultFeeRate
|
// 2. Only baseFee provided to OpenChannelRequest:
|
||||||
// 3.) only feeRate provided to OpenChannelRequest
|
// ChannelUpdate --> provided baseFee, defaultFeeRate
|
||||||
// ChannelUpdate --> defaultBaseFee, provided FeeRate
|
// 3. Only feeRate provided to OpenChannelRequest:
|
||||||
// 4.) baseFee and feeRate provided to OpenChannelRequest
|
// ChannelUpdate --> defaultBaseFee, provided FeeRate
|
||||||
// ChannelUpdate --> provided baseFee, provided feeRate.
|
// 4. baseFee and feeRate provided to OpenChannelRequest:
|
||||||
|
// ChannelUpdate --> provided baseFee, provided feeRate
|
||||||
|
// 5. Both baseFee and feeRate are set to a value lower than the default:
|
||||||
|
// ChannelUpdate --> provided baseFee, provided feeRate
|
||||||
func testOpenChannelUpdateFeePolicy(ht *lntest.HarnessTest) {
|
func testOpenChannelUpdateFeePolicy(ht *lntest.HarnessTest) {
|
||||||
const (
|
const (
|
||||||
defaultBaseFee = 1000
|
defaultBaseFee = 1000
|
||||||
@ -180,6 +184,8 @@ func testOpenChannelUpdateFeePolicy(ht *lntest.HarnessTest) {
|
|||||||
defaultMinHtlc = 1000
|
defaultMinHtlc = 1000
|
||||||
optionalBaseFee = 1337
|
optionalBaseFee = 1337
|
||||||
optionalFeeRate = 1337
|
optionalFeeRate = 1337
|
||||||
|
lowBaseFee = 0
|
||||||
|
lowFeeRate = 900
|
||||||
)
|
)
|
||||||
|
|
||||||
defaultMaxHtlc := lntest.CalculateMaxHtlc(funding.MaxBtcFundingAmount)
|
defaultMaxHtlc := lntest.CalculateMaxHtlc(funding.MaxBtcFundingAmount)
|
||||||
@ -216,6 +222,14 @@ func testOpenChannelUpdateFeePolicy(ht *lntest.HarnessTest) {
|
|||||||
UseBaseFee: true,
|
UseBaseFee: true,
|
||||||
UseFeeRate: true,
|
UseFeeRate: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Amt: chanAmt,
|
||||||
|
PushAmt: pushAmt,
|
||||||
|
BaseFee: lowBaseFee,
|
||||||
|
FeeRate: lowFeeRate,
|
||||||
|
UseBaseFee: true,
|
||||||
|
UseFeeRate: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedPolicies := []lnrpc.RoutingPolicy{
|
expectedPolicies := []lnrpc.RoutingPolicy{
|
||||||
@ -247,6 +261,13 @@ func testOpenChannelUpdateFeePolicy(ht *lntest.HarnessTest) {
|
|||||||
MinHtlc: defaultMinHtlc,
|
MinHtlc: defaultMinHtlc,
|
||||||
MaxHtlcMsat: defaultMaxHtlc,
|
MaxHtlcMsat: defaultMaxHtlc,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
FeeBaseMsat: lowBaseFee,
|
||||||
|
FeeRateMilliMsat: lowFeeRate,
|
||||||
|
TimeLockDelta: defaultTimeLockDelta,
|
||||||
|
MinHtlc: defaultMinHtlc,
|
||||||
|
MaxHtlcMsat: defaultMaxHtlc,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
bobExpectedPolicy := lnrpc.RoutingPolicy{
|
bobExpectedPolicy := lnrpc.RoutingPolicy{
|
||||||
@ -257,19 +278,29 @@ func testOpenChannelUpdateFeePolicy(ht *lntest.HarnessTest) {
|
|||||||
MaxHtlcMsat: defaultMaxHtlc,
|
MaxHtlcMsat: defaultMaxHtlc,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// In this basic test, we'll need a third node, Carol, so we can forward
|
||||||
|
// a payment through the channel we'll open with the different fee
|
||||||
|
// policies.
|
||||||
|
carol := ht.NewNode("Carol", nil)
|
||||||
|
|
||||||
alice, bob := ht.Alice, ht.Bob
|
alice, bob := ht.Alice, ht.Bob
|
||||||
|
nodes := []*node.HarnessNode{alice, bob, carol}
|
||||||
|
|
||||||
runTestCase := func(ht *lntest.HarnessTest,
|
runTestCase := func(ht *lntest.HarnessTest,
|
||||||
fs lntest.OpenChannelParams,
|
chanParams lntest.OpenChannelParams,
|
||||||
alicePolicy, bobPolicy *lnrpc.RoutingPolicy) {
|
alicePolicy, bobPolicy *lnrpc.RoutingPolicy) {
|
||||||
|
|
||||||
// Create a channel Alice->Bob.
|
// Create a channel Alice->Bob.
|
||||||
chanPoint := ht.OpenChannel(alice, bob, fs)
|
chanPoint := ht.OpenChannel(alice, bob, chanParams)
|
||||||
defer ht.CloseChannel(alice, chanPoint)
|
defer ht.CloseChannel(alice, chanPoint)
|
||||||
|
|
||||||
// We add all the nodes' update channels to a slice, such that
|
// Create a channel Carol->Alice.
|
||||||
// we can make sure they all receive the expected updates.
|
chanPoint2 := ht.OpenChannel(
|
||||||
nodes := []*node.HarnessNode{alice, bob}
|
carol, alice, lntest.OpenChannelParams{
|
||||||
|
Amt: 500000,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
defer ht.CloseChannel(carol, chanPoint2)
|
||||||
|
|
||||||
// Alice and Bob should see each other's ChannelUpdates,
|
// Alice and Bob should see each other's ChannelUpdates,
|
||||||
// advertising the preferred routing policies.
|
// advertising the preferred routing policies.
|
||||||
@ -279,20 +310,37 @@ func testOpenChannelUpdateFeePolicy(ht *lntest.HarnessTest) {
|
|||||||
assertNodesPolicyUpdate(ht, nodes, bob, bobPolicy, chanPoint)
|
assertNodesPolicyUpdate(ht, nodes, bob, bobPolicy, chanPoint)
|
||||||
|
|
||||||
// They should now know about the default policies.
|
// They should now know about the default policies.
|
||||||
for _, node := range nodes {
|
for _, n := range nodes {
|
||||||
ht.AssertChannelPolicy(
|
ht.AssertChannelPolicy(
|
||||||
node, alice.PubKeyStr, alicePolicy, chanPoint,
|
n, alice.PubKeyStr, alicePolicy, chanPoint,
|
||||||
)
|
)
|
||||||
ht.AssertChannelPolicy(
|
ht.AssertChannelPolicy(
|
||||||
node, bob.PubKeyStr, bobPolicy, chanPoint,
|
n, bob.PubKeyStr, bobPolicy, chanPoint,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We should be able to forward a payment from Carol to Bob
|
||||||
|
// through the new channel we opened.
|
||||||
|
payReqs, _, _ := ht.CreatePayReqs(bob, paymentAmt, 1)
|
||||||
|
ht.CompletePaymentRequests(carol, payReqs)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, feeScenario := range feeScenarios {
|
for i, feeScenario := range feeScenarios {
|
||||||
ht.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
|
ht.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
|
||||||
st := ht.Subtest(t)
|
st := ht.Subtest(t)
|
||||||
ht.EnsureConnected(alice, bob)
|
st.EnsureConnected(alice, bob)
|
||||||
|
|
||||||
|
st.RestartNode(carol)
|
||||||
|
|
||||||
|
// Because we're using ht.Subtest(), we need to restart
|
||||||
|
// any node we have to refresh its runtime context.
|
||||||
|
// Otherwise, we'll get a "context canceled" error on
|
||||||
|
// RPC calls.
|
||||||
|
st.EnsureConnected(alice, carol)
|
||||||
|
|
||||||
|
// Send Carol enough coins to be able to open a channel
|
||||||
|
// to Alice.
|
||||||
|
ht.FundCoins(btcutil.SatoshiPerBitcoin, carol)
|
||||||
|
|
||||||
runTestCase(
|
runTestCase(
|
||||||
st, feeScenario,
|
st, feeScenario,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user