Skip to content

Multi rfq receive itest #1050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ require (
github.com/lightninglabs/pool v0.6.5-beta.0.20250305125211-4e860ec4e77f
github.com/lightninglabs/pool/auctioneerrpc v1.1.3-0.20250305125211-4e860ec4e77f
github.com/lightninglabs/pool/poolrpc v1.0.1-0.20250305125211-4e860ec4e77f
github.com/lightninglabs/taproot-assets v0.5.2-0.20250508000445-bb5a2a6f154a
github.com/lightninglabs/taproot-assets v0.6.0-rc1.0.20250509145623-77dd73f686e5
github.com/lightninglabs/taproot-assets/taprpc v1.0.2
github.com/lightningnetwork/lnd v0.19.0-beta.rc3
github.com/lightningnetwork/lnd/cert v1.2.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,8 @@ github.com/lightninglabs/pool/poolrpc v1.0.1-0.20250305125211-4e860ec4e77f h1:5p
github.com/lightninglabs/pool/poolrpc v1.0.1-0.20250305125211-4e860ec4e77f/go.mod h1:lGs2hSVZ+GFpdv3btaIl9icG5/gz7BBRfvmD2iqqNl0=
github.com/lightninglabs/protobuf-go-hex-display v1.34.2-hex-display h1:w7FM5LH9Z6CpKxl13mS48idsu6F+cEZf0lkyiV+Dq9g=
github.com/lightninglabs/protobuf-go-hex-display v1.34.2-hex-display/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
github.com/lightninglabs/taproot-assets v0.5.2-0.20250508000445-bb5a2a6f154a h1:Jd2ned2248idCMgHirLYOtgJQp54GSNMFfOPH8bVSj0=
github.com/lightninglabs/taproot-assets v0.5.2-0.20250508000445-bb5a2a6f154a/go.mod h1:OdeFcj2bnJf6aaYjBB5c8KdNI3aDaEMQpsSu2EqvMlw=
github.com/lightninglabs/taproot-assets v0.6.0-rc1.0.20250509145623-77dd73f686e5 h1:LlPi9n8XGbFCSSbUrA4Q3TzSiMFn6YmiQOqwKHQjn18=
github.com/lightninglabs/taproot-assets v0.6.0-rc1.0.20250509145623-77dd73f686e5/go.mod h1:OdeFcj2bnJf6aaYjBB5c8KdNI3aDaEMQpsSu2EqvMlw=
github.com/lightninglabs/taproot-assets/taprpc v1.0.2 h1:LcK62+X7UYGFEwUgGwnKXLdoTOsBPFc6FOYXm7jiFFU=
github.com/lightninglabs/taproot-assets/taprpc v1.0.2/go.mod h1:Ccq0t2GsXzOtC8qF0U1ux/yTF5HcBbVrhCb0tb/jObM=
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb h1:yfM05S8DXKhuCBp5qSMZdtSwvJ+GFzl94KbXMNB1JDY=
Expand Down
287 changes: 267 additions & 20 deletions itest/assets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
"github.com/lightningnetwork/lnd/lntest"
"github.com/lightningnetwork/lnd/lntest/rpc"
"github.com/lightningnetwork/lnd/lntest/wait"
"github.com/lightningnetwork/lnd/lntypes"
Expand Down Expand Up @@ -66,6 +67,242 @@ var (
failureNone = lnrpc.PaymentFailureReason_FAILURE_REASON_NONE
)

