Skip to content

itest: add BTC-only keysend and invoice payments #775

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

Merged
merged 2 commits into from
Jun 22, 2024
Merged
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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ require (
github.com/lightninglabs/loop/swapserverrpc v1.0.8
github.com/lightninglabs/pool v0.6.5-beta.0.20240604070222-e121aadb3289
github.com/lightninglabs/pool/auctioneerrpc v1.1.2
github.com/lightninglabs/taproot-assets v0.3.3-0.20240609154533-2b3c60ae77a9
github.com/lightningnetwork/lnd v0.18.0-beta.rc3.0.20240607141010-393d6829ca7d
github.com/lightninglabs/taproot-assets v0.3.3-0.20240621151738-7a0a009cea0b
github.com/lightningnetwork/lnd v0.18.0-beta.rc3.0.20240621142354-5fc4d4b1ec2b
github.com/lightningnetwork/lnd/cert v1.2.2
github.com/lightningnetwork/lnd/fn v1.0.8
github.com/lightningnetwork/lnd/kvdb v1.4.8
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1172,12 +1172,12 @@ github.com/lightninglabs/pool/auctioneerrpc v1.1.2 h1:Dbg+9Z9jXnhimR27EN37foc4aB
github.com/lightninglabs/pool/auctioneerrpc v1.1.2/go.mod h1:1wKDzN2zEP8srOi0B9iySlEsPdoPhw6oo3Vbm1v4Mhw=
github.com/lightninglabs/protobuf-go-hex-display v1.30.0-hex-display h1:pRdza2wleRN1L2fJXd6ZoQ9ZegVFTAb2bOQfruJPKcY=
github.com/lightninglabs/protobuf-go-hex-display v1.30.0-hex-display/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
github.com/lightninglabs/taproot-assets v0.3.3-0.20240609154533-2b3c60ae77a9 h1:A7GSIxahO2AaYnDaruiHh5kqmQ1ilEo2L76TGjU7B0o=
github.com/lightninglabs/taproot-assets v0.3.3-0.20240609154533-2b3c60ae77a9/go.mod h1:Km86kikQR/ZVPgK/bi9khZnt/FOoHEErx4itPiHi2i4=
github.com/lightninglabs/taproot-assets v0.3.3-0.20240621151738-7a0a009cea0b h1:VFDiq9WM8XuQ8/Q13gzvXE6MZ+bp4U3idTHCVFYG+YI=
github.com/lightninglabs/taproot-assets v0.3.3-0.20240621151738-7a0a009cea0b/go.mod h1:6pirBUx8UaalAug+XR2g+TsaivwT6+nVcQZwC571rl4=
github.com/lightningnetwork/lightning-onion v1.2.1-0.20230823005744-06182b1d7d2f h1:Pua7+5TcFEJXIIZ1I2YAUapmbcttmLj4TTi786bIi3s=
github.com/lightningnetwork/lightning-onion v1.2.1-0.20230823005744-06182b1d7d2f/go.mod h1:c0kvRShutpj3l6B9WtTsNTBUtjSmjZXbJd9ZBRQOSKI=
github.com/lightningnetwork/lnd v0.18.0-beta.rc3.0.20240607141010-393d6829ca7d h1:9tUVysV2TP6pAP4Mxcbm4TQwsMp6Vg6KiTG9ouSyACE=
github.com/lightningnetwork/lnd v0.18.0-beta.rc3.0.20240607141010-393d6829ca7d/go.mod h1:ZZ8c08GgxS6bbtPQv8hPZYB4m2SrhBQJa3N+JgnpR0o=
github.com/lightningnetwork/lnd v0.18.0-beta.rc3.0.20240621142354-5fc4d4b1ec2b h1:lXQjDLthlVKX2cR1cZzoRDhB/n1WsVm9FeiWv894d8U=
github.com/lightningnetwork/lnd v0.18.0-beta.rc3.0.20240621142354-5fc4d4b1ec2b/go.mod h1:ZZ8c08GgxS6bbtPQv8hPZYB4m2SrhBQJa3N+JgnpR0o=
github.com/lightningnetwork/lnd/cert v1.2.2 h1:71YK6hogeJtxSxw2teq3eGeuy4rHGKcFf0d0Uy4qBjI=
github.com/lightningnetwork/lnd/cert v1.2.2/go.mod h1:jQmFn/Ez4zhDgq2hnYSw8r35bqGVxViXhX6Cd7HXM6U=
github.com/lightningnetwork/lnd/clock v1.1.1 h1:OfR3/zcJd2RhH0RU+zX/77c0ZiOnIMsDIBjgjWdZgA0=
Expand Down
53 changes: 46 additions & 7 deletions itest/litd_custom_channels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ func testCustomChannels(_ context.Context, net *NetworkHarness,
// Test case 1: Send a direct keysend payment from Charlie to Dave.
// ------------
const keySendAmount = 100
sendKeySendPayment(t.t, charlie, dave, keySendAmount, assetID)
sendAssetKeySendPayment(t.t, charlie, dave, keySendAmount, assetID)
logBalance(t.t, nodes, assetID, "after keysend")

charlieAssetBalance -= keySendAmount
Expand All @@ -386,12 +386,16 @@ func testCustomChannels(_ context.Context, net *NetworkHarness,
// We should be able to send the 100 assets back immediately, because
// there is enough on-chain balance on Dave's side to be able to create
// an HTLC.
sendKeySendPayment(t.t, dave, charlie, keySendAmount, assetID)
sendAssetKeySendPayment(t.t, dave, charlie, keySendAmount, assetID)
logBalance(t.t, nodes, assetID, "after keysend back")

charlieAssetBalance += keySendAmount
daveAssetBalance -= keySendAmount

// We should also be able to do a non-asset (BTC only) keysend payment.
sendKeySendPayment(t.t, charlie, dave, 2000, nil)
logBalance(t.t, nodes, assetID, "after BTC only keysend")

// ------------
// Test case 2: Pay a normal invoice from Dave by Charlie, making it
// a direct channel invoice payment with no RFQ SCID present in the
Expand All @@ -405,6 +409,11 @@ func testCustomChannels(_ context.Context, net *NetworkHarness,
charlieAssetBalance -= paidAssetAmount
daveAssetBalance += paidAssetAmount

// We should also be able to do a multi-hop BTC only payment, paying an
// invoice from Erin by Charlie.
createAndPayNormalInvoiceWithBtc(t.t, charlie, erin, 2000)
logBalance(t.t, nodes, assetID, "after BTC only invoice")
Copy link
Member

Choose a reason for hiding this comment

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

does this also assert that the balance is as expected?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, but we do that later. That's just for visual confirmation. And currently we don't track and/or assert the BTC balance. But since we don't really change any logic in the BTC-only flow, just making sure the payment arrives should be enough.


// ------------
// Test case 3: Pay an asset invoice from Dave by Charlie, making it
// a direct channel invoice payment with an RFQ SCID present in the
Expand Down Expand Up @@ -861,7 +870,7 @@ func getAssetChannelBalance(t *testing.T, node *HarnessNode, assetID []byte,
return localSum, remoteSum
}

func sendKeySendPayment(t *testing.T, src, dst *HarnessNode, amt uint64,
func sendAssetKeySendPayment(t *testing.T, src, dst *HarnessNode, amt uint64,
assetID []byte) {

ctxb := context.Background()
Expand All @@ -886,9 +895,22 @@ func sendKeySendPayment(t *testing.T, src, dst *HarnessNode, amt uint64,
)
require.NoError(t, err)

const htlcCarrierAmt = 500
sendKeySendPayment(
t, src, dst, htlcCarrierAmt, encodeResp.CustomRecords,
)
}

func sendKeySendPayment(t *testing.T, src, dst *HarnessNode, amt btcutil.Amount,
firstHopCustomRecords map[uint64][]byte) {

ctxb := context.Background()
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
defer cancel()

// Read out the custom preimage for the keysend payment.
var preimage lntypes.Preimage
_, err = rand.Read(preimage[:])
_, err := rand.Read(preimage[:])
require.NoError(t, err)

hash := preimage.Hash()
Expand All @@ -898,12 +920,11 @@ func sendKeySendPayment(t *testing.T, src, dst *HarnessNode, amt uint64,
customRecords := make(map[uint64][]byte)
customRecords[record.KeySendType] = preimage[:]

const htlcCarrierAmt = 500
req := &routerrpc.SendPaymentRequest{
Dest: dst.PubKey[:],
Amt: htlcCarrierAmt,
Amt: int64(amt),
DestCustomRecords: customRecords,
FirstHopCustomRecords: encodeResp.CustomRecords,
FirstHopCustomRecords: firstHopCustomRecords,
PaymentHash: hash[:],
TimeoutSeconds: 3,
}
Expand All @@ -918,6 +939,24 @@ func sendKeySendPayment(t *testing.T, src, dst *HarnessNode, amt uint64,
require.Equal(t, lnrpc.Payment_SUCCEEDED, result.Status)
}

func createAndPayNormalInvoiceWithBtc(t *testing.T, src, dst *HarnessNode,
amountSat btcutil.Amount) {

ctxb := context.Background()
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
defer cancel()

expirySeconds := 10
invoiceResp, err := dst.AddInvoice(ctxt, &lnrpc.Invoice{
Value: int64(amountSat),
Memo: "normal invoice",
Expiry: int64(expirySeconds),
})
require.NoError(t, err)

payInvoiceWithSatoshi(t, src, invoiceResp)
}

func createAndPayNormalInvoice(t *testing.T, src, rfqPeer, dst *HarnessNode,
amountSat btcutil.Amount, assetID []byte) uint64 {

Expand Down
Loading