diff --git a/lntemp/harness.go b/lntemp/harness.go index 68817eea4..b979ceaef 100644 --- a/lntemp/harness.go +++ b/lntemp/harness.go @@ -822,6 +822,26 @@ type OpenChannelParams struct { // ScidAlias denotes whether the channel will be an option-scid-alias // channel type negotiation. ScidAlias bool + + // BaseFee is the channel base fee applied during the channel + // announcement phase. + BaseFee uint64 + + // FeeRate is the channel fee rate in ppm applied during the channel + // announcement phase. + FeeRate uint64 + + // UseBaseFee, if set, instructs the downstream logic to apply the + // user-specified channel base fee to the channel update announcement. + // If set to false it avoids applying a base fee of 0 and instead + // activates the default configured base fee. + UseBaseFee bool + + // UseFeeRate, if set, instructs the downstream logic to apply the + // user-specified channel fee rate to the channel update announcement. + // If set to false it avoids applying a fee rate of 0 and instead + // activates the default configured fee rate. + UseFeeRate bool } // prepareOpenChannel waits for both nodes to be synced to chain and returns an @@ -858,6 +878,10 @@ func (h *HarnessTest) prepareOpenChannel(srcNode, destNode *node.HarnessNode, CommitmentType: p.CommitmentType, ZeroConf: p.ZeroConf, ScidAlias: p.ScidAlias, + BaseFee: p.BaseFee, + FeeRate: p.FeeRate, + UseBaseFee: p.UseBaseFee, + UseFeeRate: p.UseFeeRate, } } diff --git a/lntest/itest/list_on_test.go b/lntest/itest/list_on_test.go index 71b2cc703..a6c695a5d 100644 --- a/lntest/itest/list_on_test.go +++ b/lntest/itest/list_on_test.go @@ -493,4 +493,8 @@ var allTestCasesTemp = []*lntemp.TestCase{ Name: "trackpayments", TestFunc: testTrackPayments, }, + { + Name: "open channel fee policy", + TestFunc: testOpenChannelUpdateFeePolicy, + }, } diff --git a/lntest/itest/lnd_open_channel_test.go b/lntest/itest/lnd_open_channel_test.go index 959506f3f..6289b5773 100644 --- a/lntest/itest/lnd_open_channel_test.go +++ b/lntest/itest/lnd_open_channel_test.go @@ -2,6 +2,7 @@ package itest import ( "fmt" + "testing" "github.com/btcsuite/btcd/btcjson" "github.com/btcsuite/btcd/chaincfg/chainhash" @@ -12,7 +13,6 @@ import ( "github.com/lightningnetwork/lnd/lntemp" "github.com/lightningnetwork/lnd/lntemp/node" "github.com/lightningnetwork/lnd/lntemp/rpc" - "github.com/lightningnetwork/lnd/lntest" "github.com/lightningnetwork/lnd/lntest/wait" "github.com/stretchr/testify/require" ) @@ -172,9 +172,7 @@ func testOpenChannelAfterReorg(ht *lntemp.HarnessTest) { // ChannelUpdate --> defaultBaseFee, provided FeeRate // 4.) baseFee and feeRate provided to OpenChannelRequest // ChannelUpdate --> provided baseFee, provided feeRate. -func testOpenChannelUpdateFeePolicy(net *lntest.NetworkHarness, - t *harnessTest) { - +func testOpenChannelUpdateFeePolicy(ht *lntemp.HarnessTest) { const ( defaultBaseFee = 1000 defaultFeeRate = 1 @@ -189,7 +187,7 @@ func testOpenChannelUpdateFeePolicy(net *lntest.NetworkHarness, chanAmt := funding.MaxBtcFundingAmount pushAmt := chanAmt / 2 - feeScenarios := []lntest.OpenChannelParams{ + feeScenarios := []lntemp.OpenChannelParams{ { Amt: chanAmt, PushAmt: pushAmt, @@ -259,51 +257,48 @@ func testOpenChannelUpdateFeePolicy(net *lntest.NetworkHarness, MaxHtlcMsat: defaultMaxHtlc, } - for i, feeScenario := range feeScenarios { + alice, bob := ht.Alice, ht.Bob + + runTestCase := func(ht *lntemp.HarnessTest, + fs lntemp.OpenChannelParams, + alicePolicy, bobPolicy *lnrpc.RoutingPolicy) { + // Create a channel Alice->Bob. - chanPoint := openChannelAndAssert( - t, net, net.Alice, net.Bob, - feeScenario, - ) + chanPoint := ht.OpenChannel(alice, bob, fs) + defer ht.CloseChannel(alice, chanPoint) - defer closeChannelAndAssert(t, net, net.Alice, chanPoint, false) + // We add all the nodes' update channels to a slice, such that + // we can make sure they all receive the expected updates. + nodes := []*node.HarnessNode{alice, bob} - // We add all the nodes' update channels to a slice, such that we can - // make sure they all receive the expected updates. - nodes := []*lntest.HarnessNode{net.Alice, net.Bob} - - // Alice and Bob should see each other's ChannelUpdates, advertising - // the preferred routing policies. - assertPolicyUpdate( - t, nodes, net.Alice.PubKeyStr, - &expectedPolicies[i], chanPoint, - ) - assertPolicyUpdate( - t, nodes, net.Bob.PubKeyStr, - &bobExpectedPolicy, chanPoint, + // Alice and Bob should see each other's ChannelUpdates, + // advertising the preferred routing policies. + assertNodesPolicyUpdate( + ht, nodes, alice, alicePolicy, chanPoint, ) + assertNodesPolicyUpdate(ht, nodes, bob, bobPolicy, chanPoint) // They should now know about the default policies. for _, node := range nodes { - assertChannelPolicy( - t, node, net.Alice.PubKeyStr, - &expectedPolicies[i], chanPoint, + ht.AssertChannelPolicy( + node, alice.PubKeyStr, alicePolicy, chanPoint, ) - assertChannelPolicy( - t, node, net.Bob.PubKeyStr, - &bobExpectedPolicy, chanPoint, + ht.AssertChannelPolicy( + node, bob.PubKeyStr, bobPolicy, chanPoint, ) } + } - require.NoError( - t.t, net.Alice.WaitForNetworkChannelOpen(chanPoint), - "alice reports channel opening", - ) + for i, feeScenario := range feeScenarios { + ht.Run(fmt.Sprintf("%d", i), func(t *testing.T) { + st := ht.Subtest(t) + ht.EnsureConnected(alice, bob) - require.NoError( - t.t, net.Bob.WaitForNetworkChannelOpen(chanPoint), - "bob reports channel opening", - ) + runTestCase( + st, feeScenario, + &expectedPolicies[i], &bobExpectedPolicy, + ) + }) } } diff --git a/lntest/itest/lnd_test_list_on_test.go b/lntest/itest/lnd_test_list_on_test.go index 38489f510..97d5282a4 100644 --- a/lntest/itest/lnd_test_list_on_test.go +++ b/lntest/itest/lnd_test_list_on_test.go @@ -8,10 +8,6 @@ var allTestCases = []*testCase{ name: "async bidirectional payments", test: testBidirectionalAsyncPayments, }, - { - name: "open channel fee policy", - test: testOpenChannelUpdateFeePolicy, - }, { name: "custom messaging", test: testCustomMessage,