// createTestMultiRFQAssetNetwork creates a lightning network topology which
// consists of both bitcoin and asset channels. It focuses on the property of
// having multiple channels available on both the sender and receiver side.
//
// The topology we are going for looks like the following:
//
// /---[sats]--> Erin --[assets]--\
// / \
// / \
//
// Charlie -----[sats]--> Dave --[assets]---->Fabia
//
// \ /
// \ /
// \---[sats]--> Yara --[assets]--/
func createTestMultiRFQAssetNetwork(t *harnessTest, net *NetworkHarness,
charlie, dave, erin, fabia, yara *HarnessNode, charlieTap, daveTap,
erinTap, fabiaTap, yaraTap, universeTap *tapClient,
mintedAsset *taprpc.Asset, assetSendAmount, fundingAmount uint64,
pushSat int64) (*lnrpc.ChannelPoint, *lnrpc.ChannelPoint,
*lnrpc.ChannelPoint) {
Comment on lines +86 to +90
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a lot of arguments. how about using this sort of helper structs to clean this up:

	type nodeComponents struct {
		Lnd *HarnessNode
		Tapd: *tapClient
	}

	type testFramework struct {
		charlie nodeComponents
		dave nodeComponents
		erin nodeComponents
		fabia nodeComponents
		yara nodeComponents

		universeTap *tapClient
	}

and then the rest of the args


// Let's open the normal sats channels between Charlie and the routing
// peers.
_ = openChannelAndAssert(
t, net, charlie, erin, lntest.OpenChannelParams{
Amt: 10_000_000,
SatPerVByte: 5,
},
)

_ = openChannelAndAssert(
t, net, charlie, dave, lntest.OpenChannelParams{
Amt: 10_000_000,
SatPerVByte: 5,
},
)

_ = openChannelAndAssert(
t, net, charlie, yara, lntest.OpenChannelParams{
Amt: 10_000_000,
SatPerVByte: 5,
},
)

ctxb := context.Background()
assetID := mintedAsset.AssetGenesis.AssetId
var groupKey []byte
if mintedAsset.AssetGroup != nil {
groupKey = mintedAsset.AssetGroup.TweakedGroupKey
}

fundingScriptTree := tapscript.NewChannelFundingScriptTree()
fundingScriptKey := fundingScriptTree.TaprootKey
fundingScriptTreeBytes := fundingScriptKey.SerializeCompressed()

// We need to send some assets to Dave, so he can fund an asset channel
// with Fabia.
daveAddr, err := daveTap.NewAddr(ctxb, &taprpc.NewAddrRequest{
Amt: assetSendAmount,
AssetId: assetID,
ProofCourierAddr: fmt.Sprintf(
"%s://%s", proof.UniverseRpcCourierType,
charlieTap.node.Cfg.LitAddr(),
),
})
require.NoError(t.t, err)

t.Logf("Sending %v asset units to Dave...", assetSendAmount)

// Send the assets to Dave.
itest.AssertAddrCreated(t.t, daveTap, mintedAsset, daveAddr)
sendResp, err := charlieTap.SendAsset(ctxb, &taprpc.SendAssetRequest{
TapAddrs: []string{daveAddr.Encoded},
})
require.NoError(t.t, err)
itest.ConfirmAndAssertOutboundTransfer(
t.t, t.lndHarness.Miner.Client, charlieTap, sendResp, assetID,
[]uint64{mintedAsset.Amount - assetSendAmount, assetSendAmount},
0, 1,
)
itest.AssertNonInteractiveRecvComplete(t.t, daveTap, 1)

// We need to send some assets to Erin, so he can fund an asset channel
// with Fabia.
erinAddr, err := erinTap.NewAddr(ctxb, &taprpc.NewAddrRequest{
Amt: assetSendAmount,
AssetId: assetID,
ProofCourierAddr: fmt.Sprintf(
"%s://%s", proof.UniverseRpcCourierType,
charlieTap.node.Cfg.LitAddr(),
),
})
require.NoError(t.t, err)

t.Logf("Sending %v asset units to Erin...", assetSendAmount)

// Send the assets to Erin.
itest.AssertAddrCreated(t.t, erinTap, mintedAsset, erinAddr)
sendResp, err = charlieTap.SendAsset(ctxb, &taprpc.SendAssetRequest{
TapAddrs: []string{erinAddr.Encoded},
})
require.NoError(t.t, err)
itest.ConfirmAndAssertOutboundTransfer(
t.t, t.lndHarness.Miner.Client, charlieTap, sendResp, assetID,
[]uint64{
mintedAsset.Amount - 2*assetSendAmount, assetSendAmount,
}, 1, 2,
)
itest.AssertNonInteractiveRecvComplete(t.t, erinTap, 1)

// We need to send some assets to Yara, so he can fund an asset channel
// with Fabia.
yaraAddr, err := yaraTap.NewAddr(ctxb, &taprpc.NewAddrRequest{
Amt: assetSendAmount,
AssetId: assetID,
ProofCourierAddr: fmt.Sprintf(
"%s://%s", proof.UniverseRpcCourierType,
charlieTap.node.Cfg.LitAddr(),
),
})
require.NoError(t.t, err)

t.Logf("Sending %v asset units to Yara...", assetSendAmount)

// Send the assets to Yara.
itest.AssertAddrCreated(t.t, yaraTap, mintedAsset, yaraAddr)
sendResp, err = charlieTap.SendAsset(ctxb, &taprpc.SendAssetRequest{
TapAddrs: []string{yaraAddr.Encoded},
})
require.NoError(t.t, err)
itest.ConfirmAndAssertOutboundTransfer(
t.t, t.lndHarness.Miner.Client, charlieTap, sendResp, assetID,
[]uint64{
mintedAsset.Amount - 3*assetSendAmount, assetSendAmount,
}, 2, 3,
)
itest.AssertNonInteractiveRecvComplete(t.t, yaraTap, 1)

// We fund the Dave->Fabia channel.
fundRespDF, err := daveTap.FundChannel(
ctxb, &tchrpc.FundChannelRequest{
AssetAmount: fundingAmount,
AssetId: assetID,
PeerPubkey: fabiaTap.node.PubKey[:],
FeeRateSatPerVbyte: 5,
PushSat: pushSat,
},
)
require.NoError(t.t, err)
t.Logf("Funded channel between Dave and Fabia: %v", fundRespDF)

// We fund the Erin->Fabia channel.
fundRespEF, err := erinTap.FundChannel(
ctxb, &tchrpc.FundChannelRequest{
AssetAmount: fundingAmount,
AssetId: assetID,
PeerPubkey: fabiaTap.node.PubKey[:],
FeeRateSatPerVbyte: 5,
PushSat: pushSat,
},
)
require.NoError(t.t, err)
t.Logf("Funded channel between Erin and Fabia: %v", fundRespEF)

// We fund the Yara->Fabia channel.
fundRespYF, err := yaraTap.FundChannel(
ctxb, &tchrpc.FundChannelRequest{
AssetAmount: fundingAmount,
AssetId: assetID,
PeerPubkey: fabiaTap.node.PubKey[:],
FeeRateSatPerVbyte: 5,
PushSat: pushSat,
},
)
require.NoError(t.t, err)
t.Logf("Funded channel between Yara and Fabia: %v", fundRespYF)

// Make sure the pending channel shows up in the list and has the
// custom records set as JSON.
assertPendingChannels(
t.t, daveTap.node, mintedAsset, 1, fundingAmount, 0,
)
assertPendingChannels(
t.t, erinTap.node, mintedAsset, 1, fundingAmount, 0,
)
assertPendingChannels(
t.t, yaraTap.node, mintedAsset, 1, fundingAmount, 0,
)

// Now that we've looked at the pending channels, let's actually confirm
// all three of them.
mineBlocks(t, net, 6, 3)

// We'll be tracking the expected asset balances throughout the test, so
// we can assert it after each action.
charlieAssetBalance := mintedAsset.Amount - 3*assetSendAmount
daveAssetBalance := assetSendAmount - fundingAmount
erinAssetBalance := assetSendAmount - fundingAmount
yaraAssetBalance := assetSendAmount - fundingAmount

itest.AssertBalances(
t.t, charlieTap, charlieAssetBalance,
itest.WithAssetID(assetID), itest.WithNumUtxos(1),
)

itest.AssertBalances(
t.t, daveTap, daveAssetBalance, itest.WithAssetID(assetID),
)

itest.AssertBalances(
t.t, erinTap, erinAssetBalance, itest.WithAssetID(assetID),
)

itest.AssertBalances(
t.t, yaraTap, yaraAssetBalance, itest.WithAssetID(assetID),
)

// Assert that the proofs for both channels has been uploaded to the
// designated Universe server.
assertUniverseProofExists(
t.t, universeTap, assetID, groupKey, fundingScriptTreeBytes,
fmt.Sprintf("%v:%v", fundRespDF.Txid, fundRespDF.OutputIndex),
)
assertUniverseProofExists(
t.t, universeTap, assetID, groupKey, fundingScriptTreeBytes,
fmt.Sprintf("%v:%v", fundRespEF.Txid, fundRespEF.OutputIndex),
)
assertUniverseProofExists(
t.t, universeTap, assetID, groupKey, fundingScriptTreeBytes,
fmt.Sprintf("%v:%v", fundRespYF.Txid, fundRespYF.OutputIndex),
)

return nil, nil, nil
}

