lntemp+itest: refactor testMultiHopPayments

This commit is contained in:
yyforyongyu 2022-08-05 18:44:52 +08:00
parent 130c4e325a
commit f1f3d22a81
No known key found for this signature in database
GPG key ID: 9BCD95C4FF296868
5 changed files with 195 additions and 336 deletions

View file

@ -1852,3 +1852,78 @@ func (h *HarnessTest) AssertHtlcEventTypes(client rpc.HtlcEventsClient,
return event return event
} }
// AssertFeeReport checks that the fee report from the given node has the
// desired day, week, and month sum values.
func (h *HarnessTest) AssertFeeReport(hn *node.HarnessNode,
day, week, month int) {
ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
defer cancel()
feeReport, err := hn.RPC.LN.FeeReport(ctxt, &lnrpc.FeeReportRequest{})
require.NoError(h, err, "unable to query for fee report")
require.EqualValues(h, day, feeReport.DayFeeSum, "day fee mismatch")
require.EqualValues(h, week, feeReport.WeekFeeSum, "day week mismatch")
require.EqualValues(h, month, feeReport.MonthFeeSum,
"day month mismatch")
}
// AssertHtlcEvents consumes events from a client and ensures that they are of
// the expected type and contain the expected number of forwards, forward
// failures and settles.
//
// TODO(yy): needs refactor to reduce its complexity.
func (h *HarnessTest) AssertHtlcEvents(client rpc.HtlcEventsClient,
fwdCount, fwdFailCount, settleCount int,
userType routerrpc.HtlcEvent_EventType) []*routerrpc.HtlcEvent {
var forwards, forwardFails, settles int
numEvents := fwdCount + fwdFailCount + settleCount
events := make([]*routerrpc.HtlcEvent, 0)
// It's either the userType or the unknown type.
//
// TODO(yy): maybe the FinalHtlcEvent shouldn't be in UNKNOWN type?
eventTypes := []routerrpc.HtlcEvent_EventType{
userType, routerrpc.HtlcEvent_UNKNOWN,
}
for i := 0; i < numEvents; i++ {
event := h.ReceiveHtlcEvent(client)
require.Containsf(h, eventTypes, event.EventType,
"wrong event type, got %v", userType, event.EventType)
events = append(events, event)
switch e := event.Event.(type) {
case *routerrpc.HtlcEvent_ForwardEvent:
forwards++
case *routerrpc.HtlcEvent_ForwardFailEvent:
forwardFails++
case *routerrpc.HtlcEvent_SettleEvent:
settles++
case *routerrpc.HtlcEvent_FinalHtlcEvent:
if e.FinalHtlcEvent.Settled {
settles++
}
default:
require.Fail(h, "assert event fail",
"unexpected event: %T", event.Event)
}
}
require.Equal(h, fwdCount, forwards, "num of forwards mismatch")
require.Equal(h, fwdFailCount, forwardFails,
"num of forward fails mismatch")
require.Equal(h, settleCount, settles, "num of settles mismatch")
return events
}

View file

@ -591,3 +591,21 @@ func (h *HarnessRPC) DecodePayReq(req string) *lnrpc.PayReq {
return resp return resp
} }
// ForwardingHistory makes a RPC call to the node's ForwardingHistory and
// asserts.
func (h *HarnessRPC) ForwardingHistory(
req *lnrpc.ForwardingHistoryRequest) *lnrpc.ForwardingHistoryResponse {
ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
defer cancel()
if req == nil {
req = &lnrpc.ForwardingHistoryRequest{}
}
resp, err := h.LN.ForwardingHistory(ctxt, req)
h.NoError(err, "ForwardingHistory")
return resp
}

View file

@ -259,4 +259,8 @@ var allTestCasesTemp = []*lntemp.TestCase{
Name: "multi-hop htlc error propagation", Name: "multi-hop htlc error propagation",
TestFunc: testHtlcErrorPropagation, TestFunc: testHtlcErrorPropagation,
}, },
{
Name: "multi-hop payments",
TestFunc: testMultiHopPayments,
},
} }

View file

