itest: refactor testUpdateChannelPolicyScidAlias

This commit is contained in:
yyforyongyu
2022-08-11 10:52:35 +08:00
parent 6b82676ca2
commit 48aa84a08c
3 changed files with 80 additions and 175 deletions

View File

@@ -425,4 +425,8 @@ var allTestCasesTemp = []*lntemp.TestCase{
Name: "option scid alias", Name: "option scid alias",
TestFunc: testOptionScidAlias, TestFunc: testOptionScidAlias,
}, },
{
Name: "scid alias channel update",
TestFunc: testUpdateChannelPolicyScidAlias,
},
} }

View File

@@ -56,10 +56,6 @@ var allTestCases = []*testCase{
name: "taproot", name: "taproot",
test: testTaproot, test: testTaproot,
}, },
{
name: "scid alias channel update",
test: testUpdateChannelPolicyScidAlias,
},
{ {
name: "scid alias upgrade", name: "scid alias upgrade",
test: testOptionScidUpgrade, test: testOptionScidUpgrade,

View File

@@ -407,9 +407,7 @@ func waitForZeroConfGraphChange(hn *node.HarnessNode,
// testUpdateChannelPolicyScidAlias checks that option-scid-alias, zero-conf // testUpdateChannelPolicyScidAlias checks that option-scid-alias, zero-conf
// channel-types, and option-scid-alias feature-bit-only channels have the // channel-types, and option-scid-alias feature-bit-only channels have the
// expected graph and that payments work when updating the channel policy. // expected graph and that payments work when updating the channel policy.
func testUpdateChannelPolicyScidAlias(net *lntest.NetworkHarness, func testUpdateChannelPolicyScidAlias(ht *lntemp.HarnessTest) {
t *harnessTest) {
tests := []struct { tests := []struct {
name string name string
@@ -447,10 +445,11 @@ func testUpdateChannelPolicyScidAlias(net *lntest.NetworkHarness,
for _, test := range tests { for _, test := range tests {
test := test test := test
success := t.t.Run(test.name, func(t *testing.T) { success := ht.Run(test.name, func(t *testing.T) {
ht := newHarnessTest(t, net) st := ht.Subtest(t)
testPrivateUpdateAlias( testPrivateUpdateAlias(
net, ht, test.zeroConf, test.scidAliasType, st, test.zeroConf, test.scidAliasType,
test.private, test.private,
) )
}) })
@@ -460,17 +459,13 @@ func testUpdateChannelPolicyScidAlias(net *lntest.NetworkHarness,
} }
} }
func testPrivateUpdateAlias(net *lntest.NetworkHarness, t *harnessTest, func testPrivateUpdateAlias(ht *lntemp.HarnessTest,
zeroConf, scidAliasType, private bool) { zeroConf, scidAliasType, private bool) {
ctxb := context.Background()
defer ctxb.Done()
// We'll create a new node Eve that will not have option-scid-alias // We'll create a new node Eve that will not have option-scid-alias
// channels. // channels.
eve := net.NewNode(t.t, "Eve", nil) eve := ht.NewNode("Eve", nil)
net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, eve) ht.FundCoins(btcutil.SatoshiPerBitcoin, eve)
defer shutdownAndAssert(net, t, eve)
// Since option-scid-alias is opt-in we'll need to specify the protocol // Since option-scid-alias is opt-in we'll need to specify the protocol
// arguments when creating a new node. // arguments when creating a new node.
@@ -479,52 +474,39 @@ func testPrivateUpdateAlias(net *lntest.NetworkHarness, t *harnessTest,
"--protocol.zero-conf", "--protocol.zero-conf",
"--protocol.anchors", "--protocol.anchors",
} }
carol := ht.NewNode("Carol", scidAliasArgs)
carol := net.NewNode(t.t, "Carol", scidAliasArgs)
defer shutdownAndAssert(net, t, carol)
// Spin-up Dave who will have an option-scid-alias feature-bit-only or // Spin-up Dave who will have an option-scid-alias feature-bit-only or
// channel-type channel with Carol. // channel-type channel with Carol.
dave := net.NewNode(t.t, "Dave", scidAliasArgs) dave := ht.NewNode("Dave", scidAliasArgs)
defer shutdownAndAssert(net, t, dave)
// We'll give Carol some coins in order to fund the channel. // We'll give Carol some coins in order to fund the channel.
net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, carol) ht.FundCoins(btcutil.SatoshiPerBitcoin, carol)
// Ensure that Carol and Dave are connected. // Ensure that Carol and Dave are connected.
net.EnsureConnected(t.t, carol, dave) ht.EnsureConnected(carol, dave)
// We'll open a regular public channel between Eve and Carol here. Eve // We'll open a regular public channel between Eve and Carol here. Eve
// will be the one receiving the onion-encrypted ChannelUpdate. // will be the one receiving the onion-encrypted ChannelUpdate.
net.EnsureConnected(t.t, eve, carol) ht.EnsureConnected(eve, carol)
chanAmt := btcutil.Amount(1_000_000) chanAmt := btcutil.Amount(1_000_000)
fundingPoint := openChannelAndAssert( p := lntemp.OpenChannelParams{
t, net, eve, carol,
lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
PushAmt: chanAmt / 2, PushAmt: chanAmt / 2,
}, }
) fundingPoint := ht.OpenChannel(eve, carol, p)
defer closeChannelAndAssert(t, net, eve, fundingPoint, false)
// Wait for all to view the channel as active. // Make sure Dave has seen this public channel.
err := eve.WaitForNetworkChannelOpen(fundingPoint) ht.AssertTopologyChannelOpen(dave, fundingPoint)
require.NoError(t.t, err, "eve didn't report channel")
err = carol.WaitForNetworkChannelOpen(fundingPoint)
require.NoError(t.t, err, "carol didn't report channel")
err = dave.WaitForNetworkChannelOpen(fundingPoint)
require.NoError(t.t, err, "dave didn't report channel")
// Setup a ChannelAcceptor for Dave. // Setup a ChannelAcceptor for Dave.
ctxc, cancel := context.WithCancel(ctxb) acceptStream, cancel := dave.RPC.ChannelAcceptor()
acceptStream, err := dave.ChannelAcceptor(ctxc) go acceptChannel(ht.T, zeroConf, acceptStream)
require.NoError(t.t, err)
go acceptChannel(t.t, zeroConf, acceptStream)
// Open a private channel, optionally specifying a channel-type. // Open a private channel, optionally specifying a channel-type.
params := lntest.OpenChannelParams{ params := lntemp.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
Private: private, Private: private,
CommitmentType: lnrpc.CommitmentType_ANCHORS, CommitmentType: lnrpc.CommitmentType_ANCHORS,
@@ -532,26 +514,11 @@ func testPrivateUpdateAlias(net *lntest.NetworkHarness, t *harnessTest,
ScidAlias: scidAliasType, ScidAlias: scidAliasType,
PushAmt: chanAmt / 2, PushAmt: chanAmt / 2,
} }
chanOpenUpdate := openChannelStream(t, net, carol, dave, params) fundingPoint2 := ht.OpenChannelNoAnnounce(carol, dave, params)
// Remove the ChannelAcceptor. // Remove the ChannelAcceptor.
cancel() cancel()
if !zeroConf {
// If this is not a zero-conf channel, mine a single block to
// confirm the channel.
_ = mineBlocks(t, net, 1, 1)
}
// Wait for both Carol and Dave to see the channel as open.
fundingPoint2, err := net.WaitForChannelOpen(chanOpenUpdate)
require.NoError(t.t, err, "error while waiting for channel open")
err = carol.WaitForNetworkChannelOpen(fundingPoint2)
require.NoError(t.t, err, "carol didn't report channel")
err = dave.WaitForNetworkChannelOpen(fundingPoint2)
require.NoError(t.t, err, "dave didn't report channel")
// Carol will now update the channel edge policy for her channel with // Carol will now update the channel edge policy for her channel with
// Dave. // Dave.
baseFeeMSat := 33000 baseFeeMSat := 33000
@@ -565,9 +532,7 @@ func testPrivateUpdateAlias(net *lntest.NetworkHarness, t *harnessTest,
ChanPoint: fundingPoint2, ChanPoint: fundingPoint2,
}, },
} }
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) carol.RPC.UpdateChannelPolicy(updateFeeReq)
_, err = carol.UpdateChannelPolicy(ctxt, updateFeeReq)
require.NoError(t.t, err, "unable to update chan policy")
expectedPolicy := &lnrpc.RoutingPolicy{ expectedPolicy := &lnrpc.RoutingPolicy{
FeeBaseMsat: int64(baseFeeMSat), FeeBaseMsat: int64(baseFeeMSat),
@@ -578,9 +543,8 @@ func testPrivateUpdateAlias(net *lntest.NetworkHarness, t *harnessTest,
} }
// Assert that Dave receives Carol's policy update. // Assert that Dave receives Carol's policy update.
assertChannelPolicyUpdate( ht.AssertChannelPolicyUpdate(
t.t, dave, carol.PubKeyStr, expectedPolicy, fundingPoint2, dave, carol, expectedPolicy, fundingPoint2, true,
true,
) )
// Have Dave also update his policy. // Have Dave also update his policy.
@@ -594,9 +558,7 @@ func testPrivateUpdateAlias(net *lntest.NetworkHarness, t *harnessTest,
ChanPoint: fundingPoint2, ChanPoint: fundingPoint2,
}, },
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) dave.RPC.UpdateChannelPolicy(updateFeeReq)
_, err = dave.UpdateChannelPolicy(ctxt, updateFeeReq)
require.NoError(t.t, err, "unable to update chan policy")
expectedPolicy = &lnrpc.RoutingPolicy{ expectedPolicy = &lnrpc.RoutingPolicy{
FeeBaseMsat: int64(baseFeeMSat), FeeBaseMsat: int64(baseFeeMSat),
@@ -607,9 +569,8 @@ func testPrivateUpdateAlias(net *lntest.NetworkHarness, t *harnessTest,
} }
// Assert that Carol receives Dave's policy update. // Assert that Carol receives Dave's policy update.
assertChannelPolicyUpdate( ht.AssertChannelPolicyUpdate(
t.t, carol, dave.PubKeyStr, expectedPolicy, fundingPoint2, carol, dave, expectedPolicy, fundingPoint2, true,
true,
) )
// Assert that if Dave disables the channel, Carol sees it. // Assert that if Dave disables the channel, Carol sees it.
@@ -617,16 +578,11 @@ func testPrivateUpdateAlias(net *lntest.NetworkHarness, t *harnessTest,
ChanPoint: fundingPoint2, ChanPoint: fundingPoint2,
Action: routerrpc.ChanStatusAction_DISABLE, Action: routerrpc.ChanStatusAction_DISABLE,
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) dave.RPC.UpdateChanStatus(disableReq)
_, err = dave.RouterClient.UpdateChanStatus(ctxt, disableReq)
require.NoError(t.t, err)
davePolicy := getChannelPolicies( expectedPolicy.Disabled = true
t, carol, dave.PubKeyStr, fundingPoint2, ht.AssertChannelPolicyUpdate(
)[0] carol, dave, expectedPolicy, fundingPoint2, true,
davePolicy.Disabled = true
assertChannelPolicyUpdate(
t.t, carol, dave.PubKeyStr, davePolicy, fundingPoint2, true,
) )
// Assert that if Dave enables the channel, Carol sees it. // Assert that if Dave enables the channel, Carol sees it.
@@ -634,13 +590,11 @@ func testPrivateUpdateAlias(net *lntest.NetworkHarness, t *harnessTest,
ChanPoint: fundingPoint2, ChanPoint: fundingPoint2,
Action: routerrpc.ChanStatusAction_ENABLE, Action: routerrpc.ChanStatusAction_ENABLE,
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) dave.RPC.UpdateChanStatus(enableReq)
_, err = dave.RouterClient.UpdateChanStatus(ctxt, enableReq)
require.NoError(t.t, err)
davePolicy.Disabled = false expectedPolicy.Disabled = false
assertChannelPolicyUpdate( ht.AssertChannelPolicyUpdate(
t.t, carol, dave.PubKeyStr, davePolicy, fundingPoint2, true, carol, dave, expectedPolicy, fundingPoint2, true,
) )
// Create an invoice for Carol to pay. // Create an invoice for Carol to pay.
@@ -648,27 +602,16 @@ func testPrivateUpdateAlias(net *lntest.NetworkHarness, t *harnessTest,
Value: int64(10_000), Value: int64(10_000),
Private: true, Private: true,
} }
daveInvoiceResp, err := dave.AddInvoice(ctxb, invoiceParams) daveInvoiceResp := dave.RPC.AddInvoice(invoiceParams)
require.NoError(t.t, err, "unable to add invoice")
// Carol will attempt to send Dave an HTLC. // Carol will attempt to send Dave an HTLC.
payReqs := []string{daveInvoiceResp.PaymentRequest} payReqs := []string{daveInvoiceResp.PaymentRequest}
require.NoError( ht.CompletePaymentRequests(carol, payReqs)
t.t, completePaymentRequests(
carol, carol.RouterClient, payReqs, true,
), "unable to send payment",
)
// Now Eve will create an invoice that Dave will pay. // Now Eve will create an invoice that Dave will pay.
eveInvoiceResp, err := eve.AddInvoice(ctxb, invoiceParams) eveInvoiceResp := eve.RPC.AddInvoice(invoiceParams)
require.NoError(t.t, err, "unable to add invoice")
payReqs = []string{eveInvoiceResp.PaymentRequest} payReqs = []string{eveInvoiceResp.PaymentRequest}
require.NoError( ht.CompletePaymentRequests(dave, payReqs)
t.t, completePaymentRequests(
dave, dave.RouterClient, payReqs, true,
), "unable to send payment",
)
// If this is a public channel, it won't be included in the hop hints, // If this is a public channel, it won't be included in the hop hints,
// so we'll mine enough for 6 confs here. We only expect a tx in the // so we'll mine enough for 6 confs here. We only expect a tx in the
@@ -678,18 +621,19 @@ func testPrivateUpdateAlias(net *lntest.NetworkHarness, t *harnessTest,
if zeroConf { if zeroConf {
expectTx = 1 expectTx = 1
} }
_ = mineBlocks(t, net, 6, expectTx) ht.MineBlocksAndAssertNumTxes(6, expectTx)
// Sleep here so that the edge can be deleted and re-inserted. // Sleep here so that the edge can be deleted and re-inserted.
// This is necessary since the edge may have a policy for the // This is necessary since the edge may have a policy for the
// peer that is "correct" but has an invalid signature from the // peer that is "correct" but has an invalid signature from the
// PoV of BOLT#7. // PoV of BOLT#7.
//
// TODO(yy): further investigate this sleep.
time.Sleep(time.Second * 5) time.Sleep(time.Second * 5)
} }
// Dave creates an invoice that Eve will pay. // Dave creates an invoice that Eve will pay.
daveInvoiceResp2, err := dave.AddInvoice(ctxb, invoiceParams) daveInvoiceResp2 := dave.RPC.AddInvoice(invoiceParams)
require.NoError(t.t, err, "unable to add invoice")
// Carol then updates the channel policy again. // Carol then updates the channel policy again.
feeRate = int64(2) feeRate = int64(2)
@@ -701,9 +645,7 @@ func testPrivateUpdateAlias(net *lntest.NetworkHarness, t *harnessTest,
ChanPoint: fundingPoint2, ChanPoint: fundingPoint2,
}, },
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) carol.RPC.UpdateChannelPolicy(updateFeeReq)
_, err = carol.UpdateChannelPolicy(ctxt, updateFeeReq)
require.NoError(t.t, err, "unable to update chan policy")
expectedPolicy = &lnrpc.RoutingPolicy{ expectedPolicy = &lnrpc.RoutingPolicy{
FeeBaseMsat: int64(baseFeeMSat), FeeBaseMsat: int64(baseFeeMSat),
@@ -714,38 +656,26 @@ func testPrivateUpdateAlias(net *lntest.NetworkHarness, t *harnessTest,
} }
// Assert Dave receives Carol's policy update. // Assert Dave receives Carol's policy update.
assertChannelPolicyUpdate( ht.AssertChannelPolicyUpdate(
t.t, dave, carol.PubKeyStr, expectedPolicy, fundingPoint2, dave, carol, expectedPolicy, fundingPoint2, true,
true,
) )
// If the channel is public, check that Eve receives Carol's policy // If the channel is public, check that Eve receives Carol's policy
// update. // update.
if !private { if !private {
assertChannelPolicyUpdate( ht.AssertChannelPolicyUpdate(
t.t, eve, carol.PubKeyStr, expectedPolicy, eve, carol, expectedPolicy, fundingPoint2, true,
fundingPoint2, true,
) )
} }
// Eve will pay Dave's invoice and should use the updated base fee. // Eve will pay Dave's invoice and should use the updated base fee.
payReqs = []string{daveInvoiceResp2.PaymentRequest} payReqs = []string{daveInvoiceResp2.PaymentRequest}
require.NoError( ht.CompletePaymentRequests(eve, payReqs)
t.t, completePaymentRequests(
eve, eve.RouterClient, payReqs, true,
), "unable to send payment",
)
// Eve will issue an invoice that Dave will pay. // Eve will issue an invoice that Dave will pay.
eveInvoiceResp2, err := eve.AddInvoice(ctxb, invoiceParams) eveInvoiceResp2 := eve.RPC.AddInvoice(invoiceParams)
require.NoError(t.t, err, "unable to add invoice")
payReqs = []string{eveInvoiceResp2.PaymentRequest} payReqs = []string{eveInvoiceResp2.PaymentRequest}
require.NoError( ht.CompletePaymentRequests(dave, payReqs)
t.t, completePaymentRequests(
dave, dave.RouterClient, payReqs, true,
), "unable to send payment",
)
// If this is a private channel, we'll mine 6 blocks here to test the // If this is a private channel, we'll mine 6 blocks here to test the
// funding manager logic that deals with ChannelUpdates. If this is not // funding manager logic that deals with ChannelUpdates. If this is not
@@ -755,62 +685,45 @@ func testPrivateUpdateAlias(net *lntest.NetworkHarness, t *harnessTest,
if zeroConf { if zeroConf {
expectTx = 1 expectTx = 1
} }
_ = mineBlocks(t, net, 6, expectTx) ht.MineBlocksAndAssertNumTxes(6, expectTx)
} }
// Dave will issue an invoice and Eve will pay it. // Dave will issue an invoice and Eve will pay it.
daveInvoiceResp3, err := dave.AddInvoice(ctxb, invoiceParams) daveInvoiceResp3 := dave.RPC.AddInvoice(invoiceParams)
require.NoError(t.t, err, "unable to add invoice")
payReqs = []string{daveInvoiceResp3.PaymentRequest} payReqs = []string{daveInvoiceResp3.PaymentRequest}
require.NoError( ht.CompletePaymentRequests(eve, payReqs)
t.t, completePaymentRequests(
eve, eve.RouterClient, payReqs, true,
), "unable to send payment",
)
// Carol will disable the channel, assert that Dave sees it and Eve as // Carol will disable the channel, assert that Dave sees it and Eve as
// well if the channel is public. // well if the channel is public.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) carol.RPC.UpdateChanStatus(disableReq)
_, err = carol.RouterClient.UpdateChanStatus(ctxt, disableReq)
require.NoError(t.t, err)
carolPolicy := getChannelPolicies( expectedPolicy.Disabled = true
t, dave, carol.PubKeyStr, fundingPoint2, ht.AssertChannelPolicyUpdate(
)[0] dave, carol, expectedPolicy, fundingPoint2, true,
carolPolicy.Disabled = true
assertChannelPolicyUpdate(
t.t, dave, carol.PubKeyStr, carolPolicy, fundingPoint2, true,
) )
if !private { if !private {
assertChannelPolicyUpdate( ht.AssertChannelPolicyUpdate(
t.t, eve, carol.PubKeyStr, carolPolicy, fundingPoint2, eve, carol, expectedPolicy, fundingPoint2, true,
true,
) )
} }
// Carol will enable the channel, assert the same as above. // Carol will enable the channel, assert the same as above.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) carol.RPC.UpdateChanStatus(enableReq)
_, err = carol.RouterClient.UpdateChanStatus(ctxt, enableReq) expectedPolicy.Disabled = false
require.NoError(t.t, err) ht.AssertChannelPolicyUpdate(
dave, carol, expectedPolicy, fundingPoint2, true,
carolPolicy.Disabled = false
assertChannelPolicyUpdate(
t.t, dave, carol.PubKeyStr, carolPolicy, fundingPoint2, true,
) )
if !private { if !private {
assertChannelPolicyUpdate( ht.AssertChannelPolicyUpdate(
t.t, eve, carol.PubKeyStr, carolPolicy, fundingPoint2, eve, carol, expectedPolicy, fundingPoint2, true,
true,
) )
} }
// Dave will issue an invoice and Eve should pay it after Carol updates // Dave will issue an invoice and Eve should pay it after Carol updates
// her channel policy. // her channel policy.
daveInvoiceResp4, err := dave.AddInvoice(ctxb, invoiceParams) daveInvoiceResp4 := dave.RPC.AddInvoice(invoiceParams)
require.NoError(t.t, err, "unable to add invoice")
feeRate = int64(3) feeRate = int64(3)
updateFeeReq = &lnrpc.PolicyUpdateRequest{ updateFeeReq = &lnrpc.PolicyUpdateRequest{
@@ -821,9 +734,7 @@ func testPrivateUpdateAlias(net *lntest.NetworkHarness, t *harnessTest,
ChanPoint: fundingPoint2, ChanPoint: fundingPoint2,
}, },
} }
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) carol.RPC.UpdateChannelPolicy(updateFeeReq)
_, err = carol.UpdateChannelPolicy(ctxt, updateFeeReq)
require.NoError(t.t, err, "unable to update chan policy")
expectedPolicy = &lnrpc.RoutingPolicy{ expectedPolicy = &lnrpc.RoutingPolicy{
FeeBaseMsat: int64(baseFeeMSat), FeeBaseMsat: int64(baseFeeMSat),
@@ -834,24 +745,18 @@ func testPrivateUpdateAlias(net *lntest.NetworkHarness, t *harnessTest,
} }
// Assert Dave and optionally Eve receives Carol's update. // Assert Dave and optionally Eve receives Carol's update.
assertChannelPolicyUpdate( ht.AssertChannelPolicyUpdate(
t.t, dave, carol.PubKeyStr, expectedPolicy, fundingPoint2, dave, carol, expectedPolicy, fundingPoint2, true,
true,
) )
if !private { if !private {
assertChannelPolicyUpdate( ht.AssertChannelPolicyUpdate(
t.t, eve, carol.PubKeyStr, expectedPolicy, eve, carol, expectedPolicy, fundingPoint2, true,
fundingPoint2, true,
) )
} }
payReqs = []string{daveInvoiceResp4.PaymentRequest} payReqs = []string{daveInvoiceResp4.PaymentRequest}
require.NoError( ht.CompletePaymentRequests(eve, payReqs)
t.t, completePaymentRequests(
eve, eve.RouterClient, payReqs, true,
), "unable to send payment",
)
} }
// testOptionScidUpgrade tests that toggling the option-scid-alias feature bit // testOptionScidUpgrade tests that toggling the option-scid-alias feature bit