// createTestAssetNetwork sends asset funds from Charlie to Dave and Erin, so
// they can fund asset channels with Yara and Fabia, respectively. So the asset
// channels created are Charlie->Dave, Dave->Yara, Erin->Fabia. The channels
Expand Down Expand Up @@ -1100,7 +1337,7 @@ func sendKeySendPayment(t *testing.T, src, dst *HarnessNode,
stream, err := src.RouterClient.SendPaymentV2(ctxt, req)
require.NoError(t, err)

result, err := getFinalPaymentResult(stream)
result, err := getPaymentResult(stream, false)
require.NoError(t, err)
require.Equal(t, lnrpc.Payment_SUCCEEDED, result.Status)
}
Expand Down Expand Up @@ -1160,13 +1397,20 @@ func payPayReqWithSatoshi(t *testing.T, payer *HarnessNode, payReq string,
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
defer cancel()

shardSize := uint64(0)

if cfg.smallShards {
shardSize = 80_000_000
}

sendReq := &routerrpc.SendPaymentRequest{
PaymentRequest: payReq,
TimeoutSeconds: int32(PaymentTimeout.Seconds()),
FeeLimitMsat: 1_000_000,
MaxParts: cfg.maxShards,
OutgoingChanIds: cfg.outgoingChanIDs,
AllowSelfPayment: cfg.allowSelfPayment,
MaxShardSizeMsat: shardSize,
}

if cfg.smallShards {
Expand All @@ -1176,17 +1420,9 @@ func payPayReqWithSatoshi(t *testing.T, payer *HarnessNode, payReq string,
stream, err := payer.RouterClient.SendPaymentV2(ctxt, sendReq)
require.NoError(t, err)

if cfg.payStatus == lnrpc.Payment_IN_FLIGHT {
t.Logf("Waiting for initial stream response...")
result, err := stream.Recv()
require.NoError(t, err)

require.Equal(t, cfg.payStatus, result.Status)

return
}

result, err := getFinalPaymentResult(stream)
result, err := getPaymentResult(
stream, cfg.payStatus == lnrpc.Payment_IN_FLIGHT,
)
if cfg.errSubStr != "" {
require.ErrorContains(t, err, cfg.errSubStr)
} else {
Expand Down Expand Up @@ -1496,16 +1732,21 @@ func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,

timeoutSeconds := int64(rfq.DefaultInvoiceExpiry.Seconds())

t.Logf("Asking peer %x for quote to buy assets to receive for "+
"invoice over %d units; waiting up to %ds",
dstRfqPeer.PubKey[:], assetAmount, timeoutSeconds)
var peerPubKey []byte
if dstRfqPeer != nil {
peerPubKey = dstRfqPeer.PubKey[:]

t.Logf("Asking peer %x for quote to buy assets to receive for "+
"invoice over %d units; waiting up to %ds",
dstRfqPeer.PubKey[:], assetAmount, timeoutSeconds)
}

dstTapd := newTapClient(t, dst)

request := &tchrpc.AddInvoiceRequest{
GroupKey: cfg.groupKey,
AssetAmount: assetAmount,
PeerPubkey: dstRfqPeer.PubKey[:],
PeerPubkey: peerPubKey,
InvoiceRequest: &lnrpc.Invoice{
Memo: fmt.Sprintf("this is an asset invoice for "+
"%d units", assetAmount),
Expand Down Expand Up @@ -1560,7 +1801,7 @@ func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,

t.Logf("Got quote for %d mSats at %3f msat/unit from peer %x with "+
"SCID %d", decodedInvoice.NumMsat, mSatPerUnit,
dstRfqPeer.PubKey[:], resp.AcceptedBuyQuote.Scid)
resp.AcceptedBuyQuote.Peer, resp.AcceptedBuyQuote.Scid)

return resp.InvoiceResult
}
Expand Down Expand Up @@ -1694,9 +1935,15 @@ func createAssetHodlInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,

timeoutSeconds := int64(rfq.DefaultInvoiceExpiry.Seconds())

var rfqPeer []byte

if dstRfqPeer != nil {
rfqPeer = dstRfqPeer.PubKey[:]
}

t.Logf("Asking peer %x for quote to buy assets to receive for "+
"invoice for %d units; waiting up to %ds",
dstRfqPeer.PubKey[:], assetAmount, timeoutSeconds)
rfqPeer, assetAmount, timeoutSeconds)

dstTapd := newTapClient(t, dst)

Expand All @@ -1709,7 +1956,7 @@ func createAssetHodlInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
payHash := preimage.Hash()
request := &tchrpc.AddInvoiceRequest{
AssetAmount: assetAmount,
PeerPubkey: dstRfqPeer.PubKey[:],
PeerPubkey: rfqPeer,
InvoiceRequest: &lnrpc.Invoice{
Memo: fmt.Sprintf("this is an asset invoice for "+
"%d units", assetAmount),
Expand Down Expand Up @@ -1747,7 +1994,7 @@ func createAssetHodlInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
require.EqualValues(t, uint64(numMSats), uint64(decodedInvoice.NumMsat))

t.Logf("Got quote for %d msat at %v msat/unit from peer %x with SCID "+
"%d", decodedInvoice.NumMsat, mSatPerUnit, dstRfqPeer.PubKey[:],
"%d", decodedInvoice.NumMsat, mSatPerUnit, rfqPeer,
resp.AcceptedBuyQuote.Scid)

return assetHodlInvoice{
Expand Down
Loading
Loading