@ -1,146 +1,70 @@
package itest package itest
import ( import (
"context"
"time"
"github.com/btcsuite/btcd/btcutil" "github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/chainreg" "github.com/lightningnetwork/lnd/chainreg"
"github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/routerrpc" "github.com/lightningnetwork/lnd/lnrpc/routerrpc"
"github.com/lightningnetwork/lnd/lntest" "github.com/lightningnetwork/lnd/lntemp"
"github.com/lightningnetwork/lnd/lntemp/node"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) { func testMultiHopPayments(ht *lntemp.HarnessTest) {
ctxb := context.Background()
const chanAmt = btcutil.Amount(100000) const chanAmt = btcutil.Amount(100000)
var networkChans []*lnrpc.ChannelPoint
// Open a channel with 100k satoshis between Alice and Bob with Alice
// being the sole funder of the channel.
chanPointAlice := openChannelAndAssert(
t, net, net.Alice, net.Bob,
lntest.OpenChannelParams{
Amt: chanAmt,
},
)
networkChans = append(networkChans, chanPointAlice)
aliceChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointAlice)
if err != nil {
t.Fatalf("unable to get txid: %v", err)
}
aliceFundPoint := wire.OutPoint{
Hash: *aliceChanTXID,
Index: chanPointAlice.OutputIndex,
}
// As preliminary setup, we'll create two new nodes: Carol and Dave, // As preliminary setup, we'll create two new nodes: Carol and Dave,
// such that we now have a 4 node, 3 channel topology. Dave will make a // such that we now have a 4 node, 3 channel topology. Dave will make a
// channel with Alice, and Carol with Dave. After this setup, the // channel with Alice, and Carol with Dave. After this setup, the
// network topology should now look like: // network topology should now look like:
// Carol -> Dave -> Alice -> Bob // Carol -> Dave -> Alice -> Bob
// alice, bob := ht.Alice, ht.Bob
// First, we'll create Dave and establish a channel to Alice. Dave will
// be running an older node that requires the legacy onion payload.
daveArgs := []string{"--protocol.legacy.onion"} daveArgs := []string{"--protocol.legacy.onion"}
dave := net.NewNode(t.t, "Dave", daveArgs) dave := ht.NewNode("Dave", daveArgs)
defer shutdownAndAssert(net, t, dave) carol := ht.NewNode("Carol", nil)
net.ConnectNodes(t.t, dave, net.Alice) // Subscribe events early so we don't miss it out.
net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, dave) aliceEvents := alice.RPC.SubscribeHtlcEvents()
bobEvents := bob.RPC.SubscribeHtlcEvents()
carolEvents := carol.RPC.SubscribeHtlcEvents()
daveEvents := dave.RPC.SubscribeHtlcEvents()
chanPointDave := openChannelAndAssert( // Once subscribed, the first event will be UNKNOWN.
t, net, dave, net.Alice, ht.AssertHtlcEventType(aliceEvents, routerrpc.HtlcEvent_UNKNOWN)
lntest.OpenChannelParams{ ht.AssertHtlcEventType(bobEvents, routerrpc.HtlcEvent_UNKNOWN)
Amt: chanAmt, ht.AssertHtlcEventType(carolEvents, routerrpc.HtlcEvent_UNKNOWN)
}, ht.AssertHtlcEventType(daveEvents, routerrpc.HtlcEvent_UNKNOWN)
// Connect the nodes.
ht.ConnectNodes(dave, alice)
ht.ConnectNodes(carol, dave)
// Open a channel with 100k satoshis between Alice and Bob with Alice
// being the sole funder of the channel.
chanPointAlice := ht.OpenChannel(
alice, bob, lntemp.OpenChannelParams{Amt: chanAmt},
)
// We'll create Dave and establish a channel to Alice. Dave will be
// running an older node that requires the legacy onion payload.
ht.FundCoins(btcutil.SatoshiPerBitcoin, dave)
chanPointDave := ht.OpenChannel(
dave, alice, lntemp.OpenChannelParams{Amt: chanAmt},
) )
networkChans = append(networkChans, chanPointDave)
daveChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointDave)
if err != nil {
t.Fatalf("unable to get txid: %v", err)
}
daveFundPoint := wire.OutPoint{
Hash: *daveChanTXID,
Index: chanPointDave.OutputIndex,
}
// Next, we'll create Carol and establish a channel to from her to // Next, we'll create Carol and establish a channel to from her to
// Dave. // Dave.
carol := net.NewNode(t.t, "Carol", nil) ht.FundCoins(btcutil.SatoshiPerBitcoin, carol)
defer shutdownAndAssert(net, t, carol) chanPointCarol := ht.OpenChannel(
carol, dave, lntemp.OpenChannelParams{Amt: chanAmt},
net.ConnectNodes(t.t, carol, dave)
net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, carol)
chanPointCarol := openChannelAndAssert(
t, net, carol, dave,
lntest.OpenChannelParams{
Amt: chanAmt,
},
) )
networkChans = append(networkChans, chanPointCarol)
carolChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointCarol)
if err != nil {
t.Fatalf("unable to get txid: %v", err)
}
carolFundPoint := wire.OutPoint{
Hash: *carolChanTXID,
Index: chanPointCarol.OutputIndex,
}
// Wait for all nodes to have seen all channels.
nodes := []*lntest.HarnessNode{net.Alice, net.Bob, carol, dave}
nodeNames := []string{"Alice", "Bob", "Carol", "Dave"}
for _, chanPoint := range networkChans {
for i, node := range nodes {
txid, err := lnrpc.GetChanPointFundingTxid(chanPoint)
if err != nil {
t.Fatalf("unable to get txid: %v", err)
}
point := wire.OutPoint{
Hash: *txid,
Index: chanPoint.OutputIndex,
}
err = node.WaitForNetworkChannelOpen(chanPoint)
if err != nil {
t.Fatalf("%s(%d): timeout waiting for "+
"channel(%s) open: %v", nodeNames[i],
node.NodeID, point, err)
}
}
}
// Create 5 invoices for Bob, which expect a payment from Carol for 1k // Create 5 invoices for Bob, which expect a payment from Carol for 1k
// satoshis with a different preimage each time. // satoshis with a different preimage each time.
const numPayments = 5 const numPayments = 5
const paymentAmt = 1000 const paymentAmt = 1000
payReqs, _, _, err := createPayReqs( payReqs, _, _ := ht.CreatePayReqs(bob, paymentAmt, numPayments)
net.Bob, paymentAmt, numPayments,
)
if err != nil {
t.Fatalf("unable to create pay reqs: %v", err)
}
// We'll wait for all parties to recognize the new channels within the
// network.
err = dave.WaitForNetworkChannelOpen(chanPointDave)
if err != nil {
t.Fatalf("dave didn't advertise his channel: %v", err)
}
err = carol.WaitForNetworkChannelOpen(chanPointCarol)
if err != nil {
t.Fatalf("carol didn't advertise her channel in time: %v",
err)
}
time.Sleep(time.Millisecond * 50)
// Set the fee policies of the Alice -> Bob and the Dave -> Alice // Set the fee policies of the Alice -> Bob and the Dave -> Alice
// channel edges to relatively large non default values. This makes it // channel edges to relatively large non default values. This makes it
@ -149,61 +73,21 @@ func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) {
const aliceBaseFeeSat = 1 const aliceBaseFeeSat = 1
const aliceFeeRatePPM = 100000 const aliceFeeRatePPM = 100000
updateChannelPolicy( updateChannelPolicy(
t, net.Alice, chanPointAlice, aliceBaseFeeSat*1000, ht, alice, chanPointAlice, aliceBaseFeeSat*1000,
aliceFeeRatePPM, chainreg.DefaultBitcoinTimeLockDelta, maxHtlc, aliceFeeRatePPM, chainreg.DefaultBitcoinTimeLockDelta,
carol, maxHtlc, carol,
) )
const daveBaseFeeSat = 5 const daveBaseFeeSat = 5
const daveFeeRatePPM = 150000 const daveFeeRatePPM = 150000
updateChannelPolicy( updateChannelPolicy(
t, dave, chanPointDave, daveBaseFeeSat*1000, daveFeeRatePPM, ht, dave, chanPointDave, daveBaseFeeSat*1000, daveFeeRatePPM,
chainreg.DefaultBitcoinTimeLockDelta, maxHtlc, carol, chainreg.DefaultBitcoinTimeLockDelta, maxHtlc, carol,
) )
// Before we start sending payments, subscribe to htlc events for each
// node.
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
defer cancel()
aliceEvents, err := net.Alice.RouterClient.SubscribeHtlcEvents(
ctxt, &routerrpc.SubscribeHtlcEventsRequest{},
)
if err != nil {
t.Fatalf("could not subscribe events: %v", err)
}
assertSubscribed(t, aliceEvents)
bobEvents, err := net.Bob.RouterClient.SubscribeHtlcEvents(
ctxt, &routerrpc.SubscribeHtlcEventsRequest{},
)
if err != nil {
t.Fatalf("could not subscribe events: %v", err)
}
assertSubscribed(t, bobEvents)
carolEvents, err := carol.RouterClient.SubscribeHtlcEvents(
ctxt, &routerrpc.SubscribeHtlcEventsRequest{},
)
if err != nil {
t.Fatalf("could not subscribe events: %v", err)
}
assertSubscribed(t, carolEvents)
daveEvents, err := dave.RouterClient.SubscribeHtlcEvents(
ctxt, &routerrpc.SubscribeHtlcEventsRequest{},
)
if err != nil {
t.Fatalf("could not subscribe events: %v", err)
}
assertSubscribed(t, daveEvents)
// Using Carol as the source, pay to the 5 invoices from Bob created // Using Carol as the source, pay to the 5 invoices from Bob created
// above. // above.
err = completePaymentRequests(carol, carol.RouterClient, payReqs, true) ht.CompletePaymentRequests(carol, payReqs)
if err != nil {
t.Fatalf("unable to send payments: %v", err)
}
// At this point all the channels within our proto network should be // At this point all the channels within our proto network should be
// shifted by 5k satoshis in the direction of Bob, the sink within the // shifted by 5k satoshis in the direction of Bob, the sink within the
@ -215,10 +99,10 @@ func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) {
// The final node bob expects to get paid five times 1000 sat. // The final node bob expects to get paid five times 1000 sat.
expectedAmountPaidAtoB := int64(numPayments * paymentAmt) expectedAmountPaidAtoB := int64(numPayments * paymentAmt)
assertAmountPaid(t, "Alice(local) => Bob(remote)", net.Bob, ht.AssertAmountPaid("Alice(local) => Bob(remote)", bob,
aliceFundPoint, int64(0), expectedAmountPaidAtoB) chanPointAlice, int64(0), expectedAmountPaidAtoB)
assertAmountPaid(t, "Alice(local) => Bob(remote)", net.Alice, ht.AssertAmountPaid("Alice(local) => Bob(remote)", alice,
aliceFundPoint, expectedAmountPaidAtoB, int64(0)) chanPointAlice, expectedAmountPaidAtoB, int64(0))
// To forward a payment of 1000 sat, Alice is charging a fee of // To forward a payment of 1000 sat, Alice is charging a fee of
// 1 sat + 10% = 101 sat. // 1 sat + 10% = 101 sat.
@ -229,10 +113,10 @@ func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) {
// Dave needs to pay what Alice pays plus Alice's fee. // Dave needs to pay what Alice pays plus Alice's fee.
expectedAmountPaidDtoA := expectedAmountPaidAtoB + expectedFeeAlice expectedAmountPaidDtoA := expectedAmountPaidAtoB + expectedFeeAlice
assertAmountPaid(t, "Dave(local) => Alice(remote)", net.Alice, ht.AssertAmountPaid("Dave(local) => Alice(remote)", alice,
daveFundPoint, int64(0), expectedAmountPaidDtoA) chanPointDave, int64(0), expectedAmountPaidDtoA)
assertAmountPaid(t, "Dave(local) => Alice(remote)", dave, ht.AssertAmountPaid("Dave(local) => Alice(remote)", dave,
daveFundPoint, expectedAmountPaidDtoA, int64(0)) chanPointDave, expectedAmountPaidDtoA, int64(0))
// To forward a payment of 1101 sat, Dave is charging a fee of // To forward a payment of 1101 sat, Dave is charging a fee of
// 5 sat + 15% = 170.15 sat. This is rounded down in rpcserver to 170. // 5 sat + 15% = 170.15 sat. This is rounded down in rpcserver to 170.
@ -244,10 +128,10 @@ func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) {
// Carol needs to pay what Dave pays plus Dave's fee. // Carol needs to pay what Dave pays plus Dave's fee.
expectedAmountPaidCtoD := expectedAmountPaidDtoA + expectedFeeDave expectedAmountPaidCtoD := expectedAmountPaidDtoA + expectedFeeDave
assertAmountPaid(t, "Carol(local) => Dave(remote)", dave, ht.AssertAmountPaid("Carol(local) => Dave(remote)", dave,
carolFundPoint, int64(0), expectedAmountPaidCtoD) chanPointCarol, int64(0), expectedAmountPaidCtoD)
assertAmountPaid(t, "Carol(local) => Dave(remote)", carol, ht.AssertAmountPaid("Carol(local) => Dave(remote)", carol,
carolFundPoint, expectedAmountPaidCtoD, int64(0)) chanPointCarol, expectedAmountPaidCtoD, int64(0))
// Now that we know all the balances have been settled out properly, // Now that we know all the balances have been settled out properly,
// we'll ensure that our internal record keeping for completed circuits // we'll ensure that our internal record keeping for completed circuits
@ -256,206 +140,92 @@ func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) {
// First, check that the FeeReport response shows the proper fees // First, check that the FeeReport response shows the proper fees
// accrued over each time range. Dave should've earned 170 satoshi for // accrued over each time range. Dave should've earned 170 satoshi for
// each of the forwarded payments. // each of the forwarded payments.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ht.AssertFeeReport(
feeReport, err := dave.FeeReport(ctxt, &lnrpc.FeeReportRequest{}) dave, expectedFeeDave, expectedFeeDave, expectedFeeDave,
require.NoError(t.t, err) )
require.EqualValues(t.t, expectedFeeDave, feeReport.DayFeeSum)
require.EqualValues(t.t, expectedFeeDave, feeReport.WeekFeeSum)
require.EqualValues(t.t, expectedFeeDave, feeReport.MonthFeeSum)
// Next, ensure that if we issue the vanilla query for the forwarding // Next, ensure that if we issue the vanilla query for the forwarding
// history, it returns 5 values, and each entry is formatted properly. // history, it returns 5 values, and each entry is formatted properly.
// From David's perspective he receives a payement from Carol and // From David's perspective he receives a payement from Carol and
// forwards it to Alice. So let's ensure that the forwarding history // forwards it to Alice. So let's ensure that the forwarding history
// returns Carol's peer alias as inbound and Alice's alias as outbound. // returns Carol's peer alias as inbound and Alice's alias as outbound.
info, err := carol.GetInfo(ctxt, &lnrpc.GetInfoRequest{}) info := carol.RPC.GetInfo()
require.NoError(t.t, err)
carolAlias := info.Alias carolAlias := info.Alias
info, err = net.Alice.GetInfo(ctxt, &lnrpc.GetInfoRequest{}) info = alice.RPC.GetInfo()
require.NoError(t.t, err)
aliceAlias := info.Alias aliceAlias := info.Alias
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) fwdingHistory := dave.RPC.ForwardingHistory(nil)
fwdingHistory, err := dave.ForwardingHistory( require.Len(ht, fwdingHistory.ForwardingEvents, numPayments)
ctxt, &lnrpc.ForwardingHistoryRequest{},
)
require.NoError(t.t, err)
require.Len(t.t, fwdingHistory.ForwardingEvents, numPayments)
expectedForwardingFee := uint64(expectedFeeDave / numPayments) expectedForwardingFee := uint64(expectedFeeDave / numPayments)
for _, event := range fwdingHistory.ForwardingEvents { for _, event := range fwdingHistory.ForwardingEvents {
// Each event should show a fee of 170 satoshi. // Each event should show a fee of 170 satoshi.
require.Equal(t.t, expectedForwardingFee, event.Fee) require.Equal(ht, expectedForwardingFee, event.Fee)
// Check that peer aliases are empty since the // Check that peer aliases are empty since the
// ForwardingHistoryRequest did not specify the PeerAliasLookup // ForwardingHistoryRequest did not specify the PeerAliasLookup
// flag. // flag.
require.Empty(t.t, event.PeerAliasIn) require.Empty(ht, event.PeerAliasIn)
require.Empty(t.t, event.PeerAliasOut) require.Empty(ht, event.PeerAliasOut)
} }
// Lookup the forwarding history again but this time also lookup the // Lookup the forwarding history again but this time also lookup the
// peers' alias names. // peers' alias names.
fwdingHistory, err = dave.ForwardingHistory( fwdingHistory = dave.RPC.ForwardingHistory(
ctxt, &lnrpc.ForwardingHistoryRequest{ &lnrpc.ForwardingHistoryRequest{
PeerAliasLookup: true, PeerAliasLookup: true,
}, },
) )
require.NoError(t.t, err) require.Len(ht, fwdingHistory.ForwardingEvents, numPayments)
require.Len(t.t, fwdingHistory.ForwardingEvents, numPayments)
for _, event := range fwdingHistory.ForwardingEvents { for _, event := range fwdingHistory.ForwardingEvents {
// Each event should show a fee of 170 satoshi. // Each event should show a fee of 170 satoshi.
require.Equal(t.t, expectedForwardingFee, event.Fee) require.Equal(ht, expectedForwardingFee, event.Fee)
// Check that peer aliases adhere to payment flow, namely // Check that peer aliases adhere to payment flow, namely
// Carol->Dave->Alice. // Carol->Dave->Alice.
require.Equal(t.t, carolAlias, event.PeerAliasIn) require.Equal(ht, carolAlias, event.PeerAliasIn)
require.Equal(t.t, aliceAlias, event.PeerAliasOut) require.Equal(ht, aliceAlias, event.PeerAliasOut)
} }
// We expect Carol to have successful forwards and settles for // We expect Carol to have successful forwards and settles for
// her sends. // her sends.
assertHtlcEvents( ht.AssertHtlcEvents(
t, numPayments, 0, numPayments, routerrpc.HtlcEvent_SEND, carolEvents, numPayments, 0, numPayments,
carolEvents, routerrpc.HtlcEvent_SEND,
) )
// Dave and Alice should both have forwards and settles for // Dave and Alice should both have forwards and settles for
// their role as forwarding nodes. // their role as forwarding nodes.
assertHtlcEvents( ht.AssertHtlcEvents(
t, numPayments, 0, numPayments, routerrpc.HtlcEvent_FORWARD, daveEvents, numPayments, 0, numPayments,
daveEvents, routerrpc.HtlcEvent_FORWARD,
) )
assertHtlcEvents( ht.AssertHtlcEvents(
t, numPayments, 0, numPayments, routerrpc.HtlcEvent_FORWARD, aliceEvents, numPayments, 0, numPayments,
aliceEvents, routerrpc.HtlcEvent_FORWARD,
) )
// Bob should only have settle events for his receives. // Bob should only have settle events for his receives.
assertHtlcEvents( ht.AssertHtlcEvents(
t, 0, 0, numPayments, routerrpc.HtlcEvent_RECEIVE, bobEvents, bobEvents, 0, 0, numPayments, routerrpc.HtlcEvent_RECEIVE,
) )
closeChannelAndAssert(t, net, net.Alice, chanPointAlice, false) // Finally, close all channels.
closeChannelAndAssert(t, net, dave, chanPointDave, false) ht.CloseChannel(alice, chanPointAlice)
closeChannelAndAssert(t, net, carol, chanPointCarol, false) ht.CloseChannel(dave, chanPointDave)
ht.CloseChannel(carol, chanPointCarol)
} }
// assertHtlcEvents consumes events from a client and ensures that they are of // updateChannelPolicy updates the channel policy of node to the given fees and
// the expected type and contain the expected number of forwards, forward // timelock delta. This function blocks until listenerNode has received the
// failures and settles. // policy update.
func assertHtlcEvents(t *harnessTest, fwdCount, fwdFailCount, settleCount int, //
userType routerrpc.HtlcEvent_EventType, // NOTE: only used in current test.
client routerrpc.Router_SubscribeHtlcEventsClient) { func updateChannelPolicy(ht *lntemp.HarnessTest, hn *node.HarnessNode,
chanPoint *lnrpc.ChannelPoint, baseFee int64,
var forwards, forwardFails, settles, finalSettles, finalFails int feeRate int64, timeLockDelta uint32,
maxHtlc uint64, listenerNode *node.HarnessNode) {
var finalFailCount, finalSettleCount int
if userType != routerrpc.HtlcEvent_SEND {
finalFailCount = fwdFailCount
finalSettleCount = settleCount
}
numEvents := fwdCount + fwdFailCount + settleCount +
finalFailCount + finalSettleCount
for i := 0; i < numEvents; i++ {
event, err := client.Recv()
if err != nil {
t.Fatalf("could not get event")
}
expectedEventType := userType
switch e := event.Event.(type) {
case *routerrpc.HtlcEvent_ForwardEvent:
forwards++
case *routerrpc.HtlcEvent_ForwardFailEvent:
forwardFails++
case *routerrpc.HtlcEvent_SettleEvent:
settles++
case *routerrpc.HtlcEvent_FinalHtlcEvent:
if e.FinalHtlcEvent.Settled {
finalSettles++
} else {
finalFails++
}
expectedEventType = routerrpc.HtlcEvent_UNKNOWN
default:
t.Fatalf("unexpected event: %T", event.Event)
}
if event.EventType != expectedEventType {
t.Fatalf("expected: %v, got: %v", expectedEventType,
event.EventType)
}
}
if forwards != fwdCount {
t.Fatalf("expected: %v forwards, got: %v", fwdCount, forwards)
}
if forwardFails != fwdFailCount {
t.Fatalf("expected: %v forward fails, got: %v", fwdFailCount,
forwardFails)
}
if finalFails != finalFailCount {
t.Fatalf("expected: %v final fails, got: %v", finalFailCount,
finalFails)
}
if settles != settleCount {
t.Fatalf("expected: %v settles, got: %v", settleCount, settles)
}
if finalSettles != finalSettleCount {
t.Fatalf("expected: %v settles, got: %v", finalSettleCount,
finalSettles)
}
}
// assertEventAndType reads an event from the stream provided and ensures that
// it is associated with the correct user related type - a user initiated send,
// a receive to our node or a forward through our node. Note that this event
// type is different from the htlc event type (forward, link failure etc).
func assertEventAndType(t *harnessTest, eventType routerrpc.HtlcEvent_EventType,
client routerrpc.Router_SubscribeHtlcEventsClient) *routerrpc.HtlcEvent {
event, err := client.Recv()
if err != nil {
t.Fatalf("could not get event")
}
if event.EventType != eventType {
t.Fatalf("expected: %v, got: %v", eventType,
event.EventType)
}
return event
}
func assertSubscribed(t *harnessTest,
client routerrpc.Router_SubscribeHtlcEventsClient) {
event, err := client.Recv()
require.NoError(t.t, err)
require.NotNil(t.t, event.GetSubscribedEvent())
}
// updateChannelPolicy updates the channel policy of node to the
// given fees and timelock delta. This function blocks until
// listenerNode has received the policy update.
func updateChannelPolicy(t *harnessTest, node *lntest.HarnessNode,
chanPoint *lnrpc.ChannelPoint, baseFee int64, feeRate int64,
timeLockDelta uint32, maxHtlc uint64, listenerNode *lntest.HarnessNode) {
ctxb := context.Background()
expectedPolicy := &lnrpc.RoutingPolicy{ expectedPolicy := &lnrpc.RoutingPolicy{
FeeBaseMsat: baseFee, FeeBaseMsat: baseFee,
@ -475,14 +245,10 @@ func updateChannelPolicy(t *harnessTest, node *lntest.HarnessNode,
MaxHtlcMsat: maxHtlc, MaxHtlcMsat: maxHtlc,
} }
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) hn.RPC.UpdateChannelPolicy(updateFeeReq)
if _, err := node.UpdateChannelPolicy(ctxt, updateFeeReq); err != nil {
t.Fatalf("unable to update chan policy: %v", err)
}
// Wait for listener node to receive the channel update from node. // Wait for listener node to receive the channel update from node.
assertChannelPolicyUpdate( ht.AssertChannelPolicyUpdate(
t.t, listenerNode, node.PubKeyStr, listenerNode, hn, expectedPolicy, chanPoint, false,
expectedPolicy, chanPoint, false,
) )
} }

View file

@ -12,10 +12,6 @@ var allTestCases = []*testCase{
name: "single hop invoice", name: "single hop invoice",
test: testSingleHopInvoice, test: testSingleHopInvoice,
}, },
{
name: "multi-hop payments",
test: testMultiHopPayments,
},
{ {
name: "single-hop send to route", name: "single-hop send to route",
test: testSingleHopSendToRoute, test: testSingleHopSendToRoute,